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
//BUYING & SELLING between 22H and 23H
IF time >= 220000 and time <= 230000 and dayofweek <> 5 THEN
Buy PositionSize shares at opening - amplitude limit
Sellshort PositionSize shares at opening + amplitude limit
ENDIF
// SL & TP
SL=0.6//0.8
TP=1.5//1.2
SET STOP %LOSS SL
SET TARGET %PROFIT TP
Do you have multiple orders on market at the same time?
Well, 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.
Ok, so that’s only a supposition, but %LOSS and %PROFIT are calculated with the average price of the whole orders, so maybe the remaining LIMIT order is taken in this calculation.
So 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?
One 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
Please include the spread in your calculation. We buy at Ask and sell at Bid. What are the difference in pips between your calculation without spread and the real orders on your track record?
It 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
Sorry, 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..
if 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?
Or 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
Thanks Noobywan, I guess me and Elsborgtrading have to pay you a cold beer 🙂
Thanks 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.
Well, I encourage you to do so while I’m doing the same thing with my own “network”.
Hi 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
// TimeFrame H1
// USD/JPY
Defparam cumulateorders = false
//REM Money Management
reinvest=1
if reinvest then
Capital = 60000
MINPosisionSize=1
Riskprocent=10 //your max risk in %
Risk =Riskprocent/100
StopLoss = 0.6//the "STP" var. not working
REM Calculate contracts
equity = Capital + StrategyProfit
maxrisk = round(equity*Risk)
PositionSize = abs(MINPosisionSize+round((maxrisk/StopLoss)/PointValue)*pipsize)
else
positionsize=1
endif
// Candle reference 18 to 22H
If time = 220000 THEN
amplitude = highest[4](high) - lowest[4](low)
amplitude = amplitude*0.1
opening = close
ENDIF
//BUYING & SELLING between 22H and 23H
IF time >= 220000 and time <= 230000 and dayofweek <> 5 THEN
Buy PositionSize shares at opening - amplitude limit
Sellshort PositionSize shares at opening + amplitude limit
//STP=ABS(tradeprice-(tradeprice-((tradeprice*sl)/100)))
//bull=opening-amplitude
//bear=opening+amplitude
ENDIF
// SL & TP
SL=0.6//0.8
TP=1.5//1.2
SET STOP %LOSS SL
SET TARGET %PROFIT TP
// EXIT
IF time = 100000 THEN
SELL AT MARKET
EXITSHORT AT MARKET
ENDIF
//pv=pointvalue
//graph pv COLOURED(0,255,0) AS "buy"//GREEN
//graph (tradeprice*positionsize*SL/equity)*10000 COLOURED(255,255,255) AS "MAXRISK"//Aqua
graph (((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