Hi,
Following sample code in Nifty symbol for Amibroker is not registering any order with Pi Bridge. Please analyze code and let me know the reasons for the same.
brd.GetConnectionStatus() always registers status as -1 in log file and orders don’t reach to Pi.
_SECTION_BEGIN(“Price”);
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(“Nifty_SMA”);
fh = fopen( “C:\OUTPUT\”+“test.txt”, “a”);
SMA7 = MA(Close,7);
SMA21 = MA(Close,21);
Sig = “”;
CurrSig = “”;
Chk0 = (Cross( SMA7, SMA21));
Chk1 = (Cross( SMA21, SMA7));
Buy = Cross( SMA7, SMA21 );
Sell = Cross( SMA21, SMA7);
Short = Cross( SMA21, SMA7) ;
Cover = Cross( SMA7, SMA21 ) ;
Buy=ExRem(Buy,Sell);
Sell=ExRem(Sell,Buy);
Short = ExRem( Short, Cover );
Cover = ExRem( Cover, Short );
BuyFlag = LastValue(Buy);
SellFlag = LastValue(Sell);
ShortFlag = LastValue(Short);
CoverFlg = LastValue(Cover);
shape = Buy * shapeUpArrow +Sell * shapeDownArrow ;
PlotShapes( shape, IIf( Buy, colorGreen, colorRed ),0, IIf( Buy, Low, High ) );
Shortshape = Short * shapeDownArrow;
CoverShape = Cover * shapeUpArrow;
PlotShapes( Shortshape, colorOrange, 0, High, -30);
PlotShapes( CoverShape, colorTurquoise, 0, Low, -30 );
ClientId = “TESTCLIENT”;
TrdSymbol = “NIFTY15APRFUT”;
Symbol = “NIFTY”;
Qty = “25”;
Exch =“NFO”;
PType = “NRML”;
OType = “MKT”;
BuyP = LastValue(ValueWhen(Buy,C),1);
ShortP = LastValue(ValueWhen(Short,C),1);
SellP = LastValue(ValueWhen(Sell,C),1);
CoverP = LastValue(ValueWhen(Cover,C),1);
Checkone=Nz(StaticVarGet(“Check”),0);
Checktwo = LastValue(BarIndex(),1);
OrdCond = LastValue(Buy) OR LastValue(Short) OR LastValue(Sell) OR LastValue(Cover);
GfxTextOut("Last Buy : " + BuyP + " Last Short : " + ShortP,25,125);
brd = Null;
if((OrdCond))
{
if(IsNull(brd))
{
brd = CreateStaticObject(“pibridge.Bridge”);
}
if(!brd.GetConnectionStatus()) brd.Reconnect();
fputs("Date : " + NumToStr(DateTime()) + " Pi Bridge Status - Checked " + brd.GetConnectionStatus() + "\n",fh);
if(LastValue(Buy))
{
fputs("Date : " + NumToStr(DateTime(),formatDateTime) + " Buy @ " + BuyP + "\n" , fh);
brd.PlaceOrder (Exch, TrdSymbol ,Symbol,"MyAFL", 1,Qty,0, BuyP, 0, OType, PType, ClientId,"Day");
}
if(LastValue(Sell))
{
fputs("Date : " + NumToStr(DateTime(),formatDateTime) + " Sell @ " + SellP + "\n" , fh);
brd.PlaceOrder (Exch, TrdSymbol,Symbol,"MyAFL", 2,Qty,0, SellP, 0, OType,PType, ClientId,"Day");
}
if(LastValue(Cover))
{
fputs("Date : " + NumToStr(DateTime(),formatDateTime) + " Cover @ " + CoverP + "\n" , fh);
brd.PlaceOrder (Exch, TrdSymbol,Symbol,"MyAFL", 1,Qty,0, CoverP, 0, OType, PType, ClientId,"Day");
}
if(LastValue(Short))
{
fputs("Date : " + NumToStr(DateTime(),formatDateTime) + " Short @ " + ShortP + "\n" , fh);
brd.PlaceOrder (Exch, TrdSymbol,Symbol,"MyAFL", 2,Qty,0, ShortP, 0, OType,PType, ClientId,"Day");
}
StaticVarSet("Check",CheckTwo );
}
fclose( fh );
_SECTION_END();
Please support.
Thanks,
Birju