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

Awerage of the Open-Close range.

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

    Awerage of the Open-Close range.

    Hello.
    I'm looking for indicator what shows me the average between the open and close range. Something simpler than ATR.
    Any suggestions appreciated.
    Rgds
    Czarek.

    #2
    I am not aware of an indicator which performs as you describe. I found several variations of the Average True Range indicator in a list of search results for 'Range' on the forums:



    If none of these indicators are what you;'re looking for, could you go into further detail about exactly what this "average between the open and close range" does? If you've seen it on a website or video, could you provide those resources?

    Also, I noticed that you posted in the Indicator Development forums. Please clarify - are you asking for assistance with programming this yourself? Or are you just interested in obtaining this indicator without any programming by yourself?

    Comment


      #3
      I cannot anything suitable in the link.
      I can try to programme myself or adjust the ATR indicator code.
      I would like to take Open and Close of each bar and compute the range. Then it compute the average of those ranges during a period.
      For example period 3.

      1bar Open- Close = 6
      2bar Open-Close = -4 (this have to changed for positive 4)
      3bar Open-Close = 11

      6+4+11= 21/3 =7


      Just this simple :-))

      Comment


        #4
        Hello Czarek,

        Below is a link to a forum post with helpful information about getting started with NinjaScript.


        The open is provided with the Open series that provides the open prices for each bar. This is accessed with a bars ago index.
        Below is a public link to the help guide on Open.

        And a public link to the help on Close.


        To always have a positive value you can use Math.Abs() for the absolute value.
        For example:
        Print(Math.Abs(Open[0]-Close[0]));

        This would print the absolute difference between the high and the low.
        Chelsea B.NinjaTrader Customer Service

        Comment


          #5
          Hello.
          I edited ATR code and I got this:
          Code:
          {
          		protected override void OnStateChange()
          		{
          			if (State == State.SetDefaults)
          			{
          				//Description					= NinjaTrader.Custom.Resource.NinjaScriptIndicatorDescriptionATR;
          				Name						= "OCATR";
          				IsSuspendedWhileInactive	= true;
          				Period						= 14;
          
          				AddPlot(Brushes.DarkCyan, NinjaTrader.Custom.Resource.NinjaScriptIndicatorNameATR);
          			}
          		}
          
          		protected override void OnBarUpdate()
          		{
          			double open0	= Open[0];
          			double close0	= Close[0];
          
          			if (CurrentBar == 0)
          				Value[0] = Math.Abs(close0 - open0);
          		else
          			{
          			//	double close1		= Close[1];
          				double trueRange	= Math.Abs(close0 - open0);
          				Value[0]			= ((Math.Min(CurrentBar + 1, Period) -1) * Value[1] + trueRange) / Math.Min(CurrentBar + 1, Period);
          			}
          		}
          
          		#region Properties
          		[Range(1, int.MaxValue), NinjaScriptProperty]
          		[Display(ResourceType = typeof(Custom.Resource), Name = "Period", GroupName = "NinjaScriptParameters", Order = 0)]
          		public int Period
          		{ get; set; }
          		#endregion
          	}

          Unfortunately it still counting a little bit more than expected. Could you advise me where to look for this issue??

          Comment


            #6
            try this one
            Attached Files

            Comment


              #7
              Hello Czarek,

              When you mention "Unfortunately it still counting a little bit more than expected" can you clarify what is counting higher?

              Are you saying that Math.Abs(Open[0] - Close[0]) is giving a value higher than from the open to the close?

              Print the value of Open[0], the value of Close[0], and the value of Math.Abs(Open[0] - Close[0]) in the same print and provide the output with your next post so that I can see that the values produced are incorrect.

              Print(string.Format("{0} | Open[0]: {1}, Close[0]: {2}, Abs(): {3}", Time[0], Open[0], Close[0], Math.Abs(Open[0] - Close[0]) ));
              Chelsea B.NinjaTrader Customer Service

              Comment


                #8
                Time period is .
                Output shows:
                8/1/2018 10:00:00 PM | Open[0]: 281.56, Close[0]: 280.86, Abs(): 0.699999999999989
                8/2/2018 10:00:00 PM | Open[0]: 279.38, Close[0]: 282.39, Abs(): 3.00999999999999
                So average of this 2 candles is about 1.85 but indicator shows : 1.94

                Comment


                  #9
                  Hello Czarek,

                  What instrument are you running this on?

                  The value produced by Math.Abs(Open[0] - Close[0]) should be at an exact tick size.

                  I am expecting .7 and -3.01 exactly.

                  This is not an average. It is the absolute difference between the open and the close..

                  Have you modified the print?
                  Chelsea B.NinjaTrader Customer Service

                  Comment


                    #10
                    No I did not modified the print.
                    Instrument is SPY.
                    See attached print screens.
                    Attached Files
                    Last edited by Czarek; 08-07-2018, 03:46 PM.

                    Comment


                      #11
                      Hey Czarek,

                      Thank you for letting me know the instrument so I could test as well.

                      I think this is just a floating point arithmetic issue.

                      Below is a link to a forum post that goes into detail.


                      You could round the value with Instrument.MasterInstrument.RoundToTickSize().
                      Below is a public link to the help guide.


                      For comparisons you can check if the difference is smaller than a double.Epsilon.
                      if (Open[0] - Close[0] < double.Epsilon)
                      Chelsea B.NinjaTrader Customer Service

                      Comment


                        #12
                        Hello.
                        Thanks for your answer.
                        Actually rounding is not a point.
                        Problem is that the indicator shows wrong value.

                        Sample:
                        Period : 2
                        Range on first candle is: 0.7
                        Range on second candle is: 3.01
                        I want to calculate like this: (0.7+3.01)/2=1.855
                        but indicator shows 1.93 see attached picture.
                        Here is the code:
                        Code:
                        / This namespace holds indicators in this folder and is required. Do not change it.
                        namespace NinjaTrader.NinjaScript.Indicators
                        {
                        	/// <summary>
                        	/// The Average True Range (ATR) is a measure of volatility. It was introduced by Welles Wilder
                        	/// in his book 'New Concepts in Technical Trading Systems' and has since been used as a component
                        	/// of many indicators and trading systems.
                        	/// </summary>
                        	public class OCATR : Indicator
                        	{
                        		protected override void OnStateChange()
                        		{
                        			if (State == State.SetDefaults)
                        			{
                        				//Description					= NinjaTrader.Custom.Resource.NinjaScriptIndicatorDescriptionATR;
                        				Name						= "OCATR";
                        				IsSuspendedWhileInactive	= true;
                        				Period						= 2;
                        
                        				AddPlot(Brushes.DarkCyan, NinjaTrader.Custom.Resource.NinjaScriptIndicatorNameATR);
                        			}
                        		}
                        
                        		protected override void OnBarUpdate()
                        		{
                        			double open0	= Open[0];
                        			double close0	= Close[0];
                        
                        			if (CurrentBar == 0)
                        				Value[0] = Math.Abs(open0 - close0);
                        		else
                        			{
                        			
                        				double trueRange	= Math.Abs(open0 - close0);
                        				Value[0]			= ((Math.Min(CurrentBar + 1, Period) - 1 ) * Value[1] + trueRange) / Math.Min(CurrentBar + 1, Period);
                        			
                        			}
                        		
                        	    
                        		Print(string.Format("{0} | Open[0]: {1}, Close[0]: {2}, Abs(): {3}", Time[0], Open[0], Close[0], Math.Abs(Open[0] - Close[0])) ); 
                        		
                        	       }
                        Attached Files

                        Comment


                          #13
                          Hello Czarek,

                          Our NinjaScript Support is not able to assist with custom calculations or custom logic, but this thread will remain open for any community members that would like to assist.

                          You can also contact a professional NinjaScript Consultant who would be eager to create or modify this script at your request or assist you with your script. The NinjaTrader Ecosystem has affiliate contacts who provide educational as well as consulting services. Please let me know if you would like our business development follow up with you with a list of affiliate consultants who would be happy to create this script or any others at your request.
                          Chelsea B.NinjaTrader Customer Service

                          Comment


                            #14
                            Originally posted by Czarek View Post
                            Hello.
                            Thanks for your answer.
                            Actually rounding is not a point.
                            Problem is that the indicator shows wrong value.

                            Sample:
                            Period : 2
                            Range on first candle is: 0.7
                            Range on second candle is: 3.01
                            I want to calculate like this: (0.7+3.01)/2=1.855
                            but indicator shows 1.93 see attached picture.
                            Here is the code:
                            Code:
                            / This namespace holds indicators in this folder and is required. Do not change it.
                            namespace NinjaTrader.NinjaScript.Indicators
                            {
                            	/// <summary>
                            	/// The Average True Range (ATR) is a measure of volatility. It was introduced by Welles Wilder
                            	/// in his book 'New Concepts in Technical Trading Systems' and has since been used as a component
                            	/// of many indicators and trading systems.
                            	/// </summary>
                            	public class OCATR : Indicator
                            	{
                            		protected override void OnStateChange()
                            		{
                            			if (State == State.SetDefaults)
                            			{
                            				//Description					= NinjaTrader.Custom.Resource.NinjaScriptIndicatorDescriptionATR;
                            				Name						= "OCATR";
                            				IsSuspendedWhileInactive	= true;
                            				Period						= 2;
                            
                            				AddPlot(Brushes.DarkCyan, NinjaTrader.Custom.Resource.NinjaScriptIndicatorNameATR);
                            			}
                            		}
                            
                            		protected override void OnBarUpdate()
                            		{
                            			double open0	= Open[0];
                            			double close0	= Close[0];
                            
                            			if (CurrentBar == 0)
                            				Value[0] = Math.Abs(open0 - close0);
                            		else
                            			{
                            			
                            				double trueRange	= Math.Abs(open0 - close0);
                            				Value[0]			= ((Math.Min(CurrentBar + 1, Period) - 1 ) * Value[1] + trueRange) / Math.Min(CurrentBar + 1, Period);
                            			
                            			}
                            		
                            	    
                            		Print(string.Format("{0} | Open[0]: {1}, Close[0]: {2}, Abs(): {3}", Time[0], Open[0], Close[0], Math.Abs(Open[0] - Close[0])) ); 
                            		
                            	       }
                            That is because you have just tried to make substitutions instead of coding to the requirements that you described. Value[0] as you have assigned it is calculating the Wilder Average, not the SMA that you have specified.

                            You have to use a Series<double> to hold the values of the Close to Open range, and then take the SMA of that Series, and assign that value to the Plot.

                            Comment


                              #15
                              Hello.
                              Thanks for your answer. I'm getting closer and closer :-)))
                              Can you show me the sample of the snippet of the Series<double> what hold the values of the Close to Open range?

                              Comment

                              Latest Posts

                              Collapse

                              Topics Statistics Last Post
                              Started by jclose, Today, 09:37 PM
                              0 responses
                              5 views
                              0 likes
                              Last Post jclose
                              by jclose
                               
                              Started by WeyldFalcon, 08-07-2020, 06:13 AM
                              10 responses
                              1,413 views
                              0 likes
                              Last Post Traderontheroad  
                              Started by firefoxforum12, Today, 08:53 PM
                              0 responses
                              11 views
                              0 likes
                              Last Post firefoxforum12  
                              Started by stafe, Today, 08:34 PM
                              0 responses
                              11 views
                              0 likes
                              Last Post stafe
                              by stafe
                               
                              Started by sastrades, 01-31-2024, 10:19 PM
                              11 responses
                              169 views
                              0 likes
                              Last Post NinjaTrader_Manfred  
                              Working...
                              X