Rajandran R Telecom Engineer turned Full-time Derivative Trader. Mostly Trading Nifty, Banknifty, USDINR and High Liquid Stock Derivatives. Trading the Markets Since 2006 onwards. Using Market Profile and Orderflow for more than a decade. Designed and published 100+ open source trading systems on various trading tools. Strongly believe that market understanding and robust trading frameworks are the key to the trading success. Writing about Markets, Trading System Design, Market Sentiment, Trading Softwares & Trading Nuances since 2007 onwards. Author of Marketcalls.in and Co-Creator of Algomojo (Algorithmic Trading Platform for DIY Traders)

Code Snippets – Plot Buy and Sell Arrows in Amibroker

1 min read

AFL Tutorial : Beginners

Amibroker AFL script based trading system generally consist of four trading conditions Buy(go long), Sell(Exit Long), Short(go short) and Cover(Exit Short). In todays tutorial we are going to concentrate only how to plot a Buy Signal(Generally we Up arrow is preferred) and Sell Signal(Generally Down Arrow is preferred) using Amibroker.

[wp_ad_camp_5]

 
The following Example discusses plotting arrows with simple EMA crossover trading system.

EMA Crossover with Simple Arrows

Buy and Sell Rules are defined as

EMA1 = EMA( C,20);
EMA2 = EMA( C,50);

/*Buy and Sell Condition */
Buy = Cross(EMA1,EMA2);
Sell = Cross(EMA2,EMA1);

This code snippet plots a plain vanilla simple Buy(Green) and Sell Arrows(Red) and this snippet should be pasted below the Buy and Sell Trading conditions in the AFL code.

Nifty Daily – Simple Arrows
Simple Arrows

/* Plot Buy and Sell Signal Arrows */
shape = Buy * shapeUpArrow + Sell * shapeDownArrow;
PlotShapes( shape, IIf( Buy, colorGreen, colorRed ), 0, IIf( Buy, Low, High ) );
GraphXSpace = 5;

The PlotShapes Functionality is generally used to plot shapes like Square,Arrows,Triangle,Circle,Digits etc., to indicate the trading conditions visually over/below the candlesticks. However the simple method is not preferred instead one can try with plotting Block Arrows for better user experience.

Download EMA Crossover Simple Arrows afl code

EMA Crossover with Block Arrows

The following code snippet plots a Block Arrows with Buy(Green) and Sell Arrows(Red) Signals and has better user experience when compared to simple arrow plots.

Nifty Daily – Block Arrows
Block Arrows

/* Plot Buy and Sell Signal Arrows */
PlotShapes(IIf(Buy, shapeSquare, shapeNone),colorGreen, 0, L, Offset=-40);
PlotShapes(IIf(Buy, shapeSquare, shapeNone),colorLime, 0,L, Offset=-50);                      
PlotShapes(IIf(Buy, shapeUpArrow, shapeNone),colorWhite, 0,L, Offset=-45); 
PlotShapes(IIf(Short, shapeSquare, shapeNone),colorRed, 0, H, Offset=40);
PlotShapes(IIf(Short, shapeSquare, shapeNone),colorOrange, 0,H, Offset=50);                      
PlotShapes(IIf(Short, shapeDownArrow, shapeNone),colorWhite, 0,H, Offset=-45);

PlotShapes(Sell * shapestar, colorBrightGreen, 0, High, 12);
PlotShapes(Cover * shapestar, colorRed, 0, Low, -12);

Download EMA Crossover Simple Arrows afl code

Rajandran R Telecom Engineer turned Full-time Derivative Trader. Mostly Trading Nifty, Banknifty, USDINR and High Liquid Stock Derivatives. Trading the Markets Since 2006 onwards. Using Market Profile and Orderflow for more than a decade. Designed and published 100+ open source trading systems on various trading tools. Strongly believe that market understanding and robust trading frameworks are the key to the trading success. Writing about Markets, Trading System Design, Market Sentiment, Trading Softwares & Trading Nuances since 2007 onwards. Author of Marketcalls.in and Co-Creator of Algomojo (Algorithmic Trading Platform for DIY Traders)

How to Perform Machine Learning Using Amibroker and Python

Amibroker is a powerful technical analysis and trading system development platform, used extensively by traders and analysts for developing and deploying trading strategies. Python,...
Rajandran R
5 min read

Preparing the Features Dataset using Amibroker Exploration – Machine…

There are various methods to prepare the feature dataset, which is a crucial input for a machine learning prediction model. One approach is to...
Rajandran R
1 min read

Dynamic Color Coding in Amibroker Profit Tables: A Visually…

Profit tables are a valuable tool for traders and investors to analyze the trading strategy performance of their investments over time. However, the traditional...
Rajandran R
3 min read

8 Replies to “Code Snippets – Plot Buy and Sell Arrows in…”

  1. Dear Sir

    if my Red Line Cuts the Green Line several times Than how can we stop the system to take Multiple Positions

  2. I have written some ‘if/else if’ condition depending on price, from which I am getting trend. I am assigning this trend to buy and sell signals. After that I am display buy/sell signal and it is displaying correctly.
    After ExRem these buy/sell signals are becoming zero. why ? Could please suggest me.

  3. I have already sent the same request by mail and Mr. Rajendran asked me the whole code snippet. I have already sent it to him.

  4. Hello Sir,

    I would like to plot a square or a rectangle on the chart to indicate the candlestick patterns. For ex: If a bullish Engulfing pattern is formed on the chart, I would like to high light the pattern i.e. both candles by drawing a square on that pattern. Is that possible, if yes, then how can I achieve that? please help me on that.

    Thanks
    Tej

Leave a Reply

Get Notifications, Alerts on Market Updates, Trading Tools, Automation & More