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

Establish Open Value of an Indicator

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

    Establish Open Value of an Indicator

    Good Morning,

    I need a little help. I am trying to create a Condition within my Strategy that establishes the open value of a moving average. This value would then be used throughout the day as a reference point. I tried the Open from the CurrentOHL Indicator and used the moving average as the Input Series but that doesn't work. Not sure but it appears that with that setup, it is giving me the moving average value of all the Opens. I am guessing there is an easy way to get this but it just isn't hitting me. Greatly appreciate the help if someone has an idea. Thank you.



    #2
    Originally posted by Ram011558 View Post
    Good Morning,

    I need a little help. I am trying to create a Condition within my Strategy that establishes the open value of a moving average. This value would then be used throughout the day as a reference point. I tried the Open from the CurrentOHL Indicator and used the moving average as the Input Series but that doesn't work. Not sure but it appears that with that setup, it is giving me the moving average value of all the Opens. I am guessing there is an easy way to get this but it just isn't hitting me. Greatly appreciate the help if someone has an idea. Thank you.

    The CurrentOHL at open has an idex value of 0. A moving average needs at least "n #" of bars before can calculate a value. i.e. SMA(14) needs 14 bars after the open time to calculate a SMA value.

    Depending on the type of instrument and time frame you may be able to get a MA value at the open if you use full session, however, values may not be accurate due to nightly gaps.

    Comment


      #3
      Originally posted by aligator View Post

      The CurrentOHL at open has an idex value of 0. A moving average needs at least "n #" of bars before can calculate a value. i.e. SMA(14) needs 14 bars after the open time to calculate a SMA value.

      Depending on the type of instrument and time frame you may be able to get a MA value at the open if you use full session, however, values may not be accurate due to nightly gaps.



      Thank you for the reply. I am using the RTH chart. So I changed the strategy to use the Prior Close instead of Current Open. Entry point for the strategy is 18 bars into the day with a SMA(16). So there is sufficient time for the SMA to calculate based on the current days data. Still doesn't work. I am assuming that Prior OHLC and Current OHL can be used on indicators? Any thoughts from anyone? Again, I am trying to compare indicator values through out the day to an established start of session value using an OHLC with the Input set to the indicator. Appreciate the help.

      Comment


        #4
        Hello Ram011558,

        When you mention that it doesn't work, are you getting an error message?

        What is the full error message?

        CurrentDayOHL and PriorDayOHL will have an open price that will not change for the day. However, I don't see any issue supplying this to an SMA call. Are you trying to supply the SMA to the CurrentDayOHL indicator? (These indicators would ignore the SMA and just use the prices from the data on the chart)
        Chelsea B.NinjaTrader Customer Service

        Comment


          #5
          Originally posted by NinjaTrader_ChelseaB View Post
          Hello Ram011558,

          When you mention that it doesn't work, are you getting an error message?

          What is the full error message?

          CurrentDayOHL and PriorDayOHL will have an open price that will not change for the day. However, I don't see any issue supplying this to an SMA call. Are you trying to supply the SMA to the CurrentDayOHL indicator? (These indicators would ignore the SMA and just use the prices from the data on the chart)

          Hi Chelsea,

          Thank you for getting back to me. I am trying to get the current open or prior close value of the SMA. So I use the OHLC indicator and insert the SMA indicator in the Input Series in the Condition Builder. I am not getting an error message, but is is giving me the wrong value. Thanks again.

          Comment


            #6
            Hello Ram011558,

            The PriorDayOHLC indicator produces the same value for every bar until the day changes. This means an SMA using the PriorDayOHLC would be averaging many bars with the same value, until the value changes.

            When you say the value is incorrect, are you comparing this with a chart that is using the PriorDayOHLC as the input series for the SMA and this is showing the correct values?

            Are you wanting an average of daily bar closes? In which case, add a secondary series of day bars and use that as the input series for the SMA.
            Last edited by NinjaTrader_ChelseaB; 05-02-2019, 07:02 AM.
            Chelsea B.NinjaTrader Customer Service

            Comment


              #7
              Originally posted by Ram011558 View Post


              Hi Chelsea,

              Thank you for getting back to me. I am trying to get the current open or prior close value of the SMA. So I use the OHLC indicator and insert the SMA indicator in the Input Series in the Condition Builder. I am not getting an error message, but is is giving me the wrong value. Thanks again.
              So just record the value at the change of day. No?

              For example:

              In Variables section
              private double refSmaValue = 0;
              private SMA sma;
              private int smaPeriod = 10; //or whatever you want. Maybe make this an input parameter for the indicator?

              In OnBarUpdate()
              if (CurrentBar == 0) sma = SMA(smaPeriod); //initialize the indicator variable
              if (Time[1].Date != Time[0].Date) refSmaValue = sma[1]; //to use previous day's closing value. If you want to use the current day's open value, use sma[0]

              Comment


                #8
                Hello koganam,

                Thanks for your input here. I wasn't quite understanding the goal.

                Ram011558, is the goal is to get a snap shot of the SMA using the primary series at each day close?
                Chelsea B.NinjaTrader Customer Service

                Comment


                  #9
                  Originally posted by NinjaTrader_ChelseaB View Post
                  Hello koganam,

                  Thanks for your input here. I wasn't quite understanding the goal.

                  Ram011558, is the goal is to get a snap shot of the SMA using the primary series at each day close?
                  Yes, Chelsea, his requirement is very poorly stated. But, at least he tried. You would be surprised at what some people want to be coded, while not willing to clarify their statements. I actually had one customer tell me that he was not educated enough to even describe what he was physically doing, so that I could try to replicate it in code!

                  Comment


                    #10
                    Originally posted by NinjaTrader_ChelseaB View Post
                    Hello Ram011558,

                    The PriorDayOHLC indicator produces the same value for every bar until the day changes. This means an SMA using the PriorDayOHLC would be averaging many bars with the same value, until the value changes.

                    When you say the value is incorrect, are you comparing this with a chart that is using the PriorDayOHLC as the input series for the SMA and this is showing the correct values?

                    Are you wanting an average of daily bar closes? In which case, add a secondary series of day bars and use that as the input series for the SMA.


                    Hi Chelsea,

                    I'll start from the beginning and lay this out for you:


                    I do not have experience with programming so I am using the Strategy Builder in NT7

                    At the beginning of each new session, I want to establish the opening value of an SMA for that day.

                    Once established/calculated, I want to use this opening value throughout the same day to compare subsequent SMA values

                    An example of what I am trying to achieve. The opening value of the SMA was at $50. If at 1:00 PM, the current SMA is above the opening value of $50, place a long position.

                    In my strategy, I tried comparing an SMA to the Open of OLC indicator with the SMA set as the Input Series and it is not working as expected. I know this because when I back-test the strategy, it is not placing orders as it should. When the current SMA is higher than the Open SMA, the strategy did not fire a Long position.

                    Attached is what I have in the strategy.

                    Does this help clarify the situation?

                    Click image for larger version

Name:	SMAOHL.jpg
Views:	654
Size:	194.5 KB
ID:	1055947

                    Comment


                      #11
                      Hello Ram011558,

                      Thanks for your reply.

                      This is Paul responding for Chelsea who is out of the office today.

                      We appreciate the effort to clarify and can offer a way to accomplish your goal. After reading through all of the posts you have stated you want to obtain the value of a moving average at the beginning of the session and then use that as a comparison value.

                      In the NT7 strategy wizard, what I suggest is using a time check to see if the close time of the bar is equal to what the close time of the first bar of the session would be. So for example, if using 1-minute bars on the chart and the session open time was 9:30 AM then you would create a condition that checks to see if the current bar time is equal to 9:31 AM which would be the first 1-minute bar close in a new session. In the wizard that would look like: ToTime(Time[0]) == ToTime(9, 31, 0). So that provides a condition that will trigger on the close of the first bar of the RTH session.

                      For the action of that same set, you would store the value of any indicator or price into any of the 10 available user defined variables labeled Variable0 - Variable9. Does not matter which you use as long as you use the same one later. Using a 14 period SMA for example this would look like: Variable0 = SMA(14)[0].

                      So in the one set, you have a time-based trigger on the first bar of the session and the action is to save the current value of the SMA into a user-defined variable called Variable0. This set can only trigger once at that time of day so each day you would have the latest value.

                      You can now use Variable0 in your other sets to compare to as Variable0 will only hold the value from the SMA at the beginning of the session.

                      So if you are using time-based bars, that would be how you can accomplish your goal.

                      Please note that using an RTH template means that any moving average you are using will be subjected to price jumps/gaps from one session to the next and this will certainly skew the SMA values.
                      Paul H.NinjaTrader Customer Service

                      Comment


                        #12
                        Originally posted by NinjaTrader_PaulH View Post
                        Hello Ram011558,

                        Thanks for your reply.

                        This is Paul responding for Chelsea who is out of the office today.

                        We appreciate the effort to clarify and can offer a way to accomplish your goal. After reading through all of the posts you have stated you want to obtain the value of a moving average at the beginning of the session and then use that as a comparison value.

                        In the NT7 strategy wizard, what I suggest is using a time check to see if the close time of the bar is equal to what the close time of the first bar of the session would be. So for example, if using 1-minute bars on the chart and the session open time was 9:30 AM then you would create a condition that checks to see if the current bar time is equal to 9:31 AM which would be the first 1-minute bar close in a new session. In the wizard that would look like: ToTime(Time[0]) == ToTime(9, 31, 0). So that provides a condition that will trigger on the close of the first bar of the RTH session.

                        For the action of that same set, you would store the value of any indicator or price into any of the 10 available user defined variables labeled Variable0 - Variable9. Does not matter which you use as long as you use the same one later. Using a 14 period SMA for example this would look like: Variable0 = SMA(14)[0].

                        So in the one set, you have a time-based trigger on the first bar of the session and the action is to save the current value of the SMA into a user-defined variable called Variable0. This set can only trigger once at that time of day so each day you would have the latest value.

                        You can now use Variable0 in your other sets to compare to as Variable0 will only hold the value from the SMA at the beginning of the session.

                        So if you are using time-based bars, that would be how you can accomplish your goal.

                        Please note that using an RTH template means that any moving average you are using will be subjected to price jumps/gaps from one session to the next and this will certainly skew the SMA values.

                        Thank you Paul. This makes a lot of sense. Quick question. If I am using a 5 minute chart and I set the Variable at 9:35 with the SMA set to 1 Bars Ago, would that then establish the SMA at the close of the previous day? Appreciate your help.

                        Comment


                          #13
                          Hello,

                          Thanks for your reply.

                          Yes, based on an RTH trading hours chart that should work.

                          Paul H.NinjaTrader Customer Service

                          Comment


                            #14
                            Originally posted by NinjaTrader_PaulH View Post
                            Hello,

                            Thanks for your reply.

                            Yes, based on an RTH trading hours chart that should work.


                            Thank you Paul. You've been very helpful.

                            As a side note. Is there a way that I can contact NT Customer Service directly with technical questions rather than going through the forums? Again, your help is appreciated.
                            Last edited by Ram011558; 05-04-2019, 08:01 AM.

                            Comment


                              #15
                              Hello Ram011558,

                              Thanks for your reply.

                              You do not need to use the forum at all for help from us. At any time, please feel free to write in directly to PlatformSupport[at]NinjaTrader[dot]Com. Note that in the forum we are using [at] to represent the normal @ and [dot] to represent the normal ".". We do this to prevent spambots from directly grabbing the support e-mail address so you would need to replace [at] and [dot] with the actual @ and .

                              You can also write to us directly through the platform itself by going to Help>Mail to platform support, make sure to add your e-mail address if not already added.

                              In both cases, when writing to us you will get an immediate autoresponse advising that we received your e-mail. We typically follow-up shortly there after. Please make sure to add our e-mail address to your safe list as your e-mail system may detect our autoreply as spam.

                              Finally, while you are welcome to write in to us directly, we ask that you do not also post in the forum on the same subject.
                              Paul H.NinjaTrader Customer Service

                              Comment

                              Latest Posts

                              Collapse

                              Topics Statistics Last Post
                              Started by rtwave, 04-12-2024, 09:30 AM
                              5 responses
                              37 views
                              0 likes
                              Last Post NinjaTrader_ChelseaB  
                              Started by funk10101, Today, 12:02 AM
                              1 response
                              11 views
                              0 likes
                              Last Post NinjaTrader_LuisH  
                              Started by GLFX005, Today, 03:23 AM
                              1 response
                              6 views
                              0 likes
                              Last Post NinjaTrader_Erick  
                              Started by nandhumca, Yesterday, 03:41 PM
                              1 response
                              13 views
                              0 likes
                              Last Post NinjaTrader_Gaby  
                              Started by The_Sec, Yesterday, 03:37 PM
                              1 response
                              11 views
                              0 likes
                              Last Post NinjaTrader_Gaby  
                              Working...
                              X