Getting wrong position without cross

Created at 30 Jul 2024, 15:11
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!
AD

adab.omid

Joined 04.04.2024

Getting wrong position without cross
30 Jul 2024, 15:11


I am working on a bot for more than 6 months, it is working on cross of 2 timeseries MA, yesterday it get sell position without any cross and after that it get buy position on crossbelow. 

At the end of the day i checked it with ctrader backtest, and it worked well, can someone tell me whats happend in real time? 


@adab.omid
Replies

PanagiotisCharalampous
31 Jul 2024, 06:11

Hi there,

It's hard to tell without specific information. Can you share the cBot, parameters, broker and the live execution log? There might me some clues there.

Best regards,

Panagiotis 


@PanagiotisCharalampous

arz9704
31 Jul 2024, 08:41 ( Updated at: 01 Aug 2024, 06:21 )

I have the same problem

I use the same strategy and exactly the same thing happened to me


@arz9704

adab.omid
19 Aug 2024, 20:36 ( Updated at: 20 Aug 2024, 04:33 )

RE: Getting position without cross

PanagiotisCharalampous said: 

Hi there,

It's hard to tell without specific information. Can you share the cBot, parameters, broker and the live execution log? There might me some clues there.

Best regards,

Panagiotis 

Hi dear,

last time, I couldn't find position log, but it happened again today, it get 2 positions without any cross,  live result is -6.71 but in backtest +4

I cant send you all part of my source because it is more than 1000 line of code,  but the main part for execution is :

  if ((_fastTimeSeriesMovingAverage.Result.Last(1) < _slowTimeSeriesMovingAverage.Result.Last(1) && _fastTimeSeriesMovingAverage.Result.Last(0) > _slowTimeSeriesMovingAverage.Result.Last(0))
              {
                    if (longPosition == null)
                        ExecuteMarketOrder(TradeType.Buy, SymbolName, _volumeInUnits, Label, StopLossInPips, TakeProfitInPips);
                }

                if ((_fastTimeSeriesMovingAverage.Result.Last(1) > _slowTimeSeriesMovingAverage.Result.Last(1) && _fastTimeSeriesMovingAverage.Result.Last(0) < _slowTimeSeriesMovingAverage.Result.Last(0)) 
                {

                    if (shortPosition == null)
                        ExecuteMarketOrder(TradeType.Sell, SymbolName, _volumeInUnits, Label, StopLossInPips, TakeProfitInPips);
                }

parameters for today: Fast =9, Slow = 19

broker: litefinance

Symbol : dawjones

Utc: +3:30

Best regards,


@adab.omid

PanagiotisCharalampous
20 Aug 2024, 04:46

Hi there,

This happens because you are using the current open bar value in your conditions. The value of the current open bar can change by the time the bar closes, leading to several false signals. Try checking closed bars only e.g.

  if ((_fastTimeSeriesMovingAverage.Result.Last(2) < _slowTimeSeriesMovingAverage.Result.Last(2) && _fastTimeSeriesMovingAverage.Result.Last(1) > _slowTimeSeriesMovingAverage.Result.Last(1))

Best regards,

Panagiotis


@PanagiotisCharalampous

adab.omid
20 Aug 2024, 09:33

RE: Getting wrong position without cross
PanagiotisCharalampous said:

Hi there,

This happens because you are using the current open bar value in your conditions. The value of the current open bar can change by the time the bar closes, leading to several false signals. Try checking closed bars only e.g.

  if ((_fastTimeSeriesMovingAverage.Result.Last(2) < _slowTimeSeriesMovingAverage.Result.Last(2) && _fastTimeSeriesMovingAverage.Result.Last(1) > _slowTimeSeriesMovingAverage.Result.Last(1))

Best regards,

Panagiotis


@adab.omid

adab.omid
20 Aug 2024, 09:36

RE: RE: Getting wrong position without cross

adab.omid said: 

PanagiotisCharalampous said: 

Hi there,

This happens because you are using the current open bar value in your conditions. The value of the current open bar can change by the time the bar closes, leading to several false signals. Try checking closed bars only e.g.

  if ((_fastTimeSeriesMovingAverage.Result.Last(2) < _slowTimeSeriesMovingAverage.Result.Last(2) && _fastTimeSeriesMovingAverage.Result.Last(1) > _slowTimeSeriesMovingAverage.Result.Last(1))

Best regards,

Panagiotis

Thanks for your reply,

Actually, i used yor suggestion before,  but it has 1 candle delay for getting position and some times this candle is fatefu  

Best regards,

 

 


@adab.omid