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

5 Paisa Webhook – Amibroker Button Trading Module

3 min read

In this tutorial, we will be using 5 Paisa Webhooks to Send Orders using the Amibroker Button Trading Module. This Button trading module provides 4 modes of the button to place orders with a single click directly from Amibroker using simple order controls.

Limitation: Currently 5 Paisa Supports Tradingview Webhook-based automation only for Equity Symbols and in the future this could change based on the demand from the 5Paisa users. And in case if you are planning to automate investment ideas then you have to submit Demat Debit and Pledge Instructions to the broker to sell stocks from holdings without entering CDSL OTP or T-PIN-based e-DIS process.

Four Button Types

BE – Buy Entry Button – Enter longs for the selected quantity
BX – Buy Exit Button – Exit Long Positions
SE – Short Entry Button – Enter Shorts for the selected quantity
SX – Short Exit Button – Exit Short Positions

Steps to Set Up Automated Trading with 5Paisa and Webhook

Below is an overview of how to set up automated trading using 5paisa through the webhook.

Login to your 5paisa account
Tap on FnO 360 icon in the upper right corner
Click on the profile section in the upper right corner
Click on Webhook. Now Generate the Webhook with suitable expiry and Click Generate the JSON object.

Configure the Webhook URL in the Button Trading Module

Copy the webhook URL and now goto the Amibroker button trading module, open the parameter window, and enter the webhook URL as shown below.

Button Trading Amibroker AFL Code


/*
5 Paisa - Button Trading Module using 5 Paisa Webhook
Coded by - Rajandran R (Founder - Marketcalls) 
Created on : 24 Jan 2024.
Website : www.marketcalls.in
*/


_SECTION_BEGIN("5Paisa Order - Controls");

RequestTimedRefresh(1, False); 


strategy = ParamStr("Strategy Name", "Ami Strategy");
orderType = "MKT";
exchange = "NSE";
Symbol = ParamStr("Trading Symbol","RELIANCE");
productType = ParamList("ProductType","D|I");
quantity = Param("Quantity",1,1,10000,1);


VoiceAlert = ParamList("Voice Alert","Disable|Enable",1);
EnableAlgo = ParamList("AlgoStatus","Disable|Enable",0);
webhookurl = ParamStr("Webhook Url","xxxxx");  //Get the webhook url from 5 paisa


EnableScript("vbscript");

<%
Public Sub placeOrder(transactionType, quantity)

    ' Create a new instance of the XMLHTTP object
    Dim objHTTP
    Set objHTTP = CreateObject("MSXML2.ServerXMLHTTP")

    ' Specify the Webhook URL for 5Paisa
    Dim url
    url = AFL.Var("webhookurl")
    
    exchange = AFL.Var("exchange")
	symbol = AFL.Var("symbol")
	productType = AFL.Var("productType")
	
   

    ' Prepare the data in the format required by 5Paisa
    Dim jsonData
    jsonData = "{" & _
        """transactionType"":""" & transactionType & """," & _
        """orderType"":""MKT""," & _
        """quantity"":" & quantity & "," & _
        """price"":""0""," & _
        """exchange"":""" & exchange & """," & _
        """Symbol"":""" & symbol & """," & _
        """productType"":""" & productType & """" & _
        "}"

    ' Open the HTTP request
    objHTTP.Open "POST", url, False

    ' Set the necessary request headers (may need to add authentication headers for 5Paisa)
    objHTTP.setRequestHeader "Content-Type", "application/json"

    ' Send the request with the data
    objHTTP.Send jsonData
    
    'MsgBox "JSON Data to be sent: " & vbCrLf & jsonData

    

End Sub
%>


bo_5paisa = GetScriptObject();



//Static Variables for Order protection

static_name_ = Name()+GetChartID()+interval(2)+strategy;
static_name_algo = Name()+GetChartID()+interval(2)+strategy+"algostatus";



//Algomojo Dashboard

GfxSelectFont( "BOOK ANTIQUA", 14, 100 );
GfxSetBkMode( 1 );
if(EnableAlgo == "Enable")
{
AlgoStatus = "Algo Enabled";
GfxSetTextColor( colorGreen ); 
GfxTextOut( "Algostatus : "+AlgoStatus , 20, 40); 
if(Nz(StaticVarGet(static_name_algo),0)!=1)
{
_TRACE("Algo Status : Enabled");
StaticVarSet(static_name_algo, 1);
}
}
if(EnableAlgo == "Disable")
{
AlgoStatus = "Algo Disabled";
GfxSetTextColor( colorRed ); 
GfxTextOut( "Algostatus : "+AlgoStatus , 20, 40); 
if(Nz(StaticVarGet(static_name_algo),0)!=0)
{
_TRACE("Algo Status : Disabled");
StaticVarSet(static_name_algo, 0);
}
}



_SECTION_END();




_SECTION_BEGIN("Button Trading Module - 5Paisa For Old Amibroker Versions");

X0 = 20;
Y0 = 100;
X1 = 60;

LBClick = GetCursorMouseButtons() == 9;	// Click
MouseX  = Nz(GetCursorXPosition(1));		// 
MouseY  = Nz(GetCursorYPosition(1));		//

procedure DrawButton (Text, x1, y1, x2, y2, colorFrom, colorTo)
{
	GfxSetOverlayMode(0);
	GfxSelectFont("Verdana", 9, 700);
	GfxSetBkMode(1);
	GfxGradientRect(x1, y1, x2, y2, colorFrom, colorTo);
	GfxDrawText(Text, x1, y1, x2, y2, 32|1|4|16);
}
GfxSetTextColor(colorWhite);

resp = "";

if(EnableAlgo == "Enable")
{  

	DrawButton("BE", X0, Y0, X0+X1, Y0+50, colorGreen, colorGreen);
	CursorInBEButton = MouseX >= X0 AND MouseX <= X0+X1 AND MouseY >= Y0 AND MouseY <= Y0+50;
	BEButtonClick = CursorInBEButton AND LBClick;
	
	DrawButton("BX", X0+65, Y0, X0+X1+65, Y0+50, colorRed, colorRed);
	CursorInBXButton = MouseX >= X0+65 AND MouseX <= X0+X1+65 AND MouseY >= Y0 AND MouseY <= Y0+50;
	BxButtonClick = CursorInBXButton AND LBClick;
	
	DrawButton("SE", X0, Y0+55, X0+X1, Y0+105, colorRed, colorRed);
	CursorInSEButton = MouseX >= X0 AND MouseX <= X0+X1 AND MouseY >= Y0+55 AND MouseY <= Y0+105;
	SEButtonClick = CursorInSEButton AND LBClick;
	
	DrawButton("SX", X0+65, Y0+55, X0+X1+65, Y0+105, colorGreen, colorGreen);
	CursorInSXButton = MouseX >= X0+65 AND MouseX <= X0+X1+65 AND MouseY >= Y0+55 AND MouseY <= Y0+105;
	SXButtonClick = CursorInSXButton AND LBClick;
	
	if( BEButtonClick AND StaticVarGet(static_name_+"BEAlgo")==0 ) 
	{
		bo_5paisa.placeOrder("Buy", quantity);
        if(VoiceAlert == "Enable"){
				Say("Buy Order Triggered");  	
			}
		StaticVarSet(static_name_+"BEAlgo",1); 
	}
	else
	{
		StaticVarSet(static_name_+"BEAlgo",0);
	}
	if( BXButtonClick AND StaticVarGet(static_name_+"BXAlgo")==0 ) 
	{
		bo_5paisa.placeOrder("Sell", quantity);
        if(VoiceAlert == "Enable"){
				Say("Sell Order Triggered");  	
			}
		
		StaticVarSet(static_name_+"BXAlgo",1); 
	}
	else
	{
		StaticVarSet(static_name_+"BXAlgo",0);
	}
		
	if( SEButtonClick AND StaticVarGet(static_name_+"SEAlgo")==0 ) 
	{
		bo_5paisa.placeOrder("Sell", quantity);
        if(VoiceAlert == "Enable"){
				Say("Short Order Triggered");  	
			}
		StaticVarSet(static_name_+"SEAlgo",1); 
	}
	else
	{
		StaticVarSet(static_name_+"SEAlgo",0);
	}

	if( SXButtonClick AND StaticVarGet(static_name_+"SXAlgo")==0 ) 
	{
		bo_5paisa.placeOrder("Buy", quantity);
        if(VoiceAlert == "Enable"){
				Say("Cover Order Triggered");  	
			}
		StaticVarSet(static_name_+"SXAlgo",1); 
	}
	else
	{
		StaticVarSet(static_name_+"SXAlgo",0); 
	}
}

_SECTION_END();


_SECTION_BEGIN("Candlestick Charts with Date & Time Axis");

//Enable the Date & Time Axis
SetChartOptions(0, chartShowArrows | chartShowDates);

//Plotting Candlestick charts
Plot(Close,"Candle",colorDefault,styleCandle);


_SECTION_END();

Trade Execution

Once configured, Amibroker will send automated orders to 5 Paisa based on the click on of the button.

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

Leave a Reply

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