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 Option Whisperer, Today, 09:55 AM
        0 responses
        4 views
        0 likes
        Last Post Option Whisperer  
        Started by geddyisodin, 04-25-2024, 05:20 AM
        8 responses
        58 views
        0 likes
        Last Post NinjaTrader_Gaby  
        Started by halgo_boulder, 04-20-2024, 08:44 AM
        2 responses
        22 views
        0 likes
        Last Post halgo_boulder  
        Started by mishhh, 05-25-2010, 08:54 AM
        19 responses
        6,189 views
        0 likes
        Last Post rene69851  
        Started by gwenael, Today, 09:29 AM
        0 responses
        5 views
        0 likes
        Last Post gwenael
        by gwenael
         
        Working...
        X