It takes trade even with wrong condition
11 May 2019, 11:28
Hi, Why in this case the bot takes trades even when the condition is wrong?
Thanks in advance for your help.
if (_smaTrend1.Result.LastValue < _smaTrend2.Result.LastValue)
{
if (!IsPositionOpenByType(TradeType.Sell))
{
OpenPosition(TradeType.Sell);
}
}
ClosePosition(TradeType.Buy);
}
private void OpenPosition(TradeType type)
{
// calculate volume from lot size.
long volume = Symbol.QuantityToVolume(LotSize);
// open a new position
ExecuteMarketOrder(type, this.Symbol, volume, InstanceName, StopLoss, TakeProfit);
}
private void ClosePosition(TradeType type)
{
var p = Positions.Find(InstanceName, this.Symbol, type);
if (p != null)
{
ClosePosition(p);
}
}
private bool IsPositionOpenByType(TradeType type)
{
var p = Positions.FindAll(InstanceName, Symbol, type);
if (p.Count() >= 1)
{
return true;
}
return false;
}
#endregion
}
}
Replies
pierrecrot
13 May 2019, 09:16
Hi,
I'd like the robot to take position when the SMA Trend1 is lower than the SMA Trend2. Now it takes also position when Trend1 is higher than Trend2.
Thanks.
@pierrecrot
PanagiotisCharalampous
13 May 2019, 10:10
Hi pierrecrot,
Can you provide the full cBot code, cBot parameters and backtesting dates so that we can reproduce this and provide an explanation?
Best Regards,
Panagiotis
@PanagiotisCharalampous

erisoftdevelop
13 May 2019, 01:43
What do you expect to do the robot...
What is the error clearly a good description?
@erisoftdevelop