Cumulate orders and stops & targetsView all attachments
02/06/2018 at 3:29 PM #61719
Hi all, I have a question related to the placement of stops and targets when a strategy cumulates positions.
Here is a simple code:1234567891011121314151617181920// Definition of code parametersDEFPARAM CumulateOrders = True // Cumulating positions activated// Conditions to enter long positionsindicator1 = RSI(close)c1 = (indicator1 CROSSES UNDER 5)if barindex - tradeindex = 0 thenSL = lowest(low)TGT = 6*(tradeprice-SL)endifIF c1 THENBUY 1 CONTRACT AT high+1 stopset target profit TGTENDIFIF longonmarket THENsell at SL stopENDIF
With this code, every time a position is added to an existing position, it changes the previously set target and stop of the previous position.
Anybody an idea how you can add a stop and target to an “add” position, without messing with the previous position its stop and target?02/06/2018 at 4:10 PM #6173102/06/2018 at 5:49 PM #6174702/06/2018 at 6:39 PM #6175602/06/2018 at 7:26 PM #6177502/06/2018 at 7:44 PM #61777
I don’t think so, because condition at line 8 is only true during 1 period.
You are right, lines 9 and 10 do not recalculate TGT and SL after every bar, but only in those bars, when a new position has just been opened (barindex – tradeindex = 0).
But still, these new values for TGT and SL are then applied later to all open positions, in line 15 only when c1 is true, and in line 19 all the time, as far as I see it.02/06/2018 at 8:06 PM #61779
Also, there is a fundamental difference between the commands1set target profit TGT
and1sell at SL stop
which is not well explained in the manual.1set target profit TGT
sets the target price by TGT units away from the opening price of each open individual position. So, each position will have the same difference between its opening and target price, which will be TGT. But all positions will have different values of their target prices, whenever their opening prices are different.
On the other hand, the command1sell at SL stop
will set the same exit price SL for all positions, irrespective of their individual opening prices. All open positions will have the same absolute stop price SL, which can be altered several times in line 19 during the course of the system.02/06/2018 at 9:28 PM #61783
Sorry to say this, @nicolas, but I think I just found another quite serious PRT bug, dealing with the “set target pprofit” commands, when multiple positions are open.
The English manual says on page 12 :
SET TARGET PROFIT x: Set a profit target to close the position x units from the average position price.
So, when multiple positions are open, and we say : “set target pprofit 20”, this should mean that a single average limit 20 points away from the average position price of all positions will be set, not different limits for every position 20 points away from the different position prices.
But : now here comes reality.
Take this little test system (I really do like them, meanwhile) :test system for1234567891011121314151617// test system for "set target pprofit" bug// DAX 1 minute chartdefparam cumulateorders = trueONCE TI = 0If barindex = TI + 20 thenbuy 1 contract at marketTI = barindexendifset target pprofit 20set stop ploss 20If positionprice <> 0 thengraph positionpriceendif
This system buys a new position every 20 bars, irrespective of what happens. It sets a stop loss of 20 points and a target profit of 20 points, too. Backtest has been done with a spread of 1 point.
According to the manual, this should set at least the target 20 points away from the average position price, when multiple positions are open.
It remains unclear in the manual whether the stop loss will be set 20 points away from each individual position price, or 20 points away from the average position price.
But here, we deal only with the target price, now :
Take the chart and look at the date 01.02.2018, TIME = 8:00. At this time, 19 open positions are closed and their target profit is taken.
According to the manual, this should happen 20 points away from the average position price, which was 13229,7 at this time (for all 19 positions). So, all 19 positions should be closed at the same price of 13249,7
But now look at the chart : It reports that all positions have been closed at 8:00 at different exit prices, all 20 points away from their individual opening price, not 20 points away from the average position price :
The backtest report tells us the same different exit prices for these 19 positions, 20 points away from their entry price :
Because all of these positions are reported to have been closed 20 points away from their entry price, their results should be + 20,00 € for all of them.
However, in the list of all closed positions in the same backtest report, all of these 19 positions are shown to have different results, as if they would indeed have been closed at the same price, 20 points away from an average position price !!
Now, what is true in reality ? The command “set target pprofit x” : does it close multiple positions all at the same target price, x points away from the average position price, or does it close them all at different individual prices, x points away from their individual opening price ?
The backtest report and the chart say all different things together at the same time, unfortunately.02/06/2018 at 9:32 PM #61789
Addendum : What about the “set stop ploss x” command for multiple positions ?
Does it set the stop x points away from the individual opening price of each single position, or does it set a combined stop loss 20 points away from the average position price ?
Unfortunately, this is not clear to me at this time anymore.02/06/2018 at 10:01 PM #61794
To make things a little clearer, I redisplay figure 1 once again, with the entry prices of all 19 positions highlighted:
Now you can clearly see that all positions are reported to have been closed exactly 20 points away from their entry price.
But the backtest reports different results for all of them, from 10,96 € to 27,46 €. What is true, now ?02/06/2018 at 10:47 PM #61801
The same mess for the command “set stop ploss 20” also, tested with the same code as above.
DAX 1 minute chart.
On 29.01.2018, 21:40:00, three positions are closed by running into the stop :
In the chart, all three positions are reported to have been closed exactly 20 points away from their entry price. So they all should have a result of -20,00 €.
However, the backtest reports three different results for them, between -15,87 € and -17,37 € :
Do we have the same problem here ??
Also, the duration of these positions seems to be wrong; it cannot be 9, 0 and 0 bars as the backtest report says, but it is longer. What is wrong here ?02/06/2018 at 11:03 PM #61810
In my post #61783 above, the duration of the wrongly reported positions in the backtest is wrong, too; they are all displayed as 0 bars, but in fact, they are much longer.
See the last figure at the bottom of this post #61783.02/06/2018 at 11:34 PM #61818
@ilaria : Please read my posts above and forward them to your team, so they can correct (or explain) the bugs I described. And please, give us further information as to what the commands
set target pprofit xx
set stop ploss xx
really do, when multiple positions are open. The manual and the backtest results are entirely inconsistent, in this regard.02/07/2018 at 8:49 AM #61825
It’s not a bug. Your assumption is true but for IG or PRT CFD, not with prorealtime software and its paper trading where profits and losses are set with the average position price. The documentation is talking about how prorealtime handle it,not how broker are dealing with these price levels. However I think that to be perfectly clear, an addendum should be added to the documentation, you are right.02/07/2018 at 9:28 AM #61828
It’s not a bug. Your assumption is true but for IG or PRT CFD, not with prorealtime software and its paper trading where profits and losses are set with the average position price. The documentation is talking about how prorealtime handle it,not how broker are dealing with these price levels. However I think that to be perfectly clear, an addendum should be added to the documentation, you are right.
And so how about all the inconsistencies in the backtest reports ? Positions that should have -20 € result are shown to have -15,67 € ?? And when in fact they have a duration of 23 bars, they are shown with 0 bars ? No bug ? Please…
The backtest does not know any broker, Nicolas.
It is a clear bug, as the backtests above show. They are full of errors.
Clear question : Where does
set target pprofit 20
set the limits of multiple positions ?
20 points away from an individual position price, or 20 points away from the average position price ?
Everyone using PRT software needs to know this.
And the backtest errors and inconsistencies need to be removed.