Multi-timeframe robots/indicators

PanagiotisCharalampous's avatar

PanagiotisCharalampous since: 13 Jan 2017;

  04 Aug 2020, 08:14
Multi-timeframe robots/indicators

Hi alexnikon,

Thanks for the additional information but the screenshot does not explain what is the problem with higher timeframes. Can you elaborate? What does it do and what should it do instead?

Best Regards,

Panagiotis 

Join us on Telegram

Head of Community Management at cTrader

alexnikon since: 28 Feb 2020;

  04 Aug 2020, 11:14
RE: RE:

alexnikon said:

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

Dear Panagiotic

Here you can see what the H1 chart looks like when I use consecutively M5, Daily and H1 (normal) custom frames.

(Sorry for publishing them this way. Can not see how to attach the link from cTrader directly...)

Thank you very much.

PanagiotisCharalampous's avatar

PanagiotisCharalampous since: 13 Jan 2017;

  04 Aug 2020, 12:03

Hi alexnikon,

I used the same timeframes but the chart looks fine to me

Best Regards,

Panagiotis 

Join us on Telegram

Head of Community Management at cTrader

alexnikon since: 28 Feb 2020;

  04 Aug 2020, 12:18
RE:

PanagiotisCharalampous said:

Hi alexnikon,

I used the same timeframes but the chart looks fine to me

Best Regards,

Panagiotis 

Join us on Telegram

Oooo!! I hope I'm wrong. I'll try to fit it in a robot. Thank you very much. I highly appreciate your help!

xeulav since: 10 Dec 2020;

  11 Dec 2020, 11:06
RE: RE:

Hello,

the MarketData.GetSeries is obsolete now.

FalcoPereGrinus since: 21 Oct 2020;

  28 Jan 2021, 11:49

Hello there I want to add ma50 and ma200 values ​​to my strategy in the daily period, but both give the same value of ma50. Where am I making a mistake? Thanks for your help.

namespace cAlgo.Robots
{
    [Robot(TimeZone = TimeZones.UTC, AccessRights = AccessRights.None)]
    public class NewcBot : Robot
    {
        [Parameter(DefaultValue = 0.0)]
        public double Parameter { get; set; }

        [Parameter("Slow Periods", Group = "Simple Moving Average", DefaultValue = 200)]
        public int SlowPeriods { get; set; }

        [Parameter("Fast Periods", Group = "Simple Moving Average", DefaultValue = 50)]
        public int FastPeriods { get; set; }

        private MovingAverage FastSMA;
        private MovingAverage SlowSMA;
        private Bars D1;

        protected override void OnStart()
        {
            D1 = MarketData.GetBars(TimeFrame.Daily);
            FastSMA = Indicators.SimpleMovingAverage(D1.ClosePrices, FastPeriods);
            SlowSMA = Indicators.SimpleMovingAverage(D1.ClosePrices, SlowPeriods);
        }

        protected override void OnTick()
        {
            Print("FSMA={0},SSMA={0}", FastSMA.Result.LastValue, SlowSMA.Result.LastValue);
        }

        protected override void OnStop()
        {
            // Put your deinitialization logic here
        }
    }
}

PanagiotisCharalampous's avatar

PanagiotisCharalampous since: 13 Jan 2017;

  28 Jan 2021, 13:45

Hi FalcoPereGrinus,

Try 

Print("FSMA={0},SSMA={1}", FastSMA.Result.LastValue, SlowSMA.Result.LastValue);

instead.

Best Regards,

Panagiotis 

Join us on Telegram

Head of Community Management at cTrader

FalcoPereGrinus since: 21 Oct 2020;

  28 Jan 2021, 13:52
RE:

PanagiotisCharalampous said:

Hi FalcoPereGrinus,

Try 

Print("FSMA={0},SSMA={1}", FastSMA.Result.LastValue, SlowSMA.Result.LastValue);

instead.

Best Regards,

Panagiotis 

Join us on Telegram

Hi Panagiotis;

Thank you very much. I apologize for my carelessness.

cW22Trader since: 16 Mar 2021;

  08 Sep 2021, 23:28
Historical Data is wrong

Hi,

Why is the historical data wrong when using a different time frame and retrieving the index by GetIndexByTime? How could the indicator already know the high and low value (sma period = 1) at 9 pm of the previous day (see 1. screen shot)? If I a reduce dataIndex by 1 it is correct but is this how you should use GetIndexByTime? If you leave the indicator on the chart for a while, the values calculated while the chart was open behave different then the ones calculated from historical data during initializaiton of the indicator (see 2. screen shot). The last 3 bars all have different low values (red line) but all others (calculated during init) alway have 2 same values (this was done on 1m chart with tf parameter set to 2m).

Kind regards

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

namespace cAlgo
{
    [Indicator(IsOverlay = true, TimeZone = TimeZones.UTC, AccessRights = AccessRights.None)]
    public class TimeFrameMA : Indicator
    {
        [Parameter("Time Frame", DefaultValue = "Daily")]
        public TimeFrame Timeframe { get; set; }

        [Parameter("MA Periods", DefaultValue = 3, MinValue = 1)]
        public int Periods { get; set; }

        [Parameter("MA Type", DefaultValue = MovingAverageType.Exponential)]
        public MovingAverageType MAType { get; set; }

        [Output("High", Thickness = 3)]
        public IndicatorDataSeries High { get; set; }

        [Output("Low", Thickness = 3, LineColor = "Red")]
        public IndicatorDataSeries Low { get; set; }

        private Bars data;
        private MovingAverage maH, maL;


        protected override void Initialize()
        {
            data = MarketData.GetBars(Timeframe);
            maH = Indicators.MovingAverage(data.HighPrices, Periods, MAType);
            maL = Indicators.MovingAverage(data.LowPrices, Periods, MAType);
        }

        public override void Calculate(int index)
        {
            var indexData = data.OpenTimes.GetIndexByTime(Bars.OpenTimes[index]);
            if (indexData > 0)
            {
                High[index] = maH.Result[indexData];
                Low[index] = maL.Result[indexData];
            }
        }
    }
}

PanagiotisCharalampous's avatar

PanagiotisCharalampous since: 13 Jan 2017;

  09 Sep 2021, 08:43

Hi cW22Trader,

How could the indicator already know the high and low value (sma period = 1) at 9 pm of the previous day (see 1. screen shot)?

Because you are retrieving data for historical bars that have already been closed. All the bars you retrieve are closed bars. When you get data using GetIndexByTime(), you don't get the bar as it was at the specific point of time, but the completed bar where the requested time falls in.

If you are looking to find the bar state at the specific point of time, then this functionality is not offered by the API. You will need to develop something yourself.

Best Regards,

Panagiotis 

Join us on Telegram and Facebook  

Head of Community Management at cTrader