Pips condition above or below EMA to trigger an order

Viewing 8 posts - 1 through 8 (of 8 total)
  • Author
    Posts
  • #81668 quote
    Wolf Trades
    Participant
    Average

    Hi,

    my expert has 2 EMA: 36 and 12.

    When  12EMA cross over or under 36EMA and price go away from 36 about X=number of pips and then return and touch 12EMA:

    Open long if 12 EMA cross over 36 EMA and price go away X numeber of pips.

    Open short if 12 EMA cross under 36 EMA and price go away X numeber of pips.

    Could you write me how can I code that price have to go away for example 30 pips from EMA 36???

    Thanks

    #81727 quote
    Nicolas
    Keymaster
    Master

    The below code should trigger the orders as per your description.

    defparam cumulateorders=false
    
    fast = average[12,1]
    slow = average[36,1]
    distance = 30
    
    if (fast>slow and high crosses over level) or (fast<slow and low crosses under level) then
    trigger = 1
    endif
    
    if fast crosses over slow then 
    if trigger=1 then 
    buy at market 
    endif
    level = slow+distance*pointsize
    trigger = 0
    elsif fast crosses under slow then 
    if trigger=1 then 
    sellshort at market 
    endif
    level = slow-distance*pointsize
    trigger = 0
    endif
    
    //graph fast coloured(0,200,0)
    //graph slow coloured(200,0,0)
    //graph high
    //graph low
    //graph level
    graph trigger
    Wolf Trades thanked this post
    EMA-crossover-with-distance-trigger.png EMA-crossover-with-distance-trigger.png
    #81780 quote
    Wolf Trades
    Participant
    Average

    Grazie Nicolas,

    puoi aiutarmi ancora?

    La condizione dei 30 pips ci deve essere dopo che è avvenuto l’incrocio della 12 con la 36, e questo è ok.

    Ma per aprire un trade short o long il prezzo una volta superato il limite dei 30 pips deve tornare indietro, toccare la ema 36 ed il trade si apre ad apertura candela successiva al tocco.

    #81781 quote
    Nicolas
    Keymaster
    Master

    Sorry, please write in English.

    #81783 quote
    Wolf Trades
    Participant
    Average

    Thanks, Nicolas

    can you help me again?

    The condition of the 30 pips must be there after the crossing of 12 with 36 has occurred, and this is ok.

    But to open a trade short or long the price once exceeded the limit of 30 pips must go back, touch ema 36 and the trade opens at the opening candle next to touch.

    #81886 quote
    Nicolas
    Keymaster
    Master

    I don’t understand since this is what the code does actually. By “touch ema 36”, do you mean a new crossover ? Or a single touch ? and the trade should open in what direction ?

    Wolf Trades thanked this post
    #82067 quote
    Wolf Trades
    Participant
    Average

    If I have a cross over this is level=0, price have to move level+30pips, then price have to return down and touch EMA36, after touch I open a long trade.

    If I have a cross under this is level=0, price have to move level-25pips, then price have to return up and touch EMA36, after touch I open a short trade.

    #82233 quote
    Nicolas
    Keymaster
    Master

    Ok, so that’s almost completely different, the below code should work as intended:

    defparam cumulateorders=false
    
    fast = average[12,1]
    slow = average[36,1]
    buydistance = 30
    selldistance = 25
    
    if onmarket then 
    buytrigger=0
    selltrigger=0
    endif
    
    if fast>slow and high crosses over slow+buydistance*pointsize and not onmarket then 
    buytrigger = 1
    endif
    
    if buytrigger then 
    buy at slow limit 
    endif
    
    if fast<slow and low crosses under slow-selldistance*pointsize and not onmarket then 
    selltrigger=1
    endif
    
    if selltrigger then 
    sellshort at slow limit
    endif
    
    set target pprofit 10
    set stop ploss 20

    I added takeprofit and stoploss values, otherwise the first trade will never end! 🙂

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

Pips condition above or below EMA to trigger an order


ProOrder: Automated Strategies & Backtesting

New Reply
Author
author-avatar
Wolf Trades @lupo32 Participant
Summary

This topic contains 7 replies,
has 2 voices, and was last updated by Nicolas
7 years, 4 months ago.

Topic Details
Forum: ProOrder: Automated Strategies & Backtesting
Language: English
Started: 10/01/2018
Status: Active
Attachments: 1 files
Logo Logo
Loading...