FR
Very simple CCI bot but entries are not accurate
07 May 2015, 09:09
Hi all, i am coding my first bot mostly as learning experience.
My first bot simply sell when the CCI cross below 100 level and buy when it crosses above -100.
The bot works and opens positions, the problem is that studying the backtesting the entry are not accurate.
Sometimes the cci never cross 100/-100 level and the bot opens a position, some other time is late few bars.
Maybe some of you know a solution to this.
I appreciate any help, Thanks
using cAlgo.API;
using cAlgo.API.Indicators;
namespace cAlgo.Robots
{
[Robot(AccessRights = AccessRights.None)]
public class CciBot : Robot
{
private CommodityChannelIndex _cci;
[Parameter(DefaultValue = 10000, MinValue = 0)]
public int Volume { get; set; }
[Parameter("Period", DefaultValue = 20)]
public int CciPeriod { get; set; }
[Parameter("Stop Loss", DefaultValue = 10.0)]
public double StopLoss { get; set; }
[Parameter("Take Profit", DefaultValue = 20.0)]
public double TakeProfit { get; set; }
[Parameter("Starting Lot", DefaultValue = 0.1, MinValue = 0.01, Step = 0.01)]
public double Lot { get; set; }
protected override void OnStart()
{
//Initialise CCi
_cci = Indicators.CommodityChannelIndex(CciPeriod);
}
protected override void OnBar()
{
var volumeInUnits = Symbol.QuantityToVolume(Lot);
if (Positions.Count != 0)
return;
if (_cci.Result.HasCrossedBelow(200, 1))
{
ExecuteMarketOrder(TradeType.Sell, Symbol, volumeInUnits, "buy", StopLoss, TakeProfit);
}
if (_cci.Result.HasCrossedAbove(-200, 1))
{
ExecuteMarketOrder(TradeType.Buy, Symbol, volumeInUnits, "sell", StopLoss, TakeProfit);
}
}
}

Fran_Petraroli
07 May 2015, 09:27
Sorry for the few mistakes in the code as i was testing different parameter, however the problem persist.
@Fran_Petraroli