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

Multi Timeframe and Method Name Expected

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

    Multi Timeframe and Method Name Expected

    Hi Guys, I'm trying to do a multitimeframe strategy which was working ok on other indicators until I used the MACD. I keep getting the Method Name Expected error. Has anyone seen this before? I have checked the syntax on the MACD and it seems ok. Any ideas would be appreciated. The other thing is is says the error is on row 89 and there is row 89! Thanks. DJ



    Code is below:

    #region Using declarations
    using System;
    using System.ComponentModel;
    using System.Diagnostics;
    using System.Drawing;
    using System.Drawing.Drawing2D;
    using System.Xml.Serialization;
    using NinjaTrader.Cbi;
    using NinjaTrader.Data;
    using NinjaTrader.Indicator;
    using NinjaTrader.Gui.Chart;
    using NinjaTrader.Strategy;
    #endregion

    // This namespace holds all strategies and is required. Do not change it.
    namespace NinjaTrader.Strategy
    {
    /// <summary>
    /// Enter the description of your strategy here
    /// </summary>
    [Description("Enter the description of your strategy here")]
    public class MyCustomStrategy : 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 a 10 Range Bars object to the strategy - Primary Bar 1
    Add(PeriodType.Range, 10);

    Add("TF 12-10", PeriodType.Range, 15);
    // Note: Bars are added to the BarsArray and can be accessed via an index value
    // E.G. BarsArray[1] ---> Accesses the 5 minute Bars object added above

    // Add simple moving averages to the chart for display
    // This only displays the SMA's for the primary Bars object on the chart
    CalculateOnBarClose = true;
    }

    /// <summary>
    /// Called on each bar update event (incoming tick)
    /// </summary>
    protected override void OnBarUpdate()
    {

    {
    // Checks for a cross above condition of the 8 and 18 period SMA on the primary Bars object and enters long
    if (MACD(BarsArray[2](9, 12, 3)[0]) >= MACD(BarsArray[2](9,12,3).Avg)[0])
    DrawArrowDown("My down arrow" + CurrentBar, false, 0, Low[0] + 15 * TickSize, Color.Yellow);
    }
    }

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

    #2
    Hello djkiwi,

    It should compile if you change to this. There were parentheses in the wrong place.
    if (MACD(BarsArray[2], 9, 12, 3)[0] >= MACD(BarsArray[2], 9, 12, 3).Avg[0])
    Last edited by NinjaTrader_RyanM1; 10-21-2010, 10:46 AM.
    Ryan M.NinjaTrader Customer Service

    Comment


      #3
      Method name expected

      Thanks Kyle, actually as part of my quest to fix that I did try that iteration as well and still get the "Method name expected error" . I'm not even sure it's the code because it showing this error on blank lines of the code. Thanks. DJ

      Comment


        #4
        Ok Now

        Hi Kyle, it seems to be working ok now. Not sure what I did. Thanks for your help. Cheers. DJ

        Comment


          #5
          Cancel Orders

          Hi Kyle, I am having a big problem canceling orders and was hoping for some help. I have read the cancel orders section and have tried to apply it but no luck. My full code is below:

          What I'd like to do is cancel all orders if not filled after 5 bars as per your example. I tried to cancel target 1 after trying to cancel the GoLong() instruction which didn't work either. Any ideas on this one? Thanks. DJ

          // Cancel Orders section as per below:

          if (myEntryOrder == null)
          {
          myEntryOrder = target1;
          }

          // If more than 5 bars has elapsed, cancel the entry order
          if (CurrentBar > barNumberOfOrder + 5)
          CancelOrder(myEntryOrder);

          #region Using declarations
          using System;
          using System.ComponentModel;
          using System.Diagnostics;
          using System.Drawing;
          using System.Drawing.Drawing2D;
          using System.Xml.Serialization;
          using NinjaTrader.Cbi;
          using NinjaTrader.Data;
          using NinjaTrader.Indicator;
          using NinjaTrader.Gui.Chart;
          using NinjaTrader.Strategy;
          #endregion

          // This namespace holds all strategies and is required. Do not change it.
          namespace NinjaTrader.Strategy
          {
          /// <summary>
          /// Enter the description of your strategy here
          /// </summary>
          [Description("Enter the description of your strategy here")]
          public class bigmikeexample4 : Strategy
          {
          #region Variables
          // Wizard generated variables

          private int barsago = 0; // Default setting for Barsago
          private int difference = 5; // Default setting for Barsago
          private int rsihigh = 70;
          private int rsilow = 30;
          private int dm33 = 20;
          private int dmnumber = 12;
          private int barNumberOfOrder = 0;
          private IOrder myEntryOrder = null;

          private int target1 = 12;
          private int target2 = 24;
          private int target3 = 36;
          private int timefrom = 63000;
          private int timeto = 123000;

          private int stop = 25;

          private bool be2 = true;
          private bool be3 = true;

          // 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()
          {

          CalculateOnBarClose = false;
          EntryHandling = EntryHandling.UniqueEntries;
          }

          private void GoLong()
          {

          SetStopLoss("target1",CalculationMode.Price, Close[0] - (Stop*TickSize), false);
          SetStopLoss("target2",CalculationMode.Price, Close[0] - (Stop*TickSize), false);
          SetStopLoss("target3",CalculationMode.Price, Close[0] - (Stop*TickSize), false);

          SetProfitTarget("target1",CalculationMode.Price, Close[0] + (Target1*TickSize));
          SetProfitTarget("target2",CalculationMode.Price, Close[0] + ((Target1+Target2)*TickSize));
          SetProfitTarget("target3",CalculationMode.Price, Close[0] + ((Target1+Target2+Target3)*TickSize));

          EnterLongLimit(DefaultQuantity, GetCurrentBid() - difference * TickSize, "target1");
          EnterLongLimit(DefaultQuantity, GetCurrentBid() - difference * TickSize, "target2");
          EnterLongLimit(DefaultQuantity, GetCurrentBid() - difference * TickSize, "target3");

          }

          private void GoShort()

          {

          SetStopLoss("target1",CalculationMode.Price, Close[0] + (Stop*TickSize), false);
          SetStopLoss("target2",CalculationMode.Price, Close[0] + (Stop*TickSize), false);
          SetStopLoss("target3",CalculationMode.Price, Close[0] + (Stop*TickSize), false);

          SetProfitTarget("target1",CalculationMode.Price, Close[0] - (Target1*TickSize));
          SetProfitTarget("target2",CalculationMode.Price, Close[0] - ((Target1+Target2)*TickSize));
          SetProfitTarget("target3",CalculationMode.Price, Close[0] - ((Target1+Target2+Target3)*TickSize));

          EnterShortLimit(DefaultQuantity, GetCurrentAsk() + difference * TickSize, "target1");
          EnterShortLimit(DefaultQuantity, GetCurrentAsk() + difference * TickSize, "target2");
          EnterShortLimit(DefaultQuantity, GetCurrentAsk() + difference * TickSize, "target3");

          }

          private void ManageOrders()
          {
          if (Position.MarketPosition == MarketPosition.Long)
          {

          if (Be2 && High[0]> Position.AvgPrice + (Target1*TickSize))
          SetStopLoss("target2", CalculationMode.Price, Position.AvgPrice, false);
          if (Be3 && High[0] > Position.AvgPrice + (Target1*TickSize))
          SetStopLoss("target3", CalculationMode.Price, Position.AvgPrice, false);

          }

          if (Position.MarketPosition == MarketPosition.Short)
          {

          if (Be2 && Low[0] < Position.AvgPrice - (Target1*TickSize))
          SetStopLoss("target2", CalculationMode.Price, Position.AvgPrice, false);
          if (Be3 && Low[0] < Position.AvgPrice - (Target1*TickSize))
          SetStopLoss("target3", CalculationMode.Price, Position.AvgPrice, false);

          }

          }
          /// <summary>
          /// Called on each bar update event (incoming tick)
          /// </summary>
          protected override void OnBarUpdate()

          {
          EntryHandling = EntryHandling.UniqueEntries;

          ManageOrders();
          if (Position.MarketPosition != MarketPosition.Flat) return;


          // Condition set 1 DM + > 20
          if (Position.MarketPosition != MarketPosition.Short
          && (CrossAbove(DM(dmnumber).DiPlus, dm33, 1))
          && ToTime(Time[0]) >= timefrom && ToTime(Time[0])<= timeto)

          {
          GoLong();

          }

          // Condition set 1 DM - > 20
          else if (Position.MarketPosition != MarketPosition.Long
          && (CrossAbove(DM(dmnumber).DiMinus, dm33, 1))
          && ToTime(Time[0]) >= timefrom && ToTime(Time[0])<= timeto)

          {
          GoShort();
          }

          // Cancel Orders

          if (myEntryOrder == null)
          {
          myEntryOrder = target1;
          }

          // If more than 5 bars has elapsed, cancel the entry order
          if (CurrentBar > barNumberOfOrder + 5)
          CancelOrder(myEntryOrder);
          }

          #region Properties
          [Description("")]
          [GridCategory("Parameters")]
          public int Bbwidth
          {
          get { return bbwidth; }
          set { bbwidth = Math.Max(1, value); }
          }

          [Description("")]
          [GridCategory("Parameters")]
          public int Stop
          {
          get { return stop; }
          set { stop = Math.Max(1, value); }
          }

          [Description("")]
          [GridCategory("Parameters")]
          public int Barsago
          {
          get { return barsago; }
          set { barsago = Math.Max(1, value); }
          }

          [Description("")]
          [GridCategory("Parameters")]
          public int Target1
          {
          get { return target1; }
          set { target1 = Math.Max(1, value); }
          }
          [Description("")]
          [GridCategory("Parameters")]
          public int Target2
          {
          get { return target2; }
          set { target2 = Math.Max(1, value); }
          }
          [Description("")]
          [GridCategory("Parameters")]
          public int Target3
          {
          get { return target3; }
          set { target3 = Math.Max(1, value); }
          }

          [Description("")]
          [GridCategory("Parameters")]
          public bool Be2
          {
          get { return be2; }
          set { be2 = value; }
          }

          [Description("")]
          [GridCategory("Parameters")]
          public bool Be3
          {
          get { return be3; }
          set { be3 = value; }
          }

          [Description("")]
          [GridCategory("Parameters")]
          public int Difference
          {
          get { return difference; }
          set { difference = value; }
          }

          [Description("")]
          [GridCategory("Parameters")]
          public int Dm33
          {
          get { return dm33; }
          set { dm33 = value; }
          }

          [Description("")]
          [GridCategory("Parameters")]
          public int Dmnumber
          {
          get { return dmnumber; }
          set { dmnumber = value; }
          }

          [Description("")]
          [GridCategory("Parameters")]
          public int Timefrom
          {
          get { return timefrom; }
          set { timefrom = Math.Max(1, value); }
          }

          [Description("")]
          [GridCategory("Parameters")]
          public int Timeto
          {
          get { return timeto; }
          set { timeto = Math.Max(1, value); }
          }

          #endregion
          }
          }

          Comment


            #6
            djkiwi,

            You'll have to debug this. I suggest simplifying. Get the sample working first and then start adding complexity only when you've verified everything works as you expect.

            Debugging your NinjaScript Code
            Using CancelOrder() method to cancel orders
            Ryan M.NinjaTrader Customer Service

            Comment


              #7
              Method name again

              Thanks Kyle, still working through the debugging issues. This "method name expected: code CS0149 has cropped up again. Can you please advise whether I have done this correctly for a MACD crossover. Thanks. DJ


              (CrossAbove(MACD(BarsArray[1],12, 26, 9), MACD(BarsArray[1],12, 26, 9).Avg, 1))

              It works ok on this one but not the one above:

              (CrossAbove(MACD(BarsArray[1],12, 26, 9), MACD(BarsArray[1],12, 26, 9).Avg, 1))

              Comment


                #8
                Hello DJ,

                Both lines are the same and it compiles correctly. The error you're getting is likely due to another line of code.
                Ryan M.NinjaTrader Customer Service

                Comment


                  #9
                  Bars array

                  Thanks Kyle, well now I'm having another issue. Basically the code below put dots above candle (for short signal) and below candle (for long) based on MACD. If it is above or below on 3 timeframes it puts red dots and 2 timeframes white dots. The problem is only condition and conditions 4 are actioning. I did change the "else if" to if but still the same problem. Is there some sort of ordering system I need to do? Thanks. DJ

                  // Condition set 1

                  if (ToTime(Time[0]) >= timefrom && ToTime(Time[0])<= timeto
                  &&(MACD(BarsArray[3], MACDfast, MACDDslow, Smoothing)[0] >= MACD(BarsArray[3], MACDfast, MACDDslow, Smoothing).Avg[0])
                  &&(MACD(BarsArray[2], MACDfast, MACDDslow, Smoothing)[0] >= MACD(BarsArray[2], MACDfast, MACDDslow, Smoothing).Avg[0])
                  &&(MACD(BarsArray[1], MACDfast, MACDDslow, Smoothing)[0] >= MACD(BarsArray[1], MACDfast, MACDDslow, Smoothing).Avg[0])
                  && (BarsInProgress == 0)
                  )

                  {
                  DrawDot("My dot" + CurrentBar, false, 0, Low[0] + -15 * TickSize, Color.Red);

                  }

                  // Condition set 2

                  else if (ToTime(Time[0]) >= timefrom && ToTime(Time[0])<= timeto
                  &&(MACD(BarsArray[3], MACDfast, MACDDslow, Smoothing)[0] <= MACD(BarsArray[3], MACDfast, MACDDslow, Smoothing).Avg[0])
                  &&(MACD(BarsArray[2], MACDfast, MACDDslow, Smoothing)[0] <= MACD(BarsArray[2], MACDfast, MACDDslow, Smoothing).Avg[0])
                  &&(MACD(BarsArray[1], MACDfast, MACDDslow, Smoothing)[0] <= MACD(BarsArray[1], MACDfast, MACDDslow, Smoothing).Avg[0])
                  && (BarsInProgress == 0)
                  )

                  {
                  DrawDot("My dot" + CurrentBar, false, 0, High[0] + 15 * TickSize, Color.Red);

                  // Condition set 3

                  if (ToTime(Time[0]) >= timefrom && ToTime(Time[0])<= timeto
                  &&(MACD(BarsArray[2], MACDfast, MACDDslow, Smoothing)[0] >= MACD(BarsArray[2], MACDfast, MACDDslow, Smoothing).Avg[0])
                  &&(MACD(BarsArray[1], MACDfast, MACDDslow, Smoothing)[0] >= MACD(BarsArray[1], MACDfast, MACDDslow, Smoothing).Avg[0])
                  && (BarsInProgress == 0)
                  )

                  {
                  DrawDot("My dot" + CurrentBar, false, 0, Low[0] + -15 * TickSize, Color.White);

                  }

                  // Condition set 4

                  else if (ToTime(Time[0]) >= timefrom && ToTime(Time[0])<= timeto
                  &&(MACD(BarsArray[2], MACDfast, MACDDslow, Smoothing)[0] <= MACD(BarsArray[2], MACDfast, MACDDslow, Smoothing).Avg[0])
                  &&(MACD(BarsArray[1], MACDfast, MACDDslow, Smoothing)[0] <= MACD(BarsArray[1], MACDfast, MACDDslow, Smoothing).Avg[0])
                  && (BarsInProgress == 0)
                  )

                  DrawDot("My dot" + CurrentBar, false, 0, High[0] + 15 * TickSize, Color.White);

                  Comment


                    #10
                    Hello DJ,

                    You'll have to simplify and debug. Try evaluating only one block at a time and print all the values associated with that block.

                    You use else if when you want to check that the previous conditions are false first. For your testing you should start with if until everything works as you expect.
                    Ryan M.NinjaTrader Customer Service

                    Comment


                      #11
                      Problem

                      Hy Kyle, I have found the problem and it works now as a strategy no problem. What I want to do though is have this as an indicator, but when I converted it to an indicator it wouldn't work. So then I stripped it right down to one line of code and that didn't work either. It compiles ok no problem but doesn't paint the bar as it does in the strategy. I think the problem is with the BarsArray. I have 3 instruments below.

                      Add("TF 12-10", PeriodType.Range, 12);
                      Add("TF 12-10", PeriodType.Range, 25);
                      Add("TF 12-10", PeriodType.Range, 50);


                      I guess the question is does barsarray work as an indicator or does it only work as a strategy?

                      Thanks
                      DJ


                      // This namespace holds all indicators and is required. Do not change it.
                      namespace NinjaTrader.Indicator
                      {
                      /// <summary>
                      /// Enter the description of your new custom indicator here
                      /// </summary>
                      [Description("Enter the description of your new custom indicator here")]
                      public class djmultipletimeframemacd : Indicator
                      {
                      #region Variables
                      // Wizard generated variables

                      private int mACDslow = 26; // Default setting for MACDslow
                      private int mACDfast = 12; // Default setting for MACDfast
                      private int smoothing = 9; // Default setting for Smoothing

                      // 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("TF 12-10", PeriodType.Range, 12);
                      Add("TF 12-10", PeriodType.Range, 25);
                      Add("TF 12-10", PeriodType.Range, 50);

                      CalculateOnBarClose = false;
                      }

                      /// <summary>
                      /// Called on each bar update event (incoming tick)
                      /// </summary>
                      protected override void OnBarUpdate()
                      {




                      // Condition set 2

                      if ((MACD(BarsArray[3], MACDfast, MACDslow, Smoothing)[0] >= MACD(BarsArray[3], MACDfast, MACDslow, Smoothing).Avg[0])
                      &&(MACD(BarsArray[2], MACDfast, MACDslow, Smoothing)[0] >= MACD(BarsArray[2], MACDfast, MACDslow, Smoothing).Avg[0])
                      &&(MACD(BarsArray[1], MACDfast, MACDslow, Smoothing)[0] >= MACD(BarsArray[1], MACDfast, MACDslow, Smoothing).Avg[0])

                      && (BarsInProgress == 0)

                      )

                      {

                      BarColor = Color.Lime;

                      }


                      }

                      Comment


                        #12
                        What version are you using?

                        Multiseries indicators are possible in NinjaTrader 7, but not 6.5.

                        In 6.5, multiseries can only be strategies.
                        Ryan M.NinjaTrader Customer Service

                        Comment


                          #13
                          Verison

                          Hi Ryan, using the latest version of Windows 7. Cheers. DJ

                          Comment


                            #14
                            Multiseries works the same no matter the operating system.

                            Click Help > About within your NinjaTrader application to identify the version of NinjaTrader you're using.
                            Ryan M.NinjaTrader Customer Service

                            Comment


                              #15
                              System

                              H Ryan, sorry I meant Ninja 7!

                              Comment

                              Latest Posts

                              Collapse

                              Topics Statistics Last Post
                              Started by Stanfillirenfro, Today, 07:23 AM
                              3 responses
                              10 views
                              0 likes
                              Last Post NinjaTrader_ChelseaB  
                              Started by FitSpressoHonest, Today, 09:14 AM
                              0 responses
                              0 views
                              0 likes
                              Last Post FitSpressoHonest  
                              Started by Davide999, 05-18-2023, 03:55 AM
                              4 responses
                              556 views
                              1 like
                              Last Post kcwasher  
                              Started by rexsole, Today, 08:39 AM
                              2 responses
                              7 views
                              0 likes
                              Last Post NinjaTrader_Erick  
                              Started by cmtjoancolmenero, Yesterday, 03:58 PM
                              6 responses
                              29 views
                              0 likes
                              Last Post NinjaTrader_ChelseaB  
                              Working...
                              X