Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Simple script that changes color of candle if wick is larger than candle

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

    #16
    Originally posted by NinjaTrader_PaulH View Post
    Hello WeyldFalcon,

    Thanks for your reply.

    Already answered 01-22-2021, 02:33 PM, "You will need to change the property IsOverLay to true in State.SetDefaults as that is what creates the indicator panel."

    Here is a reference link on that property: https://ninjatrader.com/support/help...?isoverlay.htm
    Strange, that did not work, I had to recreate the Indicator from scratch and check off the box "Overlay on Price" to get it to stop creating the new panel.

    Comment


      #17
      Hello WeyldFalcon,

      Thanks for your replies.

      Regarding the IsOverLay, the check box in the strategy wizard will set the IsOverlay true or false for you in OnStateChange(). You can always change it directly in the code. When making changes especially to indicators plots or panels, make sure that you remove the indicator from the chart and then apply the new indicator. If you use reload Ninjascript the newest changes would not be applied.

      Regarding not working as expected, I would suggest using print statement to print out all the values you are working with, including the math results such as Print ("High = "High[0]+" Open = "+Open[0]+ " H-O / Ticksize = "+(High[0]-Open[0])/TickSize).ToString()); I suspect it may be a rounding issue but the print should help clarify.
      Paul H.NinjaTrader Customer Service

      Comment


        #18
        modified it a little

        Draw.Text(this, "test"+CurrentBar, "L="+Low[0]+"O="+Open[0]+"T="+TickSize+"O-L/T="+(Open[0]-Low[0])/TickSize, 0, Low[0]);

        You are correct but why? I get 1847.3 for Open, 1846.6 for Low, 0.1 for Tick size but then 7.00000000000045 for (Open-Low)/TickSize. If I do that in my head I get .7/.1=7 exactly, what am I missing?
        Is it cleaner to cast the final value to Int or cast each value to int prior to doing the division? or is there a better way to grab the values so they are not slightly off?

        Comment


          #19
          Hello WeyldFalcon,

          Thanks for your reply.

          When you cast to an int, you end up throwing off (not using) the remainder so 8.9999 becomes 8.

          You may want to use Math.Round() and then cast, Math.Round() is not a Ninjascript item so I can only provide a link to an external reference here: https://www.dotnetperls.com/math-round

          Paul H.NinjaTrader Customer Service

          Comment


            #20
            Got it thank you.

            if (Close[0]/TickSize>Open[0]/TickSize && Math.Round((Open[0]-Low[0])/TickSize, MidpointRounding.AwayFromZero)>=WickSizeMin && Math.Round((Open[0]-Low[0])/TickSize, MidpointRounding.AwayFromZero)<=WickSizeMax)
            // { //hammer
            BarBrush = BarColorUp;
            // Draw.Text(this, "test"+CurrentBar, "O="+Open[0]+"L="+Low[0]+"T="+TickSize+"O-L/T="+Math.Round((Open[0]-Low[0])/TickSize, MidpointRounding.AwayFromZero), 0, Low[0]);
            // }
            else if (Close[0]/TickSize<Open[0]/TickSize && Math.Round((High[0]-Open[0])/TickSize, MidpointRounding.AwayFromZero)>=WickSizeMin && Math.Round((High[0]-Open[0])/TickSize, MidpointRounding.AwayFromZero)<=WickSizeMax)
            // {//inverted hammer
            BarBrush = BarColorDown;
            // Draw.Text(this, "test"+CurrentBar, "H="+High[0]+"O="+Open[0]+"T="+TickSize+"H-O/T="+Math.Round((High[0]-Open[0])/TickSize, MidpointRounding.AwayFromZero), 0, High[0]);
            // }

            Comment


              #21
              For those confused as to why I used Draw.Text instead of Print there are 2 reasons
              1) I did not know I needed to check NinjaScript Output for print data
              2) I wanted to see the output on the specific candle that was causing the issue

              Comment


                #22
                Here is my update now that I realized I will want to use this with more than just ES one day so I implemented percentage-based instead of tick-based.
                Code:
                if (Close[0]>Open[0] && (Open[0]-Low[0])/(High[1]-Low[1])*100>=WickPercMin && (Open[0]-Low[0])/(High[1]-Low[1])*100<=WickPercMax)
                    BarBrush = BarColorUp;
                else if (Close[0]<Open[0] && (High[0]-Open[0])/(High[1]-Low[1])*100>=WickPercMin && (High[0]-Open[0])/(High[1]-Low[1])*100<=WickPercMax)
                    BarBrush = BarColorDown;

                Comment


                  #23
                  Any chance you guys could share an indicator to upload into NT as a ZIP? Or maybe upload it into ecosystem? Not a developer here, but it's exactly what was looking for... percetage-based results even better. Would be greatly appreciated!

                  Comment


                    #24
                    Example script:

                    Comment

                    Latest Posts

                    Collapse

                    Topics Statistics Last Post
                    Started by helpwanted, Today, 03:06 AM
                    0 responses
                    3 views
                    0 likes
                    Last Post helpwanted  
                    Started by Brevo, Today, 01:45 AM
                    0 responses
                    6 views
                    0 likes
                    Last Post Brevo
                    by Brevo
                     
                    Started by aussugardefender, Today, 01:07 AM
                    0 responses
                    5 views
                    0 likes
                    Last Post aussugardefender  
                    Started by pvincent, 06-23-2022, 12:53 PM
                    14 responses
                    242 views
                    0 likes
                    Last Post Nyman
                    by Nyman
                     
                    Started by TraderG23, 12-08-2023, 07:56 AM
                    9 responses
                    384 views
                    1 like
                    Last Post Gavini
                    by Gavini
                     
                    Working...
                    X