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

Code snippet for Parabolic SAR

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

    Code snippet for Parabolic SAR

    Dear Support
    Regarding the Indicator "Parabolic SAR", can you help me with a code snippet that I can see the dots colored (i.e. up color green, down color red). And how must I implement this code snippet to the right place?
    Thanks for advice.
    Best
    Markus

    #2
    Hello FutureTrade,

    The dots from the ParabolicSAR are a plot.

    Plot can be colored on each bar by setting the PlotBrushes for the plot index and bars ago index.

    Below is a link to the help guide.


    I would recommend doing this in OnBarUpdate after the plot Value[0] is set.

    Below is a link to an example script that does something similar. It colors the plot differently for up bars than it does for down bars.
    This is a conversion of the NT7 indicator EMASlopeColor. Please contact the original author for any questions or comments. Colors the EMA plot when rising or falling.



    The NinjaTrader Ecosystem website is for educational and informational purposes only and should not be considered a solicitation to buy or sell a futures contract or make any other type of investment decision. The add-ons listed on this website are not to be considered a recommendation and it is the reader's responsibility to evaluate any product, service, or company. NinjaTrader Ecosystem LLC is not responsible for the accuracy or content of any product, service or company linked to on this website.
    Chelsea B.NinjaTrader Customer Service

    Comment


      #3
      Dear Chelsea

      Sorry for late answer and thank you for suggestion. I copied the Standard Parabolic SAR as SARcolored and added following in OnBarUpdate:

      if(IsRising(Value))
      {
      PlotBrushes[0][0] = Brushes.Green;
      }
      else if (IsFalling(Value))
      {
      PlotBrushes[0][0] = Brushes.Red;
      }

      Now I see the dots in Green and Red, but unfortunatelly, the first dot starts with the wrong color i.e. if the trend is long the dots are green but the first dot of this trend is red - but must be in green also - and if the value of a green dot (or red dot) is the same as one bar before, the unchanged dot is "Goldenrod" as defined in AddPlot.

      see a picture from the Chart as dpf..

      Question: what made I wrong?

      Thank you and best regards
      Markus
      Attached Files

      Comment


        #4
        Hello Markus,

        Thanks for your reply.

        This is Paul responding for Chelsea who is out of the office today.

        The first dot is not being colored because the methods IsRising() and IsFalling() require two data points to determine the rise and fall status. The dots are colored the original color because they are neither rising nor falling so you have no condition to color them.

        If I may suggest, please comment out your code and try this: PlotBrushes[0][0] = Value[0] > Close[0] ? Brushes.Green : Brushes.Red; as i think that will get you what you are looking for.
        For clarity: Value[0] > Close[0] ? Brushes.Green : Brushes.Red is read as: If the current Psar value is greater than the current close price, color the brush green, otherwise color the brush red.
        Paul H.NinjaTrader Customer Service

        Comment


          #5
          Dear Paul

          Wow - so easy with your suggestion. Now it works very fine. I have to learn a lot more in programming...

          Thank you so much for this and I wish you a very nice weekend.

          Best
          Markus

          Comment


            #6
            Hello Markus,

            Thanks for your reply.

            I have to correct something, "The first dot is not being colored because the methods IsRising() and IsFalling() require two data points to determine the rise and fall status. The dots are colored the original color because they are neither rising nor falling so you have no condition to color them." That was incorrect, they were not colored the original color, rather they were colored according to the previous direction. Sorry if that added any confusion.

            Glad the example worked for you.
            Paul H.NinjaTrader Customer Service

            Comment


              #7
              Dear Paul

              Your answer / feedback is very appreciated and helps me, to understand it better.
              Thank you.
              Best
              Markus

              Comment

              Latest Posts

              Collapse

              Topics Statistics Last Post
              Started by fitspressoburnfat, Today, 04:25 AM
              0 responses
              2 views
              0 likes
              Last Post fitspressoburnfat  
              Started by Skifree, Today, 03:41 AM
              1 response
              4 views
              0 likes
              Last Post Skifree
              by Skifree
               
              Started by usazencort, Today, 01:16 AM
              0 responses
              1 view
              0 likes
              Last Post usazencort  
              Started by kaywai, 09-01-2023, 08:44 PM
              5 responses
              603 views
              0 likes
              Last Post NinjaTrader_Jason  
              Started by xiinteractive, 04-09-2024, 08:08 AM
              6 responses
              23 views
              0 likes
              Last Post xiinteractive  
              Working...
              X