• If this is your first visit, you will have to register before you can post. To view messages, please scroll below and select the forum that you would like to visits. Questions? Be sure to check out the Forum FAQ.

Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

First change of direction

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

    First change of direction

    Hi,

    I want to write a strategy and need some input how to begin because I'm not the best code writer.

    The strategy is something like:
    Enter short if RSI (or any other indicator) crosses below a certain level, let's say 50 and the MACD for example changes direction above its zero line for the first time from rising to falling.
    I know how to implement all the codes beside the MACD changing direction (first MACD high above its zero line).
    Is there someone, who can give me a hint how to start? Or does anybody know a link to a similar case. I didn't find anything in my search.
    Thanks!

    #2
    Hello Hanko,

    Thank you for the post.

    I wanted to first ask, are you trying to accomplish this using the strategy wizard or manually coding? I noted that you said you know how to implement these items but I wanted to be sure on which method you were actually using.

    If you are manually coding, you could use a bool variable as one solution.

    For example, you could check if the MACD is Rising or Falling and set variables to true or false depending on which direction the price is going.
    Later you could compare the current Rising or Falling values against the bool variables, depending on the value that the variable currently has you could check if the current Rising or Falling is now different than the stored value and if so complete an action.
    You may need to use further logic to reset these variables later or after a trade as an example.

    The wizard would be slightly more complicated but would be generally the same process. Setting a user variable when the condition is true, and resetting it later as needed.

    I look forward to being of further assistance.
    JesseNinjaTrader Customer Service

    Comment


      #3
      this is what i'm trying to do in strategy builder....
      i'ld like a signal to print and a sound when two indicators both change directions from both going down to both going up but i'm stuck on rising falling because i can't enter bars ago anywhere ??


      i.e.:
      ema13 and ema34 are going down i'ld like to run a strategy that plays a sound when they both turn up... and visa versa...


      thanks,
      w

      Comment


        #4
        i decided to code this as an indicator but i've run into a problem using IsFalling IsRising:


        i'm trying to check several bars back for the falling condition then check the current bar for the rising condition and i thought mistakenly that i could just force bars ago into the mix...


        if ( IsFalling(emaFast[2]) && IsFalling(emaFast[1]) && IsRising(emaFast[0]) )


        but i get an invalid argument error...
        is there a quick way to do this ?


        thanks,
        w

        Comment


          #5
          Hello stafe,

          Thank you for the post.

          The reason for the error is that Falling takes an IDataSeries and you are giving it a double. Also I see you are using IsFalling as your syntax, is this an NT7 or NT8 question? NT7 uses Falling, NT8 uses IsFalling

          You would likely need to make a BoolSeries to store the previous Falling or Rising values if you need to check a prior bars Falling or Rising.

          Rising and Falling simply checks "now" while the bars are processing. If you wanted to refer back to a prior bar that has been processed, you would need to have stored the value at the time the bar was processed.

          After creating a BoolSeries you could set the value of the series on each bar to the Rising or Falling value. Then you can use the series to look back at a previously evaluated bar and see if it was rising or falling.

          https://ninjatrader.com/support/help...sub=boolseries

          I look forward to being of further assistance.
          JesseNinjaTrader Customer Service

          Comment


            #6
            thanks Jesse, it is NT8 - but i didn't find any questions like this one in the NT8 section...
            i'm just trying to make a strat that detects when both averages are going up after having been going the other direction -- i hacked one out using the strat builder like EMA[3] > EMA[2] && EMA[2] > EMA[1] && EMA[0] > EMA[1] for the long term EMA and EMA[2] < EMA[1] && EMA[1] < EMA[0]


            but that seems really clunky....


            do you have any previous examples of code or strats that detect two indicators both having changed directions or say the longer term indi having just changed to the same direction the short term one was going ?


            i was actually trying to make an indicator that would do this instead of a strategy so i can see my trade locations but i can't get the signals to fire for some reason... should we change over to the NT8 forum and i can share my coding attempt ?



            thx
            Last edited by stafe; 06-14-2018, 09:27 AM.

            Comment


              #7
              Hello stafe,

              Thank you for the reply.

              I went ahead and moved this to the NT8 forum, in the future please ensure to either post in the NT8 forum for NT8 questions or mark the question as NT8 so that we can provide the most relevant help/syntax.

              The way you have created this with the builder is fine it is just a larger condition because of what is required. This is actually basically the same as what I had suggested with the series, you are just skipping the IsFalling so a series wouldn't be needed to access prior values.

              For what you are trying I am not sure there is a more elegant way to do this as you need to check the prior values for what you are trying to do.

              If you would like to upload what you tried that didn't work, I could take a look and see if I can note anything that might help.


              I look forward to being of further assistance.
              JesseNinjaTrader Customer Service

              Comment


                #8
                i ran across a post where someone gave some code using a bool series to do the same thing but i don't keep browsing history and i can't find it now....
                i'm not very versed in using a series to store indicator direction attributes...

                Comment


                  #9
                  Hello stafe,

                  Thank you for the reply.

                  We have a sample of creating a bool series, I will provide that below. If you dont want to use a series, that would be the same as using a bool series it just true or false instead of a price value.

                  I think the easiest way is going to be what you had shown or just using the prices, that is using the least syntax so far.

                  https://ninjatrader.com/support/help...us/seriest.htm

                  bool would replace T or double shown in the examples, T is a C# generic replaceable type that can be substituted with bool or double as an example.

                  I look forward to being of further assistance.
                  JesseNinjaTrader Customer Service

                  Comment

                  Latest Posts

                  Collapse

                  Topics Statistics Last Post
                  Started by Rednael90, Today, 07:22 AM
                  0 responses
                  7 views
                  0 likes
                  Last Post Rednael90  
                  Started by dadarara, Today, 02:42 AM
                  0 responses
                  4 views
                  0 likes
                  Last Post dadarara  
                  Started by TraderYoda, 10-17-2018, 09:06 AM
                  14 responses
                  163 views
                  1 like
                  Last Post TraderYoda  
                  Started by Johnny Santiago, Yesterday, 09:31 PM
                  0 responses
                  7 views
                  0 likes
                  Last Post Johnny Santiago  
                  Started by DarkCloudCover, Yesterday, 07:29 PM
                  1 response
                  28 views
                  1 like
                  Last Post TraderYoda  
                  Working...
                  X