Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

problem adding second instrument to strategy

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

    problem adding second instrument to strategy

    Following is a very basic strategy that won't compile in NT6.5. The compiler generates errors upon adding the code referencing the second instrument(YM)'s MACD.

    [Description("Enter the description of your strategy here")]
    publicclass MyBasic : Strategy
    {
    #region Variables
    // Wizard generated variables
    privateint myInput0 = 1; // Default setting for MyInput0
    // User defined variables (add any user defined variables below)
    #endregion
    ///<summary>
    /// This method is used to configure the strategy and is called once before any strategy method is called.
    ///</summary>
    protectedoverridevoid Initialize()
    {
    Add (
    "YM 06-10", PeriodType.Minute, 5);


    Add(LinReg(
    25));
    Add(MACD(
    12,26,7));

    SetProfitTarget(
    "M2LS", CalculationMode.Ticks, 32);
    SetStopLoss(
    "M2LS", CalculationMode.Ticks, 18, false);
    CalculateOnBarClose =
    true;
    }
    ///<summary>
    /// Called on each bar update event (incoming tick)
    ///</summary>
    protectedoverridevoid OnBarUpdate()
    {

    if (BarsInProgress != 0)
    return;

    // Condition set 1 if the primary index price closes below the 25LSMA
    // and the MACD on the YM 5 minute is below the 0 line -- go short
    if (Close[0] < LinReg(25)[0] && MACD(BarsArray[1], (12,26,7))[0] < 0)

    {
    EnterShort(DefaultQuantity,
    "M2LS");
    }
    }
    #region Properties
    [Description(
    "")]
    [Category(
    "Parameters")]
    publicint MyInput0
    {
    get { return myInput0; }
    set { myInput0 = Math.Max(1, value); }
    }
    #endregion
    }
    }

    Please advise

    Merrill

    #2
    Hello,

    You think it is in adding the instrument? To test this put the exact initialization block in the SampleMACrossOver strategy and see if it compiles. I did this and it work fine for me. Please do this and let us know.

    So replace the SampleMACrossOver strategy Initialization block with this:
    protectedoverridevoid Initialize()
    {
    Add (
    "YM 06-10", PeriodType.Minute, 5);
     
    Add(LinReg(
    25));
    Add(MACD(
    12,26,7));
    SetProfitTarget(
    "M2LS", CalculationMode.Ticks, 32);
    SetStopLoss(
    "M2LS", CalculationMode.Ticks, 18, false);
    CalculateOnBarClose =
    true;
    }
    DenNinjaTrader Customer Service

    Comment


      #3
      Hi Ben,
      Thanks for your response to my question. I've gotten past the initiial compilation with just the Initialization code(ie Add ("YM etc).

      My problem is adding the && MACD(BarsArray[1], (12,26,7))[0] logic to the On Bar Update Method. I can get it to compile and operate with code that use other indicators such as EMA(BarsArray[1], 34)[0] which is very similiar to the 'sample multi instrument strategy' which uses the ADX indicator. I am mostly having problems with the MACD Indicator which has a more complicated argument (ie (12,26,7) verses just on argument such as the ADX (ie (14). I don't know if that is the problem.

      Another thougt was that the indicators that work, all plot on the price region of the chart.(ie ADX, EMA) However, the MACD indicator plots on it's own panel below the price panel. Maybe I need some additional statements in the Initialize Method just for the MACD indicator. Just some food for thought.
      Merrill

      Comment


        #4
        Merrill,

        The issue is you added extra ( ) around your 12, 26, 7 settings.

        Please use this instead:

        MACD(BarsArray[1], 12, 26, 7)[0]
        Josh P.NinjaTrader Customer Service

        Comment


          #5
          Josh,

          That did it. Your the man.

          Thanks,
          Merrill

          Comment

          Latest Posts

          Collapse

          Topics Statistics Last Post
          Started by Geovanny Suaza, 02-11-2026, 06:32 PM
          0 responses
          649 views
          0 likes
          Last Post Geovanny Suaza  
          Started by Geovanny Suaza, 02-11-2026, 05:51 PM
          0 responses
          370 views
          1 like
          Last Post Geovanny Suaza  
          Started by Mindset, 02-09-2026, 11:44 AM
          0 responses
          109 views
          0 likes
          Last Post Mindset
          by Mindset
           
          Started by Geovanny Suaza, 02-02-2026, 12:30 PM
          0 responses
          573 views
          1 like
          Last Post Geovanny Suaza  
          Started by RFrosty, 01-28-2026, 06:49 PM
          0 responses
          576 views
          1 like
          Last Post RFrosty
          by RFrosty
           
          Working...
          X