Multi-TimeFrame Issue

Created at 27 Jun 2015, 17:10
How’s your experience with the cTrader Platform?
Your feedback is crucial to cTrader's development. Please take a few seconds to share your opinion and help us improve your trading experience. Thanks!
DO

dopper3

Joined 27.06.2015

Multi-TimeFrame Issue
27 Jun 2015, 17:10


Hi,

I'm having some trouble with my indicator. I'm trying to get it to draw text based on if the various TF candles are up or down (essentially a direction dashboard). So I look at each TF's close and compare to the open. If close > open, draw green text, and red if close < open. I will perform more operations once I get this piece to work.

My problem is if I select the TF for the chart to be daily or anything less than Monthly, the Monthly (and weekly) close data is only pulling the last completed bar (i.e. for Monthly TF, since we are not done June bar, it is evaluating the close vs. open of the May monthly bar). I would expect it to use the current price vs. the open of the current month (June in this case) to calculate but it doesn't seem to. It seems to only reference already completed bars. However, when I change my chart TF to Monthly, it works as expected for the monthly data, but since the current weekly bar is not completed yet, the weekly bar is referencing the last 'completed' weekly bar only and not in the 'in-process' bar (but again, if I switch chart TF to weekly, it works as expected) . Here is a screen shot, right now my indicator text is showing the close value of each TF. I would expect the close value of all TF to be the same since these are all the current price. Below is also my code.

Anyone have any ideas what I'm doing wrong? I hope I am clear enough with what my problem is... Thanks in advance for any help!

using System;
using cAlgo.API;
using cAlgo.API.Internals;
using cAlgo.API.Indicators;
using cAlgo.Indicators;

namespace cAlgo
{
    [Indicator(IsOverlay = false, TimeZone = TimeZones.UTC, AccessRights = AccessRights.None)]
    public class DanBoard : Indicator
    {

        private string[] Direction;
        private Colors[] BarClr;
        private MarketSeries[] MS;


        //+-----------------------------------------------------------------+

        protected override void Initialize()
        {
            Direction = new string[3];
            Direction[0] = "Dn";
            Direction[1] = "Up";
            Direction[2] = "--";

            BarClr = new Colors[3];
            BarClr[0] = Colors.Red;
            BarClr[1] = Colors.Green;
            BarClr[2] = Colors.Gray;

            MS = new MarketSeries[9];
            MS[0] = MarketData.GetSeries(TimeFrame.Minute);
            MS[1] = MarketData.GetSeries(TimeFrame.Minute5);
            MS[2] = MarketData.GetSeries(TimeFrame.Minute15);
            MS[3] = MarketData.GetSeries(TimeFrame.Minute30);
            MS[4] = MarketData.GetSeries(TimeFrame.Hour);
            MS[5] = MarketData.GetSeries(TimeFrame.Hour4);
            MS[6] = MarketData.GetSeries(TimeFrame.Daily);
            MS[7] = MarketData.GetSeries(TimeFrame.Weekly);
            MS[8] = MarketData.GetSeries(TimeFrame.Monthly);

            string str = "";
            str = xySpace(1, 0) + "m1";
            str += xySpace(2, 0) + "m5";
            str += xySpace(2, 0) + "m15";
            str += xySpace(2, 0) + "m30";
            str += xySpace(2, 0) + "h1";
            str += xySpace(2, 0) + "h4";
            str += xySpace(2, 0) + "d1";
            str += xySpace(2, 0) + "w1";
            str += xySpace(2, 0) + "M";
            ChartObjects.DrawText("tfs", str, StaticPosition.TopLeft, Colors.Turquoise);

        }

        //+-----------------------------------------------------------------+

        public override void Calculate(int index)
        {

            if (!IsLastBar)
                return;

            string str = "";

            for (int i = 0; i < 9; i++)
            {

                int CandleDir = 0;

                if (MS[i].Close[index] < MS[i].Open[index])
                {
                    CandleDir = (0);
                }
                else if (MS[i].Close[index] > MS[i].Open[index])
                {
                    CandleDir = (1);
                }
                else
                {
                    CandleDir = (2);
                }

                str = xySpace(1 + (i * 2), 1);
                str += MS[i].Close.LastValue;
                ChartObjects.DrawText("CandleDir" + i.ToString(), str, StaticPosition.TopLeft, BarClr[CandleDir]);
            }
        }

        //+-----------------------------------------------------------------+

        private string xySpace(int x, int y)
        {
            if (x < 0 || y < 0)
                return ("");
            string str = "";
            for (int i = 0; i < y; i++)
                str += "\n";
            for (int i = 0; i < x; i++)
                str += "\t";
            return (str);
        }
    }
}

 


@dopper3
Replies

Spotware
29 Jun 2015, 12:00

Dear Trader,

We do not provide coding assistance services. We more than glad to assist you with specific questions about cAlgo.API. You also can contact one of our Partners or post a job in Development Jobs section for further coding assistance.


@Spotware