Adjustment in code because combined stops can not be used with pro order
Forums › ProRealTime English forum › ProOrder support › Adjustment in code because combined stops can not be used with pro order
- This topic has 34 replies, 4 voices, and was last updated 4 years ago by Vonasi.
-
-
09/17/2019 at 9:19 AM #107826
If you SET your SL when placing orders, the second (short) will override the first one (long). Now think what happens if your long trade is entered, what kind of SL will it cope with?
I suggest that you set you SL the next bar, when you are on market so you know what kind of calculation you have to do (but you must have saved your values before).
09/17/2019 at 7:33 PM #107853Hi
This part of the code is not to add 60 points to my entry but 60 points to my sl. I want it to buy as close as possible to the high of the previous 6 bars (5 min) and sell as close to the low of the last 6 bars. I want the sl to be 60 points below the high for a buy trade and 60 points above the low of the last 6 bars.
12345678if not onmarket and time >= starttime and flag = 0 thenbuy Nlots contract at MaxPrice STOPset stop loss close- Minprice - 60 * pointsizeendifif not onmarket and time >= starttime and flag = 0 thensellshort Nlots contract at MinPrice STOPset stop loss MaxPrice - close + 60 * pointsizeThe problem i have is that its not placing trades in real time.. in backtest the code works but in real time it doesnt place any trades.. how can i change the code so that it does place a trade even if price is volatile and already moved and orders are too close to price?
Another thing is it also doesnt keep orders open till its filled,, if not filled in first 5 min it cancels all pending orders.
Please run a backtest and see some days it doesnt place any trades. This is the code i have now.
1234567891011121314151617181920212223242526272829303132333435363738394041424344//-------------------------------------------------------------------------// Main code : UltimateSAF//-------------------------------------------------------------------------//-------------------------------------------------------------------------// Main code : MySystem(8)//-------------------------------------------------------------------------DEFPARAM CumulateOrders = falseDEFPARAM FLATBefore = 084500 //09:00DEFPARAM FLATAfter = 210000 //21:00DEFPARAM PreLoadBars = 2000ONCE nLots = 5ONCE MaxPrice = 999999ONCE MinPrice = 0starttime = 090000SET TARGET PROFIT 120IF time = starttime THENMaxPrice = max(close, highest[6](high)) //Il massimo/minimo delle ultime 12 barreMinPrice = min(close, lowest[6](low)) // (ogni ora = 12 barre da 5 minuti)flag=0ENDIFif onmarket thenflag = 1endif//************************************************************************// LONGif not onmarket and time >= starttime and flag = 0 thenbuy Nlots contract at MaxPrice STOPset stop loss close- Minprice - 60 * pointsizeendifif not onmarket and time >= starttime and flag = 0 thensellshort Nlots contract at MinPrice STOPset stop loss MaxPrice - close + 60 * pointsizeMaxPrice = 999999MinPrice = 0endifIf you can please adjust code.
Thank you
09/17/2019 at 8:50 PM #107855The problem i have is that its not placing trades in real time.. in backtest the code works but in real time it doesnt place any trades.. how can i change the code so that it does place a trade even if price is volatile and already moved and orders are too close to price?
You can’t!
PRT is just a trading platform. When you place an order it is sent by PRT to your broker. If it is below the minimum distance from the current price that your broker allows for an order on the instrument that you are trading then that order will be rejected by the broker. There is no fix and there is no work around. You have tried to place an order closer than your broker will allow and that is that and the order is rejected.
09/17/2019 at 10:53 PM #107862I suggest that you create a new constant to store the minimum distance required by your broker, then place a BUY/SELLSHORT pending order at a price that at least is equal to, or exceeds, such requirement (my example is 10 pips):
123456789101112131415161718192021222324252627282930313233DEFPARAM CumulateOrders = falseDEFPARAM FLATBefore = 084500 //09:00DEFPARAM FLATAfter = 210000 //21:00DEFPARAM PreLoadBars = 2000ONCE nLots = 5ONCE MaxPrice = 999999ONCE MinPrice = 0ONCE starttime = 090000ONCE Distance = 10 * pipsizeSET TARGET PROFIT 120IF time = starttime THENMaxPrice = max(close, highest[6](high)) //Il massimo/minimo delle ultime 12 barreMinPrice = min(close, lowest[6](low)) // (ogni ora = 12 barre da 5 minuti)flag=0ENDIFif onmarket thenflag = 1endif//************************************************************************// LONGif not onmarket and time >= starttime and flag = 0 thenbuy Nlots contract at max(close + Distance,MaxPrice) STOPset stop loss close- Minprice - 60 * pointsizeendif//************************************************************************// SHORTif not onmarket and time >= starttime and flag = 0 thensellshort Nlots contract at min(close - Distance,MinPrice) STOPset stop loss MaxPrice - close + 60 * pointsizeendif09/18/2019 at 7:10 AM #107868Roberto’s suggestion is the same as mine mentioned in this post:
https://www.prorealcode.com/topic/adjustment-in-code-help-please/page/2/#post-107819
It does however mean that you will sometimes not be entering at the price you think you should be. Their is also the additional problem that on faster time frames – for example in a 1 second time frame that price will likely creep up to your desired buy price and then when it is too close your minimum distance code will start moving your order level further away to ensure orders are not rejected. If you use a slower time frame then you don’t have this issue so much but you increase the risk of both your long and short orders being hit within one bar.
-
AuthorPosts
Find exclusive trading pro-tools on