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

Making SampleMultiColoredPlot Generic

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

    Making SampleMultiColoredPlot Generic

    If I replace the hard-coded SMA(Period) with Value.Set(SMA(Period)[0]); first, and then try to substitute the "Value" reference for the SMA(Period) condition for the coloring of the plots, it stops working. I've tried different combos, but nothing seems to work - it either ignores the color changes or plots nothing. My goal is to make the coloring code portion generic with the Values set for it above the conditions.

    #2
    Hi marketmasher, not sure what you are trying to achieve, can you please post the code you already have? You would still need 3 Plots for every color you wish to use and link to those to your dataseries objects (Values[0], Values[1], Values[2])
    BertrandNinjaTrader Customer Service

    Comment


      #3
      Originally posted by NinjaTrader_Bertrand View Post
      Hi marketmasher, not sure what you are trying to achieve, can you please post the code you already have? You would still need 3 Plots for every color you wish to use and link to those to your dataseries objects (Values[0], Values[1], Values[2])
      Thanks for the response. Basically I am trying to make it so I can substitute any Data Series into the mulit-color plot, but in this case I 1st tried to just generalize what SampleMultiColorPlot is doing, trying to make the Value series hold the result of SMA(Period) - which I could then replace to get the coloring effect on any other calc.

      {
      // Checks to make sure we have at least 1 bar before continuing
      if (CurrentBar < 1)
      return;
      Value.Set(SMA(Period)[0]); // Try to make this calc part interchangeable with another calc later...
      // Plot green if the SMA is rising
      // Rising() returns true when the current value is greater than the value of the previous bar.
      if (Rising(Value))
      {
      // Connects the rising plot segment with the other plots
      RisingPlot.Set(1, Value[1]);

      // Adds the new rising plot line segment to the line
      RisingPlot.Set(Value[0]);
      }

      // Plot red if the SMA is falling
      // Falling() returns true when the current value is less than the value of the previous bar.
      else if (Falling(Value))
      {
      // Connects the new falling plot segment with the rest of the line
      FallingPlot.Set(1, Value[1]);

      // Adds the new falling plot line segment to the line
      FallingPlot.Set(Value[0]);
      }

      // Plot yellow if the SMA is neutral
      else
      {
      // Connects the neutral plot segment with the rest of the line
      NeutralPlot.Set(1, Value[1]);

      // Adds the new neutral plot line segment to the line
      NeutralPlot.Set(Value[0]);
      }

      Comment


        #4
        marketmasher,

        Like Bertrand mentioned, you need three plots. Value[] only references the first plot or whichever plot is assigned to Values[0].

        You need to make your own DataSeries to store your calculation. Your current code is likely trying to set RisingPlot.Set() and then take Value.Set(). They are referencing the same Values[0].
        Josh P.NinjaTrader Customer Service

        Comment


          #5
          Ok now I follow you, please check this zip - I guess it implements what you look for.
          Attached Files
          BertrandNinjaTrader Customer Service

          Comment


            #6
            Originally posted by NinjaTrader_Bertrand View Post
            Ok now I follow you, please check this zip - I guess it implements what you look for.

            Aces! Thank you. I guess I can't use the Value series that gets created with the Plot for this and have to create a dataseries.

            Comment

            Latest Posts

            Collapse

            Topics Statistics Last Post
            Started by tkaboris, Today, 08:32 AM
            5 responses
            8 views
            0 likes
            Last Post NinjaTrader_Jesse  
            Started by f.saeidi, Today, 07:07 AM
            3 responses
            9 views
            0 likes
            Last Post NinjaTrader_ChelseaB  
            Started by Philippe56140, 04-27-2024, 02:35 PM
            9 responses
            72 views
            0 likes
            Last Post backtester831  
            Started by algospoke, Yesterday, 06:36 PM
            3 responses
            15 views
            0 likes
            Last Post NinjaTrader_Gaby  
            Started by sugalt, 04-30-2024, 04:02 AM
            4 responses
            17 views
            0 likes
            Last Post backtester831  
            Working...
            X