coding a variable stopplacement

Viewing 3 posts - 1 through 3 (of 3 total)
  • Author
    Posts
  • #185274 quote
    Jaldidee
    Participant
    Average

    Hello everybody,

     

    Hope someone can help me.

    I am trying to code a stopplacement depending on the position of the close to the EMA20, ema50 and ema 100.

    The idea is simple. If the close is above the ema 20 and the distance to the ema20 is greater then 6 the stop is placed at the ema20.

    If the distance is smaller then 6 or the close is smaller then the ema20 and the the distance to the ema50 is greater then 6 the stop is placed at the ema50. and so on…

    I wrote the following code, but clearly i have made a mistake, cause it doen not influence the outcome.

    If close[0] > EMA20 AND (close[0] - EMA20) > 6 then 
    mystoplong = ema20[2]
    ELSIF close[0] > ema20 and (close[0] - ema20) =< 6 then 
    mystoplong = EMA50[2] 
    ELSIF close[0] > ema50 AND close[0] < EMA20 and (close[0] - ema50) > 6 then
    mystoplong =EMA50[2]
    ELSIF close[0] > ema50 AND close[0] < EMA20 and (close[0] - ema50) =< 6 then 
    mystoplong = EMA100[2] 
    endif

    Hope someone can tell me what i did wrong 🙂

    Kind regards,

    Jaldidee

    #185275 quote
    PeterSt
    Participant
    Master

    Hi Jalidee,

    Put this on top of the code you just showed (thus after the EMA20 is known) :

    Graph (close[0] - EMA20)

    and you will see what’s the culprit …

    #185283 quote
    robertogozzi
    Moderator
    Master

    In line 1 you use EMA20 in the expression, while in line 2 you use EMA20[2], which is the value retained two bars prior to the current one.
    I think this is the culprit.
    Try removing [2].

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

coding a variable stopplacement


ProOrder: Automated Strategies & Backtesting

New Reply
Author
author-avatar
Jaldidee @jaldidee Participant
Summary

This topic contains 2 replies,
has 3 voices, and was last updated by robertogozzi
4 years, 1 month ago.

Topic Details
Forum: ProOrder: Automated Strategies & Backtesting
Language: English
Started: 01/12/2022
Status: Active
Attachments: No files
Logo Logo
Loading...