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 NullPointStrategies, Today, 05:17 AM
        0 responses
        50 views
        0 likes
        Last Post NullPointStrategies  
        Started by argusthome, 03-08-2026, 10:06 AM
        0 responses
        126 views
        0 likes
        Last Post argusthome  
        Started by NabilKhattabi, 03-06-2026, 11:18 AM
        0 responses
        69 views
        0 likes
        Last Post NabilKhattabi  
        Started by Deep42, 03-06-2026, 12:28 AM
        0 responses
        42 views
        0 likes
        Last Post Deep42
        by Deep42
         
        Started by TheRealMorford, 03-05-2026, 06:15 PM
        0 responses
        46 views
        0 likes
        Last Post TheRealMorford  
        Working...
        X