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

High since x bars

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

    High since x bars

    how can I implement this settlement " High since X bars" where X is a parameter ?

    #2
    double myHigh = MAX(High, X)[0];
    RayNinjaTrader Customer Service

    Comment


      #3
      thanks for your answer

      Comment


        #4
        I have another question. I'm trying to code an indicator which plot a signal for 3 different periods x1,x2,x3 on the same window.
        Here is the script i've coded so far :

        protected override void Initialize()
        {
        Add(new Plot(Color.Red, "repulse1"));
        Add(new Plot(Color.Black, "repulse2"));
        Add(new Plot(Color.Green, "repulse3"));
        Add(new Line(Color.Black,0, "Zero line"));
        }
        protected override void OnBarUpdate()
        {
        double myHigh1=Max(High,x1)[0];
        double myLow1=MIN(Low,x1)[0];
        double bullishthrust1=3*Close[0]-2*myLow1-Open[x1];
        double bearishthrust1=Open[x1]+2*myhigh1-3*Close[0];
        BEMA1.Set(EMA(bullishthrust, 5*x1));
        BEMA2.Set(EMA(bullishthrust, 5*x1));
        double repulse1=(BEMA1-BEMA2)/Close[0]*100;
        }

        How can I modify this script in order to avoid writing things 3 times ?
        Feel free to tell me if there are some mistakes (this is my first script)

        Comment


          #5
          not sure what you mean by three times...

          You can not pass in a double to EMA() method. You need to store calculations in a DataSeries object and pass that in.

          See this reference - http://www.ninjatrader-support.com/v...ead.php?t=7299
          RayNinjaTrader Customer Service

          Comment


            #6
            What I mean is that each parameter is using the same formula.
            In the script below I only wrote the code for x1 (for x2 and x3 I would have written the same thing )

            Comment


              #7
              Then you write some sort of loop:

              for (x = 1; x < 3, x++)
              {
              // Calculations here
              }
              RayNinjaTrader Customer Service

              Comment


                #8
                here is my script,can you tell me what is wrong or what can be done to shorten the code, please?

                private int x1=1;
                private int x2=5;
                private int x3=15;
                private Dataseries EMAbull1;
                private Dataseries EMAbear1;
                private Dataseries EMAbull2;
                private Dataseries EMAbear2;
                private Dataseries EMAbull3;
                private Dataseries EMAbear3;

                protected override void Initialize()
                {
                Add(new Plot(Color.Red, "repulse x1"));
                Add(new Plot(Color.Black, "repulse x2"));
                Add(new Plot(Color.Green, "repulse x3"));
                Add(new Line(Color.Black,0, "Zero line"));

                EMAbull1 =new Dataseries(this);
                EMAbear1 =new Dataseries(this);
                EMAbull2 =new Dataseries(this);
                EMAbear2 =new Dataseries(this);
                EMAbull2 =new Dataseries(this);
                EMAbear2 =new Dataseries(this);
                }

                protected override void OnBarUpdate()
                {

                double myHigh1=Max(High,x1)[0];
                double myLow1=MIN(Low,x1)[0];
                double bullishthrust1=3*Close[0]-2*myLow1-Open[x1];
                double bearishthrust1=Open[x1]+2*myhigh1-3*Close[0];
                EMAbull1.Set(EMA(bullishthrust, 5*x1));
                EMAbear1.Set(EMA(bearishthrust, 5*x1));
                double repulse x1=(EMAbull1-EMAbear1)/Close[0]*100;

                double myHigh2=Max(High,x2)[0];
                double myLow2=MIN(Low,x2)[0];
                double bullishthrust1=3*Close[0]-2*myLow1-Open[x2];
                double bearishthrust1=Open[x2]+2*myhigh1-3*Close[0];
                EMAbull2.Set(EMA(bullishthrust, 5*x2));
                EMAbear2.Set(EMA(bearishthrust, 5*x2));
                double repulse x2=(EMAbull2-EMAbear2)/Close[0]*100;

                double myHigh3=Max(High,x3)[0];
                double myLow3=MIN(Low,x3)[0];
                double bullishthrust1=3*Close[0]-2*myLow1-Open[x3];
                double bearishthrust1=Open[x3]+2*myhigh1-3*Close[0];
                EMAbull3.Set(EMA(bullishthrust, 5*x3));
                EMAbear3.Set(EMA(bearishthrust, 5*x3));
                double repulse x3=(EMAbull2-EMAbear2)/Close[0]*100;
                }

                Comment


                  #9
                  We are happy to help if we can glance at the code and see anything that sticks out but what we don't do is provide support in debugging user generated code. You would have to debug on your own.

                  Here is a helpful resource - http://www.ninjatrader-support.com/v...ead.php?t=3418
                  RayNinjaTrader Customer Service

                  Comment

                  Latest Posts

                  Collapse

                  Topics Statistics Last Post
                  Started by alifarahani, Today, 09:40 AM
                  6 responses
                  31 views
                  0 likes
                  Last Post alifarahani  
                  Started by Waxavi, Today, 02:10 AM
                  1 response
                  17 views
                  0 likes
                  Last Post NinjaTrader_LuisH  
                  Started by Kaledus, Today, 01:29 PM
                  5 responses
                  14 views
                  0 likes
                  Last Post NinjaTrader_Jesse  
                  Started by Waxavi, Today, 02:00 AM
                  1 response
                  12 views
                  0 likes
                  Last Post NinjaTrader_LuisH  
                  Started by gentlebenthebear, Today, 01:30 AM
                  3 responses
                  17 views
                  0 likes
                  Last Post NinjaTrader_Jesse  
                  Working...
                  X