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

Avg Range indicator

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

    Avg Range indicator

    I want to create an indicator with the following condition " if the 14 EMA of current bar range is 50% greater than the14 EMA of previous bar range" here is my code

    if (EMA(Range(), 14)[0] > (EMA(Range(), 14)[1]) * (1 + 50))

    I'm not getting the desired plot, can someone please help correct this?

    #2
    Originally posted by chakriare View Post
    I want to create an indicator with the following condition " if the 14 EMA of current bar range is 50% greater than the14 EMA of previous bar range" here is my code

    if (EMA(Range(), 14)[0] > (EMA(Range(), 14)[1]) * (1 + 50))

    I'm not getting the desired plot, can someone please help correct this?
    Your code contains 1 + 50 = 51. This cannot work. Please replace "1 + 50" with "1.5".

    Comment


      #3
      yes, I changed to 1.5, still not working. I changed to compare just with previous bar (ignoring 50%) but still not working.

      (EMA(Range(), 14)[0] > (EMA(Range(), 14)[1]) ...this is not working too.

      Comment


        #4
        Originally posted by chakriare View Post
        yes, I changed to 1.5, still not working. I changed to compare just with previous bar (ignoring 50%) but still not working.

        (EMA(Range(), 14)[0] > (EMA(Range(), 14)[1]) ...this is not working too.
        This line should work, but something else does not work. If you wish us to find the bug, you would need to post the entire code that you have created and not just one line.

        Comment


          #5
          Hello chakriare,

          Based on your original statement:
          if the 14 EMA of current bar range is 50% greater than the14 EMA of previous bar range
          This would be the correct condition:
          Code:
          if(EMA(Range(), 14)[0] > (EMA(Range(), 14)[1] * 1.5))
          {
          //Do something
          }
          This indicates that either you are trying to do something else or you have your condition in the wrong place in your code.

          Please provide additional information or the surrounding code you are using so we can better assist.

          Thank you in advance.
          Michael M.NinjaTrader Quality Assurance

          Comment


            #6
            Thanks all, still not working. I'm sure I'm doing wrong in the code or chart settings. here is my full code..

            protected override void OnBarUpdate()
            {
            //Add your custom indicator logic here.

            if (EMA(Range(), 14)[0] > (EMA(Range(), 14)[1] * 1.5))
            {

            Draw.Diamond(this, "MyDiamond" + CurrentBar.ToString(), false, 0, High[0] + 2 * TickSize, Brushes.Blue);
            }

            }

            Comment


              #7
              Hello chakraire,

              Thank you for the update. Could you please let me know what is happening when this is applied to a chart and whether this is code from a strategy or an indicator?

              Thank you in advance.
              Michael M.NinjaTrader Quality Assurance

              Comment


                #8
                its an indicator (price overlay is true so there is no separate plot). I would expect the blue dots above the price bar when the condition is true on the chart, and I"m not even seeing one blue dot in the last 4 months. I changed the if condition to something simple (like close >open), just to check if anything wrong on the chart settings, but with that condition it is accurately plotting the blue dots. however when I change it back to actual logic its not plotting.

                Comment


                  #9
                  Hello Chakriare,

                  Thank you for the update. You are likely getting an error in your log and the indicator is not running because you are trying to access an index which is out of range. Please add the following code to the top of your OnBarUpdate() method and let me know if the issue persists:
                  Code:
                  if(CurrentBar < 1) return;
                  Thank you in advance.
                  Michael M.NinjaTrader Quality Assurance

                  Comment

                  Latest Posts

                  Collapse

                  Topics Statistics Last Post
                  Started by CortexZenUSA, Today, 12:53 AM
                  0 responses
                  1 view
                  0 likes
                  Last Post CortexZenUSA  
                  Started by CortexZenUSA, Today, 12:46 AM
                  0 responses
                  1 view
                  0 likes
                  Last Post CortexZenUSA  
                  Started by usazencortex, Today, 12:43 AM
                  0 responses
                  5 views
                  0 likes
                  Last Post usazencortex  
                  Started by sidlercom80, 10-28-2023, 08:49 AM
                  168 responses
                  2,265 views
                  0 likes
                  Last Post sidlercom80  
                  Started by Barry Milan, Yesterday, 10:35 PM
                  3 responses
                  11 views
                  0 likes
                  Last Post NinjaTrader_Manfred  
                  Working...
                  X