Strange behaviour of Limit order
Forums › ProRealTime English forum › ProOrder support › Strange behaviour of Limit order
- This topic has 19 replies, 3 voices, and was last updated 8 years ago by Elsborgtrading.
-
-
09/19/2016 at 7:09 AM #13252
Hi Guys. I have observed a strange behaviour of a filled order and a limit order for take profit. It least it strange to me as I cannot explain this. Perhaps someone can?
Initial orders are placed at 22:00 each night- one buy, one sell. one or both gets filled between 22:00 and 23:00- if both is filled the first is closed. Then it seems like the TP change at the end of 2 time frames, after the order is filled, but only the TP order change- not SL? Also when the order gets filled it only shows the take profit limit order sometimes.
I have attached 2 scrndump, one from PRT that shows 2 orders from 2 different days, and one that shows the activity from the account.
Both you can see the TP order change at 00:00:01 – that’s one sec after midnight.
also the lates order the initial TP order is not shown in PRT?
So question is, why does PRT change my TP order at midnight?
And why is it only the TP and not SL?
Cheers Kasper
12345678910111213141516//BUYING & SELLING between 22H and 23HIF time >= 220000 and time <= 230000 and dayofweek <> 5 THENBuy PositionSize shares at opening - amplitude limitSellshort PositionSize shares at opening + amplitude limitENDIF// SL & TPSL=0.6//0.8TP=1.5//1.2SET STOP %LOSS SLSET TARGET %PROFIT TP09/19/2016 at 8:15 AM #1326009/19/2016 at 9:37 AM #13266Well, there is a buy and a sell order at the same time. Not everytime they both gets filled, so if not -there is one order pending until midnight where it is deleted. At least that is what I can see in the activity log.
09/19/2016 at 11:16 AM #1328109/19/2016 at 11:26 AM #13282So when the suppostion is deleted at 00:00:00 a new %Profit is calculated 1 sec after. Makes sense if it’s calculated on average price, but why is %Loss not re-calculated then?
09/19/2016 at 12:15 PM #13285One sample for the whole trade.
%Profit:1.5
%Loss:0.6
@22:00 there are two limit orders placed.
One buy @102.116 and one Sellshort @102.188
Average price = 102.116+102.188/2= 102.152 (is this correct?)
One buy order gets filled @22:35 @102.116
and One stoploss order @101.503 and one takeprofit @102.188 is placed.
I cannot calculate the stoploss @101.503 with the average price- only from the filled one.
102.116-(102.116*0,006)=101.503
so the %loss is not calculated from average price- only the filled one?
When the remaining pending order gets deleted a new TP is calculated for the open position.
102.116+102.116*0,015=103.648. So this must be correct.
I just cannot figure out the TP @102.188 between 22:00 and 23:00 is comming from?
Do I calculate the average price correct?
if not It seems like that the %profit is calculated from average price but %Loss is not, but calculated from the filled order/open position.
It just that I would like to know exactly what is going on, and if this is a bug or expected behaviour 🙂
Cheers Kasper
09/19/2016 at 1:06 PM #1328809/19/2016 at 2:15 PM #13290It not a lot. I think that IG has 0.7 on USD/JPY FX It would not be enough to explain the 102.188
pipsize=0.01
09/19/2016 at 2:34 PM #13291Sorry, my bad, I just get an information on this. %LOSS and %PROFIT are calculated on average price, only @ PRT, but it is still individual for each order with IG. I need to change the online documentation accordingly…
But I think your problem is still not solved with this new information..
09/19/2016 at 2:56 PM #13295if I understand your code properly, your take profit limit is a 1.5% improvement, and if I calcultate the percentage at the midnight change, it is the proper 1.5%, so it looks like the question is not so much why is there another take profit at midnight, but instead why is the first take profit before 23h not equal to 1.5% in the first place, both for the red box and green box examples, before it finally becomes correct at midnight.
And for the question “why only TP and not SL, well it turns out SL is at the correct value 0.6% in the first place, that’s why it doesn’t change.
The line jump before the endif, and the “sellshort” not appearing in blue seem to indicate there might have been some other text deleted. Is this all of your code? Or is it just an extraction of some of the lines and maybe there are other lines we don’t see here that would affect the target profit between 22h and 23h within the if statement?
09/19/2016 at 3:10 PM #13296Or could it be that the “sellshort at opening+amplitude” takes priority over the set target %profit in case “opening+amplitude” is lower than the target?
If yes, as long as we are in a candle closing >=22h and <=23h, the limit is determined by opening+amplitude (need to check if opening+amplitude=102.188 and 102.322) rather than set target %profit TP
And when next candle the if statement is not visited, so the order “sellshort at opening+amplitude” is not valid anymore, and the target becomes determined by the set target %profit TP line.
I think that’s probably it, but I can’t check it for sure without knowing “amplitude” value for the “opening+amplitude=102.188 and 102.322” check
09/19/2016 at 3:16 PM #13302Thanks Noobywan, I guess me and Elsborgtrading have to pay you a cold beer 🙂
09/19/2016 at 3:35 PM #13304Thanks Nicolas, although the transportation costs to bring the 3 of us together in the same location could make it a too expensive beer… So to save you money, instead of the expensive beer, I’d settle for some news in my “stochastic bug in probacktest” topic if there is any from your contacts at PRT? I don’t know if you had time to discuss it with them, and I haven’t reported it as a bug in the prt technical help contact menu yet, but I can if needed.
09/19/2016 at 4:34 PM #1330509/19/2016 at 6:34 PM #13321Hi Noobywan- beers is good 😀 , you you are right-“ why is the first take profit before 23h not equal to 1.5% in the first place??“, we found out that the SL is valid and accounted for, also the TP at midnight, but initially the information was the %LOSS and %PROFIT was on average price for all open positions. I’m happy that we found out that it’s individual- more flexibility and control.
Remember the two order is place as “limit” and not “at market” so from 22:00 unto one is filled they are both pending. if not filled both- 2nd one is deleted at midnight. At least that is what I see in the activity log. btw the activity log are the orginal from the IG account- nothings changed or left out.
There should be nothing else in the code that could generate the strange TP @102.188- at least I can’t see it?
“The line jump before the endif, and the “sellshort” not appearing in blue seem to indicate there might have been some other text deleted“- well I deleted some REMcode nothing else.
The full code is shown here and can also be found in the strategy library
Cheers Kasper
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667// TimeFrame H1// USD/JPYDefparam cumulateorders = false//REM Money Managementreinvest=1if reinvest thenCapital = 60000MINPosisionSize=1Riskprocent=10 //your max risk in %Risk =Riskprocent/100StopLoss = 0.6//the "STP" var. not workingREM Calculate contractsequity = Capital + StrategyProfitmaxrisk = round(equity*Risk)PositionSize = abs(MINPosisionSize+round((maxrisk/StopLoss)/PointValue)*pipsize)elsepositionsize=1endif// Candle reference 18 to 22HIf time = 220000 THENamplitude = highest[4](high) - lowest[4](low)amplitude = amplitude*0.1opening = closeENDIF//BUYING & SELLING between 22H and 23HIF time >= 220000 and time <= 230000 and dayofweek <> 5 THENBuy PositionSize shares at opening - amplitude limitSellshort PositionSize shares at opening + amplitude limit//STP=ABS(tradeprice-(tradeprice-((tradeprice*sl)/100)))//bull=opening-amplitude//bear=opening+amplitudeENDIF// SL & TPSL=0.6//0.8TP=1.5//1.2SET STOP %LOSS SLSET TARGET %PROFIT TP// EXITIF time = 100000 THENSELL AT MARKETEXITSHORT AT MARKETENDIF//pv=pointvalue//graph pv COLOURED(0,255,0) AS "buy"//GREEN//graph (tradeprice*positionsize*SL/equity)*10000 COLOURED(255,255,255) AS "MAXRISK"//Aquagraph (((tradeprice-(tradeprice-((tradeprice*sl)/100)))*positionsize*pointvalue*100)/(equity+capital))*100 COLOURED(0,0,0) AS "MAXRISK"//Aqua//graph PointValue COLOURED(0,255,255) AS "sell"//Aqua//graph stp COLOURED(0,255,255) AS "sell"//Aqua -
AuthorPosts
Find exclusive trading pro-tools on