Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Help Developing Average Price Points Indicator

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

    Help Developing Average Price Points Indicator

    Hi all,

    I want to develop a very basic indicator that draws a horizontal line on the live chart based on the following criteria.

    When: Starting at session open after every X bars (resetting at session close)
    What: The average price of the previous X bars

    Distance of horizontal line drawn should be equal to number of X bars chosen.

    All X variables should be equal.


    For example, 5 minute chart, X bar variable set to 12, instrument ES


    I would want the indicator to start running at 6pm eastern (session open) and after the first 12 bars (1 hour) a horizontal line stretching right the length of the next 12 bars will be drawn at the average price of the first/previous 12 bars (6 to 7pm) I would like the indicator to continue to run until session close drawing a new horizontal line every 12 bars.

    All horizontal lines should stay visible.


    I'm watching videos and looking at other indicator code as guidance, but I am having a rough time writing my own code.

    Could someone help me get started?


    Thank you so much,
    Mark

    #2
    Welcome to the forums mlprice!

    If you are new to NinjaScript and drawing with NinjaScript, I may suggest using the Strategy Builder to generate syntax to draw on the chart. You can click View Code to see the generated C# code.

    Strategy Builder 301 (publicly available) - https://www.youtube.com/watch?v=_KQF2Sv27oE

    Drawing on a chart - https://ninjatrader.com/support/help...ToDrawOnAChart

    Once familiar you can reference further drawing overloads in the Help Guide.

    Drawing - https://ninjatrader.com/support/help...t8/drawing.htm

    You will want to use Draw.Line to draw a horizontal line over X number of bars since Draw.HorizontalLine creates a horizontal line that does not end.

    Having something done every 12 bars would be done most easily using the modulus operator (%.) For example, you could create a condition like:

    if (CurrentBar % 12 == 0)
    {
    // Do something here
    }

    and this action would be taken every 12 bars.

    The indicator can be applied a data series with your desired Trading Hours template to have the indicator only operate between certain time frames. You could also consider adding time checks within the code.

    Time checks (Strategy Builder) - https://ninjatrader.com/support/help...ateTimeFilters

    ToTime (NinjaScript) - https://ninjatrader.com/support/help...8/?totime.htm\

    We look forward to assisting.

    Comment


      #3
      Thanks for the assistance Jim,

      I will continue to try and write the code and will post back with more questions as they come up.

      Comment

      Latest Posts

      Collapse

      Topics Statistics Last Post
      Started by Geovanny Suaza, 02-11-2026, 06:32 PM
      0 responses
      581 views
      0 likes
      Last Post Geovanny Suaza  
      Started by Geovanny Suaza, 02-11-2026, 05:51 PM
      0 responses
      338 views
      1 like
      Last Post Geovanny Suaza  
      Started by Mindset, 02-09-2026, 11:44 AM
      0 responses
      103 views
      0 likes
      Last Post Mindset
      by Mindset
       
      Started by Geovanny Suaza, 02-02-2026, 12:30 PM
      0 responses
      554 views
      1 like
      Last Post Geovanny Suaza  
      Started by RFrosty, 01-28-2026, 06:49 PM
      0 responses
      552 views
      1 like
      Last Post RFrosty
      by RFrosty
       
      Working...
      X