Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Strategy to draw only on current bars

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

    Strategy to draw only on current bars

    Hi,

    I understand my question is a little complicated, and I cannot post all my code, but I'll try to explain as well as I can my problem. I have a strategy that draws and relies on RegionHighlightY zones on the chart, that I use to manage entries and exits. Everything works well, except that when the markets are closed, I would like to set up my zone in advance for the next morning, but if I leave my strategy as-is, they are not appearing until the first bar of the market open.

    Some details:
    - the strategy needs to work in Calculate.OnPriceChange
    - at first I was using
    Code:
    if (State == State.Historical) {return;}
    to prevent the strategy to draw everywhere when not in real-time, but that part prevents me to set up in advance my region when the markets are closed
    - I changed that part for
    Code:
    if ((CurrentBar < Count-1)
    , but it's causing me issues I didn't have before, saying there is no instance of an object (most likely a drawing object missing somewhere)
    - if I could only keep the strategy working on state realtime it would be better, because on the historical bars it is very slow before reaching realtime.

    So the strategy works and I understand it might be difficult for you to give hints without seeing the rest of the code, but if there's something that crosses your mind I'd be happy to try it!

    Thanks

    #2
    Hi RT001, thanks for posting. Depending on what kind of bar you are using on the chart, you can look for a certain time stamp on the current bar and perform the draw at the end of the session (or some time very close to the end). See the SessionIterator:



    This will let you get the session to begin and end time, then you can set up a condition that will execute when a certain timestamp is seen or when within in a certain time frame.

    This example might also be helpful:

    https://ninjatrader.com/support/help...to_limit_t.htm - time filter

    Kind regards,
    -ChrisL

    Comment


      #3
      Nice! Thanks for your help Chris!

      Comment

      Latest Posts

      Collapse

      Topics Statistics Last Post
      Started by NullPointStrategies, Today, 05:17 AM
      0 responses
      50 views
      0 likes
      Last Post NullPointStrategies  
      Started by argusthome, 03-08-2026, 10:06 AM
      0 responses
      126 views
      0 likes
      Last Post argusthome  
      Started by NabilKhattabi, 03-06-2026, 11:18 AM
      0 responses
      69 views
      0 likes
      Last Post NabilKhattabi  
      Started by Deep42, 03-06-2026, 12:28 AM
      0 responses
      42 views
      0 likes
      Last Post Deep42
      by Deep42
       
      Started by TheRealMorford, 03-05-2026, 06:15 PM
      0 responses
      46 views
      0 likes
      Last Post TheRealMorford  
      Working...
      X