Strategyprofit Bug (doesnt work when in negative)

Viewing 12 posts - 1 through 12 (of 12 total)
  • Author
    Posts
  • #196211 quote
    Amin1233
    Participant
    Junior
    ONCE TradeOK = 1
    ONCE MyLimit = 300
    IF time = 100000 THEN
    TradeOK = 1
    Myprofit=strategyprofit
    ENDIF
    IF (Myprofit- strategyprofit) >= MyLimit THEN
    TradeOK = 0
    ENDIF

    Hi I have been having this issue for a longtime. The result from backtest does not match the actual performance.

    I have the below code where if the Strategy profit from 10:00 am fall below 300 I would like to stop orders for the rest of the day.

    It works perfectly in the probacktest but as you can see in the below pictures: the backtest does not place order however in the reality it has placed an order.

    In the picture with the extra order (that happened in the real market)  Ihave just initiated the strategy so the “myprofit” from yesterday was “0” and when the first order is closed in loss the strategyprofit become negative and the formula will be “0- (-400) = 400 which is bigger than 300 and the system should stop for the day. My theory is that there is a bug in the Prorealtime that where the startegy profit turns negative the formula doesnot work.

    Backtest.png Backtest.png Actual-Market.png Actual-Market.png
    #196215 quote
    PeterSt
    Participant
    Master
    ONCE TradeOK = 1
    ONCE MyLimit = 300
    IF time = 100000 THEN
      TradeOK = 1
      Myprofit=strategyprofit   // E.g. -500.
    ENDIF
    
    // Now x bars later you lost two trades and StrategyProfit = -700.
    
    IF (Myprofit- strategyprofit) >= MyLimit THEN
    // IF -700 >= -500 then   // This returns False.
      TradeOK = 0   // So TradeOK remains 1.
    ENDIF
    
    // And this is what you would be having for a long time. :-)

    Amin, If you try to read my comments say 5 times, you are sure I am right but that something must be wrong with my thinking. Still I am right so your code is wrong. 🙂
    Next you might be set on the wrong foot because the backtest shows that it works. But this does not tell much without the proof that the backtest did not perform other trades in advance of what you showed.

    At the bottom of your code add this line :

    Graph StrategyProfit

    And you will see where it goes off, if so. Thus, I was not saying that your statement is wrong. Only that your code is (unless I just see it wrongly).

    Additionally, it looks like you add position underway. That is a good recipe to not understand what’s happening. *And* mind you please, backtest report data deals differently with that than Live (or Demo-Live). So this confuses (just look at the number of bars of the 2nd trade and how that reports).

    #196221 quote
    Amin1233
    Participant
    Junior

    Hi Peter

    Thanks for your reply , This is what happened today:

    ONCE TradeOK = 1
    ONCE MyLimit = 300
    IF time = 100000 THEN
    TradeOK = 1
    Myprofit=strategyprofit // Today = 0
    ENDIF

    // Now x bars later you lost one trade and StrategyProfit = -400.

    IF (Myprofit- strategyprofit) >= MyLimit THEN

    // IF 0 -(-400) >300 then // This should return true. TradeOK = 0 // So TradeOK should be 0 and stop trading.
    ENDIF

    Not sure what you mean in your example.But  it returns False in reality . However in the backtest because the strategyprofit was in positive it work correctly.

    #196226 quote
    PeterSt
    Participant
    Master

    // IF 0 -(-400) >300 then // This should return true.

    I am really sorry, but it doesn’t. -400 is smaller than +300. Not larger (>).
    🙂

    #196227 quote
    Amin1233
    Participant
    Junior

    This is the math issue in the system then because -(-400)=+400

    eg.   y= 100-x

    if x=-400 then

    y = 100 -(-400) = 100 + 400 = 500 which is > 300

    #196229 quote
    PeterSt
    Participant
    Master

    Haha, no … you changed the code (but your last post would be correct).

    Even if I could wonder what the PRT language would do with –400 (I have not the best hopes for that turning out to be +400, you are telling the system something quite else :

    Suppose we change this

    If 0 -(-400) >300

    into this

    If 0 -(-400-200)  > … then this will work out to

    If 0- (-600) > …

    So all (ad all programming languages) anticipate that. Anticipate because it is done all over the place.
    According to you it would work out to something like

    If  0-(+400-200) =

    only because you see

    0-(-


    If I made mistakes or typos somewhere, I blame you. 🙂
    I just can’t think in explaining the obvious.

    #196230 quote
    robertogozzi
    Moderator
    Master

    Your code seems to work perfectly (tested on DAX, 30-minute TF):

    ONCE TradeOK = 1
    ONCE MyLimit = 300
    IF time = 100000 THEN
       TradeOK = 1
       Myprofit=strategyprofit
    ENDIF
    IF (Myprofit- strategyprofit) >= MyLimit THEN
       TradeOK = 0
    ENDIF
    if TradeOK AND close crosses over average[100] and Not OnMarket then
       buy at market
       set target pprofit 400
       set stop ploss 100
    endif
    graph StrategyProfit
    graph MyProfit
    graph (Myprofit - strategyprofit)
    graph TradeOK
    #196232 quote
    Amin1233
    Participant
    Junior

    Hi Robert. My code works perfectly in backtest but in real market I have issue with negative strategyprofit. Please have a look at my screenshots that shows the backtest vs real market

    #196234 quote
    JS
    Participant
    Senior
    ONCE TradeOK = 1
    ONCE MyLimit = 300
    
    IF time = 100000 THEN
    TradeOK = 1
    Myprofit=strategyprofit
    ENDIF
    IF (StrategyProfit - MyProfit) < -MyLimit THEN
    TradeOK = 0
    ENDIF

    Hi @Amin1233

    You can try this:

    robertogozzi thanked this post
    #196244 quote
    JS
    Participant
    Senior

    @PeterSt

    0 – (-400) = 400

    0 – (-400) > 300  (true)

    #196248 quote
    PeterSt
    Participant
    Master

    Looking for the Blush smiley !

    JS thanked this post
    image_2022-06-28_043128603.png image_2022-06-28_043128603.png
    #197103 quote
    Amin1233
    Participant
    Junior

    Hi Peter, I changed it to your code and it didn’t work. Last night it happened again and after loss still opened new position. I also tried simply if strategyprofit<my profit. This one añdo didn’t work. So there is absolutely a bug here .

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

Strategyprofit Bug (doesnt work when in negative)


ProOrder: Automated Strategies & Backtesting

New Reply
Author
author-avatar
Amin1233 @amin1233 Participant
Summary

This topic contains 11 replies,
has 4 voices, and was last updated by Amin1233
3 years, 7 months ago.

Topic Details
Forum: ProOrder: Automated Strategies & Backtesting
Language: English
Started: 06/27/2022
Status: Active
Attachments: 3 files
Logo Logo
Loading...