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

simple multi-time frame strategy not working

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

    simple multi-time frame strategy not working

    I've made several indicators that use multiple time frames and none of them work as intended. In most cases it's only accurate on the main data series so it appears that I'm not accessing the data correctly for the additional data series.I made a very simple indicator to test and it doesn't work either. It compiles and sends out alerts but it doesn't appear to even be using the higher time frames macd (macdhtf) in the if statement. It's like its completely ignoring it. Can somebody with experience using more than one data series in an indicator tell me what is going on here:


    ************************************************** **************************

    else if (State == State.Configure)
    {

    AddDataSeries(HTFPeriodType, HTFPeriod);

    }
    }

    protected override void OnBarUpdate()


    {
    if(CurrentBar < 50 || CurrentBars[1] < 50) return;



    if(string.IsNullOrEmpty(period_string))
    {

    Print("BarType: " + Bars.BarsType.ToString() + " BarsPeriod: " + Bars.BarsPeriod.BarsPeriodType.ToString());
    if(Bars.BarsPeriod.BarsPeriodType == BarsPeriodType.Second)
    {
    period_string = Bars.BarsPeriod.Value + "S";
    }
    else if(Bars.BarsPeriod.BarsPeriodType == BarsPeriodType.Minute)
    {
    period_string = Bars.BarsPeriod.Value + "M";
    }
    else if(Bars.BarsPeriod.BarsPeriodType == BarsPeriodType.Day)
    {
    period_string = Bars.BarsPeriod.Value + "D";
    }
    else if(Bars.BarsPeriod.BarsPeriodType == BarsPeriodType.Month)
    {
    period_string = Bars.BarsPeriod.Value + "MN";
    }

    Print(period_string);
    }



    double macdhtf = MACD(MACDFast, MACDSlow, MACDLine).Avg[1];

    double macd = MACD(MACDFast, MACDSlow, MACDLine).Avg[0];




    if(macdhtf > 0 && macd > 0 && Close[0] > High[1])
    {
    if(AlertsOn)
    {
    Alert("DP_UP", AlertPriority, period_string + " " + AlertText + " BULL ALERT", alertfile, 10, BullAlertBackgroundBrush, BullAlertForegroundBrush);
    }
    }

    if(macdhtf < 0 && macd < 0 && Close[0] < Low[1])
    {
    if(AlertsOn)
    {
    Alert("DP_DOWN", AlertPriority, period_string + " " + AlertText + " BEAR ALERT", alertfile, 10, BearAlertBackgroundBrush, BearAlertForegroundBrush);
    }
    }

    ************************************************** ***************************
    Last edited by gordongekko; 12-11-2017, 05:16 PM.

    #2
    Not enough information?

    Assuming HTFPeriodType is defined properly.
    Assuming HTFPeriod is defined properly.

    What is this about?
    Code:
    double macdhtf = MACD(MACDFast, MACDSlow, MACDLine).Avg[1];
    double macd = MACD(MACDFast, MACDSlow, MACDLine).Avg[0];


    Returns average value
    MACD(int fast, int slow, int smooth).Avg[int barsAgo]
    MACD(IDataSeries input, int fast, int slow, int smooth).Avg[int barsAgo]


    You need to use the IDataSeries call to reference this HTFPeriodType series.
    Otherwise - it looks like you are simple referencing the previous bar of the base series.

    Comment


      #3
      This indicator was just made to test the macd levels on 2 separate time frames to figure out why my multi-time frame indicators are not working. Are you saying i need to use [1][0] for the higher time frames macd? This wont compile:

      double macdhtf = MACD(MACDFastHTF, MACDSlowHTF, MACDLineHTF).Avg[1][0];

      Says it can't index a double,

      The HTF values are input by the user in properties.
      Last edited by gordongekko; 12-12-2017, 07:51 AM.

      Comment


        #4
        Hello Gordongekko,

        Thank you for your note.

        You are currently using the syntax,

        Code:
        MACD(int fast, int slow, int smooth).Avg[int barsAgo]
        But if you’d like to pass a secondary series to the MACD indicator you should use the following,

        MACD(ISeries<double> input, int fast, int slow, int smooth).Avg[int barsAgo]
        Which would look like the following,

        Code:
        MACD(Closes[1], 10,20,6).Diff[0];
        Where Closes[1] refers to the secondary series added to the script.


        Please let us know if you need further assistance.
        Alan P.NinjaTrader Customer Service

        Comment

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by CortexZenUSA, Today, 12:53 AM
        0 responses
        1 view
        0 likes
        Last Post CortexZenUSA  
        Started by CortexZenUSA, Today, 12:46 AM
        0 responses
        1 view
        0 likes
        Last Post CortexZenUSA  
        Started by usazencortex, Today, 12:43 AM
        0 responses
        2 views
        0 likes
        Last Post usazencortex  
        Started by sidlercom80, 10-28-2023, 08:49 AM
        168 responses
        2,262 views
        0 likes
        Last Post sidlercom80  
        Started by Barry Milan, Yesterday, 10:35 PM
        3 responses
        10 views
        0 likes
        Last Post NinjaTrader_Manfred  
        Working...
        X