Rajandran R Creator of OpenAlgo - OpenSource Algo Trading framework for Indian Traders. Telecom Engineer turned Full-time Derivative Trader. Mostly Trading Nifty, Banknifty, 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. Building Algo Platforms, Writing about Markets, Trading System Design, Market Sentiment, Trading Softwares & Trading Nuances since 2007 onwards. Author of Marketcalls.in

Code Snippets – Plot Buy and Sell Arrows in Amibroker

1 min read

AFL Tutorial: Beginners

An Amibroker AFL (AmiBroker Formula Language) script-based trading system typically includes four key trading conditions: Buy (to initiate a long position), Sell (to exit a long position), Short (to initiate a short position), and Cover (to exit a short position). In today’s tutorial, we will focus exclusively on how to illustrate a Buy Signal (usually represented by an upward arrow) and a Sell Signal (commonly represented by a downward arrow) using Amibroker

The following Example discusses plotting arrows with a 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 squares, Arrows, triangles, Circles, Digits, etc., to indicate the trading conditions visually over/below the candlesticks. However, the simple method is not preferred instead one can try plotting Block Arrows for a 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 Creator of OpenAlgo - OpenSource Algo Trading framework for Indian Traders. Telecom Engineer turned Full-time Derivative Trader. Mostly Trading Nifty, Banknifty, 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. Building Algo Platforms, Writing about Markets, Trading System Design, Market Sentiment, Trading Softwares & Trading Nuances since 2007 onwards. Author of Marketcalls.in

Line Trading – OpenAlgo Automation Module for Amibroker Users

The line Trading Automation tool is designed for Manual traders who want to perform level-based trade execution faster and also bring some advanced trade...
Rajandran R
55 sec read

Mini Certification Course on Algorithmic Trading

Welcome to the Mini Certification on Algorithmic Trading using Amibroker and OpenAlgo! This comprehensive 4-part series is designed to equip you with the knowledge...
Rajandran R
1 min read

Pivot Reversal Strategy – Tradingview Pinescript to Amibroker AFL…

Pivot Reversal Strategy is a popular in-built strategy in Tradingview Platform. Here I had attempted to convert the pinescript v5 to Amibroker AFL Code....
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