Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Strategy with divergence between MNQ and MES

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

    Strategy with divergence between MNQ and MES

    Im trying to use the strategy builder to create a strategy that enters long on MNQ when MNQ takes out a pivot low while MES does not. It works for most of the time when I use the parameter (Lows[1][0] > Swing2.SwingLow[0])) in the conditions section but only with the most recent local low. It won't recognize going below 2 pivots in a row. I've tried coding a loop that will compare the current bar on MES with each previous n bars until the current bar low is greater than that n bar on MES. Then take that n number and compare the current bar low on MNQ with the n bar low on MNQ but no luck. Any suggestions?

    #2
    Hello dj19820,

    Welcome to the NinjaTrader forums!

    For the Pivots indicator to apply to an added series, select that series in the Input Series field in the condition builder.

    To understand the behavior and why the condition is not evaluating as true, debug the script by adding prints in condition sets with no conditions. Print the time and all values used in the condition set you are investigating.

    Below is a link to a video 'Debugging using prints with the Strategy Builder' which demonstrates.


    For requiring two conditions to evaluate in sequence you can use a set of bools. Below is a link to an example.
    Hi, To improve a strategy, I would like the condition to enter a trade to be triggered only after a second crossing happens. Meaning, for instance we have a sthocastics crossing, but the strategy would only trigger when a crossing between 2 emas happen. Would the looking back N bars work? Can it be done within the builder
    Chelsea B.NinjaTrader Customer Service

    Comment


      #3
      I figured out how to compare current price with previous swing highs and lows and not just the most recent swing but now i have a problem comparing previous swings of a different instrument. For my strategy, i have:

      private Swing Swing1 // This is MNQ swings
      private Swing Swing2 // This is MES swings

      For the entry conditions i have:

      if ((CrossBelow(Lows[2], Low[Math.Max(0, Swing(Strength).SwingLowBar(0, 4, 200))], 1)) // If MNQ crosses below the 4th previous swing
      && (Closes[2][0] > Low[Math.Max(0, Swing1.Swing(Strength).SwingLowBar(0, 4, 200))])) // If MNQ current bar closes back above MNQ's 4th previous swing
      && (Lows[1][0] > Low[Math.Max(0, Swing2.Swing(Strength).SwingLowBar(0, 4, 200))])) // If the low of MES current bar is above the low of MES's 4th previous swing
      {
      EnterLong(Convert.ToInt32(DefaultQuantity), "");
      }

      The code works but not when I add the Swing2 portion in the entry conditions. Also when I go to ninjascript output to debug and print out the previous 4th swing low of MES using:

      Print(string.Format("{0} ", Low[Math.Max(0, Swing2.Swing(5).SwingLowBar(0, 4, 200))]));

      I get an error that says: Error on calling 'OnBarUpdate' method on bar 4: You are accessing an index with a value that is invalid since it is out-of-range. I.E. accessing a series [barsAgo] with a value of 5 when there are only 4 bars on the chart. Any suggestions on how to compare previous swings from a different instrument?​

      Comment


        #4
        Hello dj19820,

        When calling the Swing indicator you can supply a bars object as the input series.


        When adding series, ensure that there are valid barsAgo indexes for all series.

        if (CurrentBars[1] < Math.Max(0, Swing2.Swing(Strength).SwingLowBar(0, 4, 200)) )
        return;

        Print(Lows[1][Math.Max(0, Swing2.Swing(Strength).SwingLowBar(0, 4, 200))])

        Hello, I want to create an indicator that show data in a chart but calculate in other charttime different to the time of the chart where is showed. For example:



        Also, ensure you code is running on the correct BarsInProgress.
        I would also suggest you specify which series you are trying to get bars from.
        Instead of Low, which refers to the series currently updating OnBarUpdate, use Lows[0] or Lows[1] and specific which barsInProgress you would like data from.
        Chelsea B.NinjaTrader Customer Service

        Comment

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by NullPointStrategies, Today, 05:17 AM
        0 responses
        53 views
        0 likes
        Last Post NullPointStrategies  
        Started by argusthome, 03-08-2026, 10:06 AM
        0 responses
        130 views
        0 likes
        Last Post argusthome  
        Started by NabilKhattabi, 03-06-2026, 11:18 AM
        0 responses
        70 views
        0 likes
        Last Post NabilKhattabi  
        Started by Deep42, 03-06-2026, 12:28 AM
        0 responses
        44 views
        0 likes
        Last Post Deep42
        by Deep42
         
        Started by TheRealMorford, 03-05-2026, 06:15 PM
        0 responses
        49 views
        0 likes
        Last Post TheRealMorford  
        Working...
        X