NexusFi: Find Your Edge


Home Menu

 





MC.net: (Multi-Timeframe) Directly Added Indicators vs BarsOfData/CustomInstrument


Discussion in MultiCharts

Updated
    1. trending_up 2,930 views
    2. thumb_up 0 thanks given
    3. group 2 followers
    1. forum 0 posts
    2. attach_file 2 attachments




 
Search this Thread

MC.net: (Multi-Timeframe) Directly Added Indicators vs BarsOfData/CustomInstrument

  #1 (permalink)
 rc76 
Taipei
 
Experience: Beginner
Platform: NT
Broker: IB
Trading: ES
Posts: 8 since Jul 2018
Thanks Given: 1
Thanks Received: 2

[Issue]
I am trying to create a multi-timeframe indicator both daily and weekly data-series, plotted on a daily chart. I have identified (at least from my coding knowledge so far) there is discrepancy among the indicator results from the different method I used to create the indicators.

Default Method (Indicator plots are accurate compared to ToS)
(1) Default: Add weekly data-series directly from Chart's "Insert Instrument" menu. Than add existing EMA indicators (Mov_Avg_Exponential) directly against daily and weekly data.



Coded Methods

(2) BarsOfData: Add weekly data-series directly from Chart's "Insert Instrument" menu. Than create a custom indicator using BarsOfData to retrieve weekly data, and plot the daily/weekly EMA using XAverage.

 
Code
using System;
using System.Drawing;
using System.Linq;
using PowerLanguage.Function;

namespace PowerLanguage.Indicator
{

    [SameAsSymbol(true)]
    public class _aa_MTF_BarsOfData : IndicatorObject
    {
        public _aa_MTF_BarsOfData(object _ctx) : base(_ctx) { }
        private IPlotObject plot_EMA_d;
        private IPlotObject plot_EMA_w;
        //CustomInstrument m_WeeklyData;

        XAverage ema_day;
        XAverage ema_week;

        protected override void Create()
        {
            plot_EMA_d = AddPlot(new PlotAttributes("", EPlotShapes.Line, Color.Red, Color.Black, 4, EPlotStyle.Solid, false));
            plot_EMA_w = AddPlot(new PlotAttributes("", EPlotShapes.Line, Color.Cyan, Color.Black, 4, EPlotStyle.Solid, false));
            ema_day = new XAverage(this);
            ema_week = new XAverage(this);
        }

        protected override void StartCalc()
        {
            ema_day.Price = Bars.Close;
            ema_day.Length = 9;

            ema_week.Price = BarsOfData(2).Close;
            ema_week.Length = 9;
        }

        protected override void CalcBar()
        {
            plot_EMA_d.Set(ema_day[0]);
            plot_EMA_w.Set(ema_week[0]);
        }
    }
}
(3) CustomInstrument: Create a custom indicator. Retrieve the weekly data using CustomInstrument. Plot the daily/weekly EMA using XAverage.

 
Code
using System;
using System.Drawing;
using System.Linq;
using PowerLanguage.Function;

namespace PowerLanguage.Indicator
{

    [SameAsSymbol(true)]
    public class _aa_MTF_CustomInstrument : IndicatorObject
    {
        public _aa_MTF_CustomInstrument(object _ctx) : base(_ctx) { }
        private IPlotObject plot_EMA_d;
        private IPlotObject plot_EMA_w;
        CustomInstrument m_WeeklyData;

        XAverage ema_day;
        XAverage ema_week;

        protected override void Create()
        {
            plot_EMA_d = AddPlot(new PlotAttributes("", EPlotShapes.Line, Color.Red, Color.Black, 4, EPlotStyle.Solid, false));
            plot_EMA_w = AddPlot(new PlotAttributes("", EPlotShapes.Line, Color.Cyan, Color.Black, 4, EPlotStyle.Solid, false));
            ema_day = new XAverage(this);
            ema_week = new XAverage(this);
        }

        protected override void StartCalc()
        {
            m_WeeklyData = new CustomInstrument(this, new Resolution(EResolution.Week, 1));

            ema_day.Price = Bars.Close;
            ema_day.Length = 9;

            ema_week.Price = m_WeeklyData.Close;
            ema_week.Length = 9;
        }

        protected override void CalcBar()
        {
            plot_EMA_d.Set(ema_day[0]);
            plot_EMA_w.Set(ema_week[0]);
        }

        protected override void Dispose(bool _b)
        {
            m_WeeklyData.Dispose();
        }
    }
}
[Test Results]
Both BarsOfData and CustomInstrument indicator plot results are the same. However they are different to the default method result, which is accurate as it is compared against ToS's result.



Did I use the BarsOfData/CustomInstrument incorrectly? Any tip or help will be truly appreciated!

Thank you everyone!

Started this thread Reply With Quote




Last Updated on June 12, 2021


© 2024 NexusFi™, s.a., All Rights Reserved.
Av Ricardo J. Alfaro, Century Tower, Panama City, Panama, Ph: +507 833-9432 (Panama and Intl), +1 888-312-3001 (USA and Canada)
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.
About Us - Contact Us - Site Rules, Acceptable Use, and Terms and Conditions - Privacy Policy - Downloads - Top
no new posts