Limit Orders to Avoid Spikes
Forums › ProRealTime English forum › ProOrder support › Limit Orders to Avoid Spikes
- This topic has 9 replies, 3 voices, and was last updated 5 years ago by
adeelq79.
-
-
02/06/2020 at 1:07 PM #118828
Hi,
My code has been working as expected; yesterday trading the Dow on 10min candle, my conditions triggered and the system opened a trade on the 3pm candle open. However, the price spiked. The opening price of the candle was say 29,000 but in 1 second it spiked 50 points and opened a position for me at 29,050. Consequently it fell, stopped me out and I lost money.
IG have said I should use LIMIT orders and at the minute I am using at market.
So how do I introduce this LIMIT order into my code, to say, if the price is 5 points (as an example) away from the opening candle, do not open a trade. Same for the sell side.
Thanks
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182defparam 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 ---02/06/2020 at 6:07 PM #118861All the answers to most simple coding questions can be found in the manual.
https://www.prorealcode.com/prorealtime-documentation/
https://www.prorealcode.com/documentation/limit/
02/06/2020 at 6:21 PM #118864Thanks. So to be clear, would this code for long positions:
1buy size contract at marketchange to:
1buy size contract at open +5 LIMITfor short positions would it change from:
1sellshort size contract at marketchange to:
1sellshort size contract at open -5 LIMITThanks
02/06/2020 at 6:26 PM #118865I’m not sure to perfectly understand what IG is talking about. But, bear in mind that the code is read at the close of the candle and if the condition are fullfilled, then the order is opened at next bar open.
Anyway, we could replace the AT MARKET with LIMIT orders to see how it goes, and to avoid gap, but I think that there will be some rejected orders that could lead to an automatic stop of the strategy, you should try this on demo platform first.
02/06/2020 at 6:44 PM #11886702/06/2020 at 8:19 PM #11887302/07/2020 at 8:44 AM #118912In your examples above you use OPEN. OPEN refers to the opening price of the just closed candle so it is likely that your order is sometimes the wrong side of current price for a pending order so it is rejected. Change OPEN to CLOSE.
02/09/2020 at 2:38 PM #11909002/09/2020 at 5:55 PM #1191021sellshort at close -2 limitI think will be rejected because limit orders have to be at a better/more favourable price than current price.
1sellshort at close limitWill mean that if the next open is the same as the current close or the market gaps up then your order will be filled at the opening price.
There is the possibility that this order could also be rejected if the broker sets a minimum order distance from price. They do for STOP orders but I’m not certain if they do for LIMIT orders. However as Nicolas suggested just putting the idea live in demo should tell you if this is the case or not.
02/09/2020 at 6:59 PM #119114 -
AuthorPosts
Find exclusive trading pro-tools on