Set Stop to Break Even ASAP / Real Time
Forums › ProRealTime English forum › ProOrder support › Set Stop to Break Even ASAP / Real Time
- This topic has 5 replies, 3 voices, and was last updated 4 years ago by adeelq79.
-
-
12/07/2019 at 10:01 AM #114380
Hi, I have the code which I use to trade the FTSE 1 Hour, but would like to modify the break even code to the following conditions:
If after 1 hour (i.e. during the 1st candle), the break even function is not activated, set stop to b/e on the next candle ASAP.
Currently, the b/e is only activated once the candle has closed (and conditions met) but looking for a more ‘real time’ break even code.
Thanks for the help.
FTSE 1 Hour TF - Breakeven ASAP Required12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182defparam cumulateorders=false// --- settingssize = 1 //size of ordersmaxDayOrder = 1 //max orders per daystartBreakeven = 11 //how much pips/points in gain to activate the breakeven function?PointsToKeep = 6 //how much pips/points to keep in profit above of below our entry price when the breakeven is activated (beware of spread)TakeProfit = 30 //takeprofit in points/pipsStopLoss = 45 //stoploss in points/pips// --- end of settings// Prevents the system from creating new orders to enter the market or increase position size before the specified timenoEntryBeforeTime = 090000timeEnterBefore = time >= noEntryBeforeTime// Prevents the system from placing new orders to enter the market or increase position size after the specified timenoEntryAfterTime = 160000timeEnterAfter = time < noEntryAfterTime// Prevents the system from placing new orders on specified days of the weekdaysForbiddenEntry = OpenDayOfWeek = 6 OR OpenDayOfWeek = 0//max orders each dayif intradaybarindex=0 or day<>day[1] thenorderscount=0endifallowtrading=orderscount<maxDayOrder and timeenterbefore and timeenterafter and not daysforbiddenentry//indicatorsema5=average[5,1](close)ema17=average[17,1](close)ema62=average[62,1](close)ignored, ignored, ignored, ignored, BuySignal, SellSignal, ignored = CALL "WA Explosion COMBO"[150, 30, 15, 15]irsi=rsi[7](close)//orders launchbuysig = ema5>ema17 and ema62<ema5 and BuySignal>=260 and irsi>=83sellsig = ema5<ema17 and ema62>ema5 and SellSignal>=260 and irsi<=22if allowtrading thenif buysig thenbuy size contract at marketorderscount=orderscount+1endifif sellsig thensellshort size contract at marketorderscount=orderscount+1endifendifset target pprofit takeprofitset stop ploss stoploss// --- breakeven function//reset the breakevenLevel when no trade are on marketIF NOT ONMARKET THENbreakevenLevel=0ENDIF// --- BUY SIDE ---//test if the price have moved favourably of "startBreakeven" points alreadyIF LONGONMARKET AND close-tradeprice(1)>=startBreakeven*pipsize THEN//calculate the breakevenLevelbreakevenLevel = tradeprice(1)+PointsToKeep*pipsizeENDIF//place the new stop orders on market at breakevenLevelIF breakevenLevel>0 THENSELL AT breakevenLevel STOPENDIF// --- end of BUY SIDE ---// --- SELL SIDE ---//test if the price have moved favourably of "startBreakeven" points alreadyIF SHORTONMARKET AND tradeprice(1)-close>=startBreakeven*pipsize THEN//calculate the breakevenLevelbreakevenLevel = tradeprice(1)-PointsToKeep*pipsizeENDIF//place the new stop orders on market at breakevenLevelIF breakevenLevel>0 THENEXITSHORT AT breakevenLevel STOPENDIF// --- end of SELL SIDE ---12/07/2019 at 10:12 AM #114381Decisions are made at the close of a candle and orders placed at the open of the following candle so if you want to make decisions and place orders mid way during a 1 hour candle candle then you need to use MTF within your strategy and run it on a faster time frame.
12/08/2019 at 1:05 AM #11440412/08/2019 at 9:40 AM #114410Yes – use multi time frame and trade on the 1 minute chart. You enter on the hourly time frame and then check on the minute timeframe whether you are enough points in profit and then start your breakeven by placing your stop orders at the close of every minute candle.
The downside to this is that you have very little data to backtest on due to the faster timeframe.
1 user thanked author for this post.
12/09/2019 at 11:42 AM #114489Separate the breakeven function from the strategy code into 2 different timeframes:
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384defparam cumulateorders=false// --- settingssize = 1 //size of ordersmaxDayOrder = 1 //max orders per daystartBreakeven = 11 //how much pips/points in gain to activate the breakeven function?PointsToKeep = 6 //how much pips/points to keep in profit above of below our entry price when the breakeven is activated (beware of spread)TakeProfit = 30 //takeprofit in points/pipsStopLoss = 45 //stoploss in points/pips// --- end of settings// Prevents the system from creating new orders to enter the market or increase position size before the specified timenoEntryBeforeTime = 090000timeEnterBefore = time >= noEntryBeforeTime// Prevents the system from placing new orders to enter the market or increase position size after the specified timenoEntryAfterTime = 160000timeEnterAfter = time < noEntryAfterTime// Prevents the system from placing new orders on specified days of the weekdaysForbiddenEntry = OpenDayOfWeek = 6 OR OpenDayOfWeek = 0timeframe(1 hour, updateonclose)//max orders each dayif intradaybarindex=0 or day<>day[1] thenorderscount=0endifallowtrading=orderscount<maxDayOrder and timeenterbefore and timeenterafter and not daysforbiddenentry//indicatorsema5=average[5,1](close)ema17=average[17,1](close)ema62=average[62,1](close)ignored, ignored, ignored, ignored, BuySignal, SellSignal, ignored = CALL "WA Explosion COMBO"[150, 30, 15, 15]irsi=rsi[7](close)//orders launchbuysig = ema5>ema17 and ema62<ema5 and BuySignal>=260 and irsi>=83sellsig = ema5<ema17 and ema62>ema5 and SellSignal>=260 and irsi<=22if allowtrading thenif buysig thenbuy size contract at marketorderscount=orderscount+1endifif sellsig thensellshort size contract at marketorderscount=orderscount+1endifendifset target pprofit takeprofitset stop ploss stoplosstimeframe(1 minute)// --- breakeven function//reset the breakevenLevel when no trade are on marketIF NOT ONMARKET THENbreakevenLevel=0ENDIF// --- BUY SIDE ---//test if the price have moved favourably of "startBreakeven" points alreadyIF LONGONMARKET AND close-tradeprice(1)>=startBreakeven*pipsize THEN//calculate the breakevenLevelbreakevenLevel = tradeprice(1)+PointsToKeep*pipsizeENDIF//place the new stop orders on market at breakevenLevelIF breakevenLevel>0 THENSELL AT breakevenLevel STOPENDIF// --- end of BUY SIDE ---// --- SELL SIDE ---//test if the price have moved favourably of "startBreakeven" points alreadyIF SHORTONMARKET AND tradeprice(1)-close>=startBreakeven*pipsize THEN//calculate the breakevenLevelbreakevenLevel = tradeprice(1)-PointsToKeep*pipsizeENDIF//place the new stop orders on market at breakevenLevelIF breakevenLevel>0 THENEXITSHORT AT breakevenLevel STOPENDIF// --- end of SELL SIDE ---The breakeven levels would check for update every 1 minute now, so you have to launch the strategy on the 1-minute timeframe.
12/09/2019 at 11:18 PM #114525 -
AuthorPosts
Find exclusive trading pro-tools on