Add item in list where place?

26 views
Skip to first unread message

stefano cerbioni

unread,
Aug 2, 2022, 11:35:59 AM8/2/22
to The Ring Programming Language
hi i have create a list  , after  i  add a item inside list  but  if  i call a top or bottom , return always  0  why  ? O_o

func EMA(aPrice,periodEma) {
SMA1=0
decimals(8)
v=(len(aPrice)-periodEma)
EMAt=list(v)
SF = 2/(periodEma + 1)
if len(aPrice) <= periodEma
return 0
else
for i=1 to periodEma
//?aPrice[i][1]
SMA1 +=aPrice[i][1]
next
SMA1=SMA1/periodEma
for j=periodEma to len(aPrice)
if j=periodEma
EMAi=SMA1+SF*(aPrice[j][1]-SMA1)
Add(EMAt,EMAi)
?EMAt[v]
?EMAt[1]
else
?V
?EMAt[v]
EMAi=EMAt[v]+SF*(aPrice[j][1]-EMAt[v])
?EMAi
MsgInfo("","dentro")
Add(EMAt,EMAi)
v--
ok
next
?EMAt
?"emat"
ok



}

Ilir

unread,
Aug 2, 2022, 12:56:56 PM8/2/22
to The Ring Programming Language
Hello Stefano,

as Bert noticed, your posts are next to impossible to follow. Please use indentation
Send your input data in shortest form. That is: minimal reproducible sample.

You are getting zero because you are returning nothing but zero.

aList = [[1],[2],[3],[4],[5]]
? EMA(aList,3)


func EMA(aPrice,periodEma) {
    SMA1=0
    decimals(8)
    v=(len(aPrice)-periodEma)
    EMAt=list(v)
    SF = 2/(periodEma + 1)
    if len(aPrice) <= periodEma
        return 0
    else
        for i=1 to periodEma
//            ?aPrice[i][1]
            SMA1 += aPrice[i][1]

        next
        SMA1=SMA1/periodEma
        for j=periodEma to len(aPrice)
            if j=periodEma
                EMAi=SMA1+SF*(aPrice[j][1]-SMA1)
                Add(EMAt,EMAi)
//                ?EMAt[v]
//                ?EMAt[1]
            else
//                ?V
//                ?EMAt[v]

                EMAi=EMAt[v]+SF*(aPrice[j][1]-EMAt[v])
//                ?EMAi
//                MsgInfo("","dentro")
                Add(EMAt,EMAi)
                v--
            ok
        next
//        ?EMAt
//        ?"emat"
    ok

Mansour Ayouni

unread,
Aug 2, 2022, 1:33:52 PM8/2/22
to Ilir, The Ring Programming Language
Hello Stefano,

Please take it as a friendly advice and never like a position to disencourage you from posting your questions here in the forum.

As Ring members, we always feel happy when a new friend joins. And especially when he is active and posts questions and shares experiences.

We enjoy helping each other and that's nice. But people who would help us are not supposed to work, at our place, in developing parts of our software. I'm sure you understand that their time is limited and that we should help them so they can help us.

The point is that your enquiries lack a little effort to make them minimal, clear and concise.
Also, what I observed is that you commit the same errors many times again.

My suggestion to you is to take time to learn the foundations of the languages, play with the samples we have in the documentation and in the language codebase.

Learning these techniques takes time but it is a rewarding investment.

Sincerely,
Mansour.

--

---
You received this message because you are subscribed to the Google Groups "The Ring Programming Language" group.
To unsubscribe from this group and stop receiving emails from it, send an email to ring-lang+...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/ring-lang/53259815-2b4f-40f8-9ed1-e23ab1d3070an%40googlegroups.com.

stefano cerbioni

unread,
Aug 2, 2022, 2:49:38 PM8/2/22
to Mansour Ayouni, Ilir, The Ring Programming Language
Hi Mansour Ayouni you said here in the forum., this is a mailing
list not a forum , if maybe it was a forum :D i could research much
better old question ....i forgot also my comment is a friendly , i
ask also frequently because i find some bug and some time i dont know
if a bug or my mistake (of course often ...much often is my
mistake ). if we had a forum it would be possible when you copy and
paste in the code hastag to have automatic formatting which I don't
have on google , and ofcourse sorry if you or other you have
interpretated my questions like request of spoon feed , i dont wanna
it therfore i ask excuse at you and all community if in past my
questions they might seems, sorry if commit the same errors many
times again, unfortunately i am old , and i have ADHD and often is
difficult study for me , therefore i prefer exercise but dont
worry , this is not excuse , i follow your suggest ,and rightnow i
want follow your suggest "The point is that your enquiries lack a
little effort to make them minimal, clear and concise..", in my code
in line 144 i add at list one value ,but if i print last or first
value return 0 , if i call all list ?EMAt return value , also after i
comment in line 133 //return 0 , like suggest Ilir, the result is
the same i want understund if is a bug of language or simply my code
is wrong ,if my code is wrong dont want a solution thanks , i attach
a code runnable and tidy

thanks again for suggest
Sincerely,
Stefano
>> <https://groups.google.com/d/msgid/ring-lang/53259815-2b4f-40f8-9ed1-e23ab1d3070an%40googlegroups.com?utm_medium=email&utm_source=footer>
>> .
>>
>
> --
>
> ---
> You received this message because you are subscribed to the Google Groups
> "The Ring Programming Language" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to ring-lang+...@googlegroups.com.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/ring-lang/CAFdCj1AHWng9hFxMzT%3Dgwwtdn%3DKxxW%2BiRMTUVt8ro%3DWtP6HGQg%40mail.gmail.com.
>
boiade.ring

Ilir

unread,
Aug 2, 2022, 3:23:34 PM8/2/22
to The Ring Programming Language
Hello Stefano,

use web interface


or change your email client if it lacks formatting.

Mistake you are making: creating a list of the v elements where each element is set to zero.
Then you are adding values to this list, but always printing first (zero value) and last element (zero value) of the initial length (index v).

Here is the fix, update the code so that index increases instead of calling len to get index of the last element.

        for j=periodEma to len(aPrice)      
            if j=periodEma
                EMAi=SMA1+SF*(aPrice[j]-SMA1)
                ?EMAi
                Add(EMAt,EMAi)
                ?"-----"
                ?EMAt[len(EMAt)]
                ?"-----"
                ?EMAt[1]
                ?"-----"
                ?EMAt
                ?"-----"
            else
                EMAi=EMAt[len(EMAt)]+SF*(aPrice[j]-EMAt[len(EMAt)])

                ?EMAi
                 MsgInfo("","dentro")
                Add(EMAt,EMAi)
                ?EMAt[len(EMAt)]
        v
            ok
        next

Ilir

unread,
Aug 2, 2022, 3:24:59 PM8/2/22
to The Ring Programming Language
Hello,

I forgot, EMAt must be initialized as emtpy list, e.g.

    EMAt=[]

Reply all
Reply to author
Forward
0 new messages