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

为Algomojo平台建立托架订单执行策略时要考虑的事项

12分钟阅读

我们从大多数algomojo篮球竞彩员那里得到了最迫切的需求,即制定框架定单策略。本文介绍了构建基于托架定单的日内篮球竞彩策略时需要考虑的关键信息列表。

什么是括号顺序?

括号顺序 大部分是当日订单,包括立即目标和止损订单。也称为OCO(一个取消另一个)。意味着如果当前市场概况触及目标价位,则自动取消止损订单;如果触及止损价位,则目标订单将自动取消,

1)确保使用最新的Multi Broker Bridge

如果您要部署托架定货策略,请确保您使用的是Algomojo门户网站中的最新桥(多经纪人桥)。确保已配置正确的经纪人短代码和版本。

2)从Algomojo门户获取令牌ID

登录到 Algomojo门户->goto Watchlist ->单击符号信息,如详细信息所示,并获得令牌号

例如,代币的编号为2885。可将其用作您的篮球竞彩策略的输入。如果您的经纪人使用的是NEST API,则令牌ID是发送括号定单所必需的。

3)确保快速AFL已关闭

确保快速AFL已关闭,因为您可能会在图表上绘制目标和止损位。您可以使用setbarsrequired函数禁用快速afl,如下所示

SetBarsRequired(-2,-2); //diable quick AFL

4)获取输入参数

由于基于托架定单的执行属于纯盘中篮球竞彩策略,因此在从用户那里获取输入时,需要牢记以下几点。

1)获取目标和止损(推荐基于百分比的止损)
2)获取报价水平(因为止损水平和目标水平需要四舍五入到最接近的报价水平,同时将那些止损水平和目标水平发送到托架定单中)
3)使用基于时间的篮球竞彩为您的篮球竞彩进入和退出以及篮球竞彩时间。

//////////////////////////////////////////////////////////////////////
//                Trade Input Parameters          					//



//Exit Criteria
stops = Param("Stoploss %", 0.25,0,20,0.01);
target = Param("Target %", 0.5,0,20,0.01);
TickSz = Param("TickSize",0.05); //round off the stops and target to nearest tick size


sigstarttime = ParamTime("Sig Start Time", "10:00:00"); //no fresh position before signal start time
sigendtime = ParamTime("Sig End Time", "15:00:00"); //no fresh position after signal end time
sqofftime = ParamTime("Squareoff Time", "15:15:00");  //broker square off time

5)启用正确的日志

确保已启用_Trace日志以进行适当的故障排除,这将有助于篮球竞彩员发现新生成的代码中的错误(如果有)。绝对可以帮助篮球竞彩员建立更好的篮球竞彩系统

6)仅对进入条件进行编码 并计算目标和止损值

如果您要为托架订单编码,显然应该注意 进入逻辑条件 因为出口已经照顾好了 价格达到目标水平或止损水平。

如果只有多头条件,那么要确保卖出,补仓,空头以零初始化维持。

Sell = Short = Cover = 0;

如果策略同时包含多头和空头条件,则维持退出信号(卖出和掩盖为零)

Sell =  Cover = 0;

这是具有macd正转换策略的示例代码逻辑,其中仅对长条件进行编码。因此,只有买入逻辑被编码为标准可行买入,并且退出信号未分配给卖入逻辑。

//////////////////////////////////////////////////////////////////////
//            Configure your trading condition here					//

longtradingcondition = Cross(MACD(), Signal());


//////////////////////////////////////////////////////////////////////


//////////////////////////////////////////////////////////////////////
//            Trading Logic One Intraday Trade Per Day              //


Buy = longtradingcondition AND TimeNum() >= sigstarttime AND TimeNum() < sigendtime;
Buy = Buy AND Sum( Buy, BarsSince( newDay) +1 ) <= 1; //consider only the first signal for the day

entryprice = ValueWhen(Buy AND Sum( Buy, BarsSince( newDay) +1 )==1,Ref(Open,1));  //entry price at the next bar open and at the first signal
buystops1 = (100-stops)/100 * entryprice;
buytarget1 = (100+target)/100 * entryprice;


buystops = TickSz * round( buystops1 / TickSz );
buytarget = TickSz * round( buytarget1 / TickSz );


iSell = TimeNum() >= sqofftime OR Cross(High,buytarget) OR Cross(buystops,Low);

//Remove Excessive Signals
Buy = ExRem(Buy,iSell);
iSell = ExRem(iSell,Buy);


//Non Repainting  - Signals happens only after the close of the current
Buy = Ref(Buy,-1);
BuyPrice = Open;




iSellPrice = IIf(Cross(High,buytarget), buytarget, IIf( Cross(buystops,Low), buystops, Open));


buycontinue = Flip(Buy,iSell) OR isell; //look for continuation of trades

targethit = iSell AND Cross(High,buytarget);
stophit = iSell AND Cross(buystops,Low);
sqofftime = iSell AND TimeNum() >= sqofftime;


//This code place order only on Long Entry
Sell = Short = Cover = 0;


//////////////////////////////////////////////////////////////////////

7)绘制刻度线调整后的止损和目标

这有助于在盘中可视化目标和停止水平。

Plot(IIf(buycontinue,buystops,Null),"Stops",colorRed);
Plot(IIf(buycontinue,buytarget,Null),"Target",colorgreen);

8)绘制信号

绘制括号顺序的进入和退出信号

/* 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(iSell, shapeSquare, shapeNone),colorRed, 0, H, Offset=40);
PlotShapes(IIf(iSell, shapeSquare, shapeNone),colorOrange, 0,H, Offset=50);
PlotShapes(IIf(iSell, shapeDownArrow, shapeNone),colorWhite, 0,H, Offset=-45);

9)确保退出条件显示正确。

退出可能是由于以下原因

1)目标被击中
2)点击停止
3)达到方形关闭时间

下面的代码模块配置为显示带有该特定篮球竞彩的损益数据点的进场价和退出价值。

fntsize = 8;// font size
dist = 65;// y-offset

bi = Barindex();
fvb = FirstVisiblevalue( bi );
lvb = LastVisiblevalue( bi );

bkcolor = -1;// text background color, -1 means default color (transparent)

PlotTextSetFont( "", "ARIAL", fntsize, BarCount-1, 0, -1 );

pnl = ValueWhen(iSell,iSellPrice - entryprice);

for ( i = fvb; i <= lvb; i++ ) {
    if( Buy[i] || iSell[i] )	{
		buyvar = "\[email protected]" + BuyPrice[i];
		sellvar = "\[email protected]" + iSellPrice[i]+"\nPnl= "+pnl[i];
		if( Buy[i] )  PlotText( "Long Entry" + buyvar, i, L[i], colorGreen, bkcolor, -dist-2*fntsize );
		if( targethit[i] ) PlotText( "Target Hit" + sellvar, i, H[i], colorRed, bkcolor, dist+4.5*fntsize );
		if( stophit[i] ) PlotText( "Stop Hit" + sellvar, i, H[i], colorRed, bkcolor, dist+4.5*fntsize );
		if( sqofftime[i] ) PlotText( "SQoff.Time Hit" + sellvar, i, H[i], colorRed, bkcolor, dist+4.5*fntsize );
    }
}

10)托架订单执行模块

确保仅从用户那里获得相关信息,并根据您的策略确保所有其他参数均配置为默认值。

请参阅 Algomojo文档 有关PlaceBracketOrder API要传递的参数的更多详细信息

建议在绝对模式下使用括号定单目标和止损计算。如果您是高级用户,请使用“刻度”模式。

建议仅在调整到最接近的刻度大小后才发送目标和止损信息。其他括号定单在发送定单时可能会出错。

_SECTION_BEGIN("Algomojo Bracket Order Module");

uid = ParamStr("uid ID","TS2499"); //Enter your Trading Account Login ID
user_apikey = ParamStr("user_apikey","xxxxxxxxxxxxxxxxxxxxxx"); //Enter your API key here
api_secret = ParamStr("api_secret","xxxxxxxxxxxxxxxxxxxxxx"); //Enter your API secret key here
broker = ParamStr("Broker Code1","tj"); //Enter your Broker Short Code here
ver = ParamStr("version","1.0"); //Enter your API version here
s_prdt_ali = ParamList("s_prdt_ali","BO:BO|CNC:CNC|CO:CO|MIS:MIS|NRML:NRML",0); //Type of order
Tsym = ParamStr("Tsym","RELIANCE-EQ "); //Enter the symbol name here
exch = ParamList("Exchange","NFO|NSE|BSE|CDS|MCX|NCDEX|BFO|MCXSXFO|MCXSX",1); 
Ret = ParamList("Ret","DAY|IOC",0);
//Ttranstype = ParamList("Ttranstype","B|S",0);
prctyp = ParamList("prctyp","MKT|L|SL|SL-M",0);
Price = 0; //ParamList("Price","0");
qty = Param("Quatity",1,0,10000,1); 
discqty = "0"; //ParamList("discqty","0");
AMO = "NO"; //ParamList("AMO","NO|YES",0); //After market order
TokenNo = ParamStr("TokenNo","11184"); //Enter the token number of the symbol here. Check the Algomojo Watchlist symbol info to get the relevant symbol token no.
ltpOratp = "LTP"; //ParamList("ltpOratp","LTP|ATP",0);


 
SqrOffAbsOrticks = "Absolute";  //ParamList("SqrOffAbsOrticks","Absolute|Ticks",0); //If you select absolute then you can enter a decimal quantity. If you selected ticks you need to enter in multiples of ticks
SqrOffvalue = buytarget-entryprice; //ParamStr("SqrOffvalue","1"); 
SLAbsOrticks = "Absolute";   //ParamList("SLAbsOrticks","Absolute|Ticks",0);
SLvalue = entryprice-buystops ; //ParamStr("SLvalue","30");
trailingSL = "N"; //ParamList("trailingSL","Y|N",0); 
tSLticks = 1000; //ParamStr("tSLticks","100"); //Trailing SL value in ticks if user has opted to use trailingSL
placeordertype = "Realtime"; //ParamList("Place Order On","Realtime|CandleCompletion",0); // Place Order Type
EnableAlgo = ParamList("Algo Mode","Disable|Enable",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(placeordertype == "Realtime")
{
AlgoBuy = lastvalue(Ref(Buy,0));
AlgoSell = lastvalue(Ref(Sell,0));
AlgoShort = lastvalue(Ref(Short,0));
AlgoCover = lastvalue(Ref(Cover,0));
}

if(placeordertype == "CandleCompletion")
{
AlgoBuy = lastvalue(Ref(Buy,-1));
AlgoSell = lastvalue(Ref(Sell,-1));
AlgoShort = lastvalue(Ref(Short,-1));
AlgoCover = lastvalue(Ref(Cover,-1));
}


resp = "";

function bracketorder_buy(orderqty)
{
	algomojo=CreateObject("AMAMIBRIDGE.Main");
	api_data ="{\"stgy_name\":\""+stgy_name+"\",\"s_prdt_ali\":\""+s_prdt_ali+"\",\"TokenNo\":\""+TokenNo+"\",\"exch\":\""+exch+"\",\"Ttranstype\":\""+"B"+"\",\"Ret\":\""+Ret+"\",\"prctyp\":\""+prctyp+"\",\"qty\":\""+qty+"\",\"discqty\":\""+discqty+"\",\"Price\":\""+Price+"\",\"ltpOratp\":\""+ltpOratp+"\",\"SqrOffAbsOrticks\":\""+SqrOffAbsOrticks+"\",\"SqrOffvalue\":\""+SqrOffvalue+"\",\"SLAbsOrticks\":\""+SLAbsOrticks+"\",\"SLvalue\":\""+SLvalue+"\",\"trailingSL\":\""+trailingSL+"\",\"tSLticks\":\""+tSLticks+"\"}";
	resp=algomojo.AMDispatcher(user_apikey, api_secret,"PlaceBOOrder",api_data,broker,ver);
	_TRACE(resp);
}

function bracketorder_sell(orderqty)
{
	algomojo=CreateObject("AMAMIBRIDGE.Main");
	api_data ="{\"stgy_name\":\""+stgy_name+"\",\"s_prdt_ali\":\""+s_prdt_ali+"\",\"TokenNo\":\""+TokenNo+"\",\"exch\":\""+exch+"\",\"Ttranstype\":\""+"S"+"\",\"Ret\":\""+Ret+"\",\"prctyp\":\""+prctyp+"\",\"qty\":\""+qty+"\",\"discqty\":\""+discqty+"\",\"Price\":\""+Price+"\",\"ltpOratp\":\""+ltpOratp+"\",\"SqrOffAbsOrticks\":\""+SqrOffAbsOrticks+"\",\"SqrOffvalue\":\""+SqrOffvalue+"\",\"SLAbsOrticks\":\""+SLAbsOrticks+"\",\"SLvalue\":\""+SLvalue+"\",\"trailingSL\":\""+trailingSL+"\",\"tSLticks\":\""+tSLticks+"\"}";
	resp=algomojo.AMDispatcher(user_apikey, api_secret,"PlaceBOOrder",api_data,broker,ver);
	_TRACE(resp);
}


if(EnableAlgo != "Disable")
{
        lasttime = StrFormat("%0.f",LastValue(BarIndex()));
        
        SetChartBkColor(colorDarkGrey);
        if(EnableAlgo == "Enable")
        {   
            if (AlgoBuy==True AND AlgoCover == True AND StaticVarGet(static_name_+"buyCoverAlgo")==0 )
            {
            // reverse Long Entry 
                bracketorder_buy(qty*2);
                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));
        
            }
            else if ((AlgoBuy != True OR AlgoCover != True))
            {   
                StaticVarSet(static_name_+"buyCoverAlgo",0);
            }
            
            if (AlgoBuy==True AND AlgoCover != True AND StaticVarGet(static_name_+"buyAlgo")==0 )
            {
            // Long Entry 
                bracketorder_buy(qty);
                StaticVarSet(static_name_+"buyAlgo",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 : Buy Signal  TimeFrame : "+ Interval(2)+"  Response : "+ resp +"  ChardId : "+ GetChartID() + " Latest Price : "+LastValue(C));
            }
            else if (AlgoBuy != True)
            {   
                StaticVarSet(static_name_+"buyAlgo",0);
                
            }
            if (AlgoSell==true AND AlgoShort != True AND StaticVarGet(static_name_+"sellAlgo")==0 )
            {     
            // Long Exit 
                bracketorder_sell(qty);
                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));
            }
            else if (AlgoSell != True )
            {   
                StaticVarSet(static_name_+"sellAlgo",0);
            }
            if (AlgoShort==True AND AlgoSell==True AND  StaticVarGet(static_name_+"ShortSellAlgo")==0 )
            {
            // reverse Short Entry 
                bracketorder_sell(2*qty);
                StaticVarSet(static_name_+"ShortSellAlgo",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 : Short and Sell Signal  TimeFrame : "+ Interval(2)+"  Response : "+ resp +"  ChardId : "+ GetChartID() + " Latest Price : "+LastValue(C));
            }
            else if ((AlgoShort != True OR AlgoSell != True))
            {   
                StaticVarSet(static_name_+"ShortSellAlgo",0);
            }
                
            if (AlgoShort==True  AND  AlgoSell != True AND StaticVarGet(static_name_+"ShortAlgo")==0  )
            {
            // Short Entry
                bracketorder_sell(qty);
                StaticVarSet(static_name_+"ShortAlgo",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 : Short Signal  TimeFrame : "+ Interval(2)+"  Response : "+ resp +"  ChardId : "+ GetChartID() + " Latest Price : "+LastValue(C));
            }
            else if (AlgoShort != True )
            {   
                StaticVarSet(static_name_+"ShortAlgo",0);
            }
            if (AlgoCover==true AND AlgoBuy != True AND StaticVarGet(static_name_+"CoverAlgo")==0 )
            {
            // Short Exit
                bracketorder_buy(qty);
                StaticVarSet(static_name_+"CoverAlgo",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 : Cover Signal  TimeFrame : "+ Interval(2)+"  Response : "+ resp +"  ChardId : "+ GetChartID() + " Latest Price : "+LastValue(C));
            }
            else if (AlgoCover != True )
            {   
                StaticVarSet(static_name_+"CoverAlgo",0);
            }
        }
        
}
     

这是用于带有目标和止损的仅长期执行的完整的定单定单模块。而且每天篮球竞彩仅限于一次。也就是说,在任何给定日期,每个篮球竞彩代码只会触发一个多头进场和一个多头退出。

这是带有托架订购模块的完整Amibroker AFL代码

_SECTION_BEGIN("Price");
SetBarsRequired(-2,-2); //diable quick AFL
SetChartOptions(0,chartShowArrows|chartShowDates);
_N(Title = StrFormat("{{NAME}} - {{INTERVAL}} {{DATE}} Open %g, Hi %g, Lo %g, Close %g (%.1f%%) {{VALUES}}", O, H, L, C, SelectedValue( ROC( C, 1 ) ) ));
Plot( C, "Close", ParamColor("Color", colorDefault ), styleNoTitle | ParamStyle("Style") | GetPriceStyle() ); 
_SECTION_END();


_SECTION_BEGIN("Simple MACD Intraday Trading System");

//Buy on MACD, Signals on Positive Crossover and also trade should be executed between 10a.m and 3p.m
//Exit on MACD, Signals negative crossover and also square off the position if time is 3.15p.m

// identify new day
dn = DateNum();
newDay = dn != Ref( dn,-1);



//////////////////////////////////////////////////////////////////////
//                Trade Input Parameters          					//



//Exit Criteria
stops = Param("Stoploss %", 0.25,0,20,0.01);
target = Param("Target %", 0.5,0,20,0.01);
TickSz = Param("TickSize",0.05); //round off the stops and target to nearest tick size


sigstarttime = ParamTime("Sig Start Time", "10:00:00"); //no fresh position before signal start time
sigendtime = ParamTime("Sig End Time", "15:00:00"); //no fresh position after signal end time
sqofftime = ParamTime("Squareoff Time", "15:15:00");  //broker square off time




//////////////////////////////////////////////////////////////////////
//            Configure your trading condition here					//

longtradingcondition = Cross(MACD(), Signal());


//////////////////////////////////////////////////////////////////////


//////////////////////////////////////////////////////////////////////
//            Trading Logic One Intraday Trade Per Day              //


Buy = longtradingcondition AND TimeNum() >= sigstarttime AND TimeNum() < sigendtime;
Buy = Buy AND Sum( Buy, BarsSince( newDay) +1 ) <= 1; //consider only the first signal for the day

entryprice = ValueWhen(Buy AND Sum( Buy, BarsSince( newDay) +1 )==1,Ref(Open,1));  //entry price at the next bar open and at the first signal
buystops1 = (100-stops)/100 * entryprice;
buytarget1 = (100+target)/100 * entryprice;


buystops = TickSz * round( buystops1 / TickSz );
buytarget = TickSz * round( buytarget1 / TickSz );


iSell = TimeNum() >= sqofftime OR Cross(High,buytarget) OR Cross(buystops,Low);

//Remove Excessive Signals
Buy = ExRem(Buy,iSell);
iSell = ExRem(iSell,Buy);


//Non Repainting  - Signals happens only after the close of the current
Buy = Ref(Buy,-1);
BuyPrice = Open;




iSellPrice = IIf(Cross(High,buytarget), buytarget, IIf( Cross(buystops,Low), buystops, Open));


buycontinue = Flip(Buy,iSell) OR isell; //look for continuation of trades

targethit = iSell AND Cross(High,buytarget);
stophit = iSell AND Cross(buystops,Low);
sqofftime = iSell AND TimeNum() >= sqofftime;


//This code place order only on Long Entry
Sell = Short = Cover = 0;


//////////////////////////////////////////////////////////////////////


Plot(IIf(buycontinue,buystops,Null),"Stops",colorRed);
Plot(IIf(buycontinue,buytarget,Null),"Target",colorgreen);


/* 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(iSell, shapeSquare, shapeNone),colorRed, 0, H, Offset=40);
PlotShapes(IIf(iSell, shapeSquare, shapeNone),colorOrange, 0,H, Offset=50);
PlotShapes(IIf(iSell, shapeDownArrow, shapeNone),colorWhite, 0,H, Offset=-45);


SetPositionSize(1*RoundLotSize,spsShares);


fntsize = 8;// font size
dist = 65;// y-offset

bi = Barindex();
fvb = FirstVisiblevalue( bi );
lvb = LastVisiblevalue( bi );

bkcolor = -1;// text background color, -1 means default color (transparent)

PlotTextSetFont( "", "ARIAL", fntsize, BarCount-1, 0, -1 );

pnl = ValueWhen(iSell,iSellPrice - entryprice);

for ( i = fvb; i <= lvb; i++ ) {
    if( Buy[i] || iSell[i] )	{
		buyvar = "\[email protected]" + BuyPrice[i];
		sellvar = "\[email protected]" + iSellPrice[i]+"\nPnl= "+pnl[i];
		if( Buy[i] )  PlotText( "Long Entry" + buyvar, i, L[i], colorGreen, bkcolor, -dist-2*fntsize );
		if( targethit[i] ) PlotText( "Target Hit" + sellvar, i, H[i], colorRed, bkcolor, dist+4.5*fntsize );
		if( stophit[i] ) PlotText( "Stop Hit" + sellvar, i, H[i], colorRed, bkcolor, dist+4.5*fntsize );
		if( sqofftime[i] ) PlotText( "SQoff.Time Hit" + sellvar, i, H[i], colorRed, bkcolor, dist+4.5*fntsize );
    }
}



_SECTION_END();


_SECTION_BEGIN("Algomojo Bracket Order Module");

uid = ParamStr("uid ID","TS2499"); //Enter your Trading Account Login ID
user_apikey = ParamStr("user_apikey","xxxxxxxxxxxxx"); //Enter your API key here
api_secret = ParamStr("api_secret","xxxxxxxxxxxxx"); //Enter your API secret key here
broker = ParamStr("Broker Code1","tj"); //Enter your Broker Short Code here
ver = ParamStr("version","1.0"); //Enter your API version here
s_prdt_ali = ParamList("s_prdt_ali","BO:BO|CNC:CNC|CO:CO|MIS:MIS|NRML:NRML",0); //Type of order
Tsym = ParamStr("Tsym","RELIANCE-EQ "); //Enter the symbol name here
exch = ParamList("Exchange","NFO|NSE|BSE|CDS|MCX|NCDEX|BFO|MCXSXFO|MCXSX",1); 
Ret = ParamList("Ret","DAY|IOC",0);
//Ttranstype = ParamList("Ttranstype","B|S",0);
prctyp = ParamList("prctyp","MKT|L|SL|SL-M",0);
Price = 0; //ParamList("Price","0");
qty = Param("Quatity",1,0,10000,1); 
discqty = "0"; //ParamList("discqty","0");
AMO = "NO"; //ParamList("AMO","NO|YES",0); //After market order
TokenNo = ParamStr("TokenNo","11184"); //Enter the token number of the symbol here. Check the Algomojo Watchlist symbol info to get the relevant symbol token no.
ltpOratp = "LTP"; //ParamList("ltpOratp","LTP|ATP",0);


 
SqrOffAbsOrticks = "Absolute";  //ParamList("SqrOffAbsOrticks","Absolute|Ticks",0); //If you select absolute then you can enter a decimal quantity. If you selected ticks you need to enter in multiples of ticks
SqrOffvalue = buytarget-entryprice; //ParamStr("SqrOffvalue","1"); 
SLAbsOrticks = "Absolute";   //ParamList("SLAbsOrticks","Absolute|Ticks",0);
SLvalue = entryprice-buystops ; //ParamStr("SLvalue","30");
trailingSL = "N"; //ParamList("trailingSL","Y|N",0); 
tSLticks = 1000; //ParamStr("tSLticks","100"); //Trailing SL value in ticks if user has opted to use trailingSL
placeordertype = "Realtime"; //ParamList("Place Order On","Realtime|CandleCompletion",0); // Place Order Type
EnableAlgo = ParamList("Algo Mode","Disable|Enable",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(placeordertype == "Realtime")
{
AlgoBuy = lastvalue(Ref(Buy,0));
AlgoSell = lastvalue(Ref(Sell,0));
AlgoShort = lastvalue(Ref(Short,0));
AlgoCover = lastvalue(Ref(Cover,0));
}

if(placeordertype == "CandleCompletion")
{
AlgoBuy = lastvalue(Ref(Buy,-1));
AlgoSell = lastvalue(Ref(Sell,-1));
AlgoShort = lastvalue(Ref(Short,-1));
AlgoCover = lastvalue(Ref(Cover,-1));
}


resp = "";

function bracketorder_buy(orderqty)
{
	algomojo=CreateObject("AMAMIBRIDGE.Main");
	api_data ="{\"stgy_name\":\""+stgy_name+"\",\"s_prdt_ali\":\""+s_prdt_ali+"\",\"TokenNo\":\""+TokenNo+"\",\"exch\":\""+exch+"\",\"Ttranstype\":\""+"B"+"\",\"Ret\":\""+Ret+"\",\"prctyp\":\""+prctyp+"\",\"qty\":\""+qty+"\",\"discqty\":\""+discqty+"\",\"Price\":\""+Price+"\",\"ltpOratp\":\""+ltpOratp+"\",\"SqrOffAbsOrticks\":\""+SqrOffAbsOrticks+"\",\"SqrOffvalue\":\""+SqrOffvalue+"\",\"SLAbsOrticks\":\""+SLAbsOrticks+"\",\"SLvalue\":\""+SLvalue+"\",\"trailingSL\":\""+trailingSL+"\",\"tSLticks\":\""+tSLticks+"\"}";
	resp=algomojo.AMDispatcher(user_apikey, api_secret,"PlaceBOOrder",api_data,broker,ver);
	_TRACE(resp);
}

function bracketorder_sell(orderqty)
{
	algomojo=CreateObject("AMAMIBRIDGE.Main");
	api_data ="{\"stgy_name\":\""+stgy_name+"\",\"s_prdt_ali\":\""+s_prdt_ali+"\",\"TokenNo\":\""+TokenNo+"\",\"exch\":\""+exch+"\",\"Ttranstype\":\""+"S"+"\",\"Ret\":\""+Ret+"\",\"prctyp\":\""+prctyp+"\",\"qty\":\""+qty+"\",\"discqty\":\""+discqty+"\",\"Price\":\""+Price+"\",\"ltpOratp\":\""+ltpOratp+"\",\"SqrOffAbsOrticks\":\""+SqrOffAbsOrticks+"\",\"SqrOffvalue\":\""+SqrOffvalue+"\",\"SLAbsOrticks\":\""+SLAbsOrticks+"\",\"SLvalue\":\""+SLvalue+"\",\"trailingSL\":\""+trailingSL+"\",\"tSLticks\":\""+tSLticks+"\"}";
	resp=algomojo.AMDispatcher(user_apikey, api_secret,"PlaceBOOrder",api_data,broker,ver);
	_TRACE(resp);
}


if(EnableAlgo != "Disable")
{
        lasttime = StrFormat("%0.f",LastValue(BarIndex()));
        
        SetChartBkColor(colorDarkGrey);
        if(EnableAlgo == "Enable")
        {   
            if (AlgoBuy==True AND AlgoCover == True AND StaticVarGet(static_name_+"buyCoverAlgo")==0 )
            {
            // reverse Long Entry 
                bracketorder_buy(qty*2);
                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));
        
            }
            else if ((AlgoBuy != True OR AlgoCover != True))
            {   
                StaticVarSet(static_name_+"buyCoverAlgo",0);
            }
            
            if (AlgoBuy==True AND AlgoCover != True AND StaticVarGet(static_name_+"buyAlgo")==0 )
            {
            // Long Entry 
                bracketorder_buy(qty);
                StaticVarSet(static_name_+"buyAlgo",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 : Buy Signal  TimeFrame : "+ Interval(2)+"  Response : "+ resp +"  ChardId : "+ GetChartID() + " Latest Price : "+LastValue(C));
            }
            else if (AlgoBuy != True)
            {   
                StaticVarSet(static_name_+"buyAlgo",0);
                
            }
            if (AlgoSell==true AND AlgoShort != True AND StaticVarGet(static_name_+"sellAlgo")==0 )
            {     
            // Long Exit 
                bracketorder_sell(qty);
                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));
            }
            else if (AlgoSell != True )
            {   
                StaticVarSet(static_name_+"sellAlgo",0);
            }
            if (AlgoShort==True AND AlgoSell==True AND  StaticVarGet(static_name_+"ShortSellAlgo")==0 )
            {
            // reverse Short Entry 
                bracketorder_sell(2*qty);
                StaticVarSet(static_name_+"ShortSellAlgo",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 : Short and Sell Signal  TimeFrame : "+ Interval(2)+"  Response : "+ resp +"  ChardId : "+ GetChartID() + " Latest Price : "+LastValue(C));
            }
            else if ((AlgoShort != True OR AlgoSell != True))
            {   
                StaticVarSet(static_name_+"ShortSellAlgo",0);
            }
                
            if (AlgoShort==True  AND  AlgoSell != True AND StaticVarGet(static_name_+"ShortAlgo")==0  )
            {
            // Short Entry
                bracketorder_sell(qty);
                StaticVarSet(static_name_+"ShortAlgo",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 : Short Signal  TimeFrame : "+ Interval(2)+"  Response : "+ resp +"  ChardId : "+ GetChartID() + " Latest Price : "+LastValue(C));
            }
            else if (AlgoShort != True )
            {   
                StaticVarSet(static_name_+"ShortAlgo",0);
            }
            if (AlgoCover==true AND AlgoBuy != True AND StaticVarGet(static_name_+"CoverAlgo")==0 )
            {
            // Short Exit
                bracketorder_buy(qty);
                StaticVarSet(static_name_+"CoverAlgo",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 : Cover Signal  TimeFrame : "+ Interval(2)+"  Response : "+ resp +"  ChardId : "+ GetChartID() + " Latest Price : "+LastValue(C));
            }
            else if (AlgoCover != True )
            {   
                StaticVarSet(static_name_+"CoverAlgo",0);
            }
        }
        
}
     


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

用于从Excelsheet到Algomojo下订单的VB脚本…

本教程提供了示例VB脚本代码,用于从Algomojo平台下订单。 Algomojo提供免费的API +免费的篮球竞彩平台来...
拉贾德兰R
2分钟阅读

如何使用邮递员向您的订单发送订单…

Postman是一种API测试工具,始于2012年,是Abhinav Asthana的副项目,旨在简化测试和测试过程中的API工作流程。
拉贾德兰R
1分钟阅读

什么是Algomojo API?

Algomojo为algomojo用户提供免费API +免费篮球竞彩平台,以放置,修改,取消订单。目前,Algomojo API对用户是免费的...
拉贾德兰R
2分钟阅读

3 Replies to “建立括号订单执行时要考虑的事项…”

    1. 此代码如果要回测,则必须正确配置退出指令。在上面的代码中,sell = 0和cover = 0以避免在出口点执行任何事务,因为括号顺序会解决这一问题。

      而是使用isell和icover变量。如果您分配了Sell = isell和cover = icover,则策略是可后退的,但这会在执行时产生问题,因为将下达其他退出订单。为了避免这种情况
      我一直卖=封面= 0

发表评论

获取通知,市场更新警报,篮球竞彩工具,自动化等