Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Save MAX indicator values

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

    Save MAX indicator values

    I'm creating a strategy and I need to save the last three values of the MAX indicator. I mean save the last 3 maximum peaks of 3 bullish moves.
    How can I do it?
    Cheers.

    #2
    Hello Jesus Medina,

    Thanks for your post.

    You can save this information to private variables in the script. For example:

    Code:
    public class MyCustomStrategy3 : Strategy
    {
        private MAX MAX1;
    
        protected override void OnStateChange()
        {
            if (State == State.SetDefaults)
            {
                Description                                    = @"Enter the description for your new custom Strategy here.";
                Name                                        = "Test";
            }
            else if (State == State.DataLoaded)
            {                
                MAX1                = MAX(Close, 14);
            }
        }
    
        private double last1, last2, last3;
    
        protected override void OnBarUpdate()
        {
            if (BarsInProgress != 0) 
                return;
    
            if (CurrentBars[0] < 0)
                return;
    
            if (MAX1[0] != last1)
            {
                last3 = last2;
                last2 = last1;
                last1 = MAX1[0];
            }            
        }
    }
    More information on using variables in C# can be found with educational materials on C# that are external to NinjaTrader. I have linked a publicly available resource below.



    From the Strategy Builder, you can create variables in the Inputs and Variables page. These variables can be referenced in Conditions and assigned in Actions.

    We look forward to assisting.

    Comment


      #3
      Thank you Jim.
      I'm just a beginner and I don't know how to use scripts. I'm using Strategy Builder in Ninjatrader.
      Any idea or suggestion that may help me?

      Comment


        #4
        Hello Jesus,

        You can create those three doubles on the Inputs and Variables page of the Strategy Builder under Variables.

        Inputs and Variables page - https://ninjatrader.com/support/help...ariablesScreen

        Under Conditions and Actions, you can compare if your last1 variable is not equal to the MAX indicator. Then under Actions, you can assign last3 the value of last2, assign last2 the value of last1, and then you can assign last1 the value from the indicator plot.

        Referencing indicator plots in the Strategy Builder - https://ninjatrader.com/support/help...lueComparisons

        Under Actions, you can assign variables a value under Misc > Set YourVariableName

        You can reference variables in Conditions under User Variables > YourVariableName

        We look forward to assisting.

        Comment

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by CaptainJack, 05-29-2026, 05:09 AM
        0 responses
        476 views
        0 likes
        Last Post CaptainJack  
        Started by CaptainJack, 05-29-2026, 12:02 AM
        0 responses
        317 views
        0 likes
        Last Post CaptainJack  
        Started by charlesugo_1, 05-26-2026, 05:03 PM
        0 responses
        254 views
        1 like
        Last Post charlesugo_1  
        Started by DannyP96, 05-18-2026, 02:38 PM
        1 response
        340 views
        0 likes
        Last Post NinjaTrader_ChelseaB  
        Started by CarlTrading, 05-11-2026, 05:56 AM
        0 responses
        306 views
        0 likes
        Last Post CarlTrading  
        Working...
        X