breakout buy code
Forums › ProRealTime English forum › ProOrder support › breakout buy code
- This topic has 6 replies, 2 voices, and was last updated 4 years ago by robertogozzi.
-
-
02/25/2020 at 10:24 AM #120397
Dear guys,
I am hoping to write a code for trading.
ema 50 x ema 200
accumulate order buy/sell on price break above / below or the previous candle (time frame)
stop at trailing.
i try very hard to find it. i hope you guys can help.
so many thanks
02/25/2020 at 10:54 AM #120399Please use the correct forum, I move the topic to the ProOrder support furum since you are talking about a strategy, while ProBuilder is devoted to indicators.
Thank you 🙂
02/25/2020 at 11:17 AM #120407What do you mean by “or the previous candle (time frame)“?
02/25/2020 at 11:21 AM #120408Hi.
Thank you for your reply.
What I mean is break previous price then entry order.
Thanks
02/25/2020 at 11:33 AM #120409To recap, you want to enter whenever there’s been a crossover of the two MA’s AND price breaks the price of the candle where the croccover occurred or the previous one?
02/25/2020 at 11:39 AM #120410Yes. Enter after ma cross.
Then accumulate order of contract after .
Etc. Add contract following the trend .
Condition is, price must break above or below. In order to enter . (Not the next bar)
With a trailing stop.
02/25/2020 at 12:33 PM #120424There you go, I tested it on DAX, 4h TF and it seems to work. Let me know if it’s doing what you wanted.
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778DEFPARAM CumulateOrders = trueONCE CrossOver = 0ONCE CrossUnder = 0//---------------------------------------------------------------------ONCE AvgType = 1 //1 = EmaEma50 = average[50,AvgType](close) //50Ema200 = average[200,AvgType](close) //200//---------------------------------------------------------------------// check when faster EMA crosses over/under slower EMA//CrossUnder = Ema50 CROSSES UNDER Ema200CrossOver = Ema50 CROSSES OVER Ema200//---------------------------------------------------------------------// enter a LONG trade//IF CrossOver AND Not LongOnMarket THENBUY 1 CONTRACT AT MARKETENDIF//---------------------------------------------------------------------// enter a SHORT trade//IF CrossUnder AND Not ShortOnMarket THENSELLSHORT 1 CONTRACT AT MARKETENDIF//---------------------------------------------------------------------// Accumulate LONG positions//IF LongOnMarket AND close > close[1] THENBUY 1 CONTRACT AT MARKETENDIF//---------------------------------------------------------------------// Accumulate SHORT positions//IF ShortOnMarket AND close < close[1] THENSELLSHORT 1 CONTRACT AT MARKETENDIF//---------------------------------------------------------------------// Trailing stop function//by Nicolas https://www.prorealcode.com/blog/trading/complete-trailing-stop-code-function//trailingstart = 20 //20 trailing will start @trailinstart points profittrailingstep = 20 //20 trailing step to move the "stoploss"//reset the stoploss valueIF NOT ONMARKET THENnewSL=0ENDIF//manage long positionsIF LONGONMARKET THEN//first move (breakeven)IF newSL=0 AND close-positionprice>=trailingstart*pipsize THENnewSL = positionprice+trailingstep*pipsizeENDIF//next movesIF newSL>0 AND close-newSL>=trailingstep*pipsize THENnewSL = newSL+trailingstep*pipsizeENDIFENDIF//manage short positionsIF SHORTONMARKET THEN//first move (breakeven)IF newSL=0 AND positionprice-close>=trailingstart*pipsize THENnewSL = positionprice-trailingstep*pipsizeENDIF//next movesIF newSL>0 AND newSL-close>=trailingstep*pipsize THENnewSL = newSL-trailingstep*pipsizeENDIFENDIF//stop order to exit the positionsIF newSL>0 THENSELL AT newSL STOPEXITSHORT AT newSL STOPENDIF//--------------------------------------------------------------------- -
AuthorPosts
Find exclusive trading pro-tools on