Multi-timeframe robots/indicators

RE:

PanagiotisCharalampous said:

Hi alexnikon,

To give you an advice, you need to provide more information. It would be better to create a new thread, post your code and explain your issue in detail.

Best Regards,

Panagiotis 

Join us on Telegram

Dear PanagiotisCharalampous thanks a lot for the reply. Greatly appreciated...

I'm traying to design a GannHighLow Multi-Timeframe indicator useful to build up a multi-frame cBot afterwards, and with no success at the moment.

I have tried a referencing and also a direct re-coding of the provided by cTrader samples. Still no success. Both options work well on the chats with the same time scale, but are showing some nonsense lines on the chats with longer or shorter timeframes. It looks like the problem is in re-indexing of series for the Custom Timeframe. The HiLo is using the [index - 1] value, which might be deteriorating the graph, but my knowledge is too limited to sort it out. It would be great, if you could give some advise... Thanks in advance.

One of the codes, which I'm trying to finish, is here:

// from updated "GannHighLow" by 'kalex718' at 12/09/2012
using System;
using cAlgo.API;
using cAlgo.API.Internals;
using cAlgo.API.Indicators;
using cAlgo.Indicators;

namespace cAlgo
{
    [Indicator(IsOverlay = true, AccessRights = AccessRights.None)]
    public class MyMultiFrameHiLo2 : Indicator
    {
        [Parameter("Period", DefaultValue = 10)]
        public int Period { get; set; }

        [Parameter("Timeframe1", DefaultValue = "Daily")]
        public TimeFrame Timeframe { get; set; }

        [Output("Support", LineColor = "#FF02AFF1", Thickness = 1)]
        public IndicatorDataSeries Support { get; set; }

        private Bars _bars;
        private SimpleMovingAverage _smaHigh;
        private SimpleMovingAverage _smaLow;
//-------------------------------------------------------------------------------------------------------
        protected override void Initialize()
        {
            _bars = MarketData.GetBars(Timeframe);
            _smaHigh = Indicators.SimpleMovingAverage(_bars.HighPrices, Period);
            _smaLow = Indicators.SimpleMovingAverage(_bars.LowPrices, Period);
        }
        public override void Calculate(int index)
        {
            if (index < Period)
                return;
            double close = Bars.ClosePrices[index];
            double smaHigh = _smaHigh.Result[index - 0];
            double smaHighPrev = _smaHigh.Result[index - 1];
            double smaLow = _smaLow.Result[index - 0];
            double smaLowPrev = _smaLow.Result[index - 1];
//-------------------------------------------------------------------------------------------------------
            if (close > smaHigh)
                Support[index] = smaLow;
            else
            {
                if (close < smaLow)
                    Support[index] = smaHigh;
                else
                {
                    if (Support[index - 1] == smaHighPrev)
                        Support[index] = smaHigh;
                    else
                        Support[index] = smaLow;
                }
            }
        }
    }
}

RE:

PanagiotisCharalampous said:

Hi alexnikon,

I am not sure what is the indicator supposed to do but your indexing is definitely wrong. See below how to get the correct indices for your indicators


            double smaHigh = _smaHigh.Result[_bars.OpenTimes.GetIndexByTime(Bars.OpenTimes[index]) - 0];
            double smaHighPrev = _smaHigh.Result[_bars.OpenTimes.GetIndexByTime(Bars.OpenTimes[index]) - 1];
            double smaLow = _smaLow.Result[_bars.OpenTimes.GetIndexByTime(Bars.OpenTimes[index]) - 0];
            double smaLowPrev = _smaLow.Result[_bars.OpenTimes.GetIndexByTime(Bars.OpenTimes[index]) - 1];

Let me know if this helps

Best Regards,

Panagiotis 

Join us on Telegram

Thanks a lot !! It looks better. It draws more sensible line if the Custom timescale is shorter than the carrier chart, but it is still wrong if it is longer. F.e. on the base H1 chart, the Custom frame M10 looks nearly properly (even not sure), but the D1 is wrong...

Note: I want eventually use the GannHiLo for a cBot to trigger when Close price crosses the HiLo on the triple screen view (by Elder). It seams to be working as a kind of dynamic support line...

The updated code with your suggestion follows:

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

namespace cAlgo
{
    [Indicator(IsOverlay = true, AccessRights = AccessRights.None)]
    public class MyMultiFrameHiLo2 : Indicator
    {

        [Parameter("Period", DefaultValue = 10)]
        public int Period { get; set; }

        [Parameter("Timeframe1", DefaultValue = "Daily")]
        public TimeFrame Timeframe { get; set; }

        [Output("Support", LineColor = "#FF02AFF1", Thickness = 1)]
        public IndicatorDataSeries Support { get; set; }

        private Bars _bars;
        private SimpleMovingAverage _smaHigh;
        private SimpleMovingAverage _smaLow;

        protected override void Initialize()
        {
            _bars = MarketData.GetBars(Timeframe);
            _smaHigh = Indicators.SimpleMovingAverage(_bars.HighPrices, Period);
            _smaLow = Indicators.SimpleMovingAverage(_bars.LowPrices, Period);
        }
        public override void Calculate(int index)
        {
            if (index < Period)
                return;

            double close = Bars.ClosePrices[index];

           /* ------ excluded ----------------------------------------

            double smaHigh = _smaHigh.Result[index - 0];
            double smaHighPrev = _smaHigh.Result[index - 1];
            double smaLow = _smaLow.Result[index - 0];
            double smaLowPrev = _smaLow.Result[index - 1];
            ------------------------------------------------------------*/
            double smaHigh = _smaHigh.Result[_bars.OpenTimes.GetIndexByTime(Bars.OpenTimes[index]) - 0];
            double smaHighPrev = _smaHigh.Result[_bars.OpenTimes.GetIndexByTime(Bars.OpenTimes[index]) - 1];
            double smaLow = _smaLow.Result[_bars.OpenTimes.GetIndexByTime(Bars.OpenTimes[index]) - 0];
            double smaLowPrev = _smaLow.Result[_bars.OpenTimes.GetIndexByTime(Bars.OpenTimes[index]) - 1];
//------------------------------------------------------------------------
            if (close > smaHigh)
                Support[index] = smaLow;
            else
            {
                if (close < smaLow)
                    Support[index] = smaHigh;
                else
                {
                    if (Support[index - 1] == smaHighPrev)
                        Support[index] = smaHigh;
                    else
                        Support[index] = smaLow;
                }
            }
        }
    }
}

RE:

PanagiotisCharalampous said:

Hi alexnikon,

I cannot help you further at the moment because I have no idea what is the indicator expected to do. You need to provide more information of what the expected outcome should be and what does the indicator do instead. Screenshots would be helpful.

Best Regards,

Panagiotis 

Join us on Telegram

Dear PanagiotisCharalampous. Thank you very much again. Sorry, the Gann-High-Low indicator isn't very popular. It is based on moving averages of High and Low prices of the series. It shows only one of them which is below the trend - would it be  the average of Highs or Lows depending of the trend direction. The line sharply swaps the side around the trend when the Close price penetrates the actual high or low price average line in the opposite movement and the trend changes direction (pict.1).

Not sure whether my explanation is clear, but hope the pictures can help. I sorry for asking so much attention... Thanks in advance...

Pic.1