For the above requirement you can check this below given sample code for Pi bridge - Amibroker 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() );
Buy = Cross (EMA( Close, 20 ), EMA( Close, 50 )) ;
Sell = Cross (EMA( Close, 50 ), EMA( Close, 20 )) ;
Short = Sell;
Cover = Buy;
PlotShapes (Buy*shapeHollowStar,colorGreen);
PlotShapes (Sell*shapeHollowStar,colorRed);
Plot( EMA( Close, 20 ),"med ema", colorRed,styleThick);
Plot( EMA( Close, 50 ),"long ema", colorBlue,styleThick);
//SL
Start_Trading = ParamToggle("Start Trading", "No|Yes",1);
//Bridge++
brd=Null;
if(IsNull(brd))
{
brd = CreateStaticObject("pibridge.Bridge");
}
if(!brd.GetConnectionStatus()) brd.Reconnect();
Buy = ExRem(Buy, Sell);
Sell = ExRem(Sell, Buy);
currTimestamp = LastValue( TimeNum() );
LastTimestamp = Nz( StaticVarGet("LastBarTimestamp_"+Name()+"_" +GetChartID()) );
if ( currTimestamp != LastTimestamp )
{
StaticVarSet( "LastBarTimestamp_"+Name()+"_" +GetChartID(), currTimestamp );
Start_Trading = ParamToggle("Start Trading", "No|Yes",1);
if(LastValue(Buy) AND Start_Trading==1)
{
price = LastValue(C,1);
brd.PlaceOrder("NFO", "NIFTY15NOVFUT", "NIFTY","STRATEGY-S", 1,75, 1, price, 0, "L", "NRML", "DS2941","DAY");
{
sbprice = LastValue(C-10,1);
brd.PlaceOrder("NFO", "NIFTY15NOVFUT", "NIFTY","STRATEGY-S", 2,75, 1, 0, sbprice, "SL-M", "NRML", "DS2941","DAY");
}
}
if(LastValue(Sell) AND Start_Trading==1)
{
price = LastValue(C,1);
brd.PlaceOrder("NFO", "NIFTY15NOVFUT", "NIFTY","STRATEGY-S", 2,75, 1, price, 0, "L", "NRML", "DS2941","DAY");
{
ssprice = LastValue(C+10,1);
brd.PlaceOrder("NFO", "NIFTY15NOVFUT", "NIFTY","STRATEGY-S", 1,75, 1, 0, ssprice, "SL-M", "NRML", "DS2941","DAY");
}
}
}
//Bridge++