• 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

How can I have Strategy Wizard wait to confirm a trigger?

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

    How can I have Strategy Wizard wait to confirm a trigger?

    New to the Strategy Wizard and Condition Builder, my apologies if this has an obvious answer I'm overlooking.
    I'm putting together a basic moving average cross where the cross will trigger a trade.
    I put the lookback period on the cross to "4" and have a separate condition where the fast moving avg is either greater than or less than the slow moving avg (depending on the cross) as a confirmation. Moving averages can stay together or intertwine for an extended period. I am looking for the trade to be triggered based on the cross but actually occur once the averages diverge, if they indeed diverge in the direction of said cross. If they diverge in the opposite direction of the cross, than trade wouldn't occur. Any thoughts on which conditions can do that for me. Any help is most appreciated.
    Thanks

    #2
    Hello decoda,

    Thank you for your post and welcome to the NinjaTrader Support Forum!

    So we are looking for the fast crossing above the slow, then we say the direction is up, if the fast goes down then trade cannot occur? Likewise, if the fast crosses below the slow, then we say the direction is down, is the fast goes up then trade cannot occur?

    I look forward to your response.
    Patrick H.NinjaTrader Customer Service

    Comment


      #3
      Patrick,
      Yes, that is correct. In addition, the trade would not happen until an actual divergence beyond the cross has occurred.
      Thanks for your help.

      Comment


        #4
        Hello decoda,

        Thank you for your response.

        Please detail what you mean by divergence. Is this both moving averages trending in the same direction but different from the previous direction, or is this both moving average moving away from each other by a set value?
        Patrick H.NinjaTrader Customer Service

        Comment


          #5
          Patrick,
          Essentially, I want the two moving averages moving away from each other. It doesn't matter direction, as long as the divergence is in the same direction as the cross (ex: fast crosses above slow but stays with the slow for a number of bars, once the fast breaks away from the slow in the upward direction; the trade is triggered. If it breaks away to the downside, the signal is reset til the next cross). My main concern is getting whipsawed when the two averages sit on top of each other for a period of time. The divergence can be a set tick/$ amount or a "greater than/less than" scenario. Thanks again for your help.

          Comment


            #6
            Hello decoda,

            Thank you for your response.

            Can you provide the set tick amount and expand on how you would calculate the divergence base don greater than or less than?
            Patrick H.NinjaTrader Customer Service

            Comment


              #7
              Patrick,
              For example, the divergence could be 1 tick or .01 of $ value on a crude oil (CL) future as one option or another option would be the following statement (change terminology as needed so Strategy Wizard/Condition Builder understands):
              "after fast MA crosses above slow MA, trade when fast MA > slow MA". I have the cross above setting with a lookback of 4, so the hope is the trade occurs 4 bars after the cross, provided the fast MA stays above slow MA. If they're still more or less equal at that point, I would still like the trade to trigger once the fast MA breaks away to the upside, no matter how many bars down the road it is.
              Thanks

              Comment


                #8
                Hello decoda,

                Thank you for your patience.

                I have crated a strategy outside of the Strategy Wizard for this example as I needed to use items that are not available in the Strategy Wizard. I have also created a video explaining the strategy.

                The video is available at the following link: http://screencast.com/t/wKQtBtW1

                Download the .zip attached to this response to your desktop and then go to File > Utilities > Import NinjaScript > and select the file. You can then view the file under Tools > Options > Edit NinjaScript Strategy. It will be called DecodasCrossStrategy.
                Attached Files
                Patrick H.NinjaTrader Customer Service

                Comment


                  #9
                  Patrick,
                  That's awesome, thanks for going through the trouble of putting this together for me. The video explained everything well, I shouldn't have a difficult time tweaking things if need be. I appreciate
                  the help!
                  Thanks again

                  Comment


                    #10
                    Hi,
                    I know it is very late for comments, but I just saw, accidentally, Patrick's code (which I am not sure that it is absolutely correct). Instaead, I created a similar code which I think gives a better solution/approach to this issue :

                    ...
                    #region Variables
                    ...
                    private int barAtCrossLong;
                    private int barAtCrossShort;
                    ...

                    protected override void OnBarUpdate()
                    {
                    if(CurrentBar <= Slow)
                    {return;}

                    if(Bars.FirstBarOfSession)
                    {
                    barAtCrossLong = 0;
                    barAtCrossShort = 0;
                    }

                    // ========== For Long entry ===============


                    if( Position.MarketPosition == MarketPosition.Short
                    && CrossAbove(SMA(Fast), SMA(Slow),1))
                    {
                    ExitShort();
                    barAtCrossLong = CurrentBar;
                    }

                    if(Position.MarketPosition == MarketPosition.Flat
                    && CurrentBar > barAtCrossLong + 4
                    && SMA(Fast)[3] > SMA(Slow)[3]
                    && SMA(Fast)[2] > SMA(Slow)[2]
                    && SMA(Fast)[1] > SMA(Slow)[1]
                    && SMA(Fast)[0] > SMA(Slow)[0])
                    {
                    EnterLong();
                    }

                    // ========== For Short entry ===============


                    if( Position.MarketPosition == MarketPosition.Long
                    && CrossBelow(SMA(Fast), SMA(Slow),1))
                    {
                    ExitLong();
                    barAtCrossShort = CurrentBar;
                    }

                    if(Position.MarketPosition == MarketPosition.Flat
                    && CurrentBar > barAtCrossShort + 4
                    && SMA(Fast)[3] < SMA(Slow)[3]
                    && SMA(Fast)[2] < SMA(Slow)[2]
                    && SMA(Fast)[1] < SMA(Slow)[1]
                    && SMA(Fast)[0] < SMA(Slow)[0])
                    {
                    EnterShort();
                    }
                    }

                    Thanks
                    George

                    Comment

                    Latest Posts

                    Collapse

                    Topics Statistics Last Post
                    Started by simjs, Yesterday, 08:11 PM
                    0 responses
                    3 views
                    0 likes
                    Last Post simjs
                    by simjs
                     
                    Started by mrlucky1x, Yesterday, 06:01 PM
                    0 responses
                    3 views
                    0 likes
                    Last Post mrlucky1x  
                    Started by dedouglas, Yesterday, 03:17 PM
                    1 response
                    9 views
                    0 likes
                    Last Post NinjaTrader_Jesse  
                    Started by Jugado, Yesterday, 02:22 PM
                    2 responses
                    30 views
                    0 likes
                    Last Post Jugado
                    by Jugado
                     
                    Started by login_dejavu, 04-21-2019, 04:58 AM
                    2 responses
                    24 views
                    0 likes
                    Last Post login_dejavu  
                    Working...
                    X