How to translate the metastock code to prorealcode (indicator RS EMA)?

Viewing 9 posts - 1 through 9 (of 9 total)
  • Author
    Posts
  • #183798 quote
    thomas2004ch
    Participant
    Average

    Hi,

    From the article “Relative Strength Moving Averages ” in the latest issue of Stocks & Commodities Jan 2022 there is an interessting indicator called RS EMA. But it is written in METASTOCK code and look as follow:

    Periods:=50;
    Pds:=50;
    Mltp:=10;
    Mltp1:=2/(Periods+1);
    Cup:=If(C>Ref(C,-1),C-Ref(C,-1),0);
    Cdwn:=If(C<Ref(C,-1),Ref(C,-1)-C,0);
    RS:=Abs(Mov(CUP,Pds,E)-Mov(Cdwn,Pds,E))/(Mov(CUP,Pds,E)+Mov(Cdwn,Pds,E)+0.00001);
    RS:=RS*Mltp;
    Rate:=Mltp1*(1+RS);
    
    If(Cum(1)=Periods+1,C,PREV+Rate*(C-PREV));

    It said this in RS EMA has less lags than the normal EMA (see attached png).

    I have problem to translate the last line (line 11) to prorealcode. It seems a recusive. Can someone help?

    RS_EMA.png RS_EMA.png
    #183815 quote
    thomas2004ch
    Participant
    Average

    Here is my code:

    // From S&C Jan. 2022 "Relative Strength Moving Averages" - Vitali Apirine
    
    Periods = 50
    Pds = 50
    Mltp = 10
    
    Mltp1 = 2/(Periods+1)
    
    if close >close[1] then
    Cup = close - close[1]
    else
    Cup = 0
    endif
    
    if close < close[1] then
    Cdwn = close[1] - close
    else
    Cdwn = 0
    endif
    
    EMAup = ExponentialAverage[Pds](Cup)
    EMAdwn = ExponentialAverage[Pds](Cdwn)
    
    RS1 = abs((EMAup - EMAdwn)/(EMAup + EMAdwn + 0.00001))
    RS = RS1 * Mltp
    
    Rate = Mltp1 * (1 + RS)
    
    RETURN ???
    
    #183817 quote
    robertogozzi
    Moderator
    Master

    This should be complete:

    // From S&C Jan. 2022 "Relative Strength Moving Averages" - Vitali Apirine
    Periods = 50
    Pds = 50
    Mltp = 10
    Mltp1 = 2/(Periods+1)
    if close >close[1] then
       Cup = close - close[1]
    else
       Cup = 0
    endif
    if close < close[1] then
       Cdwn = close[1] - close
    else
       Cdwn = 0
    endif
    EMAup  = ExponentialAverage[Pds](Cup)
    EMAdwn = ExponentialAverage[Pds](Cdwn)
    RS1 = abs((EMAup - EMAdwn)/(EMAup + EMAdwn + 0.00001))
    RS = RS1 * Mltp
    Rate = Mltp1 * (1 + RS)
    IF BarIndex <= (Periods + 1) THEN
       ReturnedDatum = close
    ELSE
       ReturnedDatum = ReturnedDatum[1] + Rate * (close - ReturnedDatum[1])
    ENDIF
    RETURN ReturnDatum AS "RS Moving Average"
    denmar thanked this post
    x-7.jpg x-7.jpg
    #183846 quote
    supertiti
    Participant
    Master

    it s better like that

    RETURN ReturnedDatum AS “RS Moving Average”
    robertogozzi thanked this post
    #184337 quote
    Choliver
    Participant
    Veteran

    Hi,

    Happy new Year 2022.

    Sorry but for me i have this result.
    What can i do ?
    Thanks.

    RS-EMA.png RS-EMA.png
    #184344 quote
    robertogozzi
    Moderator
    Master

    It was written incorrectly, this is the correct line:

    RETURN ReturnedDatum AS “RS Moving Average”
    #184375 quote
    Choliver
    Participant
    Veteran

    Hi Roberto,
    It’s what i wrote line 26 on my picture.
    But not ok finally. Any solution ? 😉

    #184382 quote
    JC_Bywan
    Moderator
    Master

    Hi Choliver, you forgot one d when applying your correction in your line 26, this one in red: returnedDatum

    robertogozzi thanked this post
    #184398 quote
    Choliver
    Participant
    Veteran

    Hello you 2,

    I’m really sorry.
    I am ashamed.
    Thank you for the indication. 🙂
    It’s ok now
    Great day.

Viewing 9 posts - 1 through 9 (of 9 total)
  • You must be logged in to reply to this topic.

How to translate the metastock code to prorealcode (indicator RS EMA)?


ProBuilder: Indicators & Custom Tools

New Reply
Author
Summary

This topic contains 8 replies,
has 5 voices, and was last updated by Choliver
4 years, 1 month ago.

Topic Details
Forum: ProBuilder: Indicators & Custom Tools
Language: English
Started: 12/23/2021
Status: Active
Attachments: 3 files
Logo Logo
Loading...