Only one trade per MA cross
Created at 25 Aug 2021, 15:08
CT
Only one trade per MA cross
25 Aug 2021, 15:08
Hi, I want to create a condition where a bot is only allowed one trade per moving average cross.
So far I have:
_MA_Cross = _FastMA.Result.Last(1) > _SlowMA.Result.Last(1) ? true : false;
if (posBuy == null && _MA_Cross && !_dir)
{
ExecuteMarketOrder(TradeType.Buy, SymbolName, 10000, _label, _SL_Para, _TP_Para);
_dir = true;
}
if (posSell == null && !_MA_Cross && _dir)
{
ExecuteMarketOrder(TradeType.Sell, SymbolName, 10000, _label, _SL_Para, _TP_Para);
_dir = false;
}
What I have implemented does not work the way I want, any tips?
Thanks.
amusleh
25 Aug 2021, 15:48
Hi,
Our example on API documentation does exactly that, please check: cAlgo API Reference - SimpleMovingAverage Interface (ctrader.com)
There are other examples for other moving average types and indicators, please check.
@amusleh