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
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
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.
Sorry, please write in English.
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.
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 ?
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.
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! 🙂