Announcement

Collapse

Looking for a User App or Add-On built by the NinjaTrader community?

Visit NinjaTrader EcoSystem and our free User App Share!

Have a question for the NinjaScript developer community? Open a new thread in our NinjaScript File Sharing Discussion Forum!
See more
See less

Partner 728x90

Collapse

Range Draw Line

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

    Range Draw Line

    I am trying to draw a line if the range is within X number of pips for Y number of bars. So after 10 bars if:

    if(MAX(High,10) - MIN(Low,10)[0] <= 20 pips)
    {
    draw a line at the Max high over the prior 10 bars until the price crosses above that high or below the low. The drawing can start at the beginning of the 10 bars that satisfy the condition or at the bar where the condition evaluates as true.
    }

    I would also like this to only look at the current days bars and not rolling overnight. would this be if(today ...) or totime ...?

    Any help is appreciated.

    Cheers!

    #2
    Hi CableTrader007,

    Welcome to the NinjaTrader Forums!

    I will be glad to help you with this.

    I need to research this and will reply soon.
    Paul H.NinjaTrader Customer Service

    Comment


      #3
      Hello CableTrader007,

      In terms of setting up your code, after OnBarUpdate you would want to check to make sure you have enough bars loaded before testing the last 10 bars. This is done by:

      Code:
      if (CurrentBar < 11 ) return ;  // Do not process the first 10 bars loaded.
      if you want to only work with the right edge data and don't care about the historical data (Historical data = data already loaded on chart) then after OnBarUpdate you would want to add:

      Code:
      if (Historical)  return ;  // Do not process old data.
      This means the indicator will only process live data (Live data = simulated data feed, actual data feed or market replay data). Here is a link to the help guide on Historical: http://www.ninjatrader.com/support/h...historical.htm

      Interms of evaluating the range of the last 10 bars I suggest this line of code:

      Code:
      if ((MAX(High,10)[0] - MIN(Low,10)[0]) <= 20 *TickSize)
      
      {
      
      // do the next thing in your program such as saving the Max and the Min values for later evaluation against a breakout price move.
      
      }
      Note that you can make the 20 (and/or the 10) an integer variable that you could adjust for different instruments or conditions.

      TickSize is a Ninjascript variable that will give you the minimum price movement on the instrument (so it self adjusts per instrument).

      Here is a reference to the language section of the help guide that has much to offer: http://www.ninjatrader.com/support/h...nt7/index.html

      This should get you started. Please let me know what questions you have.
      Paul H.NinjaTrader Customer Service

      Comment


        #4
        Paul:

        Thank you for your help. I have the range part figured out but my question above was looking for information on starting and stopping drawing the line.

        1) how do I draw a line when the range condition is true where it
        2) stops drawing when the price crosses above the line?


        Lastly, how to only look at the current day?

        Cheers!

        Comment


          #5
          Hi CableTrader007,

          Thanks for your reply,

          You can certainly add a time check such as:
          Code:
           
          if (ToTime(Time[0]) > ToTime(8,0, 0) && (ToTime(Time[0] < ToTime (15,0,0))
           { 
          // do something
           }
          The code says if time is > 8:00 AM and is less then 15:00 (3:00PM). Here is a link to ToTime: http://www.ninjatrader.com/support/h...tml?totime.htm

          If in the code after the min/max evaluation you should save the min max values, then you can use logic to verify if the High of the current bar (High[0]) is > the max value saved or if the Low of the current bar (Low[0]) is lower than the min value saved. It would be good to put boolean logic in your min/max evaluation statement so that you only execute it once until either the min or the max has been exceeded.

          You can use the DrawLine method as found in the language reference: http://www.ninjatrader.com/support/h..._reference.htm You can use the save min and max values to draw the line and as you suggest start 10 bars back. If you have logic that says price has not crossed the lines, then redraw the same line but make it 11 bars long, etc. until the line is crossed.

          Please let me know if I can be of further assistance.
          Paul H.NinjaTrader Customer Service

          Comment

          Latest Posts

          Collapse

          Topics Statistics Last Post
          Started by cre8able, Today, 01:01 PM
          0 responses
          2 views
          0 likes
          Last Post cre8able  
          Started by manitshah915, Today, 12:59 PM
          0 responses
          2 views
          0 likes
          Last Post manitshah915  
          Started by ursavent, Today, 12:54 PM
          0 responses
          3 views
          0 likes
          Last Post ursavent  
          Started by Mizzouman1, Today, 07:35 AM
          3 responses
          17 views
          0 likes
          Last Post NinjaTrader_Gaby  
          Started by RubenCazorla, Today, 09:07 AM
          2 responses
          13 views
          0 likes
          Last Post NinjaTrader_ChelseaB  
          Working...
          X