Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Multi TF MACD crossover

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

    Multi TF MACD crossover

    Hi, I'm having a slight problem coding a strategy for a MACD crossover in 2 different timeframes. I used the wizard and help pages and I'm almost there,but....
    I wanted to take a Long position when the MACD fast line crossed the slow line in the Primary timeframe but only when the 15 min MACD fast line is also above the slow line..ie the Primary dataseries (eg 5min) and 15 are both up and the 5 has just crossed.
    I have enclosed my coding below.BarsArray[1] refers to the 15min dataseries.The program checker won't let me save the strategy as it sees errors at the end of this line:

    "if (MACD(BarsArray[1],12, 26, 9)) > (MACD(BarsArray[1],12,26,9).Avg, 1))"

    Any help would be appreciated,
    Thank you,
    John
    --------------------------
    // This namespace holds all strategies and is required. Do not change it.
    namespace NinjaTrader.Strategy
    {
    /// <summary>
    /// long enrty & exit ONLY
    /// </summary>
    [Description("long enrty & exit ONLY")]
    public class JHMACDXoverLONG : Strategy
    {
    #region Variables
    // Wizard generated variables
    private int 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>
    protected override void Initialize()
    {
    Add(PeriodType.Minute, 15);
    CalculateOnBarClose = false;
    }

    /// <summary>
    /// Called on each bar update event (incoming tick)
    /// </summary>
    protected override void OnBarUpdate()
    {
    if (MACD(BarsArray[1],12, 26, 9)) > (MACD(BarsArray[1],12,26,9).Avg, 1))

    // Condition set 1
    if (CrossAbove(MACD(12, 26, 9), MACD(12, 26, 9).Avg, 1))
    {
    EnterLong(DefaultQuantity, "");
    }

    // Condition set 2
    if (CrossBelow(MACD(12, 26, 9), MACD(12, 26, 9).Avg, 1))
    {
    ExitLong("", "");
    }
    }

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

    #2
    Not sure what you wanted to code but this code

    if (MACD(BarsArray[1],12, 26, 9)[0] > MACD(BarsArray[1],12,26,9).Avg[0])

    ... compiles fine. You may need to tweak it according your requirements.

    Comment


      #3
      Thanks Dierk, the strategy compiles now. The results are a bit weird so I need to check out what 've done!
      John

      Comment


        #4
        My guess is that you might need to check BarsInProgress to make sure it's 1 before doing your comparisons of the MACD calculations of BarsArray[1].

        I suggest that you look at the following two threads:





        Good luck.

        Comment


          #5
          Thanks for the post KBJ. I've read the post links you gave and will look at my strategy again this weekend,
          Thanks,
          John

          Comment

          Latest Posts

          Collapse

          Topics Statistics Last Post
          Started by bmartz, 03-12-2024, 06:12 AM
          4 responses
          31 views
          0 likes
          Last Post bmartz
          by bmartz
           
          Started by Aviram Y, Today, 05:29 AM
          4 responses
          12 views
          0 likes
          Last Post Aviram Y  
          Started by algospoke, 04-17-2024, 06:40 PM
          3 responses
          28 views
          0 likes
          Last Post NinjaTrader_Jesse  
          Started by gentlebenthebear, Today, 01:30 AM
          1 response
          8 views
          0 likes
          Last Post NinjaTrader_Jesse  
          Started by cls71, Today, 04:45 AM
          1 response
          7 views
          0 likes
          Last Post NinjaTrader_ChelseaB  
          Working...
          X