MTF - Determining the TF - futures io
futures io futures trading



MTF - Determining the TF


Discussion in NinjaTrader

Updated by patfaninba
    1. trending_up 330 views
    2. thumb_up 0 thanks given
    3. group 2 followers
    1. forum 2 replies
    2. attach_file 0 attachments




Welcome to futures io: the largest futures trading community on the planet, with well over 100,000 members
  • Genuine reviews from real traders, not fake reviews from stealth vendors
  • Quality education from leading professional traders
  • We are a friendly, helpful, and positive community
  • We do not tolerate rude behavior, trolling, or vendors advertising in posts
  • We are here to help, just let us know what you need
You'll need to register in order to view the content of the threads and start contributing to our community.  It's free and simple.

-- Big Mike, Site Administrator

(If you already have an account, login at the top of the page)

 
Search this Thread
 

MTF - Determining the TF

(login for full post details)
  #1 (permalink)
san francisco, CA / USA
 
Experience: Beginner
Platform: TOS
Trading: Dow
 
Posts: 21 since Jan 2019
Thanks: 4 given, 4 received

Hello,

I am working on a custom multi time frame indicator that has many plots across different time frames..

Some plots should appear only if they belong to a time frame higher than the time frame of the base chart..

in other words, lets say I have plots that are based on 1 hour, 4 hour and day time frames.. if the base chart is on 4 hour time frame, the lines based on 1 hour time frame should be suppressed.

Given both time frames are user selectable options at run time...I have 2 questions..from within the indicator,

1. How do I check what the plot's time frame is?
2. How do I check what the chart's base time frame is?

Note: using the example i cited above, I have created 3 data series using AddDataSeries function in OnStateChange / Configure. The plots were created using the wizard.

Appreciate your help in advance.

Reply With Quote

Can you help answer these questions
from other members on futures io?
Market Replay and Fills (Denali data)
Sierra Chart
Das Trader Pro
Platforms and Indicators
Question of adding/programming a setting to GOMCD
NinjaTrader
Display Total Delta in Numeric form
MultiCharts
Historical option expirations
Brokers
 
 
(login for full post details)
  #2 (permalink)
Kansas City, MO/US
 
Experience: Beginner
Platform: NinjaTrader
Trading: Futures
 
Barz's Avatar
 
Posts: 18 since Jul 2018
Thanks: 32 given, 15 received


patfaninba View Post
Hello,

I am working on a custom multi time frame indicator that has many plots across different time frames..

Some plots should appear only if they belong to a time frame higher than the time frame of the base chart..

in other words, lets say I have plots that are based on 1 hour, 4 hour and day time frames.. if the base chart is on 4 hour time frame, the lines based on 1 hour time frame should be suppressed.

Given both time frames are user selectable options at run time...I have 2 questions..from within the indicator,

1. How do I check what the plot's time frame is?
2. How do I check what the chart's base time frame is?

Note: using the example i cited above, I have created 3 data series using AddDataSeries function in OnStateChange / Configure. The plots were created using the wizard.

Appreciate your help in advance.

A bit late, but perhaps this will help others who stumble on this thread.

First, note that the primary (or base) series is always the 0th series in the BarsArray property of a NinjaScript.

Next, the trick is to convert the bar period for each series to a TimeSpan so that we can easily compare them.

Here is the full strategy code (for NT8). Should be similar for an Indicator:

 
Code
using System;
using System.Windows.Media;
using NinjaTrader.Data;

//This namespace holds strategies in this folder and is required. Do not change it.
namespace NinjaTrader.NinjaScript.Strategies.Barz.Sandbox.FuturesIO
{
    public class FIO_DetermineTimeFrame : Strategy
    {
        private TimeSpan[] _PeriodSpans;

        protected override void OnBarUpdate()
        {
            if (CurrentBar < BarsRequiredToTrade) { return; }

            // Conditionally populate plots based on whether the period is less
            // than or greater than the primary period.
            if (BarsInProgress == 0)
            {
                if (_PeriodSpans[1] > _PeriodSpans[0])
                {
                    Values[0][0] = Closes[1][0] + 20;
                }
                if (_PeriodSpans[2] < _PeriodSpans[0])
                {
                    Values[1][0] = Closes[2][0] - 20;
                }
            }

        }
        protected override void OnStateChange()
        {
            if (State == State.SetDefaults)
            {
                Name = "FIO_DetermineTimeFrame";

                // This creates a plot whose current value can be set in
                // OnBarUpdate using Values[0][0] = 25.1.
                AddPlot(Brushes.Yellow, "Larger Period");

                // This creates a plot whose current value can be set in
                // OnBarUpdate using Values[1][0] = 25.1.
                AddPlot(Brushes.Red, "Smaller Period");
            }
            else if (State == State.Configure)
            {
                // Ensure a 4 hour series has been added to your chart to serve
                // as the primary (base) series.

                // Add day chart here
                AddDataSeries(BarsPeriodType.Day, 1);

                // Add the 60 minute chart here
                AddDataSeries(BarsPeriodType.Minute, 60);
            }
            else if (State == State.DataLoaded)
            {
                _PeriodSpans = new TimeSpan[BarsArray.Length];

                for (int i = 0; i < BarsArray.Length; i++)
                {
                    BarsPeriod period = BarsArray[i].BarsPeriod;
                    Print(i + ": Period=" + period.BarsPeriodType.ToString()
                        + ", TimeSpan=" + period.ToTimeSpan());

                    // Capture the period for each series as a time span so we
                    // can easily do comparisons later.
                    _PeriodSpans[i] = period.ToTimeSpan();
                }

            }
        }

    }

    public static class BarsPeriodExtensions
    {
        public static TimeSpan ToTimeSpan(this BarsPeriod period)
        {
            switch (period.BarsPeriodType)
            {
                case BarsPeriodType.Second:
                    return TimeSpan.FromSeconds(period.Value);
                case BarsPeriodType.Minute:
                    return TimeSpan.FromMinutes(period.Value);
                case BarsPeriodType.Day:
                    return TimeSpan.FromDays(period.Value);
                case BarsPeriodType.Week:
                    return TimeSpan.FromDays(7 * period.Value);
                default:
                    throw new ArgumentException("BarsPeriodType not supported for conversion to TimeSpan: "
                        + period.BarsPeriodType);
            }
        }
    }
}

Reply With Quote
 
(login for full post details)
  #3 (permalink)
san francisco, CA / USA
 
Experience: Beginner
Platform: TOS
Trading: Dow
 
Posts: 21 since Jan 2019
Thanks: 4 given, 4 received


Thank you Barz

Reply With Quote


futures io Trading Community Platforms and Indicators NinjaTrader > MTF - Determining the TF


October 5, 2019


Upcoming Webinars and Events
 

Bookmap

Nov TBD
     



Copyright © 2020 by futures io, s.a., Av Ricardo J. Alfaro, Century Tower, Panama, +507 833-9432, info@futures.io
All information is for educational use only and is not investment advice.
There is a substantial risk of loss in trading commodity futures, stocks, options and foreign exchange products. Past performance is not indicative of future results.
no new posts