Announcement

Collapse
No announcement yet.

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 t.kelly4149, Today, 05:36 PM
          1 response
          8 views
          0 likes
          Last Post bltdavid  
          Started by SilverSurfer1, Today, 06:29 PM
          0 responses
          16 views
          0 likes
          Last Post SilverSurfer1  
          Started by trader3000a, Today, 01:06 PM
          1 response
          9 views
          0 likes
          Last Post NinjaTrader_ShawnB  
          Started by marcus2300, Today, 11:45 AM
          3 responses
          31 views
          0 likes
          Last Post marcus2300  
          Started by pel11, Today, 11:06 AM
          0 responses
          13 views
          0 likes
          Last Post pel11
          by pel11
           
          Working...
          X