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 tkaboris, Today, 05:13 PM
        0 responses
        2 views
        0 likes
        Last Post tkaboris  
        Started by GussJ, 03-04-2020, 03:11 PM
        16 responses
        3,281 views
        0 likes
        Last Post Leafcutter  
        Started by WHICKED, Today, 12:45 PM
        2 responses
        19 views
        0 likes
        Last Post WHICKED
        by WHICKED
         
        Started by Tim-c, Today, 02:10 PM
        1 response
        10 views
        0 likes
        Last Post NinjaTrader_ChelseaB  
        Started by Taddypole, Today, 02:47 PM
        0 responses
        5 views
        0 likes
        Last Post Taddypole  
        Working...
        X