Strategy Profit not working in realtime

Viewing 10 posts - 1 through 10 (of 10 total)
  • Author
    Posts
  • #194829 quote
    Amin1233
    Participant
    Junior

    Hi I have the code below to stop opening new positions when one of the positions in the day closed with loss more than 200 or profit more than 350.

    It works perfectly in the proback test but when I execute it in IG in real market it still open position even after the loss happens. I am not sure what I am missing here?

     

    Please note the code works when I am in positive and will not open new position after hitting 350. Could it be because of negative number in the strategy profit somehow mess up the formula?

    This is my code:

     

    If time=100000 then

    MyProfit=STRATEGYPROFIT[0]

    endif

    if time>100000 and time <150000 and countoflongshares<90 and range[1]<14 and countofshortshares<90 and Strategyprofit[0]>MyProfit-200 and Strategyprofit[0]<MyProfit+350

     

    then  ……..

    #194830 quote
    Amin1233
    Participant
    Junior

    I am starting my code with : once myprofit=0 at the begining, could this be the reason?

    #194831 quote
    robertogozzi
    Moderator
    Master

    You have to use a variable as a signal that you don’t want to trade any longer that day (I will use TradeOK, setting to 1 at the beginning of each day), as soon as your strategy detects a loss of X, it will set TradedOK to 0. Your strategy will have to use TradeOK to tell whether trading or not:

    ONCE TradeOK = 1
    ONCE MyLimit = 200
    IF InstraDayBarIndex = 0 THEN
       TradeOK = 1
    ENDIF
    IF (StrategyProfit[1] - StrategyProfit) >= MyLimit THEN
       TradeOK = 0
    ENDIF
    IF MyLongConditions AND TradeOK THEN
       BUY AT MARKET
    ENDIF
    #194835 quote
    Amin1233
    Participant
    Junior

    thanks, so why my code worked in the probacktest but not in reallife?

    #194838 quote
    robertogozzi
    Moderator
    Master

    I have no idea without testing the complete code used.

    #194840 quote
    Amin1233
    Participant
    Junior

    since I want to look at the whole day performance , should I change your code to the below to not only check with the last bar but for the whole day from morning:

     

    ONCE TradeOK = 1
    ONCE MyLimit = 200
    IF time = 100000 THEN
    TradeOK = 1
    Myprofit=strategyprofit
    ENDIF
    IF (Myprofit- strategyprofit) >= MyLimit THEN
    TradeOK = 0
    ENDIF

    #194845 quote
    Amin1233
    Participant
    Junior

    Also will this still work if your strategy starts in negative. What I noticed is that if my total strategy profit is positive then next day the code works and when I have lost it stops but when the strategy was already in negative from last day the code somehow can’t calculate the negative minus negative and stop working

    #194848 quote
    robertogozzi
    Moderator
    Master

    Try replacing line 6 with:

    IF (abs(StrategyProfit - StrategyProfit[1]) >= MyLimit) and (StrategyProfit < StrategyProfit[1]) THEN
    #194855 quote
    Amin1233
    Participant
    Junior

    Thanks, but I need the strategy profit be calculated for the total of positions from 10:00 am. In your code if one of the positions closes in negative the strategy will stop because it will always compare the current bar with the last bar not the total strategyprofit from 10:00 am

    #194861 quote
    robertogozzi
    Moderator
    Master

    You code above works fine for me. Why don’t you think it’s correct?

    Try appending some GRAPH instructions to monitor data candle by candle:

    ONCE TradeOK = 1
    ONCE MyLimit = 200
    IF time = 100000 THEN
       TradeOK = 1
    Myprofit=strategyprofit
    ENDIF
    IF (Myprofit- strategyprofit) >= MyLimit THEN
       TradeOK = 0
    ENDIF
    if average[20] crosses over average[200] and not onmarket then
       buy at market
    endif
    set target pprofit 200
    set stop   ploss   50
    graph MyProfit                 coloured(255,0,0,255)
    graph StrategyProfit           coloured(0,255,0,255)
    graph Myprofit- strategyprofit
    Amin1233 thanked this post
Viewing 10 posts - 1 through 10 (of 10 total)
  • You must be logged in to reply to this topic.

Strategy Profit not working in realtime


ProOrder: Automated Strategies & Backtesting

New Reply
Author
author-avatar
Amin1233 @amin1233 Participant
Summary

This topic contains 9 replies,
has 2 voices, and was last updated by robertogozzi
3 years, 8 months ago.

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