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

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

    Hello,
    I have searched the indicators list and was unable to find one that simply changes the color of the candle if it meets specific criteria. For example, if the wick was longer than the body.
    I would love to learn more about coding NinjaScript so if anybody knows where I can find this indicator so I can reverse engineer it or could get me off on the right foot it would be greatly appreciated.
    Thank you in advance for any assistance.

    #2
    Hello WeyldFalcon,

    Thanks for your post.

    I am not aware of an indicator that would meet your specifications.

    You can change the color of a bar by the BarBrush method: https://ninjatrader.com/support/help.../?barbrush.htm (see the example in the help guide)

    To determine the wick length you would need to know if the bar is an up bar, a down bar or a doji bar. These can be determined like this:

    Close[0] > Open[0] is a Up bar (green)

    Close[0] < Open[0] is a Down bar (red)

    Close[0] = Open[0] is a doji bar.

    The body of the candle would be the Close[0] to Open[0]

    In an up bar (or doji), the wick can be the difference between High[0] and the Close[0] and/or the Low[0] and the Open[0]

    In a down bar (or doji), the wick can be the difference between the High[0] and the Open[0] and/or the Low[0] and the Close[0]

    Paul H.NinjaTrader Customer Service

    Comment


      #3
      Hello Paul,
      Thank you for the prompt response. Correct me if I am wrong but the [0] is only checking the current candle? What about all of the previous candles?
      I tried this but of course it did not change the previous candles
      if (Close[0]>Open[0] && Open[0]-Low[0]>=WickSizeMin && Open[0]-Low[0]<=WickSizeMax) //hammer
      {
      BarBrush = BarColor1;
      Draw.Text(this, "test", "Hammer", 0, Open[0]);
      }
      else if (Close[0]<Open[0] && High[0]-Open[0]>=WickSizeMin && High[0]-Open[0]<=WickSizeMax) //inverted hammer
      {
      BarBrush = BarColor2;
      Draw.Text(this, "test", "Inverted Hammer", 0, Open[0]);
      }

      unfortunately, the color does not change and the text does not appear. I would like the color change to happen to all the previous candles and the current one as well.
      Any thoughts as to what I am doing wrong?
      Last edited by WeyldFalcon; 01-22-2021, 03:00 PM.

      Comment


        #4
        Hello WeyldFalcon,

        Thanks for your reply.

        Correct, the code is only checking the current bar, however, when you load the indicator, the indicator will start with the very first bar of the data series and will process each one as the current bar until it get to the right edge of the chart/live data.

        Whenever you are working on a script, always check the "log" tab of the Ninjatrader control center when you run the script. An indicator will not work if there are errors.

        if WickSizeMin is in ticks then you will need to convert your code to work in ticks. This can be done using the TickSize property which provides the smallest price movement of the instrument. Reference: https://ninjatrader.com/support/help.../?ticksize.htm

        The price difference can be converted like this: ((Open[0]-Low[0])/TickSize)

        If you are going to develop code, one thing you will want to master is using Print statements to print out text, values, to help you debug your code. This will help you see what the script is actually using and then you can adjust as needed. Here is a link to our debugging tips: https://ninjatrader.com/support/help...script_cod.htm
        Paul H.NinjaTrader Customer Service

        Comment


          #5
          Hello Paul,
          Awesome, thank you they now change color!
          Any chance I can get the text to stay with the candle instead of only going to the current candle?
          Thank you in advance for your assistance.

          Comment


            #6
            Additional question, any idea why my Chart now has an extra section that goes from 0-.2 for some reason? See section circled in redClick image for larger version

Name:	Capture.jpg
Views:	1017
Size:	126.5 KB
ID:	1138018

            Comment


              #7
              Hello WeyldFalcon,

              Thanks for your reply.

              Nice work!

              To see all of the texts, for the tag name of the draw.text() add +CurrentBar to create a unique tag name: "test"+CurrentBar

              You will need to change the property IsOverLay to true in State.SetDefaults as that is what creates the indicator panel.
              Paul H.NinjaTrader Customer Service

              Comment


                #8
                Perfect that worked like a charm!

                Comment


                  #9
                  Hello Paul,
                  Please see my additional question about that script I posted further up on 01-22-2021 at 02:25 PM
                  I am curious how to get rid of that new section that was added to the bottom of my charting window.
                  In other words, how do I set the panel to default to "same as input series"?
                  IsOverlay & DrawOnPricePanel are both already set to true.
                  Thank you so much for all your help these last 2 weeks!
                  Last edited by WeyldFalcon; 01-25-2021, 09:58 AM.

                  Comment


                    #10
                    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
                    Paul H.NinjaTrader Customer Service

                    Comment


                      #11
                      Hello Paul,
                      I recreated the Indicator from the wizard and this time checked the box "Overlay on Price" and now it works. I am not sure what the difference is between setting IsOverlay to true and checking that box in the wizard but that worked. If you know why that worked I would love to know.
                      Thanks again for all your help.

                      Comment


                        #12
                        Click image for larger version

Name:	Capture.jpg
Views:	848
Size:	119.4 KB
ID:	1138270 Hello Paul,
                        New question.
                        Any idea why my code is not working as expected.
                        Here is the code:

                        if (Close[0]/TickSize>Open[0]/TickSize && (Open[0]-Low[0])/TickSize>=WickSizeMin && (Open[0]-Low[0])/TickSize<=WickSizeMax) //hammer
                        BarBrush = BarColorUp;
                        else if (Close[0]/TickSize<Open[0]/TickSize && (High[0]-Open[0])/TickSize>=WickSizeMin && (High[0]-Open[0])/TickSize<=WickSizeMax) //inverted hammer
                        BarBrush = BarColorDown;

                        Above is an image with the Min size properly working but the max size not properly working, it works if I set max size to 8 but that is not how the code is supposed to work and I can't figure out why. I used >= as well as <= so they should both be reacting the same way. Notice the inverted hammer with a 7 length wick is not yellow. This is true for the 7 wick length hammers as well. Thank you for any hints.

                        Comment


                          #13
                          Even more confusing when I use range 6 and max of 5 and min of 4 it works fine.
                          Click image for larger version

Name:	Capture.jpg
Views:	830
Size:	92.3 KB
ID:	1138274

                          Comment


                            #14
                            and 18 Range
                            Click image for larger version

Name:	Capture.jpg
Views:	945
Size:	90.2 KB
ID:	1138277

                            Comment


                              #15
                              oh wait, it appears to be GC that is the issue. ES, NQ and YM all work fine. What is it about GC that is breaking my code?
                              I am also curious about hiring somebody to write more complex code for me. Does NinjaTrader have a list of suggested coders to help with larger projects?
                              Last edited by WeyldFalcon; 01-26-2021, 07:42 AM.

                              Comment

                              Latest Posts

                              Collapse

                              Topics Statistics Last Post
                              Started by sightcareclickhere, Today, 01:55 PM
                              0 responses
                              1 view
                              0 likes
                              Last Post sightcareclickhere  
                              Started by Mindset, 05-06-2023, 09:03 PM
                              9 responses
                              258 views
                              0 likes
                              Last Post ender_wiggum  
                              Started by Mizzouman1, Today, 07:35 AM
                              4 responses
                              18 views
                              0 likes
                              Last Post Mizzouman1  
                              Started by philmg, Today, 01:17 PM
                              1 response
                              8 views
                              0 likes
                              Last Post NinjaTrader_ChristopherJ  
                              Started by cre8able, Today, 01:01 PM
                              1 response
                              9 views
                              0 likes
                              Last Post NinjaTrader_ChelseaB  
                              Working...
                              X