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

DrawArrow on all DailyHigh

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

    DrawArrow on all DailyHigh

    Hi,
    i am trying to do somthing like Current OHL Indikator.
    But i try to do Arrows Down on all DailyHigh and only 1 Arrow Up with DrawText (Counter) by the the next Candle where goes under the dailyhigh candle. Now i have the problem thats draw on all candles. See my Screenshot.

    Code:
    #region Variables
            private DateTime     currentDate         =   Cbi.Globals.MinDate;
            private double        currentOpen            =    double.MinValue;
            private double        currentHigh            =    double.MinValue;
            private double        currentLow            =    double.MaxValue;
            private bool        plotCurrentValue    =    false;
            private bool        showOpen            =    true;
            private bool        showHigh            =    true;
            private bool        showLow                =    true;
            
            private int         counter;
            private Color        colorUp = Color.Gray;
            private Color        colorDn = Color.Gray;
            
            #endregion
    Code:
    protected override void Initialize()
            {
                Add(new Plot(new Pen(Color.Orange, 2), PlotStyle.Square, "Current Open"));
                Add(new Plot(new Pen(Color.Green, 2), PlotStyle.Square, "Current High"));
                Add(new Plot(new Pen(Color.Red, 2), PlotStyle.Square, "Current Low"));
                Plots[0].Pen.DashStyle = DashStyle.Dash;
                Plots[1].Pen.DashStyle = DashStyle.Dash;
                Plots[2].Pen.DashStyle = DashStyle.Dash;
                
                AutoScale            = false;
                Overlay                = true;
                counter                = 1;
                            
            }
    
            /// <summary>
            /// Called on each bar update event (incoming tick)
            /// </summary>
            protected override void OnBarUpdate()
            {
                
                currentHigh     =     Math.Max(currentHigh, High[0]);
                currentLow        =     Math.Min(currentLow, Low[0]);
                
                bool sameDay = true;
    
                if (currentDate != Bars.GetTradingDayFromLocal(Time[0]) || currentOpen == double.MinValue)
                {
                    currentOpen     =     Open[0];
                    currentHigh     =     High[0];
                    currentLow        =    Low[0];
                    sameDay         =   false;
                    counter                = 1;
                }
    
                    if (currentHigh>High[0] && sameDay)
                    {                
                            DrawArrowUp("Up"+CurrentBar, false, 0, Low[0] - (2 * TickSize), colorUp); Print("Up");                        
                            DrawText("tag"+CurrentBar, ""+counter, 0, Low[0] - (7 * TickSize), Color.Green);
                            counter++;                    
                    } else {
                        DrawArrowDown("Dn"+CurrentBar, false, 0, High[0] + (2 * TickSize), colorDn); Print("Dn");                        
                    }
    
                currentDate     =     Bars.GetTradingDayFromLocal(Time[0]);
            }
    Anyone can help me?
    Thanks
    Attached Files
    Last edited by Lesoto; 12-14-2016, 03:23 AM.

    #2
    Hello,

    Thank you for the post.

    The reason that many objects are being drawn specifically is that you are using a Unique tag name with the object:
    Code:
    DrawArrowUp("Up"[B]+CurrentBar[/B], false, 0, Low[0] - (2 * TickSize), colorUp); Print("Up");
    To make this only draw One up arrow at a time, you could use a static tag:

    Code:
    DrawArrowUp([B]"Up"[/B], false, 0, Low[0] - (2 * TickSize), colorUp); Print("Up");
    This would remove the object off the prior bar and move to the next bar. Is this the effect you were after? After making this change, if you needed to further refine when the condition becomes true that would also change the amount of times this draws.

    I look forward to being of further assistance.
    JesseNinjaTrader Customer Service

    Comment


      #3
      Thanks for your help.
      In this case I should have 2 arrows up. (see image)
      How can I achieve this, with some for-loop it doesn't work.

      Thanks
      Attached Files

      Comment


        #4
        Hello,

        Thank you for the reply.

        If you are trying to create only 1 arrow per period, you could use a bool or other type of logic for that. Essentially you would want the arrow to be drawn only on the bar you want it on, and then prevent it from trying to draw further arrows until the next time it should become true. As the logic is now, it seems this becomes true on each bar which would make it difficult.

        What you had before using the CurrentBar would actually be fine, but the condition you are using would need to not become true on every bar.

        Can you tell me, do I understand correct that you want to place the up arrow only on the bar after the Daily High candle and then repeat this process indefinitely?

        I look forward to being of further assistance.
        JesseNinjaTrader Customer Service

        Comment


          #5
          Hi,
          only on the bar after which goes under the Daily High candle and yes repeat this processly indefinitely.

          Comment


            #6
            Hello,

            Thank you for confirming, in this case you would need to add some additional logic to prevent this condition from happening over and over on each bar.

            One simple way may be to use bool variable, an example would be the following:

            Code:
             if (currentHigh>High[0] && sameDay)
            {     
                 if(!arrowDrawn)     
                 { 
                     DrawArrowUp("Up"+CurrentBar, false, 0, Low[0] - (2 * TickSize), colorUp); Print("Up");                        
                     DrawText("tag"+CurrentBar, ""+counter, 0, Low[0] - (7 * TickSize), Color.Green);
                     arrowDrawn = true; 
                 }
                 counter++;                    
            }


            The variable arrowDrawn would need to be set to false somewhere else in the code when this should be reset such as when the high is first found or when the day changes.


            I look forward to being of further assistance.
            JesseNinjaTrader Customer Service

            Comment


              #7
              Thank you for the input.
              How can i take the information of the Daily Highs candles, for example the Low from the DailyHigh candle?

              Comment


                #8
                Hello,

                Thank you for the reply.

                If you are referring to the previosly found High values which are represented by "currentHigh" in the script, you could store the values found in the existing DataSeries you have. This would create an effect similar to Close[BarsAgo]

                Here is an example:

                Code:
                private DateTime     currentDate         =   Cbi.Globals.MinDate;
                private double        currentOpen            =    double.MinValue;
                private double        currentHigh            =    double.MinValue;
                private double        currentLow            =    double.MaxValue;
                private bool        plotCurrentValue    =    false;
                private bool        showOpen            =    true;
                private bool        showHigh            =    true;
                private bool        showLow                =    true;
                private int         counter;
                private Color        colorUp = Color.Gray;
                private Color        colorDn = Color.Gray;
                private int highCounter = 0;
                Code:
                protected override void Initialize()
                {
                    Add(new Plot(new Pen(Color.Orange, 2), PlotStyle.Square, "Current Open"));
                    Add(new Plot(new Pen(Color.Green, 2), PlotStyle.Square, "Current High"));
                    Add(new Plot(new Pen(Color.Red, 2), PlotStyle.Square, "Current Low"));
                    Plots[0].Pen.DashStyle = DashStyle.Dash;
                    Plots[1].Pen.DashStyle = DashStyle.Dash;
                    Plots[2].Pen.DashStyle = DashStyle.Dash;
                    
                    AutoScale            = false;
                    Overlay                = true;
                    counter                = 1;
                	highCounter = 0;
                }
                
                
                protected override void OnBarUpdate()
                {
                	if(CurrentBar < 1) return;
                	
                	currentHigh     =     Math.Max(currentHigh, High[0]);
                    currentLow        =     Math.Min(currentLow, Low[0]);
                	
                	[B]Values[1].Set(currentHigh);[/B]
                	
                	if(Bars.FirstBarOfSession)
                	{
                		highCounter++;
                	}
                    
                	[B]if(Values[1][0] > Values[1][1])[/B]
                	{
                	 	DrawArrowUp("Up"+highCounter, false, 0, Low[0] - (2 * TickSize), colorUp); Print("Up");                        
                                DrawText("tag"+highCounter, ""+counter, 0, Low[0] - (7 * TickSize), Color.Green);
                	} 
                
                
                    bool sameDay = true;
                
                    if (currentDate != Bars.GetTradingDayFromLocal(Time[0]) || currentOpen == double.MinValue)
                    {
                        currentOpen     =     Open[0];
                        currentHigh     =     High[0];
                        currentLow        =    Low[0];
                        sameDay         =   false;
                        counter                = 1;
                    }
                
                	currentDate     =     Bars.GetTradingDayFromLocal(Time[0]);
                }
                By setting the value to a Series, you could use that series for logic. To find the Lowest value of the series, you could utilize the MIN method: http://ninjatrader.com/support/helpG...ghlightsub=min

                Code:
                MIN(Values[1], Bars.BarsSinceSession - 1)[0]
                This would return a value, if you instead needed to know the number of BarsAgo since the lowest bar, you could instead use LowestBar:


                Code:
                LowestBar(Values[1], Bars.BarsSinceSession - 1)

                I look forward to being of further assistance.
                JesseNinjaTrader Customer Service

                Comment

                Latest Posts

                Collapse

                Topics Statistics Last Post
                Started by Jon17, Today, 04:33 PM
                0 responses
                1 view
                0 likes
                Last Post Jon17
                by Jon17
                 
                Started by Javierw.ok, Today, 04:12 PM
                0 responses
                6 views
                0 likes
                Last Post Javierw.ok  
                Started by timmbbo, Today, 08:59 AM
                2 responses
                10 views
                0 likes
                Last Post bltdavid  
                Started by alifarahani, Today, 09:40 AM
                6 responses
                41 views
                0 likes
                Last Post alifarahani  
                Started by Waxavi, Today, 02:10 AM
                1 response
                21 views
                0 likes
                Last Post NinjaTrader_LuisH  
                Working...
                X