Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Processing strategy problem

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    Processing strategy problem

    Good morning,
    I would need that my strategy in reality mode checks only the candles starting from the moment I initialized it,
    example if it activates it on 15/02/2023 at 15:00 he must consider the candles only from this moment on,
    I have made several attempts but have not given the hoped for outwards, below part of my code that does not work:
    protected override void OnBarUpdate()
    {

    if (CurrentBars[0] < BarsRequiredToTrade || CurrentBars[0] < 0 || CurrentBars[1] < 0)
    return;

    if (BarsInProgress == 0)
    {

    if (State != State.Historical)
    {
    if (Count - 1 == CurrentBar && Bars.IsFirstBarOfSession )
    {
    // i want enter here only when last bar on the right of the screen it's loaded
    Check();
    }

    }
    else
    {

    Check();

    }
    }


    }​

    Could you help me?
    Regards

    #2
    Hello, thanks for writing in. If you only want to run code on the last historical bar use this code (do not run it within if (State != State.Historical), since it is a historical bar)

    Code:
    if (BarsArray[0].Count - 2 == CurrentBar)
                        Print("last bar");​

    Comment


      #3
      Thanks for reply,
      this code work in real time or backtest?
      My goal is to discriminate when the strategy is in real time and when it is in the backtest, and when it is in real time to start making it work and then count them the candles only from the moment in which it was activated​ example if it activates it on 15/02/2023 at 15:00 he must consider the candles only from this moment on, my system work on tick.
      Last edited by termi_80; 02-15-2023, 02:48 PM.

      Comment


        #4
        Hi termi_80, To determine if the strategy is in backtest mode, the object will be in State.Historical, then State.Transition will be seen in OnStateChanged once the transition from historical to Realtime state occurs. If your script runs OnEachTick you also need to enable Tick Replay and use IsFirstTickOfBar to get the very first tick of the session.

        Comment

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by NullPointStrategies, Yesterday, 05:17 AM
        0 responses
        56 views
        0 likes
        Last Post NullPointStrategies  
        Started by argusthome, 03-08-2026, 10:06 AM
        0 responses
        132 views
        0 likes
        Last Post argusthome  
        Started by NabilKhattabi, 03-06-2026, 11:18 AM
        0 responses
        73 views
        0 likes
        Last Post NabilKhattabi  
        Started by Deep42, 03-06-2026, 12:28 AM
        0 responses
        45 views
        0 likes
        Last Post Deep42
        by Deep42
         
        Started by TheRealMorford, 03-05-2026, 06:15 PM
        0 responses
        49 views
        0 likes
        Last Post TheRealMorford  
        Working...
        X