How to Identify Trend using Algo?, How to Identify current trend automatically using afl script?
There is a famous saying in trading “Trend is always friend”. So when you identify a major trend, than you will get huge profit.
In that sense, creating an AFL for identifying trend in the charts is extremely critical. Amibroker AFL for trend identification play a vital role in any algo trading system. If you are a trader than Trend AFL absolutely save analysis time.
Today we focus on Trend Identification AFL which identifies the trend using exponential moving average(EMA) and MACD .
What this AFL will do.
This AFL will identify the trend in the chart and will color the candle accordingly for easy identification of trend while trading.
If the candle is painted in :
Red , it indicates stock is in Downtrend
Green, it indicates stock is in Uptrend
Yellow it indicates stock is in consolidation and we need to trade with Caution
This is a simple way to identify trend. We just follow the colors GREEN , RED and YELLOW . Its easy and better to watch the candle colors for trends instead of spooting it manually. This AFL is only an trend indicator and not a Trading System . But you can easily convert it into a full fledged trading system by adding few confirmation signals.
The chart shows that when candle color is Yellow than trend is side ways for sometimes. But when its show Green Candle than its going to uptrend. Reversely Red candle indicate to downtrend.
Moving to script:
Period = Optimize(“Period”, 17, 2, 200, 1);
EMACALC = EMA(C, Period);
First we are assigning the period for EMA and getting the EMA value in a variable. In this case, 17 EMA value is assigned to EMACALC
Now, we create 3 conditions
cond1 = Close > EMACALC AND MACD() > Signal();
cond2 = Close > EMACALC AND MACD() < Signal() OR Close < EMACALC AND MACD() > Signal();
cond3 = Close < EMACALC AND MACD() < Signal();
Cond1 – is true if candle closes above EMA value and MACD line is greater and above signal line.
Cond2 – is true if candle closes above EMA value and MACD line is below signal line or if candle closes below EMA value and MACD line is above signal line
Cond3 – is true if candle closes below EMA value and MACD line is lower and below signal line.
In the next 2 part of the script,
We are plotting the price chart and then we are assigning a title to the chart
Now we move to chart painting… We are assigning both trending conditions to 2 variables and then we select the chart type and data to be used. 64 here represent, candlestick charts
upbar = COND1;
downbar = COND3;
Graph0 = Close;
Graph0Style = 64;
barcolor = IIf( downbar, 4, IIf( upbar, 5, 42 ) );//number 4 = red, number 5 = green and number 42 = yellow;
Graph0BarColor = ValueWhen( barcolor != 0, barcolor );
Finally we are deciding on candle color, for upbar we are using 5, which is green color. For downbar, we are using 4, which is red color. For other candles, we will be using yellow color which is represented by number 42.
And lastly, we are plotting the EMA in the chart..
Plot(EMACALC, “EMACALC”, colorWhite, styleLine,0,0,0,0,2);
To know more, checkout:
https://youtu.be/PU08-D1fckc
Related
amibroker tutorial videos how to backtest a trading strategy? how to do algo trading in india? how to do algo trading in Zerodha? How to Identify Trend using Algo? how to learn algo trading? how to start with algo trading in india? how to use amibroker afl for algo trading? how to write algo trading scripts? Pine script tutorial videos step-by-step approach to start with algo-trading in India