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)

Button Trading in Amibroker using AlgoAction Platform

1 min read

This tutorial demonstrates how to send orders from Amibroker to Algoaction using Simple GUI buttons. GUI buttons are newer functions in Amibroker 6.21 version onwards. This utilize this afl code requires Amibroker 6.21 version or higher and access to Algoaction + Tradejini arrow API.

Currently, Amibroker version 6.22 features preliminary support for native chart GUI (buttons and edits at the moment). Voice alerts are added to the code. Voice alerts automatically gets triggered whenever buy or sell button is pressed.

Button Trading in Amibroker – AFL Code

/*
Marketcalls Financial Services Pvt Ltd.
Created By : Rajandran R(Founder - Marketcalls.
Created on : 01 Dec 2018.
Website : www.marketcalls.in
*/

_SECTION_BEGIN("Button Trading - Algoaction");

//Notes
//This afl code works only on Amibroker 6.22 and higher version
//Requires Algoaction.in + Tradejini Arrow API to place orders from button
//Replace the API Key and API Secrety key with yours

Version(6.22);

user_apikey = ParamStr("user_apikey","xxxxxxxxxxxxxxxxxxx");
user_apisecrete = ParamStr("user_apisecret","yyyyyyyyyyyyyyyyyyyyyy");
stcode = ParamList("statergy CODE","S1|S2|S3|S4|S5|S6",0);
s_prdt_ali = ParamList("s_prdt_ali","NRML:NRML|BO:BO|CNC:CNC|CO:CO|MIS:MIS",0);
Tsym = ParamStr("Symbol","BANKNIFTY18DECFUT");
exch = ParamList("Exchange","NFO|NSE|BSE|CDS|MCX|NCDEX|BFO|MCXSXFO|MCXSX",0);
qty = Param("Quatity",40,0,50000,1);
Ret = ParamList("Ret","DAY|IOC",0);
prctyp = ParamList("prctyp","MKT|L|SL|SL-M",0);
TokenNo =ParamStr("TokenNo","12345");
Pcode = ParamList("Pcode","NRML|BO|CNC|CO|MIS",0);
AMO = ParamList("AMO","NO|YES",0);
placeordertype = ParamList("Place Order On","Realtime|CandleCompletion",0);



function Buyorder()
{
	
    algoaction=CreateStaticObject("Tradejini.Algo");
    a = algoaction.PlaceOrder(user_apikey,user_apisecrete,stcode,s_prdt_ali,Tsym,exch,"B",Ret,prctyp,qty,0,TokenNo,"NA",0,0,Pcode,AMO);
    Say( "Order Placed" ); 
}

function Sellorder()
{
    algoaction=CreateStaticObject("Tradejini.Algo");
    a = algoaction.PlaceOrder(user_apikey,user_apisecrete,stcode,s_prdt_ali,Tsym,exch,"S",Ret,prctyp,qty,0,TokenNo,"NA",0,0,Pcode,AMO);
    Say( "Order Placed" );
}

function GuiButtonTrigger( ButtonName, x, y, width, Height ) {
	/// @link http://forum.amibroker.com/t/guibuttons-for-everyone/1716/4
	/// by beaver & fxshrat
	/// version 1.1
	global IDset;
	local id, event, clickeven;
	
	if( typeof( IDset ) == "undefined" ) IDset = 0; 

	//_TRACEF( "IDset before: %g", IDset );	
	GuiButton( ButtonName, ++IDset, x, y, width, height, 7 ); 
	//_TRACEF( "IDset after: %g", IDset );
	result = 0;
	id = GuiGetEvent( 0, 0 );// receiving button id
	event = GuiGetEvent( 0, 1 );// receiving notifyflag
	clickevent = event == 1;
	BuyClicked = id == 1 && clickevent;
	SellClicked = id == 2 && clickevent;
	if( BuyClicked AND StaticVarGet(Name()+GetChartID()+"buyAlgo")==0 ) 
	{
		BuyOrder();
		result = 1;
		StaticVarSet(Name()+GetChartID()+"buyAlgo",1); 
	}
	else
	{
		StaticVarSet(Name()+GetChartID()+"buyAlgo",0);
	}
	if( SellClicked AND StaticVarGet(Name()+GetChartID()+"sellAlgo")==0 ) 
	{
		SellOrder();
		result = -1;
		StaticVarSet(Name()+GetChartID()+"sellAlgo",1); 
	}
	else
	{
		StaticVarSet(Name()+GetChartID()+"sellAlgo",0); 
	}
	return result;
	
}
	
	BuyTrigger = GuiButtonTrigger( "Buy "+qty+" Shares", 0, 50, 200, 30 );
	SellTrigger = GuiButtonTrigger( "Sell "+qty+" Shares", 200, 50, 200, 30 );
	GuiSetColors( 1, 3, 2, colorRed, colorBlack, colorRed, colorWhite, colorBlue, colorYellow, colorRed, colorBlack, colorYellow ); 

Title = "Trigger: " + WriteIf(BuyTrigger==1,"Buy Triggered",WriteIf(BuyTrigger==-1,"Sell Triggered","0"));

SetChartOptions(0 , chartShowArrows | chartShowDates);
Plot(Close,"Candle", colorDefault, styleCandle);

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

Stoploss, Multi Target, and Trailing Stoploss Module – Amibroker…

After Intraday V2.0 Amibroker Module - a readymade drag and drop module to convert any trading strategy into the intraday trading system with alerts,...
Rajandran R
6 min read

Line Trading – Algomojo 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
58 sec read

Plotting Day Wise Equity Curve using Amibroker

We know that Amibroker provides an equity curve for the whole strategy. Is there a way where we can build a simple Day Wise...
Rajandran R
1 min read

Leave a Reply

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