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 BarzTrading, Today, 07:25 AM
          2 responses
          12 views
          1 like
          Last Post BarzTrading  
          Started by devatechnologies, 04-14-2024, 02:58 PM
          3 responses
          19 views
          0 likes
          Last Post NinjaTrader_BrandonH  
          Started by tkaboris, Today, 08:01 AM
          0 responses
          3 views
          0 likes
          Last Post tkaboris  
          Started by EB Worx, 04-04-2023, 02:34 AM
          7 responses
          162 views
          0 likes
          Last Post VFI26
          by VFI26
           
          Started by Mizzouman1, Today, 07:35 AM
          1 response
          9 views
          0 likes
          Last Post NinjaTrader_Gaby  
          Working...
          X