Topics
Replies

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

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
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