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

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.

    JimNinjaTrader Customer Service

    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.

        JimNinjaTrader Customer Service

        Comment

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by elirion, Today, 09:32 PM
        0 responses
        2 views
        0 likes
        Last Post elirion
        by elirion
         
        Started by cre8able, Today, 09:15 PM
        1 response
        5 views
        0 likes
        Last Post bltdavid  
        Started by cummish, Today, 08:43 PM
        0 responses
        9 views
        0 likes
        Last Post cummish
        by cummish
         
        Started by Option Whisperer, Today, 07:58 PM
        4 responses
        20 views
        0 likes
        Last Post Option Whisperer  
        Started by ETFVoyageur, 05-07-2024, 07:05 PM
        13 responses
        87 views
        0 likes
        Last Post ETFVoyageur  
        Working...
        X