Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Looking to create a "wait" for trade after trigger signal

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

    Looking to create a "wait" for trade after trigger signal

    Hi Folks,
    I've put all of my automated strategy together with the exception of one aspect. I've posted for help but either I'm not explaining myself well or the sample code I get back is much more than I need (and I'm not a good enough programmer to siphon out what's needed):
    I know this can't be done in the wizard, I think code is the only option

    Here's the deal:
    When my Fast MACD crosses over my Slow MACD, the trade is triggered BUT NOT MADE until the following confirmation:

    A)MACD diff* > "x" (ticks or currency), then trade
    or
    B) Fast MACD crosses back below Slow MACD, trigger will be reset (no trade)

    if neither A or B happens yet, wait for next bar and go from there
    Eventually, one of the two options will prevail.

    I just need the coding for the "if A is true, go to Action Command; if B is true, Reset Trigger. If both are false, wait for next bar".

    *MACD diff doesn't know the direction of divergence and could create a scenario where both A & B are true; if that is possible I can also use a "Fast EMA > Slow EMA by value of "x" " with the two EMA's having the same setting as the MACD's.
    Please help, thanks in advance.
    Decoda
    Last edited by decoda; 12-16-2014, 08:29 PM.

    #2
    Hello Decoda,

    Thanks for your post.

    To accomplish your goal what you would need to do is to use a boolean variable to hold the state of the macd cross so that if the boolean was true, then look for the next condition which is the size of the difference between the macd lines. If the Macd crosses below, set the boolean back to false to restart the sequence.

    So basically, in code:

    Code:
    private bool macdCrossedAbove = false;  // Initilize to false
    
    private bool macdCrossedBelow = false; // Initialize to false
    
    
    
    if (CrossAbove(MACD(12, 26, 9), MACD(12, 26, 9).Avg, 1))
    {
    // set bool true
    macdcrossedabove = true;  // set bool to now look for macd diff
    macdCrossedBelow = false; // reset otherside bool
    }
    
    if (macdCrossedAbove && MACD(12, 26, 9).Diff[0] > 0.1)  
    {
    // enter order long here
    macdCrossedabove = false;  // Reset bool
    }
    
    if (CrossBelow(MACD(12, 26, 9), MACD(12, 26, 9).Avg, 1))
    {
    // set bool true
    macdcrossedabove = false;  // reset otherside bool
    macdCrossedBelow = true; // set bool to now look for macd diff
    }
    
    if (macdCrossedBelow && MACD(12, 26, 9).Diff[0] < 0.1)
    {
    // enter order short here
    macdCrossedBelow = false;  // Reset bool
    }

    If you want to do this in the strategy wizard, the same thing can be accomplished by using the User defined variables as bools in this case. I have attached 4 pictures that show the 4 sets needed to accomplish what i have shown in code above. Note: I did not add code for order entry but used an arrow to indicate on chart where order would go.

    Please let me know if I can be of further assistance.
    Attached Files
    Paul H.NinjaTrader Customer Service

    Comment


      #3
      Paul,
      Awesome, this looks like exactly what I was looking for. I didn't know you could do it
      in the wizard, I'll try them both out.
      Thanks so much.

      Comment


        #4
        Paul,
        Thanks again for the code, I intergrated into the rest of the automated strategy, finally got it all compiled. Unfortunately, I'm only getting zero's when backtesting. I downloaded all the historical data for the instrument I'm testing. When I go to backtest, it doesn't seem to even start to process before returning the zero results. Is it possible to take a look at the code? I apologize, I'm not a programmer and have had invested a considerable amount of time into developing this and it's been incredibly frustrating. Please advise. Thanks

        Also, I copied the simple crossover strategy based on the four screenshots you sent me (instead of arrows though, I longed in when cross above happened and longed out when cross below happened; all other parameter were the same). I got all zero's again from the backtest, maybe there's an issue with the backtester and not the strategy?
        Last edited by decoda; 12-17-2014, 10:12 PM.

        Comment


          #5
          Hello Decoda,

          Thanks for your reply.

          I would be happy to review the code. You may post here or if you would rather, send to me via e-mail to PlatformSupport[at]NinjaTrader[dot]Com

          If you e-mail it, please reference ticket # 1219023 and atten: Paul in the subject of the e-mail.
          Paul H.NinjaTrader Customer Service

          Comment


            #6
            Thanks a lot Paul, I appreciate it. Will email it to you momentarily.

            Comment

            Latest Posts

            Collapse

            Topics Statistics Last Post
            Started by cmtjoancolmenero, Yesterday, 03:58 PM
            10 responses
            36 views
            0 likes
            Last Post NinjaTrader_ChelseaB  
            Started by DayTradingDEMON, Today, 09:28 AM
            4 responses
            24 views
            0 likes
            Last Post DayTradingDEMON  
            Started by geddyisodin, Yesterday, 05:20 AM
            8 responses
            51 views
            0 likes
            Last Post NinjaTrader_Gaby  
            Started by George21, Today, 10:07 AM
            1 response
            16 views
            0 likes
            Last Post NinjaTrader_ChristopherJ  
            Started by Stanfillirenfro, Today, 07:23 AM
            9 responses
            25 views
            0 likes
            Last Post NinjaTrader_ChelseaB  
            Working...
            X