Only one trade per MA cross

Created at 25 Aug 2021, 15:08
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!
CT

ctid4633759

Joined 25.08.2021

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.


@ctid4633759
Replies

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