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

Projection Bands

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

    Projection Bands

    Hello,

    I'm trying to code Projection Bands by Mel Widner and I need some help. Can anyone help me to see what I'm doing wrong? I will attach my file and below is the code I'm trying to convert into a NT7 indicator. Thanks, eleven

    Code:
    SlopeHigh = LINEARREGRESSIONSLOPE[n](high) 
    SlopeLow = LINEARREGRESSIONSLOPE[n](low)   
    
    UpProjBand = high 
    LoProjBand = low  
    
    FOR i = 1 TO n      
       UpProjBand = MAX(UpProjBand, high[i] + i * SlopeHigh)      
       LoProjBand = MIN(LoProjBand, low[i] - i * SlopeLow) 
    NEXT
    **** Updated **** I've attached the fixed code for ProjectionBand indicators.
    Attached Files
    Last edited by eleven; 10-20-2016, 10:31 PM.

    #2
    Hello eleven,

    When you mention you are doing something wrong, what is the wrong behavior?

    Are you getting a compile error?

    Are you getting a run time error?

    If so, what is the error message?

    Are you getting a different calculated value than expected?
    What is the incorrect value?
    What is the expected value?
    Chelsea B.NinjaTrader Customer Service

    Comment


      #3
      Hello, On every OnBarUpdate(), "UpProjBand" and "LoProjBand" is reset to 0. How can I pass the previous bar "UpProjBand/LoProjBand" to the for statement? I'm stuck. Can you point me in the direction on how to code this? Thanks, Tom

      Code:
                  if (CurrentBar < Period)
                      return;
                  
                  double SlopeHigh = LinRegSlope(High, Period)[0];
                  double SlopeLow = LinRegSlope(Low, Period)[0];
                  
                  double UpProjBand = 0; double LoProjBand = 0;
                  for (int i = 0; i < Period; i++)
                  {
                      UpProjBand = Math.Max(UpProjBand, High[i] + (i + 1) * SlopeHigh);
                      LoProjBand = Math.Min(LoProjBand, Low[i] - (i + 1) * SlopeLow);            
                  }
                  
                  PBU.Set(UpProjBand);
                  PBL.Set(LoProjBand);

      Comment


        #4
        Hello eleven,

        Please try printing the values that you are setting this plot to.
        Print(string.Format("{0} | {1} | {2}", Time[0], SlopeHigh, SlopeLow));

        The LineRegSlope indicator returns a value that is between 0 and 1.
        Last edited by NinjaTrader_ChelseaB; 10-19-2016, 07:07 AM.
        Chelsea B.NinjaTrader Customer Service

        Comment


          #5
          Hi Chelsea,

          I think I will need to convert "UpProjBand" and "LoProjBand" to a custom dataseries to accomplish what I need.

          This is the issue...it passes 0 in the for statement rather than using last calculated.
          Code:
                      double UpProjBand = 0; double LoProjBand = 0;
          eleven

          Comment


            #6
            Hello eleven,

            With the code:
            LoProjBand = Math.Min(LoProjBand, Low[i] - (i + 1) * SlopeLow);

            You are taking whichever is lower, 0 the initial value of LoProjBand or the calculated value. In this case 0 is always going to be the lower number correct?
            Chelsea B.NinjaTrader Customer Service

            Comment


              #7
              Chelsea,

              That is correct. I want to pass the last value and not 0. I just don't know how I would go about programming it. Does UpProjBand need to be a custom dataseries?

              Thanks,

              eleven

              Comment


                #8
                Hello eleven,

                I'm not quite certain that I understand.

                The code you have written I am referring to, will always produce a 0 or a negative number.

                You are using Math.Min(). Math.Min will return which ever number is lower. You are supplying 0 and a number greater than 0. This means 0 will always be returned because this is a lower number.

                I'm not quite certain how you would add a data series here or what this would be used for. Can you further describe how you would use this?
                Chelsea B.NinjaTrader Customer Service

                Comment


                  #9
                  I think I know what I did wrong. I will have another try at it later today.

                  Thanks for your reply.

                  eleven

                  Comment

                  Latest Posts

                  Collapse

                  Topics Statistics Last Post
                  Started by alifarahani, Today, 09:40 AM
                  0 responses
                  0 views
                  0 likes
                  Last Post alifarahani  
                  Started by Gerik, Today, 09:40 AM
                  0 responses
                  1 view
                  0 likes
                  Last Post Gerik
                  by Gerik
                   
                  Started by RookieTrader, Today, 09:37 AM
                  0 responses
                  4 views
                  0 likes
                  Last Post RookieTrader  
                  Started by KennyK, 05-29-2017, 02:02 AM
                  3 responses
                  1,282 views
                  0 likes
                  Last Post NinjaTrader_Clayton  
                  Started by AttiM, 02-14-2024, 05:20 PM
                  11 responses
                  184 views
                  0 likes
                  Last Post NinjaTrader_ChelseaB  
                  Working...
                  X