Command HasCrossedAbove with wrong answer

Created at 28 Jul 2020, 21:25
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!
EL

eliezer_barros

Joined 21.12.2018

Command HasCrossedAbove with wrong answer
28 Jul 2020, 21:25


There's a difference between the data results that I can see and what the software do. Sometimes when the curve are very close the system open a position but the curve didn't cross.

Please, somebody know what happen?

 

            var numfast = _emaFast.Result.Last(1);
            var numslow = _emaSlow.Result.Last(1);



            if (_emaFast.Result.HasCrossedAbove(_emaSlow.Result, 1))
            {

            do something

           }


@eliezer_barros
Replies

PanagiotisCharalampous
31 Jul 2020, 16:09

Hi Eliezer,

To help you with this, you need to provide the complete cBot code as well as steps to reproduce the problem.

Best Regards,

Panagiotis 

Join us on Telegram

 


@PanagiotisCharalampous

eliezer_barros
31 Jul 2020, 16:26

RE:

PanagiotisCharalampous said:

Hi Eliezer,

To help you with this, you need to provide the complete cBot code as well as steps to reproduce the problem.

Best Regards,

Panagiotis 

Join us on Telegram

 

ok, please see below.

tks

 

//duas curvas
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 DuasCurvasdiferentes : Robot
    {

        [Parameter("Volume", DefaultValue = 1)]
        public double VolumeToOpenOrders { get; set; }

        [Parameter("Profit", DefaultValue = 400)]
        public int TakeProfitInPips { get; set; }

        [Parameter("Stop Loss", DefaultValue = 350)]
        public int StopLoss { get; set; }

        [Parameter("Data Source")]
        public DataSeries Price { get; set; }

        //   [Parameter("Slow Periods", DefaultValue = 14)]
        public int SlowPeriods { get; set; }

        // [Parameter("Fast Periods", DefaultValue = 5)]
        public int FastPeriods { get; set; }

        // public int Parameter { get; set; }

        private ExponentialMovingAverage _emaFast;
        private ExponentialMovingAverage _emaSlow;

        private const string label = "Duas Curvas diferentes";

        private double calc = 0.0;

        protected override void OnStart()
        {
            _emaFast = Indicators.ExponentialMovingAverage(Price, 8);
            _emaSlow = Indicators.ExponentialMovingAverage(Price, 20);
        }

        //protected override void OnTick()
        protected override void OnBar()
        {

            var numfast = _emaFast.Result.Last(0);
            var numslow = _emaSlow.Result.Last(0);
            calc = numfast - numslow;

            var upposition = Positions.Find(label, SymbolName, TradeType.Buy);
            var downposition = Positions.Find(label, SymbolName, TradeType.Sell);


            if (_emaFast.Result.HasCrossedAbove(_emaSlow.Result, 0))
            {

                if (downposition != null)
                {
                    ClosePosition(downposition);
                }
                if (upposition == null)
                {
                    ExecuteMarketOrder(TradeType.Buy, Symbol.Name, VolumeToOpenOrders, label, StopLoss, TakeProfitInPips);
                }
            }


            if (_emaFast.Result.HasCrossedBelow(_emaSlow.Result, 0))
            {
                // Print("Venda calc    ", calc);
                if (upposition != null)
                {
                    ClosePosition(upposition);
                }
                if (downposition == null)
                {
                    ExecuteMarketOrder(TradeType.Sell, Symbol.Name, VolumeToOpenOrders, label, StopLoss, TakeProfitInPips);
                }
            }

        }
    }
}


@eliezer_barros

PanagiotisCharalampous
31 Jul 2020, 16:53

Hi Eliezer,

You did not provide steps to reproduce the problem

Best Regards,

Panagiotis 

Join us on Telegram


@PanagiotisCharalampous

eliezer_barros
31 Jul 2020, 18:02

RE:

PanagiotisCharalampous said:

Hi Eliezer,

You did not provide steps to reproduce the problem

Best Regards,

Panagiotis 

Join us on Telegram

 

If you check the instant when the line crossed in software and see the same point directly over the line (manually) the values are different.

Other possibility to see, if your include a Print("_emaFast.Result"); and check what the software made, the values are different and i can't understand why.

tks


@eliezer_barros

... Deleted by UFO ...

eliezer_barros
05 Aug 2020, 22:54 ( Updated at: 21 Dec 2023, 09:22 )

RE: RE:

eliezer_barros said:

PanagiotisCharalampous said:

Hi Eliezer,

You did not provide steps to reproduce the problem

Best Regards,

Panagiotis 

Join us on Telegram

 

If you check the instant when the line crossed in software and see the same point directly over the line (manually) the values are different.

Other possibility to see, if your include a Print("_emaFast.Result"); and check what the software made, the values are different and i can't understand why.

tks

Hi, Please see the picture below

This test was made with XAUUSD and if you check for July/31, the lines was not crossed, but the system open a position.

I can't find the problem and I am comparing the same values to curve and to software.

Please, can you check what is going on?

Tks

 


@eliezer_barros

PanagiotisCharalampous
06 Aug 2020, 08:49

Hi eliezer,

I tried reproducing this trade with the cBot you sent but I do not get such a position opened. See below

Best Regards,

Panagiotis 

Join us on Telegram

 


@PanagiotisCharalampous

eliezer_barros
06 Aug 2020, 20:39 ( Updated at: 21 Dec 2023, 09:22 )

RE:

PanagiotisCharalampous said:

Hi eliezer,

I tried reproducing this trade with the cBot you sent but I do not get such a position opened. See below

Best Regards,

Panagiotis 

Join us on Telegram

 

The test that you made is correct, the position was opened. Now I want to you put the two curves of the exponential average over the candle graphics and you can see that is different of the bot done.

This is my problem, the software is different of the curves and I can understand why.

tks


@eliezer_barros

PanagiotisCharalampous
07 Aug 2020, 08:16

Hi eliezer,

I still do not understand. I do not see the position in my results. Can you show it to me?

Best Regards,

Panagiotis 

Join us on Telegram


@PanagiotisCharalampous