Crossing EMAs

Created at 07 May 2018, 02:15
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!
ZA

zamoramartell

Joined 07.05.2018

Crossing EMAs
07 May 2018, 02:15


Hi, I have problems with the following code, I need the cbot not to execute operations when a fast EMA goes against the long-term EMA, but I dont get it. I need for example, when the fast EMA crosses up the long-term EMA, purchase orders are executed whenever the fast EMA continues to rise, but when it starts to decrease, stop putting operations until it crosses back to the long-term EMA and  reverse the direction of operations
if (EmaFast.Result.Last(0) < EmaSlow.Result.Last(0) && EmaFast.Result.Last(0) < EmaFast.Result.Last(1))
            {
                Buy = false;
                Sell = true;
            }
            else if (EmaFast.Result.Last(0) > EmaSlow.Result.Last(0) && EmaFast.Result.Last(0) > EmaFast.Result.Last(1))
            {
                Buy = true;
                Sell = false;
            }

            else
            {
                Buy = false;
                Sell = false;
            }

 


@zamoramartell