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

get the last bar's color

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

    get the last bar's color

    Good morning,
    How would I expose the br variable/brush/color in the following indicator so that I can grab it from my strategy?

    Code:
            protected override void OnBarUpdate()
            {
                SolidColorBrush br;
                
                ParabolicSAR sar = ParabolicSAR(0.02, 0.2, 0.02);
                bool sarUp = sar.Value[0] < Low[0] ? true : false;
                
                MACD1[0] = SMAF[0]-SMAS[0];
                if(MACD1[0] - SMA(MACD1,16)[0] > 0)
                    LMACD[0] = MACD1[0] - SMA(MACD1,16)[0] ;
                
                if(MACD1[0] - SMA(MACD1,16)[0] <= 0)
                    LMACD[0] = -1 * (MACD1[0] - SMA(MACD1,16)[0]);
    
                Value[0] = LMACD[0];
                br = MACD1[0] - SMA(MACD1,16)[0] > 0 ? Brushes.Green : Brushes.Firebrick;
                
                if (sarUp && !psarUp && br == Brushes.Green)
                    br = Brushes.Lime;
                if (!sarUp && psarUp && br == Brushes.Firebrick)
                    br = Brushes.Red;    
                    
                psarUp = sarUp;
                
                PlotBrushes[0][0] = br;​
            }​
    Click image for larger version  Name:	image.png Views:	0 Size:	11.1 KB ID:	1296080

    It looks like the indicator might be exposed already... but I'm not sure.. and I definitely am looking for the br color value so I can check the bar colors not just the numbers that it prints


    this is at the bottom of the indicator file attached:
    Code:
    namespace NinjaTrader.NinjaScript.Strategies
    {
        public partial class Strategy : NinjaTrader.Gui.NinjaScript.StrategyRenderBase
        {
            public Indicators.LindaMACD LindaMACD()
            {
                return indicator.LindaMACD(Input);
            }
    
            public Indicators.LindaMACD LindaMACD(ISeries<double> input )
            {
                return indicator.LindaMACD(input);
            }
        }
    }​
    thank you!!!
    Last edited by Lele2k24; 03-16-2024, 09:06 AM.

    #2
    any help would be epic.. thanks

    Comment


      #3
      Hello Lele2k24,

      Thanks for your post.

      I see you posted in the NinjaTrader 7 section of the forums but the script you shared seems to be for NinjaTrader 8.

      To clarify, are you using NinjaTrader 7 or NinjaTrader 8?

      You could accomplish this in NinjaTrader 8 by creating a public custom Series><int> variable in your indicator script and assigning the value of 1 to the custom Series when the plot is set to Green or assigning a value of -1 to the custom Series when the plot is set to FirebrickRed.

      Then, in the strategy you could check if the custom Series in the indicator is 1 or -1 to determine if the plot is Green or FirebrickRed.

      See this reference sample demonstrating exposing indicator values that are not plots: https://ninjatrader.com/support/help...alues_that.htm

      See this help guide documentation for more information about custom Series: https://ninjatrader.com/support/help...t8/seriest.htm
      Brandon H.NinjaTrader Customer Service

      Comment


        #4
        Thank you! Sorry for posting this in the wrong forum..

        I tried:

        Code:
                    else if (State == State.DataLoaded)
                    {                
                        ParabolicSAR1                = ParabolicSAR(Close, 0.02, 0.2, 0.02);
                        LindaMACD1                = LindaMACD(Close);
                    //    LindaMACD1.Plots[0].Brush = Brushes.Green;
                        AddChartIndicator(LindaMACD1);
                    }​
        Code:
                    Print("LindaMCAD " + LindaMACD1.Plots[0].Brush);
                    
                    Print("LindaMACD1.BarBrushes[0] " +  LindaMACD1.BarBrushes[0]);
                    
                    Print("LindaMACD1.BarBrush " + LindaMACD1.BarBrush);
         
                    Print(" LindaMACD1.LINDAMACD.NinjaScript.BarBrushes[0] " + LindaMACD1.LINDAMACD.NinjaScript.BarBrushes[0]);
                    
                    Print("LindaMACD1.LINDAMACD.NinjaScript.Plots[0].Brush " + LindaMACD1.LINDAMACD.NinjaScript.Plots[0].Brush);​
        and it only game me green or nothing:

        LindaMCAD #FF008000
        LindaMACD1.BarBrushes[0]
        LindaMACD1.BarBrush
        LindaMACD1.LINDAMACD.NinjaScript.BarBrushes[0]
        LindaMACD1.LINDAMACD.NinjaScript.Plots[0].Brush #FF008000​
        Not sure why.. I would have thought one of these would have worked

        thanks again!

        Comment


          #5
          Hello Lele2k24,

          Thanks for your notes.

          I have moved this forum thread to the NinjaTrader 8 > Strategy Development section of the forums since this question is related to NinjaTrader 8.

          In the LindaMACD indicator script, you will need to add a public custom Series. Then, you will need to assign a value of 1 to the custom Series when you are setting the plot brush to green and you will need to assign a value of -1 to the custom Series when you are setting the plot to red.

          In the strategy, you could then access the public custom Series from the indicator to use for your conditions and actions in the strategy.

          An example of this could be seen in the reference sample linked in post # 2. The reference sample uses a public Series<bool> variable. Instead of a public Series<bool> you would add a public Series<int>.

          Attached is an example of this using the MACD indicator. We create a public Series<int> object in the indicator script and assign a value of 1 or -1 to it. Then, in the strategy we draw a green dot above the bar when the indicator plot is green (1) and we draw a red dot above the bar when the indicator plot is red (-1).​
          Attached Files
          Brandon H.NinjaTrader Customer Service

          Comment


            #6
            thank you! That worked like magic

            Comment

            Latest Posts

            Collapse

            Topics Statistics Last Post
            Started by fx.practic, 10-15-2013, 12:53 AM
            5 responses
            5,404 views
            0 likes
            Last Post Bidder
            by Bidder
             
            Started by Shai Samuel, 07-02-2022, 02:46 PM
            4 responses
            95 views
            0 likes
            Last Post Bidder
            by Bidder
             
            Started by DJ888, Yesterday, 10:57 PM
            0 responses
            8 views
            0 likes
            Last Post DJ888
            by DJ888
             
            Started by MacDad, 02-25-2024, 11:48 PM
            7 responses
            159 views
            0 likes
            Last Post loganjarosz123  
            Started by Belfortbucks, Yesterday, 09:29 PM
            0 responses
            8 views
            0 likes
            Last Post Belfortbucks  
            Working...
            X