Robot not running
Robot not running
09 Jun 2022, 21:13
Hello
I wrote this code in version (4.2.10) of C Trader and it worked well, but when it works on version (4.1) that my broker has and my real account is in it , it does not work
please guide me
And If the problem is because the update version has arrived, will there be the same problem for the next time the new update comes?
I apologize for the poor English I know
thank you
.
.
using cAlgo.API;
using cAlgo.API.Indicators;
using cAlgo.API.Internals;
namespace cAlgo.RobotsKO
{
[Robot(TimeZone = TimeZones.UTC, AccessRights = AccessRights.None)]
public class FractalsSample37 : Robot
{
private double _volumeInUnits;
private Fractals _fractals;
[Parameter("Source")]
private DataSeries SourceSeries { get; set; }
[Parameter("Max Spread", DefaultValue = 2, MinValue = 0, MaxValue = 300)]
public double MaxSpread { get; set; }
[Parameter("Volume (Lots)", DefaultValue = 0.01)]
public double VolumeInLots { get; set; }
[Parameter("Stop Loss (Pips)", DefaultValue = 20)]
private double StopLossInPips { get; set; }
[Parameter("Take Profit (Pips)", DefaultValue = 60)]
private double TakeProfitInPips { get; set; }
[Parameter("Label", DefaultValue = "Sample")]
public string Label { get; set; }
private RelativeStrengthIndex _rsi;
private ExponentialMovingAverage _ema17rsi;
public Position[] BotPositions
{
get { return Positions.FindAll(Label); }
}
protected override void OnStart()
{
_volumeInUnits = Symbol.QuantityToVolumeInUnits(VolumeInLots);
_fractals = Indicators.Fractals(5);
_rsi = Indicators.RelativeStrengthIndex(SourceSeries, 14);
_ema17rsi = Indicators.ExponentialMovingAverage(_rsi.Result, 14);
}
protected override void OnBar()
{
var cBotPositions = Positions.FindAll(Label);
///////////////////////////////////////////////////////////////////////////////////////////
if (_fractals.UpFractal.LastValue < Bars.ClosePrices.Last(1))
{
ClosePositions(TradeType.Sell);
if (cBotPositions.Length == 0 && (_ema17rsi.Result.LastValue < (_rsi.Result.LastValue)) && Symbol.Spread < MaxSpread * Symbol.PipSize)
{
ExecuteMarketOrder(TradeType.Buy, SymbolName, _volumeInUnits, Label, StopLossInPips, TakeProfitInPips);
}
}
else if (_fractals.DownFractal.LastValue > Bars.ClosePrices.Last(1))
{
ClosePositions(TradeType.Buy);
if (cBotPositions.Length == 0 && _ema17rsi.Result.LastValue > (_rsi.Result.LastValue) && Symbol.Spread < MaxSpread * Symbol.PipSize)
{
ExecuteMarketOrder(TradeType.Sell, SymbolName, _volumeInUnits, Label, StopLossInPips, TakeProfitInPips);
}
}
}
private void ClosePositions(TradeType tradeType)
{
foreach (var position in BotPositions)
{
ClosePosition(position);
}
}
//////////////////////////////////////////////////////////////////////////////////////////////////////
}
}
amusleh
10 Jun 2022, 09:46
Hi,
It doesn't work on version 4.1 because your source parameter is private not public, all parameter must be public on a cBot or indicator.
Try this:
@amusleh