拉贾德兰R 市场电话的创始人和联合创始人Algomojo。全职衍生品交易员。交易系统设计专家(Amibroker,Ninjatrader,Metatrader,Python,Pinescript)。自2006年以来进行市场交易。指导交易者进行交易系统设计,市场概况,订单流和交易自动化。

使用AlgoMojo平台在Amibroker中进行按钮交易(支持较新和较旧的Amibroker版本)

5分钟阅读

本教程演示如何将订单从Amibroker发送到 Algomojo 使用现代amibroker工具使用简单的GUI按钮,以及使用低于Amibroker 6.22的较旧版本的Amibroker。

使用Amibroker 6.22版本或更高版本的按钮交易

GUI按钮是Amibroker 6.22版及更高版本中的较新功能。此AFL代码要求使用Amibroker 6.22版本或更高版本,并可以通过Algomojo Partner Broker访问Algomojo API +交易帐户

阿米经纪人 6.22版本或更高版本的Amibroker AFL代码

/*
Created By : 拉贾德兰R (Founder - 市场电话/ Co-Founder Algomojo )
Created on : 01 Oct 2020.
Website : www.marketcalls.in / www.algomojo.com
*/

_SECTION_BEGIN("Button Trading - Algomojo");

//Notes
//This afl code works only on 阿米经纪人 6.22 and higher version
//Requires Algomojo API to place orders from button
//Replace the API Key and API Secrety key with yours

Version(6.22);

RequestTimedRefresh(1, False); // Send orders even if 阿米经纪人 is minimized or Chart is not active

user_apikey = ParamStr("user_apikey","xxxxxxxxxxxxxxxxxxxxxxxxxxxxx"); //Enter your API key here
api_secretkey = ParamStr("api_secretkey","xxxxxxxxxxxxxxxxxxxxxxxxxxxxx"); //Enter your API secret key here
s_prdt_ali = ParamList("product alias","BO:BO|CNC:CNC|CO:CO|MIS:MIS|NRML:NRML",3); //Product Alias
Tsym = ParamStr("Trading Symbol","RELIANCE-EQ"); //Symbol Name
exch = ParamList("Exchange","NFO|NSE|BSE|CDS|MCX|NCDEX|BFO|MCXSXFO|MCXSX",1); //Exchange
Ret = ParamList("Ret","DAY|IOC",0); //Retention
prctyp = ParamList("prctyp","MKT|L|SL|SL-M",0); // Pricetype
Pcode = ParamList("Product code","NRML|BO|CNC|CO|MIS",4); // Product Code
qty = Param("Quantity",40,0,100000,1); // Quantity
AMO = ParamList("AMO Order","NO|YES",0); //AMO Order
placeordertype = ParamList("Place Order On","Realtime|CandleCompletion",0); // Place Order Type
EnableAlgo = ParamList("Algo Mode","Disable|Enable|LongOnly|ShortOnly",0); // Algo Mode
stgy_name = ParamStr("Strategy Name","Test Strategy Chart"); // Strategy Name

static_name_ = Name()+GetChartID()+interval(2)+stgy_name;
static_name_algo = Name()+GetChartID()+interval(2)+stgy_name+"algostatus";
//StaticVarSet(static_name_algo, -1); 
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);
}
}
if(EnableAlgo == "LongOnly")
{
AlgoStatus = "Long Only";
GfxSetTextColor( colorYellow ); 
GfxTextOut( "Algostatus : "+AlgoStatus , 20, 40); 
if(Nz(StaticVarGet(static_name_algo),0)!=2)
{
_TRACE("Algo Status : Long Only");
StaticVarSet(static_name_algo, 2);
}
}
if(EnableAlgo == "ShortOnly")
{
AlgoStatus = "Short Only";
GfxSetTextColor( colorYellow ); 
GfxTextOut( "Algostatus : "+AlgoStatus , 20, 40); 
if(Nz(StaticVarGet(static_name_algo),0)!=3)
{
_TRACE("Algo Status : Short Only");
StaticVarSet(static_name_algo, 3);
}
}



resp = "";




function Buyorder()
{
	
    algomojo=CreateObject("XLAMIBRIDGE.Main");
    api_data ="{\"stgy_name\":\""+stgy_name+"\",\"s_prdt_ali\":\""+s_prdt_ali+"\",\"Tsym\":\""+Tsym+"\",\"exch\":\""+exch+"\",\"Ttranstype\":\""+"B"+"\",\"Ret\":\""+Ret+"\",\"prctyp\":\""+prctyp+"\",\"qty\":\""+qty+"\",\"discqty\":\""+"0"+"\",\"MktPro\":\""+"NA"+"\",\"Price\":\""+"0"+"\",\"TrigPrice\":\""+"0"+"\",\"Pcode\":\""+Pcode+"\",\"AMO\":\""+AMO+"\"}";
    resp=algomojo.AMDispatcher(user_apikey, api_secretkey,"PlaceOrder",api_data);
    StaticVarSet(static_name_+"buyCoverAlgo",1); //Algo Order was triggered, no more order on this bar
    _TRACE("Strategy : "+ stgy_name +"AlgoStatus : "+ EnableAlgo +"Chart Symbol : "+ Name() +"  Trading Symbol : "+  Tsym +"  Quantity : "+ qty*2 +"  Signal : Buy and Cover Signal  TimeFrame : "+ Interval(2)+"  Response : "+ resp +"  ChardId : "+ GetChartID() + " Latest Price : "+LastValue(C));
	Say( "Order Placed" ); 
}

function Sellorder()
{
    algomojo=CreateObject("XLAMIBRIDGE.Main");
    api_data ="{\"stgy_name\":\""+stgy_name+"\",\"s_prdt_ali\":\""+s_prdt_ali+"\",\"Tsym\":\""+Tsym+"\",\"exch\":\""+exch+"\",\"Ttranstype\":\""+"S"+"\",\"Ret\":\""+Ret+"\",\"prctyp\":\""+prctyp+"\",\"qty\":\""+qty+"\",\"discqty\":\""+"0"+"\",\"MktPro\":\""+"NA"+"\",\"Price\":\""+"0"+"\",\"TrigPrice\":\""+"0"+"\",\"Pcode\":\""+Pcode+"\",\"AMO\":\""+AMO+"\"}";
    resp=algomojo.AMDispatcher(user_apikey, api_secretkey,"PlaceOrder",api_data);
    StaticVarSet(static_name_+"sellAlgo",1); //Algo Order was triggered, no more order on this bar
    _TRACE("Strategy : "+ stgy_name +"AlgoStatus : "+ EnableAlgo +"Chart Symbol : "+ Name() +"  Trading Symbol : "+  Tsym +"  Quantity : "+ qty +"  Signal : Sell Signal  TimeFrame : "+ Interval(2)+"  Response : "+ resp +"  ChardId : "+ GetChartID() + " Latest Price : "+LastValue(C));
            
    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+" 分享s", 0, 100, 200, 30 );
	SellTrigger = GuiButtonTrigger( "Sell "+qty+" 分享s", 200, 100, 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();

低于Amibroker v6.22的旧版本的Button Trading AFL模块

/*
Created By : 拉贾德兰R(Founder - 市场电话/ Co-Founder Algomojo )
Created on : 01 Oct 2020.
Website : www.marketcalls.in / www.algomojo.com
*/

_SECTION_BEGIN("Button Trading - Algomojo For Old 阿米经纪人 Versions");

//Notes
//This afl code works only on 阿米经纪人 6.22 and higher version
//Requires Algomojo API to place orders from button
//Replace the API Key and API Secret key with yours

Title = " ";


RequestTimedRefresh(1, False); // Send orders even if 阿米经纪人 is minimized or Chart is not active

user_apikey = ParamStr("user_apikey","xxxxxxxxxxxxxxxxxxxxxxxxxxxxx"); //Enter your API key here
api_secretkey = ParamStr("api_secretkey","xxxxxxxxxxxxxxxxxxxxxxxxxxxxx"); //Enter your API secret key here
s_prdt_ali = ParamList("product alias","BO:BO|CNC:CNC|CO:CO|MIS:MIS|NRML:NRML",3); //Product Alias
Tsym = ParamStr("Trading Symbol","RELIANCE-EQ"); //Symbol Name
exch = ParamList("Exchange","NFO|NSE|BSE|CDS|MCX|NCDEX|BFO|MCXSXFO|MCXSX",1); //Exchange
Ret = ParamList("Ret","DAY|IOC",0); //Retention
prctyp = ParamList("prctyp","MKT|L|SL|SL-M",0); // Pricetype
Pcode = ParamList("Product code","NRML|BO|CNC|CO|MIS",4); // Product Code
qty = Param("Quantity",40,0,100000,1); // Quantity
AMO = ParamList("AMO Order","NO|YES",0); //AMO Order
placeordertype = ParamList("Place Order On","Realtime|CandleCompletion",0); // Place Order Type
EnableAlgo = ParamList("Algo Mode","Disable|Enable|LongOnly|ShortOnly",0); // Algo Mode
stgy_name = ParamStr("Strategy Name","Test Strategy Chart"); // Strategy Name

static_name_ = Name()+GetChartID()+interval(2)+stgy_name;
static_name_algo = Name()+GetChartID()+interval(2)+stgy_name+"algostatus";
//StaticVarSet(static_name_algo, -1); 
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);
}
}
if(EnableAlgo == "LongOnly")
{
AlgoStatus = "Long Only";
GfxSetTextColor( colorYellow ); 
GfxTextOut( "Algostatus : "+AlgoStatus , 20, 40); 
if(Nz(StaticVarGet(static_name_algo),0)!=2)
{
_TRACE("Algo Status : Long Only");
StaticVarSet(static_name_algo, 2);
}
}
if(EnableAlgo == "ShortOnly")
{
AlgoStatus = "Short Only";
GfxSetTextColor( colorYellow ); 
GfxTextOut( "Algostatus : "+AlgoStatus , 20, 40); 
if(Nz(StaticVarGet(static_name_algo),0)!=3)
{
_TRACE("Algo Status : Short Only");
StaticVarSet(static_name_algo, 3);
}
}



resp = "";




function Buyorder()
{
	
    algomojo=CreateObject("XLAMIBRIDGE.Main");
    api_data ="{\"stgy_name\":\""+stgy_name+"\",\"s_prdt_ali\":\""+s_prdt_ali+"\",\"Tsym\":\""+Tsym+"\",\"exch\":\""+exch+"\",\"Ttranstype\":\""+"B"+"\",\"Ret\":\""+Ret+"\",\"prctyp\":\""+prctyp+"\",\"qty\":\""+qty+"\",\"discqty\":\""+"0"+"\",\"MktPro\":\""+"NA"+"\",\"Price\":\""+"0"+"\",\"TrigPrice\":\""+"0"+"\",\"Pcode\":\""+Pcode+"\",\"AMO\":\""+AMO+"\"}";
    resp=algomojo.AMDispatcher(user_apikey, api_secretkey,"PlaceOrder",api_data);
    StaticVarSet(static_name_+"buyCoverAlgo",1); //Algo Order was triggered, no more order on this bar
    _TRACE("Strategy : "+ stgy_name +"AlgoStatus : "+ EnableAlgo +"Chart Symbol : "+ Name() +"  Trading Symbol : "+  Tsym +"  Quantity : "+ qty*2 +"  Signal : Buy and Cover Signal  TimeFrame : "+ Interval(2)+"  Response : "+ resp +"  ChardId : "+ GetChartID() + " Latest Price : "+LastValue(C));
	Say( "Order Placed" ); 
}

function Sellorder()
{
    algomojo=CreateObject("XLAMIBRIDGE.Main");
    api_data ="{\"stgy_name\":\""+stgy_name+"\",\"s_prdt_ali\":\""+s_prdt_ali+"\",\"Tsym\":\""+Tsym+"\",\"exch\":\""+exch+"\",\"Ttranstype\":\""+"S"+"\",\"Ret\":\""+Ret+"\",\"prctyp\":\""+prctyp+"\",\"qty\":\""+qty+"\",\"discqty\":\""+"0"+"\",\"MktPro\":\""+"NA"+"\",\"Price\":\""+"0"+"\",\"TrigPrice\":\""+"0"+"\",\"Pcode\":\""+Pcode+"\",\"AMO\":\""+AMO+"\"}";
    resp=algomojo.AMDispatcher(user_apikey, api_secretkey,"PlaceOrder",api_data);
    StaticVarSet(static_name_+"sellAlgo",1); //Algo Order was triggered, no more order on this bar
    _TRACE("Strategy : "+ stgy_name +"AlgoStatus : "+ EnableAlgo +"Chart Symbol : "+ Name() +"  Trading Symbol : "+  Tsym +"  Quantity : "+ qty +"  Signal : Sell Signal  TimeFrame : "+ Interval(2)+"  Response : "+ resp +"  ChardId : "+ GetChartID() + " Latest Price : "+LastValue(C));
            
    Say( "Order Placed" );
}


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

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

if(EnableAlgo == "Enable")
{

	DrawButton("Buy", X0, Y0, X0+X1, Y0+30, colorGreen, colorGreen);
	CursorInBuyButton = MouseX >= X0 AND MouseX <= X0+X1 AND MouseY >= Y0 AND MouseY <= Y0+30;
	BuyButtonClick = CursorInBuyButton AND LBClick;
	
	DrawButton("Sell", X0, Y0+40, X0+X1, Y0+70, colorRed, colorRed);
	CursorInSellButton = MouseX >= X0 AND MouseX <= X0+X1 AND MouseY >= Y0+40 AND MouseY <= Y0+70;
	SellButtonClick = CursorInSellButton AND LBClick;
	
	if( BuyButtonClick AND StaticVarGet(Name()+GetChartID()+"buyAlgo")==0 ) 
	{
		BuyOrder();
		StaticVarSet(Name()+GetChartID()+"buyAlgo",1); 
	}
	else
	{
		StaticVarSet(Name()+GetChartID()+"buyAlgo",0);
	}
	if( SellButtonClick AND StaticVarGet(Name()+GetChartID()+"sellAlgo")==0 ) 
	{
		SellOrder();
		StaticVarSet(Name()+GetChartID()+"sellAlgo",1); 
	}
	else
	{
		StaticVarSet(Name()+GetChartID()+"sellAlgo",0); 
	}
	
	
	
	

}

_SECTION_END();

_SECTION_BEGIN("Price");
SetChartOptions(0,chartShowArrows|chartShowDates);
_N(Title = "");
Plot( C, "Close", ParamColor("Color", colorDefault ), styleNoTitle | ParamStyle("Style") | GetPriceStyle() ); 
_SECTION_END();


拉贾德兰R 市场电话的创始人和联合创始人Algomojo。全职衍生品交易员。交易系统设计专家(Amibroker,Ninjatrader,Metatrader,Python,Pinescript)。自2006年以来进行市场交易。指导交易者进行交易系统设计,市场概况,订单流和交易自动化。

[网络研讨会] Upstox用户的Algomojo平台简介

Algomojo是基于经纪人API的基于Web的自动交易平台,具有交易者为交易者构建的简约设计。
拉贾德兰R
读取25秒

Algomojo平台现已向Upstox用户开放

我们很荣幸能为Upstox用户提供我们的Algomojo访问权限。现在,Upstox的用户可以享受基于API的免费Algotrading访问。免费平台访问...
拉贾德兰R
5分钟阅读

如何使用Algomojo从Google SpreadSheets发送订单…

您可能会认为“真的有可能从Google表格发送自动订单吗?您疯了吗?”但是,感谢Google Appscript ...
拉贾德兰R
2分钟阅读

One 回复 to “使用AlgoMojo平台在Amibroker中进行按钮交易(支持更新…”

  1. 先生,请为目标,止损线开发afl,该目标可在图表上移动,例如风筝网,全局数据供稿afl

发表评论

获取通知,市场更新警报,交易工具,自动化等