Two positions with CumulateOrders = False

Viewing 14 posts - 1 through 14 (of 14 total)
  • Author
    Posts
  • #55713 quote
    Vonasi
    Moderator
    Master

    I noticed this this morning on a live strategy and again tonight on the same strategy running on demo. The system clearly shows two positions open and two being closed on more than one occasion with CumulateOrders set to False. In reality it appears that only one position is opened but it makes the results/performance analysis worthless.

    How is this possible?

    Screenshot_1-1.png Screenshot_1-1.png
    #55715 quote
    robertogozzi
    Moderator
    Master

    It might be due to insufficient liquidity, if at the best price you want to buy only a portion is available, then the rest needed to fill the order may be entered at another price.

    That’s mere speculation, I’m not aware of the policy of PRT/IG about this. Also, this should only happen, if ever, in real mode not in demo mode!

     

     

    #55717 quote
    verdi55
    Participant
    Veteran

    I have had problems with this command, too, but the other way around. In one backtest, I noticed that a few orders were NOT carried out, when I had “cumulateorders = false” at the beginning of the code, although they should have been, because there was NO position in the same direction open at the time. When I removed  “cumulateorders = false”, everything went fine. I have not experienced this in live automated trading, though.

    It appears that “cumulateorders = false” is not 100% reliable, and prorealtime should look into this command. 

    For the moment, it may raise safety, when you add to all buy or sellshort commands the following conditions :

     

    If not longonmarket then

    buy 1 contract at market

    endif

    or 

    If not shortonmarket then

    sellshort 1 contract at market

    endif

     

    I have this in all my codes all of the time, without problems. Cumulation does not occur. 

    Nobody and robertogozzi thanked this post
    #55743 quote
    Vonasi
    Moderator
    Master
    If not longonmarket then buy 1 contract at market endif or If not shortonmarket then sellshort 1 contract at market end


    I Have exactly this in the strategy except ‘PerPoint’ instead of ‘Contract’ and yet the strategy still shows that it opened 2 positions on several occasions with CumulateOrders set to False – in both demo and live. So both instructions have been ignored.

    #55746 quote
    verdi55
    Participant
    Veteran

    Can you please try what happens when you leave the “cumulateorders” command away entirely, both with the condition set to “false” and “true” ? In my case, the system made no mistakes, then. Would be very interesting !

    #55747 quote
    verdi55
    Participant
    Veteran

    Of course, I meant for both code cases : cumulation desired or not. 

    #55749 quote
    Nicolas
    Keymaster
    Master

    Bear in mind that code is read from top to bottom, and to test if an order is on market, we need at least 1 bar.

    #55750 quote
    verdi55
    Participant
    Veteran

    Sure, but in the image he shows, there are about 20 bars between the first and the second (cumulative) order.

    #55755 quote
    robertogozzi
    Moderator
    Master

    This should work without having to wait for the closing of the first candle to check if OnMarket:

    IF NOT OnMarket THEN
       IamAlreadyTrading = 0
    ENDIF
    Avg = average[20](close)
    IF close > Avg AND not IamAlreadyTrading THEN
       BUY AT MARKET
       IamAlreadyTrading = 1
    ENDIF
    IF close < Avg AND not IamAlreadyTrading THEN
       SELLSHORT AT MARKET
       IamAlreadyTrading = 1
    ENDIF

     

     

    #55756 quote
    verdi55
    Participant
    Veteran

    Yes, I use something similar in my codes, too. The “IamAlreadyTrading” parameter also avoids that more than one buy or sellshort order will be executed in one bar, if there are many of them. I set the parameter “IamAlreadyTrading” to 0 at the beginning of the next bar and always check for “longonmarket” or “shortonmarket” in addition.

     

    But, nevertheless, there is probably a small bug in the “cumulateorders = false” command, and someone at prorealtime may want to check this. 

    #55757 quote
    Vonasi
    Moderator
    Master
    But, nevertheless, there is probably a small bug in the “cumulateorders = false” command, and someone at prorealtime may want to check this.


    In my mind if CumulateOrders = False is at the start of a code then at no time should it be possible to open two positions at the same time. All the other stuff with Not LongOnMarket and snippets of code to double check we are not already on the market are unnecessary belts and braces. Well they would be unnecessary if I had not seen what I have posted in the image. In real life two positions were not opened but it makes the mind wonder what could possibly happen and it appears that the belts and braces are useless and there is the potential for us to find ourselves with our trousers around our ankles – metaphorically speaking. 

    At the moment it is a backtest and running strategy results bug only – but one I think needs killing ASAP before it gets into someone’s wallet! Backtest and forward test results are useless if they do not do what it says in the code.

    #55762 quote
    robertogozzi
    Moderator
    Master
    In my mind if CumulateOrders = False is at the start of a code then at no time should it be possible to open two positions at the same time. All the other stuff with Not LongOnMarket and snippets of code to double check we are not already on the market are unnecessary belts and braces. Well they would be unnecessary if I had not seen what I have posted in the image. In real life two positions were not opened but it makes the mind wonder what could possibly happen and it appears that the belts and braces are useless and there is the potential for us to find ourselves with our trousers around our ankles – metaphorically speaking. At the moment it is a backtest and running strategy results bug only – but one I think needs killing ASAP before it gets into someone’s wallet! Backtest and forward test results are useless if they do not do what it says in the code.

    Simply true, no matter what!

    #55770 quote
    verdi55
    Participant
    Veteran
    In my mind if CumulateOrders = False is at the start of a code then at no time should it be possible to open two positions at the same time. All the other stuff with Not LongOnMarket and snippets of code to double check we are not already on the market are unnecessary belts and braces. Well they would be unnecessary if I had not seen what I have posted in the image. In real life two positions were not opened but it makes the mind wonder what could possibly happen and it appears that the belts and braces are useless and there is the potential for us to find ourselves with our trousers around our ankles – metaphorically speaking. At the moment it is a backtest and running strategy results bug only – but one I think needs killing ASAP before it gets into someone’s wallet! Backtest and forward test results are useless if they do not do what it says in the code.
    Simply true, no matter what!


    Very true ! So, Nicolas, can you please report this issue to Prorealtime ?

    “cumulateorders = false” obviously has 2 different issues :

    Sometimes, cumulative positions ARE opened, although they should not, and sometimes “cumulateorders = false” suppresses correct orders that should be executed, but are not executed in reality. Not good for a command that suggests reliability !

    #55783 quote
    Vonasi
    Moderator
    Master

    It is still doing it. I just checked in to my demo account and the same strategy has opened lots of bets today with double positions despite CumulateOrders = False! Screenshot attached. I have stopped the live version as it made a big loss yesterday during the bank rate decisions which does not appear on the demo version. Very worrying as up until now the two versions have backtested identically on PRT Demo and PRT Complete. I’m guessing the difference in returns is due to the fixed spread on backtesting and the varying spread on live testing (another strategy hits the dirt due to that damned fixed backtesting spread!) – but this does not explain the multiple positions at all. 

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

Two positions with CumulateOrders = False


ProOrder: Automated Strategies & Backtesting

New Reply
Author
author-avatar
Vonasi @vonasi Moderator
Summary

This topic contains 13 replies,
has 4 voices, and was last updated by Vonasi
8 years, 2 months ago.

Topic Details
Forum: ProOrder: Automated Strategies & Backtesting
Language: English
Started: 12/14/2017
Status: Active
Attachments: 2 files
Logo Logo
Loading...