The Deal Map of trading with a multi-time-frame cBot doesn't match with the on-screen indicator.

Created at 16 Sep 2020, 14:35
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!
AL

alexnikon

Joined 28.02.2020

The Deal Map of trading with a multi-time-frame cBot doesn't match with the on-screen indicator.
16 Sep 2020, 14:35


Dear developers. Thank you very much for the multi-timeframe trading opportunity and examples. But the Deal Map of the back testing with multi-timeframe indicators doesn't match to the same indicator on the screen for some reason. The trading becomes chaotic in areas of the 'gaps' between the points of the indicator on the larger frame and also doesn't respect the line of the same indicator in many other moments.

I was trying to use the D1 harmonic on the M1 screen with a few indicators (including your examples), but it always happen the same. The cBot can be very profitable, but doesn't work like it supposes to be. Could you advise how to feel the 'gaps' and join trading and screen parameters.

Thanks in advance...


@alexnikon
Replies

PanagiotisCharalampous
16 Sep 2020, 14:41

Hi alexnikon,

To be able to understand the problem you need to share with us your cBot and indicators code as well as steps to reproduce the problem.

Best Regards,

Panagiotis 

Join us on Telegram


@PanagiotisCharalampous

alexnikon
16 Sep 2020, 15:02

RE:

PanagiotisCharalampous said:

Hi alexnikon,

To be able to understand the problem you need to share with us your cBot and indicators code as well as steps to reproduce the problem.

Best Regards,

Panagiotis 

Join us on Telegram

Dear Panagiotis. It's nice to hear from you again.

In this sample I have used the cBot advised by you for MA. The trading method is different to have only one open position at time.

Here it is:

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

namespace cAlgo.Robots
{
    [Robot(TimeZone = TimeZones.UTC, AccessRights = AccessRights.None)]
    public class MyBot11MTF_MA : Robot
    {
        [Parameter("Instance Name", DefaultValue = "001")]
        public string InstanceName { get; set; }

        [Parameter("Lot Size", DefaultValue = 0.01)]
        public double LotSize { get; set; }
//........................................................................
        [Parameter("MA1 Timeframe", Group = "MA1", DefaultValue = "Daily")]
        public TimeFrame TimeframeMA1 { get; set; }

        [Parameter("MA2 Timeframe", Group = "MA2", DefaultValue = "Hourly")]
        public TimeFrame TimeframeMA2 { get; set; }

        [Parameter("MA1 Period", Group = "MA1", DefaultValue = 20)]
        public int PeriodMA1 { get; set; }

        [Parameter("MA2 Period", Group = "MA2", DefaultValue = 15)]
        public int PeriodMA2 { get; set; }

        [Parameter("MA1 Type", Group = "MA1", DefaultValue = MovingAverageType.Hull)]
        public MovingAverageType MA1Type { get; set; }

        [Parameter("MA2 Type", Group = "MA2", DefaultValue = MovingAverageType.Hull)]
        public MovingAverageType MA2Type { get; set; }

//................... Indicators declarations .....................
        private Bars barsTF1;
        private Bars barsTF2;

        private MovingAverage ma1;
        private MovingAverage ma2;
//------------------- Indicators construction ---------------------
        protected override void OnStart()
        {
            barsTF1 = MarketData.GetBars(TimeframeMA1);
            barsTF2 = MarketData.GetBars(TimeframeMA2);

            ma1 = Indicators.MovingAverage(barsTF1.ClosePrices, PeriodMA1, MA1Type);
            ma2 = Indicators.MovingAverage(barsTF2.ClosePrices, PeriodMA2, MA2Type);
        }
//............................. Trading ...........................
        protected override void OnBar()
        {
            Triggers();
        }
//........................... Finish of a loop ....................
        protected override void OnStop()
        {
            Print("Successful day!");
            // this metod can be used to clean-up memory resources
        }
//==================================================================
        private void Triggers()
        {
            if (ma2.Result.LastValue > ma1.Result.LastValue)
            {
                ClosePosition(TradeType.Sell);
                if (!IsPositionOpenByType(TradeType.Buy))
                {
                    OpenPosition(TradeType.Buy);
                }
            }
//.....................................................................
            if (ma2.Result.LastValue < ma1.Result.LastValue)
            {
                ClosePosition(TradeType.Buy);
                if (!IsPositionOpenByType(TradeType.Sell))
                {
                    OpenPosition(TradeType.Sell);
                }
            }
        }
//============================ TRADING ===============================
        private void OpenPosition(TradeType type)
        {
            // calculate volume from lot size
            double volume = Symbol.QuantityToVolumeInUnits(LotSize);
            // open a new position
            ExecuteMarketOrder(type, this.SymbolName, volume, InstanceName, null, null);
        }

        private void ClosePosition(TradeType type)
        {
            var p = Positions.Find(InstanceName, this.SymbolName, type);

            if (p != null)
            {
                ClosePosition(p);
            }
        }
        // position Information
        private bool IsPositionOpenByType(TradeType type)
        {
            var p = Positions.FindAll(InstanceName, SymbolName, type);
            if (p.Count() >= 1)
            {
                return true;
            }
            return false;
        }
    }
}


@alexnikon

PanagiotisCharalampous
16 Sep 2020, 15:05

Hi alexnikon,

Thanks but I still need some steps to reproduce the problem. What am I supposed to be looking at?

Best Regards,

Panagiotis 

Join us on Telegram


@PanagiotisCharalampous

alexnikon
17 Sep 2020, 12:00 ( Updated at: 21 Dec 2023, 09:22 )

RE: Multitimrframe

PanagiotisCharalampous said:

Hi alexnikon,

Thanks but I still need some steps to reproduce the problem. What am I supposed to be looking at?

Best Regards,

Panagiotis 

Join us on Telegram

Hi Panagiotis

Here are the pictures of the deal map of back-testing of this cBot. It is testing the MA cross-over trigger over 5 years DB on the h1 screen. The indicators are the MTF_MA with a method advised by your team. The Hull-MA period 25 of D1 crosses with the Hull-MA period 6 of the h1 timeframe (as the screen).

The trading is profitable, but is clearly chaotic. You can see that the lines crossings don't match at all with the deal map trading points. I would blame. The same happen with other indicators and frames combinations.

I would be really please with your help. Thank you...


@alexnikon

PanagiotisCharalampous
17 Sep 2020, 12:30

Hi alexnikon,

I am sorry but this is still very confusing

The indicators are the MTF_MA with a method advised by your team

What is this indicator? When and where did we advise for this method? Where is this used in the cBot?

What are the lines we are looking at on the screen?

Can you provide all the cBot parameters so that we can reproduce the exact same results as you.

Best Regards,

Panagiotis 

Join us on Telegram


@PanagiotisCharalampous

alexnikon
18 Sep 2020, 13:35

RE:

PanagiotisCharalampous said:

Hi alexnikon,

I am sorry but this is still very confusing

The indicators are the MTF_MA with a method advised by your team

What is this indicator? When and where did we advise for this method? Where is this used in the cBot?

What are the lines we are looking at on the screen?

Can you provide all the cBot parameters so that we can reproduce the exact same results as you.

Best Regards,

Panagiotis 

Join us on Telegram

Hi Panagiotis

I have sent you two same texts answers to your questions, but the confirmation email never came back to me for some reason. It looks like the texts were too large with all codes and pictures included. Sorry for this. I do it again in a shorter format without repeating cBot cod and pictures published earlier on this thread…

I have used the Multi-Time-frame method described on this Forum. Click this link: https://ctrader.com/forum/announcements/1463

 This my cod is just a transparent way to see the problem, but I have tried a few options. You also published earlier on this forum a sample Bot for MACD indicator using this method. I have simplified your bot to have one only open position at time, and it has the same not-matching issue.

To reproduce this cod, open it please for the GBPUSD pare on the ‘h1’ screen with default parameters: MTF Hull-MA D1 20 and Hull-MA H1 15. In my sample I have back-tested it over 5 years period  for $1000 with total profit of $656. But the analysis shows that the Bot is running his own strategy. To see the problem you have to compare the crossover points of two MTF MA indicators with the trading points of the standard Deal Map. On my pictures the indicators are represented by yellow lines.

My MTF MA indicator is based on the cod with operator ‘GetIndexByDate’ which you have advised to me before for my MTF Gann-High-Low indicator. I also seen it in a few other examples in this forum. I have used it for different indicators, and it works perfectly for live trading on the screen. Thanks a lot. But it gives natural flat ‘gaps’ between the bars using it on the shorter time frames. This might cause the problem for cBots, as I imagine. I’ll send full code to you in next text message...

See next message...


@alexnikon

alexnikon
18 Sep 2020, 13:37

RE: RE:

alexnikon said:

PanagiotisCharalampous said:

Hi alexnikon,

I am sorry but this is still very confusing

The indicators are the MTF_MA with a method advised by your team

What is this indicator? When and where did we advise for this method? Where is this used in the cBot?

What are the lines we are looking at on the screen?

Can you provide all the cBot parameters so that we can reproduce the exact same results as you.

Best Regards,

Panagiotis 

Join us on Telegram

Hi Panagiotis

I have sent you two same texts answers to your questions, but the confirmation email never came back to me for some reason. It looks like the texts were too large with all codes and pictures included. Sorry for this. I do it again in a shorter format without repeating cBot cod and pictures published earlier on this thread…

I have used the Multi-Time-frame method described on this Forum. Click this link: https://ctrader.com/forum/announcements/1463

 This my cod is just a transparent way to see the problem, but I have tried a few options. You also published earlier on this forum a sample Bot for MACD indicator using this method. I have simplified your bot to have one only open position at time, and it has the same not-matching issue.

To reproduce this cod, open it please for the GBPUSD pare on the ‘h1’ screen with default parameters: MTF Hull-MA D1 20 and Hull-MA H1 15. In my sample I have back-tested it over 5 years period  for $1000 with total profit of $656. But the analysis shows that the Bot is running his own strategy. To see the problem you have to compare the crossover points of two MTF MA indicators with the trading points of the standard Deal Map. On my pictures the indicators are represented by yellow lines.

My MTF MA indicator is based on the cod with operator ‘GetIndexByDate’ which you have advised to me before for my MTF Gann-High-Low indicator. I also seen it in a few other examples in this forum. I have used it for different indicators, and it works perfectly for live trading on the screen. Thanks a lot. But it gives natural flat ‘gaps’ between the bars using it on the shorter time frames. This might cause the problem for cBots, as I imagine. I’ll send full code to you in next text message...

See next message...

Code of the indicator:

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

namespace cAlgo.Indicators
{
    [Indicator(IsOverlay = true, TimeZone = TimeZones.UTC)]
    public class MyMTF_MA : Indicator
    {
        [Parameter("Timeframe", DefaultValue = "Hourly")]
        public TimeFrame CustomTimeFrame { get; set; }

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

        [Parameter(DefaultValue = 5)]
        public int Period { get; set; }

        [Output("MA", LineColor = "#FFFFFF01")]
        public IndicatorDataSeries Result { get; set; }

        private Bars bars;
        private MovingAverage ma;
//-----------------------------------------------------------------------
        protected override void Initialize()
        {
            bars = MarketData.GetBars(CustomTimeFrame);
            ma = Indicators.MovingAverage(bars.ClosePrices, Period, MAType);
        }
//-----------------------------------------------------------------------
        public override void Calculate(int index)
        {
            var customIndex = GetIndexByDate(bars, Bars.OpenTimes[index]);
            if (customIndex != -1)
                Result[index] = ma.Result[customIndex];

        }
// Sub-Programme (smothing ??) -------------------------------------------
        private int GetIndexByDate(Bars bars, DateTime time)
        {
            for (int i = bars.ClosePrices.Count - 1; i > 0; i--)
            {
                if (time == bars.OpenTimes[i])
                    return i;
            }
            return -1;
        }
    }
}


@alexnikon

alexnikon
18 Sep 2020, 13:43

RE: RE: RE:

alexnikon said:

alexnikon said:

PanagiotisCharalampous said:

Hi alexnikon,

I am sorry but this is still very confusing

The indicators are the MTF_MA with a method advised by your team

What is this indicator? When and where did we advise for this method? Where is this used in the cBot?

What are the lines we are looking at on the screen?

Can you provide all the cBot parameters so that we can reproduce the exact same results as you.

Best Regards,

Panagiotis 

Join us on Telegram

Hi Panagiotis

I have sent you two same texts answers to your questions, but the confirmation email never came back to me for some reason. It looks like the texts were too large with all codes and pictures included. Sorry for this. I do it again in a shorter format without repeating cBot cod and pictures published earlier on this thread…

I have used the Multi-Time-frame method described on this Forum. Click this link: https://ctrader.com/forum/announcements/1463

 This my cod is just a transparent way to see the problem, but I have tried a few options. You also published earlier on this forum a sample Bot for MACD indicator using this method. I have simplified your bot to have one only open position at time, and it has the same not-matching issue.

To reproduce this cod, open it please for the GBPUSD pare on the ‘h1’ screen with default parameters: MTF Hull-MA D1 20 and Hull-MA H1 15. In my sample I have back-tested it over 5 years period  for $1000 with total profit of $656. But the analysis shows that the Bot is running his own strategy. To see the problem you have to compare the crossover points of two MTF MA indicators with the trading points of the standard Deal Map. On my pictures the indicators are represented by yellow lines.

My MTF MA indicator is based on the cod with operator ‘GetIndexByDate’ which you have advised to me before for my MTF Gann-High-Low indicator. I also seen it in a few other examples in this forum. I have used it for different indicators, and it works perfectly for live trading on the screen. Thanks a lot. But it gives natural flat ‘gaps’ between the bars using it on the shorter time frames. This might cause the problem for cBots, as I imagine. I’ll send full code to you in next text message...

See next message...

Code of the indicator:

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

namespace cAlgo.Indicators
{
    [Indicator(IsOverlay = true, TimeZone = TimeZones.UTC)]
    public class MyMTF_MA : Indicator
    {
        [Parameter("Timeframe", DefaultValue = "Hourly")]
        public TimeFrame CustomTimeFrame { get; set; }

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

        [Parameter(DefaultValue = 5)]
        public int Period { get; set; }

        [Output("MA", LineColor = "#FFFFFF01")]
        public IndicatorDataSeries Result { get; set; }

        private Bars bars;
        private MovingAverage ma;
//-----------------------------------------------------------------------
        protected override void Initialize()
        {
            bars = MarketData.GetBars(CustomTimeFrame);
            ma = Indicators.MovingAverage(bars.ClosePrices, Period, MAType);
        }
//-----------------------------------------------------------------------
        public override void Calculate(int index)
        {
            var customIndex = GetIndexByDate(bars, Bars.OpenTimes[index]);
            if (customIndex != -1)
                Result[index] = ma.Result[customIndex];

        }
// Sub-Programme (smothing ??) -------------------------------------------
        private int GetIndexByDate(Bars bars, DateTime time)
        {
            for (int i = bars.ClosePrices.Count - 1; i > 0; i--)
            {
                if (time == bars.OpenTimes[i])
                    return i;
            }
            return -1;
        }
    }
}

I hope this clarifies my problem. Sorry for the mess. But I'm an absolutely beginner in programming, just trying to preserve my nervous for the live trading :))

Thanks in advance... 


@alexnikon

PanagiotisCharalampous
21 Sep 2020, 10:01

Hi alexnikon,

I had a look at the cBot and the indicator and I do not see anything wrong. But from what I understand you are comparing irrelevant information. You are opening trades in the middle of the daily bar based on the current state of the daily moving average but you compare the conditions with the indicator calculated using the finalized daily bar. This is wrong since the values of the finalized daily bar are different from the value of the indicator at the current moment the order was executed.

Best Regards,

Panagiotis 

Join us on Telegram


@PanagiotisCharalampous

alexnikon
21 Sep 2020, 10:12

RE:

PanagiotisCharalampous said:

Hi alexnikon,

I had a look at the cBot and the indicator and I do not see anything wrong. But from what I understand you are comparing irrelevant information. You are opening trades in the middle of the daily bar based on the current state of the daily moving average but you compare the conditions with the indicator calculated using the finalized daily bar. This is wrong since the values of the finalized daily bar are different from the value of the indicator at the current moment the order was executed.

Best Regards,

Panagiotis 

Join us on Telegram

Ok. Thanks a lot! It's promising.

Can be a way to synchronise the visual and real trades? I did try to feel the gaps using the operators 'for' and 'if' but haven't succeed...


@alexnikon

alexnikon
22 Sep 2020, 23:38

RE:

PanagiotisCharalampous said:

Hi alexnikon,

I had a look at the cBot and the indicator and I do not see anything wrong. But from what I understand you are comparing irrelevant information. You are opening trades in the middle of the daily bar based on the current state of the daily moving average but you compare the conditions with the indicator calculated using the finalized daily bar. This is wrong since the values of the finalized daily bar are different from the value of the indicator at the current moment the order was executed.

Best Regards,

Panagiotis 

Join us on Telegram

Thank you, Panagiotis. I have tried another MTF MA method, advised by your team, and it is feeling the data from the long term frame for every bar of the shortest time frames. It looks like it will work for other indicators and the live trading. A huge thanks...


@alexnikon

csgo.expertt
24 Sep 2020, 09:12

Hey there. As I see it, I could help solve this problem. But I need to understand it. And for this, please, share your cBot code and indicator, and tell about the steps to reproduce the problem. In this case, I will know what to do and will be able to draw up an action plan. A guy recently asked me about this fastessay.net/write-my-essay.html service. I told everything only after he correctly described the problem. Thank you for understanding.