# Code Snippets – Plot Buy and Sell Arrows in Amibroker

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.

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);

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

/* 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.

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

https://gist.github.com/816b61ebc2176055ea7163a56648eeaa

## What is QuantZilla?

Quantzilla is 75+ hours of code mentoring program designed for noncoders who want to learn the coding program right from designing indicators, scanners, trading...

## Things to Consider While Building a Bracket Order Execution…

Building a Bracket Order Strategy is the most demanded request we got from most of the algomojo traders. This article explains the list of...

## PlaceOrder – Multi Broker Exectuion Code Snippets for Amibroker

This tutorial explains how to build a button trading right from scratch and with a click of a button how you can send orders...

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

1. Udit says:

Dear Sir

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

1. Hi you can remove exrem function to avoid such issues. For Example

2. Vikrant Sood says:

Can you help me how to place star sign when target or stoploss hit

3. Ravi says:

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.

4. Ravi says:

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.

5. Anil Nayak says:

How can we put alertif function when the plotshape is trigger

6. Anil Nayak says:

How can we put alertif function when the plotshape is trigger