Cumulate orders and stops & targets

Viewing 15 posts - 1 through 15 (of 35 total)
  • Author
    Posts
  • #61719 quote
    Seb
    Participant
    Average

    Hi all, I have a question related to the placement of stops and targets when a strategy cumulates positions.

    Here is a simple code:

    // Definition of code parameters
    DEFPARAM CumulateOrders = True // Cumulating positions activated
    
    // Conditions to enter long positions
    indicator1 = RSI[2](close)
    c1 = (indicator1 CROSSES UNDER 5)
    
    if barindex - tradeindex = 0 then
    SL = lowest[5](low)
    TGT = 6*(tradeprice-SL)
    endif
    
    IF c1 THEN
    BUY 1 CONTRACT AT high+1 stop
    set target profit TGT
    ENDIF
    
    IF longonmarket THEN
    sell at SL stop
    ENDIF

    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?

    #61731 quote
    Nicolas
    Keymaster
    Master

    With an IG or PRT-CFD account, you can use %PROFIT and %LOSS, it should add individual takeprofit and stoploss for each order.

    Seb and thomas_price thanked this post
    #61747 quote
    Henrik
    Participant
    Veteran

    Hi!

    so if i use

    set stop $loss 100

    then max loss for all contracts is 100?

    regards

    Henrik

    #61756 quote
    verdi55
    Participant
    Veteran

    Your problem is also that your code constantly recalculates SL and TGT. This is why the stop level is changed in every bar for all open positions, and the target level each time when c1 is true.

    #61775 quote
    Nicolas
    Keymaster
    Master

    I don’t think so, because condition at line 8 is only true during 1 period.

    #61777 quote
    verdi55
    Participant
    Veteran

    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.

    #61779 quote
    verdi55
    Participant
    Veteran

    Also, there is a fundamental difference between the commands

    set target profit TGT

    and

    sell at SL stop

    which is not well explained in the manual.

     

    set 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 command

    sell 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.

    Nicolas, Juan Salas and thomas_price thanked this post
    #61783 quote
    verdi55
    Participant
    Veteran

    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 for "set target pprofit" bug
    // DAX 1 minute chart
    defparam cumulateorders = true
    
    ONCE TI = 0
    
    If barindex = TI + 20 then
    buy 1 contract at market
    TI = barindex
    endif
    
    set target pprofit 20
    set stop ploss 20
    
    If positionprice <> 0 then
    graph positionprice
    endif

    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 :

    [attachment file=61784]

    The backtest report tells us the same different exit prices for these 19 positions, 20 points away from their entry price :

    [attachment file=61785]

    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 !!

    [attachment file=61786]

    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.

    Robb thanked this post
    Bild1.png Bild1.png Bild2.png Bild2.png Bild3.png Bild3.png
    #61789 quote
    verdi55
    Participant
    Veteran

    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.

    #61794 quote
    verdi55
    Participant
    Veteran

    To make things a little clearer, I redisplay figure 1 once again, with the entry prices of all 19 positions highlighted:

    [attachment file=61795]

    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 ?

    Bild4.png Bild4.png
    #61801 quote
    verdi55
    Participant
    Veteran

    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 :

    [attachment file=61802]

    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 € :

    [attachment file=61807]

    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 ?

    Bild6.png Bild6.png Bild7.png Bild7.png Bild7a.png Bild7a.png
    #61810 quote
    verdi55
    Participant
    Veteran

    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.

    #61818 quote
    verdi55
    Participant
    Veteran

    @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

    and

    set stop ploss xx

    really do, when multiple positions are open. The manual and the backtest results are entirely inconsistent, in this regard.

    GraHal and manel thanked this post
    #61825 quote
    Nicolas
    Keymaster
    Master

    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.

    #61828 quote
    verdi55
    Participant
    Veteran

    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.

Viewing 15 posts - 1 through 15 (of 35 total)
  • You must be logged in to reply to this topic.

Cumulate orders and stops & targets


ProOrder: Automated Strategies & Backtesting

New Reply
Author
author-avatar
Seb @seb Participant
Summary

This topic contains 34 replies,
has 2 voices, and was last updated by GraHal
1 year, 9 months ago.

Topic Details
Forum: ProOrder: Automated Strategies & Backtesting
Language: English
Started: 02/06/2018
Status: Active
Attachments: 9 files
Logo Logo
Loading...