Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Strategy to draw a sign on a chart.

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

    Strategy to draw a sign on a chart.

    Hello everyone,

    I would like to ask if there is a way to create a simple strategy that draws a sign on the chart (i.e. any kind of mark or vertical line) when 200 bars have passed since the price last touched the 800 simple moving average (SMA). Could anyone help me?

    Thank you in advance,

    Gianluca.

    #2
    Hello Gianluca,

    Thanks for the post.

    Yes, this is possible with custom programming in NinjaScript. All the drawings you would do manually can be drawn by code as well.

    There is built in function MRO() that can be used to return the number of bars since the condition you specify.
    Last edited by NinjaTrader_RyanM1; 10-17-2011, 09:27 AM.
    Ryan M.NinjaTrader Customer Service

    Comment


      #3
      Originally posted by NinjaTrader_RyanM View Post
      Hello Gianluca,

      Thanks for the post.

      Yes, this is possible with custom programming in NinjaScript. All the drawings you would do manually can be drawn by code as well.

      There is built in function MRO() that can be used to return the number of bars since the condition you specify.
      http://www.ninjatrader.com/support/h...urence_mro.htm
      Hello Ryan,
      thank you for your reply.
      Does the code look like this?

      int barsAgo = MRO(delegate {return GetCurrentBid() == SMA(800)[0];}, 1, 199);
      if (barsAgo > -1)
      Print("200 bars since last touched 800 SMA");

      sorry for asking but my programming skills are almost non-existent ;-)

      thank you,

      John.

      Comment


        #4
        Hi John,

        The main issue with that expression is that you're using GetCurrentBid() to check historical bars. This is a real time only value, so when used historically it substitutes Close[0] instead.

        Then, the condition you may be going for is when barsAgo == 200 or >= 200. BarsAgo > -1 tells it that there has been at least one occurrence of the condition, but could have happened anywhere. You will likely need to change your lookback to maybe 201 to check all the bars of your condition.

        Your condition deals with a lot of bars used in calculation and a large lookback, so probably worthwhile to get a simple example working first with MRO and then start adding complexity and more bars.

        Anytime you need to calculate more than 256 bars, will need to set MaximumBarsLookBack to infinite.
        Ryan M.NinjaTrader Customer Service

        Comment

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by argusthome, 03-08-2026, 10:06 AM
        0 responses
        65 views
        0 likes
        Last Post argusthome  
        Started by NabilKhattabi, 03-06-2026, 11:18 AM
        0 responses
        41 views
        0 likes
        Last Post NabilKhattabi  
        Started by Deep42, 03-06-2026, 12:28 AM
        0 responses
        23 views
        0 likes
        Last Post Deep42
        by Deep42
         
        Started by TheRealMorford, 03-05-2026, 06:15 PM
        0 responses
        26 views
        0 likes
        Last Post TheRealMorford  
        Started by Mindset, 02-28-2026, 06:16 AM
        0 responses
        52 views
        0 likes
        Last Post Mindset
        by Mindset
         
        Working...
        X