Why it acts weird?

Created at 08 Aug 2013, 23:43
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!
IR

iRobot

Joined 17.02.2013

Why it acts weird?
08 Aug 2013, 23:43


Hi,

so I am testing very simple robot to see how cAlgo works.

It's logic:

BUY signal -> EMA(10) HasCrossedAbove BollingerBandBottom

SELL signal -> EMA(10) HasCrossedBellow BollingerBandTop

One must stop another and open new position constantly.

 

I get mixed results from the same backtest. In the first graph you can see that short position is opened correctly, but system misses to close it even 3 times. In the second graph you can see that robot works correctly - it opens short position, closes it as should be, opens long position and closes long as it should be (and open third position).

Could you pls give suggestions if I do smth wrong, if it's some kind of bug or if there is some other explanation?


@iRobot
Replies

cAlgo_Fanatic
09 Aug 2013, 15:28

If you could post the code snippet for the logic of positions being triggered that would be helpful.

Two things you should be aware of.

  1. The functions HasCrossedAbove/HasCrossedBelow compare the two series for the specified period. If the period is set to zero, then only the last values will be compared. Usually, the last values are not the final values and what you see on the chart will not be representing the values at the time that the HasCrossedAbove/HasCrossedBelow were triggered, The series may actually cross after the HasCrossedAbove/HasCrossedBelow methods were triggered.
    It is not uncommon that the function will return true and by the end of the bar the two series will uncross. Try using the OnBar event with a period of at least one. This way the series will be compared for the last as well as the previous values.
  2. The backtesting tick data are as close to the real data as possible but due to the fact that they are being calculated each time, they will be slightly different each time you do the backtest.

@cAlgo_Fanatic