Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Entering a trade after ES moves at least 5 points in favor of a signal

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

    Entering a trade after ES moves at least 5 points in favor of a signal

    Hello,
    I am creating a strategy where I enter a trade based on following conditions.
    1. Two moving averages cross each other
    2. Once a cross over happens, I want the ES to move at least 5 points in the favor of crossover, i.e. if it is a long side signal, I want ES to go up by 5 points and then enter the trade
    3. If the above conditions are met and a trade is placed (and it could result in profit or loss), I want the system to wait until the next crossover before placing the next trade.

    So far I was able to come up with the following code, but it is not working as I expect it to.
    Can you help me to figure out what is wrong?

    #region Variables
    // Wizard generated variables
    private int vma1 = xxx; // Default setting for Vma1
    private int vma2 = xxx; // Default setting for Vma2
    private int vma3 = xxx; // Default setting for Vma3
    private int vma1vol = xxx; // Default setting for Vma1volatility
    private int vma2vol = xxx; // Default setting for Vma2volatility
    private int vma3vol = xxx; // Default setting for Vma3volaltility
    private int stoplossticks = 24; // Default setting for Stoplossticks
    private int profittargetticks = 100; // Default setting for Profittargetticks
    private double LongValue = 0;
    private double ShortValue = 0;
    private double LongHighestGain = 0;
    private double ShortHighestGain = 0;

    protected override void OnBarUpdate()
    {
    if (CurrentBar < 500)
    return;
    //VALUE CALCULATIONS
    if(CrossAbove((T3(28,1,0.7)),(VMA(vma1,vma1vol)),1 ))
    {
    LongValue =Close[0];
    }
    double CurrentLongTradeHighestGain = High[0] - LongValue;
    LongHighestGain = Math.Max(LongHighestGain, CurrentLongTradeHighestGain);

    //LONG CRITERIA
    if ((T3(28, 1, 0.7)[0] > VsVMA2(vma1,vma1vol).VMA[0])
    && LongHighestGain >=5)
    {

    EnterLong(1,"Long");
    }
    if(CrossBelow((T3(28,1,0.7)),(VMA(vma2,vma2vol)),1 ))
    {
    ExitLong(1,"Long Exit","Long");
    }

    #2
    Hello pandyav,

    Thank you for your post.

    Please try the following for the "Long Criteria":
    Code:
    if ((T3(28, 1, 0.7)[0] > VsVMA2(vma1,vma1vol).VMA[0])
    && LongHighestGain >= (5*TickSize))
    For information on TickSize please visit the following link: http://www.ninjatrader.com/support/h...7/ticksize.htm

    Comment


      #3
      Hi Patrick,
      I tried the approach you suggested but it is not working as desired. I am attaching a screenshot of the chart. The thinnest lines is T3 moving average whereas the thickest is VsVMA2. When one crosses other, there is a potential for a long/short trade but I want to wait for the market to advance 5 points before entering the trade.

      So, by putting LongValue = Close[0], I am trying to capture the Close price of the bar when one MA crossed over other and then use 'LongHighestGain' to determine if the market has moved 5 points in the favor of the crossover or not? The blue bars at the bottom of the attached chart represents 'LongHighestGain' and as you see it certainly does not represent the difference between the high of the current bar and close of the bar when crossover happened.

      Is it possible for you or someone at NT to provide a quick phone support? I am sure it will not take more than 5 mins of your time to figure this one over the phone. Please let me know if it works for you.

      Thanks!
      Attached Files

      Comment


        #4
        Hello pandyav,

        Thank you for your response.

        My mistake, the correct code to check if the current close has risen above the LongHighestGain by 5 would be the following:
        Code:
        if ((T3(28, 1, 0.7)[0] > VsVMA2(vma1,vma1vol).VMA[0])
        && LongHighestGain < Close[0]+(5*TickSize))

        Comment


          #5
          Hi Patrick,
          I am trying a different approach to make this even simpler. If a crossover happens in last bar, I want to enter at a price 5 points or 20 ticks above the closing price of the current bar for ES.

          This is what I came up with, but unfortunately when I do the backtest, the strategy is not placing any trade at all. What am I doing wrong?

          if((CrossAbove((T3(28,1,0.7)),(VMA(vma1,vma1vol)), 1)))

          {

          EnterLongStopLimit(1,Close[0] + 20 * TickSize, Close[0] + 20 * TickSize, "Long");
          }
          if(CrossBelow((T3(14,1,0.1)),(VMA(vma2,vma2vol)),1 ))
          {
          ExitLong(1,"Long Exit","Long");
          }

          Again, appreciate your help and support here.

          Comment


            #6
            Originally posted by pandyav View Post
            Hi Patrick,
            I am trying a different approach to make this even simpler. If a crossover happens in last bar, I want to enter at a price 5 points or 20 ticks above the closing price of the current bar for ES.

            This is what I came up with, but unfortunately when I do the backtest, the strategy is not placing any trade at all. What am I doing wrong?

            if((CrossAbove((T3(28,1,0.7)),(VMA(vma1,vma1vol)), 1)))

            {

            EnterLongStopLimit(1,Close[0] + 20 * TickSize, Close[0] + 20 * TickSize, "Long");
            }
            if(CrossBelow((T3(14,1,0.1)),(VMA(vma2,vma2vol)),1 ))
            {
            ExitLong(1,"Long Exit","Long");
            }

            Again, appreciate your help and support here.
            That would only ever give an entry if the very next bar after the signal moves more than 20 ticks above the signal bar. It is does not, the order will be cancelled when the bar closes. If you want to keep the order alive for multiple bars, then you either have to reissue the order until filled, or use the correct syntax for an order that will stay alive until it is explicitly cancelled.

            ref: http://www.ninjatrader.com/support/h...r_handling.htm

            Comment


              #7
              Hi Koganam,
              Thank you for your quick reply. I added a liveuntilcancelled condition in the script but still don't see any trades taken on the chart. Can you please help by pointing out what could be wrong here? Here is what I have as entry condition now.

              if((CrossAbove((T3(28,1,0.7)),(VMA(vma1,vma1vol)), 1)))

              {

              EnterLongStopLimit(0,true,1,Close[0] + 20 * TickSize,Close[0],"Long");
              }

              Comment


                #8
                Originally posted by pandyav View Post
                Hi Koganam,
                Thank you for your quick reply. I added a liveuntilcancelled condition in the script but still don't see any trades taken on the chart. Can you please help by pointing out what could be wrong here? Here is what I have as entry condition now.

                if((CrossAbove((T3(28,1,0.7)),(VMA(vma1,vma1vol)), 1)))

                {

                EnterLongStopLimit(0,true,1,Close[0] + 20 * TickSize,Close[0],"Long");
                }
                I would surmise that there are errors in your log about your Stop price. Are there?

                Comment


                  #9
                  Hello pandyav,

                  Thank you for your response.

                  I would add a Print to the condition to see if it returns any information in the Output window (Tools > Output window) to let us know that the condition has in fact returned true:
                  Originally posted by pandyav View Post
                  Code:
                  if((CrossAbove((T3(28,1,0.7)),(VMA(vma1,vma1vol)),  1)))
                            
                              {    
                                [B]Print("Cross Above has occurred at " + Time[0]);[/B]
                                EnterLongStopLimit(0,true,1,Close[0] + 20 * TickSize,Close[0],"Long");
                              }

                  Comment


                    #10
                    Patrick and Koganam,
                    Thank you so much for your replies.

                    I added the print condition and it does return a value. But when I look at the strategy results it shows 0 trades taken. I am not sure what is wrong? I am attaching the strategy file so as to give you an idea of the script. There is nothing fancy to it, a simple crossover strategy that wants to take the trades 5 points/20 ES ticks after the crossover happens.

                    Can you please let me know what am I doing wrong here?

                    Greatly appreciate your help and support.
                    Attached Files

                    Comment


                      #11
                      Originally posted by pandyav View Post
                      Patrick and Koganam,
                      Thank you so much for your replies.

                      I added the print condition and it does return a value. But when I look at the strategy results it shows 0 trades taken. I am not sure what is wrong? I am attaching the strategy file so as to give you an idea of the script. There is nothing fancy to it, a simple crossover strategy that wants to take the trades 5 points/20 ES ticks after the crossover happens.

                      Can you please let me know what am I doing wrong here?

                      Greatly appreciate your help and support.
                      There should be an error in your log; probably referring to the stop price. What is the exact text of that error?

                      Comment

                      Latest Posts

                      Collapse

                      Topics Statistics Last Post
                      Started by DJ888, 04-16-2024, 06:09 PM
                      6 responses
                      18 views
                      0 likes
                      Last Post DJ888
                      by DJ888
                       
                      Started by Jon17, Today, 04:33 PM
                      0 responses
                      1 view
                      0 likes
                      Last Post Jon17
                      by Jon17
                       
                      Started by Javierw.ok, Today, 04:12 PM
                      0 responses
                      6 views
                      0 likes
                      Last Post Javierw.ok  
                      Started by timmbbo, Today, 08:59 AM
                      2 responses
                      10 views
                      0 likes
                      Last Post bltdavid  
                      Started by alifarahani, Today, 09:40 AM
                      6 responses
                      41 views
                      0 likes
                      Last Post alifarahani  
                      Working...
                      X