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

2 Longs don't make a right!!

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

    2 Longs don't make a right!!

    I wrote a strategy script that is generating a second long order in back-testing that I don't understand and can't seem to figure out how to NOT generate? I have attached a screenshot of the orders. One of these longs should not be generated. The reason I say that is because of my crossover condition. I'm using 8 tick range bars in ES. Please see below for my script info. I'm fully prepared to be completely wrong in thinking my assumptions match my code Thanks in advance for your advice/assistance!



    protected override void Initialize()
    {
    Add(RSI45LOW55HIGH(7, 3));
    Add(MACD(12, 26, 9));
    Add(RSI45LOW55HIGH(7, 3));
    Add(MACD(12, 26, 9));
    SetProfitTarget("Long Market Entry", CalculationMode.Ticks, 4);
    SetStopLoss("Long Market Entry", CalculationMode.Ticks, 8, false);
    SetProfitTarget("Short Market Entry", CalculationMode.Ticks, 4);
    SetStopLoss("Short Market Entry", CalculationMode.Ticks, 8, false);
    CalculateOnBarClose = true;
    }
    /// <summary>
    /// Called on each bar update event (incoming tick)
    /// </summary>
    protected override void OnBarUpdate()
    {
    // Condition set 1
    if (CrossAbove(MACD(12, 26, 9), MACD(12, 26, 9).Avg, 2)
    && RSI45LOW55HIGH(7, 3).Avg[0] > 45
    && MACD(12, 26, 9).Diff[0] >= 0.1
    && Position.Quantity == 0
    && RSI45LOW55HIGH(7, 3)[0] > RSI45LOW55HIGH(7, 3)[1])
    {
    EnterLong(DefaultQuantity, "Long Market Entry");
    ExitLong("Long Exit", "Long Market Entry");
    }
    // Condition set 2
    if (CrossAbove(MACD(12, 26, 9).Avg, MACD(12, 26, 9), 2)
    && RSI45LOW55HIGH(7, 3).Avg[0] < 55
    && MACD(12, 26, 9).Diff[0] <= -0.1
    && Position.Quantity == 0)
    {
    EnterShort(DefaultQuantity, "Short Market Entry");
    ExitShort("Short Exit", "Short Market Entry");
    }
    }
    Attached Files

    #2
    user,

    CrossAbove(MACD(12, 26, 9), MACD(12, 26, 9).Avg, 2)

    The "2" here will check over the last 2 bars for crossover conditions. As such the condition could be true for one bar and the next. You can partially remedy this by setting appropriate EntriesPerDirection settings.

    Adam P.NinjaTrader Customer Service

    Comment


      #3
      Thanks so much for the information. I will certainly take and use your advice. However, just so I understand can you please describe in more detail your comment regarding "will check over the last 2 bars for crossover conditions"? My now-understood misunderstanding of the "Look back period" was that it looked back 2 bars ago, not OVER the span of 2 bars.

      Could I not accomplish my goal by changing the Look back period to 1, then change my "Bars ago" setting to 2?

      Thanks again for your assistance.

      Comment


        #4
        User,

        If the lookback period is set to 2, it will check the current bar and previous bar for a cross over condition, then it will also check the previous bar and the bar before that for a cross over condition.

        CrossAbove/CrossBelow already automatically check the current bar and previous bar for crossing conditions, so setting lookback to 1 is sufficient to check for the most recent crossover.

        Please let me know if I may assist further.
        Adam P.NinjaTrader Customer Service

        Comment


          #5
          Thanks very much for the info

          Comment

          Latest Posts

          Collapse

          Topics Statistics Last Post
          Started by jclose, Today, 09:37 PM
          0 responses
          4 views
          0 likes
          Last Post jclose
          by jclose
           
          Started by WeyldFalcon, 08-07-2020, 06:13 AM
          10 responses
          1,413 views
          0 likes
          Last Post Traderontheroad  
          Started by firefoxforum12, Today, 08:53 PM
          0 responses
          9 views
          0 likes
          Last Post firefoxforum12  
          Started by stafe, Today, 08:34 PM
          0 responses
          10 views
          0 likes
          Last Post stafe
          by stafe
           
          Started by sastrades, 01-31-2024, 10:19 PM
          11 responses
          169 views
          0 likes
          Last Post NinjaTrader_Manfred  
          Working...
          X