How to set-up Algo Trading for MA Candle Cross Strategy?

How to set-up Algo Trading for MA Candle Cross Strategy?

How to set-up Algo Trading for MA Candle Cross Strategy?

MA Candle Cross Strategy

In this episode, we will build a simple MA candle cross over strategy. Note: this is not a moving average crossover strategy but a MA Candle cross strategy. So we will just be using 1 moving average here.

Strategy:

We will go long or buy if,

If a green candle is formed in the chart by closing above MA and previous candle had closed below MA.

Reverse is true of Shorting

If a red candle is formed in the chart by closing below MA and previous candle had closed above MA

Moving on the script:

First, we are plotting the price candles.

And in the next set of lines, we are setting up a MA and then we are plotting the MA in the chart.

Then in the next set of code, we will be generating the open, high, low and close price of previous candles. This is to ensure that, a candle is crossing over the moving average. So first candle should be on or below the moving average and next candle should be above the MA. This is what we mean by MA candle cross. A candle should cross over the moving average.

Now comes the buy and sell signal setting.

We will go long or buy if,

If a green candle is formed in the chart by closing above MA and previous candle had closed below MA. To do this, we are checking 5 conditions.

1. Close of prev candle should be below MA
2. Close of current candle should be above MA
3. Open of current candle should be above MA
4. Open of current candle should be below close
5. High of previous candle should be below high of current candle

BUY=MA50 >= MCC1 && C > MA50 && O > MA50 && O < C && MCH1 < H;

Reverse is true for Shorting

If a red candle is formed in the chart by closing below MA and previous candle had closed above MA. To do this, we are checking 5 conditions.

1. Close of prev candle should be above MA
2. Close of current candle should be below MA
3. Open of current candle should be below MA
4. Open of current candle should be above close
5. Low of previous candle should be above Low of current candle

Sell = MA50 <= MCC1 && C < MA50 && O < MA50 && O > C && MCL1 > L;

Lastly we will plot the symbols for the different trading signals.

Now, let’s move to backtesting. We can run backtest of this strategy in multiple TFs.

For example, for the 5 min, long side trades, 45% returns with 24% drawdown

Check Out Script Library to get script used for this episode:

https://marketsecrets.in/script-library/

To know more, checkout:

https://youtu.be/utQMSrFT62c



 

Leave a Reply

Your email address will not be published. Required fields are marked *

error: Content is protected !!