EMA strategy 3 candles

Viewing 8 posts - 1 through 8 (of 8 total)
  • Author
    Posts
  • #233712 quote
    Aragorna
    Participant
    Junior

    Hello,

     

    I would like to ask a strategy that works this way:

    EMA50<EMA100<EMA200  and with a distance between them that can be defined

    buy if close crosses over ema 200 and the close of three candle before is lower than EMA50 (so price needs to crosse the three EMA in not more than 3 candles)

    the opposite for short.

    thank’s in advance

     

    Alessio

    #233713 quote
    Aragorna
    Participant
    Junior

    I did something like this but it opens also position when it shouldn’t.

     

    DEFPARAM CumulateOrders = false
    Ema50= ExponentialAverage[50](close)
    ema100= ExponentialAverage[100](close)
    Ema200= ExponentialAverage[200](close)
    c1= close crosses under ema200 and close[barindex-3]>=ema50
    c2= close crosses over ema200 and close[barindex-3]<=ema50
    c3=ema50>ema100
    c4=ema100>ema200
    c5=ema50<ema100
    c6=ema100<ema200
    
    If not longonmarket and c2 and c5 and c6  then
    Buy 1 contract at Market
    endif
    If longOnMarket AND (BarIndex - TradeIndex) >= 4 Then
    Sell at Market
    Endif
    If not shortonmarket and c1 and c3 and c4 then
    sellshort 1 contract at Market
    endif
    If shortOnMarket AND (BarIndex - TradeIndex) >= 4 Then
    exitshort at Market
    Endif
    

    exit is just to try, nothing defined

    #233718 quote
    JS
    Participant
    Senior

    Hi,

    Try using Close[3] instead of Close[BarIndex-3]…

    Iván González thanked this post
    #233720 quote
    Iván González
    Moderator
    Master

    Hi
    You have to change c1 and c2:

    c1= close crosses under ema200 and close[3]>=ema50
    c2= close crosses over ema200 and close[3]<=ema50
    #233721 quote
    Iván González
    Moderator
    Master

    I didn’t see your answer…
    As Roberto says, better 2 than… 🙂

    JS and robertogozzi thanked this post
    #233772 quote
    Aragorna
    Participant
    Junior

    Thank you very much Ivan, 2 is better than one, of course! by the way I don’t understand why close[barindex3]  was not correct.

    thanks

    Alessio

    #233778 quote
    Iván González
    Moderator
    Master

    Hi,

    Maybe you should check the Probuilder’s manual or at least here https://www.prorealcode.com/documentation/close/

    I think doing that will clarify your doubts.

    #233794 quote
    GraHal
    Participant
    Master

    why close[barindex–3]  was not correct.

    barindex increases by 1 for every new candle and so if your Algo has been running for 600 candles then you would have close[barindex–3] = close[597]

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

EMA strategy 3 candles


ProOrder: Automated Strategies & Backtesting

New Reply
Author
author-avatar
Aragorna @aragorna Participant
Summary

This topic contains 7 replies,
has 4 voices, and was last updated by GraHal
1 year, 9 months ago.

Topic Details
Forum: ProOrder: Automated Strategies & Backtesting
Language: English
Started: 06/10/2024
Status: Active
Attachments: No files
Logo Logo
Loading...