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

Draw objects disappearing

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

    Draw objects disappearing

    Hello,
    I created a simple indicator using the DrawDiamond(), but the diamonds do not appear on all occurrences and then disappear when the chart is scrolled. Here is my code.

    currenthigh = MRO(delegate {return High[0] == CurrentDayOHL().CurrentHigh[0];}, 1, 5);
    if (currenthigh > -1
    && RValueCharts(Color.Blue, 3, 3).VClose[0] <= -4
    )
    {
    DrawDiamond("DailyHighReversal",true,0,Low[0]-TickSize-1,Color.DarkMagenta);
    }

    currentlow = MRO(delegate {return Low[0] == CurrentDayOHL().CurrentLow[0];}, 1, 5);
    if (currentlow > -1
    && RValueCharts(Color.Blue, 3, 3).VClose[0] >= 4
    )
    { DrawDiamond("DailyLowReversal",true,0,High[0]+TickSize+1,Color.BlueViolet);
    }
    Any idea as to why the diamonds would disappear? Thanks

    #2
    Hello CaptainAmericaXX,

    Thank you for your post

    Please make sure you are attaching this object to each CurrentBar that the condition is true. Your current code will only display the Diamond on the last occurrence.

    Please try the modified code:

    Code:
    currenthigh = MRO(delegate {return High[0] ==  CurrentDayOHL().CurrentHigh[0];}, 1, 5);
                if (currenthigh > -1
                    && RValueCharts(Color.Blue, 3, 3).VClose[0]  <= -4 
                    )
                {
                    DrawDiamond("DailyHighReversal" + CurrentBar,true,0,Low[0]-TickSize-1,Color.DarkMagenta);
                }
    Noticed I added "+ CurrentBar to the DailyHighReversal string. You'd want to repeat this for the DailyLow condition/string as well.

    This will create unique tags in order to include the history.
    Last edited by NinjaTrader_Matthew; 05-27-2011, 11:51 AM.
    MatthewNinjaTrader Product Management

    Comment


      #3
      Matthew,
      Thank you for the reply. I did as you suggested, but there was no change. The diamonds are still not printing on all occurrences and then disappearing when the chart is scrolled. Any other suggestions? Thanks.

      Comment


        #4
        Oh I figured out what was wrong. I included the CurrentBar in the string. It has to be "DailyHighReversal" + CurrentBar. Thanks for the Help.

        Comment


          #5
          A new issue

          I have a new issue with the above code that I wrote. Wondering if anyone has a suggestion. I programmed the MRO() to have a lookback of 5 bars so within those 5 bars a diamond is printed every time the RValueCharts(Color.Blue, 3, 3).VClose[0] <= -4. I would like only the first occurrence to print within that 5 bar lookback. Any suggestions? Thanks.

          Comment


            #6
            CaptainAmericaXX,

            I would suggest using CrossBelow() rather than <= -4.

            When using a CrossAbove / CrossBelow condition, it will only print on the instant the condition is met and not the additional instances when the condition is true.

            MatthewNinjaTrader Product Management

            Comment


              #7
              Thank you Matthew that was a good suggestion and did work in some situations. However there are times when the VChart will, for instance, close < -4[2], -3.8[1], and -4[0]. So it crosses below -4 twice within that original 5 bar lookback period. I think I need a code that will only allow one occurrence during a lookback period and then reset after that period. Unfortunately I don't know how to write that. Any suggestions.

              Comment


                #8
                You can do this by capturing CurrentBar at the time of a condition, and working this captured value into your condition. I would move away from MRO for this.

                #region Variables
                private int myConditionBar;
                #endregion

                if (Close[0] > Open[0] && CurrentBar - myConditionBar >=5)
                {
                myConditionBar = CurrentBar;
                //DrawHere
                }
                Ryan M.NinjaTrader Customer Service

                Comment


                  #9
                  Ryan,
                  Thank you for the reply. I'm sorry for being a little slow, but that completely went over my head. I'm using the MRO because I need to capture the instance of the High/Low and then use that instance with the VChart close. I'm not sure how to work your suggestion into the equation. Could you throw me another bone?

                  Comment


                    #10
                    The CurrentBar - myConditionBar >=5 check tells the script not to check until 5 bars have passed since identifying an occurrence.

                    I would try it and see if it works for you. Just replace Close[0] > Open[0] with your custom condition, and add your draw statements.
                    Ryan M.NinjaTrader Customer Service

                    Comment


                      #11
                      Ryan,
                      I'm sorry, but I'm stumped I just don't understand how to put these things together. I'm sure it's simple I'm just not grasping it. Here's my code with your suggestion:
                      if (currenthigh > -1
                      && RValueCharts(Color.Blue, 3, 3).VClose[0] <= -4)

                      {
                      DrawDiamond("DailyHighReversal" + CurrentBar,true,0,Low[0]-1,Color.DarkMagenta);
                      }


                      if (Close[0] > Open[0] && CurrentBar - myConditionBar >=5)
                      {
                      myConditionBar = CurrentBar;
                      //DrawHere
                      }
                      Could you put these together in the way you were describing? Thanks

                      Comment


                        #12
                        Code:
                        if (currenthigh > -1 && RValueCharts(Color.Blue, 3, 3).VClose[0] <= -4 && CurrentBar - myConditionBar >=5)
                        {
                        myConditionBar = CurrentBar;
                        DrawDiamond("DailyHighReversal" + CurrentBar,true,0,Low[0]-1,Color.DarkMagenta);
                        }
                        Be sure to also declare myConditionBar in variables region.

                        #region Variables
                        private int myConditionBar;
                        #endregion
                        Ryan M.NinjaTrader Customer Service

                        Comment


                          #13
                          That did it. Thanks Ryan you've saved me once again!

                          Comment

                          Latest Posts

                          Collapse

                          Topics Statistics Last Post
                          Started by ghoul, Today, 06:02 PM
                          0 responses
                          3 views
                          0 likes
                          Last Post ghoul
                          by ghoul
                           
                          Started by Barry Milan, Yesterday, 10:35 PM
                          6 responses
                          18 views
                          0 likes
                          Last Post Barry Milan  
                          Started by DanielSanMartin, Yesterday, 02:37 PM
                          2 responses
                          13 views
                          0 likes
                          Last Post DanielSanMartin  
                          Started by DJ888, 04-16-2024, 06:09 PM
                          4 responses
                          13 views
                          0 likes
                          Last Post DJ888
                          by DJ888
                           
                          Started by terofs, Today, 04:18 PM
                          0 responses
                          12 views
                          0 likes
                          Last Post terofs
                          by terofs
                           
                          Working...
                          X