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 Mindset, 04-21-2026, 06:46 AM
      0 responses
      89 views
      0 likes
      Last Post Mindset
      by Mindset
       
      Started by M4ndoo, 04-20-2026, 05:21 PM
      0 responses
      135 views
      0 likes
      Last Post M4ndoo
      by M4ndoo
       
      Started by M4ndoo, 04-19-2026, 05:54 PM
      0 responses
      68 views
      0 likes
      Last Post M4ndoo
      by M4ndoo
       
      Started by cmoran13, 04-16-2026, 01:02 PM
      0 responses
      119 views
      0 likes
      Last Post cmoran13  
      Started by PaulMohn, 04-10-2026, 11:11 AM
      0 responses
      69 views
      0 likes
      Last Post PaulMohn  
      Working...
      X