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

Add() question

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

    Add() question

    Hello,
    I'm attempting to add a 2 range bars object to my indicator for certain calculations. The primary bars object is a 4 range bar. Here is my code:
    Code:
     
    protected override void Initialize()
            {
                Add(PeriodType.Range,2);
            }
    protected override void OnBarUpdate()
            {
                double mAverage = SMA(sMA)[0];
                //in 4 Range
                if(Close[0]<= Open[0] && Close[1] > mAverage && Close[0] <= mAverage)
                {
                    BarColor = Color.Yellow;
                }
                //in 2 Range
                if(Closes[0][1]<= Opens[0][1] && Closes[1][1] > mAverage && Closes[0][1] <= mAverage)
                {
                    DrawDot("tag1", true, 0, High[0] + 1, Color.Red);
    
                }
    Everything worked fine for the primary bars object. When I added the 2nd I'm getting yellow bars that correspond to a 2 range chart, but I didn't ask for yellow bars I asked for a red dot. Can anyone help me out with this?
    Thanks

    #2
    1) Look up 'BarsInProgress' in the help or a forum search here.

    The 4 range should be 0, and the 2 range should be 1.

    Comment


      #3
      Thanks for your help sledge I changed my code to check for BarsInProgress. However I'm still not getting the dot on the 2 range. The Print() is showing that the condition is true in the right spots but no red dot. Correction there is a red dot on the very last bar of my chart. Does anyone have any suggestions?
      Code:
       protected override void Initialize()
              {
                  Overlay                = true;
                  Add(PeriodType.Range,2);
              }
      protected override void OnBarUpdate()
              {
                  double mAverage = SMA(sMA)[0];
                  //in 4 Range
                  if (BarsInProgress == 0)
                  {
                      if(Close[0]<= Open[0] && Close[1] > mAverage && Close[0] <= mAverage)
                      {
                          BarColor = Color.Yellow;
                      }
                  }
                  //in 2 Range
                  if (BarsInProgress == 1)
                  {
                      if(Close[0]<= Open[0] && Close[1] > mAverage && Close[0] <= mAverage)
                      {
                          DrawDot("tag1", true, 0, Close[0] + 1, Color.Red);
                          Print(Time[0].ToString());
                      }
                  }

      Comment


        #4
        Perhaps not a solution, but please first add this statement at the beginning of OnBarUpdate:

        if (CurrentBars[0] == 0 || CurrentBars[1] == 0) return;
        Second, is the moving average based on the primary or secondary series?

        Thanks.
        Pi
        Last edited by ninZa; 12-29-2014, 11:04 PM.
        ninZa
        NinjaTrader Ecosystem Vendor - ninZa.co

        Comment


          #5
          CaptainAmericaXX, I would expect the red dot only seen one time now, for the last time the condition to draw / update was true. That's because of your draw object tag - "tag1"

          Try using for example a tag id like "tag1 + CurrentBar", so you create unique id's for each object you want to show.
          BertrandNinjaTrader Customer Service

          Comment

          Latest Posts

          Collapse

          Topics Statistics Last Post
          Started by ghoul, Today, 06:02 PM
          2 responses
          13 views
          0 likes
          Last Post ghoul
          by ghoul
           
          Started by jeronymite, 04-12-2024, 04:26 PM
          3 responses
          44 views
          0 likes
          Last Post jeronymite  
          Started by Barry Milan, Yesterday, 10:35 PM
          7 responses
          20 views
          0 likes
          Last Post NinjaTrader_Manfred  
          Started by AttiM, 02-14-2024, 05:20 PM
          10 responses
          180 views
          0 likes
          Last Post jeronymite  
          Started by DanielSanMartin, Yesterday, 02:37 PM
          2 responses
          13 views
          0 likes
          Last Post DanielSanMartin  
          Working...
          X