Please Code below AFL for the Pi bridge from Amibroker

The below afl code is correct and has no errors still when i try to fire orders through pi bridge it is not working,  please modify the code and reply.

SECTION_BEGIN("OH-OL scanner");
SetSortColumns( 3 );
TimeFrameSet(inDaily);
x1= TimeFrameExpand(O,inDaily,expandFirst); 
y1=TimeFrameExpand(H,inDaily,expandFirst);
z1=TimeFrameExpand(L,inDaily,expandFirst);
AddTextColumn( FullName(), "Full name", 1, IIf( z1==x1  ,colorBlue,  IIf( y1==x1  ,colorRed,colorBlack )           )   );
Filter= z1==x1 OR y1==x1 ;
AddColumn(C," LTP",1.2); 
AddColumn( y1 , " day high", 1.2, IIf( y1==x1  ,colorRed,colorBlack));
AddColumn( x1 , " day open", 1.2, colorBlack);
AddColumn( z1 , " day low", 1.2, IIf( z1==x1  ,colorBlue,colorBlack));
TimeFrameRestore(); 
AddColumn(RSI(14),"RSI",1); 
AddColumn(ADX(14),"ADX",1); 
_SECTION_END();

As per above query run this modified AFL

SECTION_BEGIN("OH-OL scanner");
Buy=Sell=Short=Cover=0;
SetSortColumns( 3 );
TimeFrameSet(inDaily);
x1= TimeFrameExpand(O,inDaily,expandFirst); 
y1=TimeFrameExpand(H,inDaily,expandFirst);
z1=TimeFrameExpand(L,inDaily,expandFirst);
AddTextColumn( FullName(), "Full name", 1, IIf( z1==x1  ,colorBlue,  IIf( y1==x1  ,colorRed,colorBlack )           )   );
Filter= z1==x1 OR y1==x1 ;
AddColumn(C," LTP",1.2); 
AddColumn( y1 , " day high", 1.2, IIf( y1==x1  ,colorRed,colorBlack));
AddColumn( x1 , " day open", 1.2, colorBlack);
AddColumn( z1 , " day low", 1.2, IIf( z1==x1  ,colorBlue,colorBlack));
TimeFrameRestore(); 
AddColumn(RSI(14),"RSI",1); 
AddColumn(ADX(14),"ADX",1); 
_SECTION_END();
_SECTION_BEGIN("PiBridge_08Apr15");
GfxSetBkMode(0);GfxSetTextColor( colorWhite );pxw = Status("pxwidth");pxh = Status("pxheight");Tikr = StrToUpper(Name());Val = StrToUpper("DAY");
BarB = BeginValue(BarIndex());BarE = EndValue(BarIndex());BarC = BarIndex();BarL = LastValue(BarC,1);BarT = BarIndex()-ValueWhen(TimeNum()==091500,BarIndex())+1;sym=TrdSym=Exch=ClientId=ORdType=ProdType="";Qty=0;
if (IsNull(fgetstatus("SymbolList.txt",1,4))){SymbolList = fopen( "SymbolList.txt", "w");if (SymbolList){fputs( "AmibrokerSymbol,TradeSymbol,Exchange,Qty,ClientID,OrderType,ProductType,Validity"+ "\n" +"EXAMPLE-I,EXAMPLE15MAYFUT,NFO,1,ABCD01,L,MIS,DAY" + "\n" , SymbolList );fclose(SymbolList);}}
Input = fopen( "SymbolList.txt", "r");if(Input){	while( ! feof(Input)){LineIn = fgets(Input);if (LineIN !=""){ if (StrToUpper(StrExtract(LineIn,0)) == Tikr){ Sym = StrToUpper(StrExtract(LineIn,0));TrdSym = StrToUpper(StrExtract(LineIn,1));Exch = StrToUpper(StrExtract(LineIn,2));Qty = StrToNum(StrExtract(LineIn,3));ClientId = StrToUpper(StrExtract(LineIn,4));OrdType = StrToUpper(StrExtract(LineIn,5));ProdType = StrToUpper(StrExtract(LineIn,6));}}}fclose( Input );}
if (ORdType == "L")TrdPrice = LastValue(C,1);else TrdPrice = 0;
BuyVar = StaticVarGetText(Name()+"-Buy");BuyVar1 = Name()+"-Buy-"+NumToStr(BarL,1.0)+"-"+NumToStr(GetChartID(),1.0);BuyL = LastValue(Buy);
SellVar = StaticVarGetText(Name()+"-Sell");SellVar1 = Name()+"-Sell-"+NumToStr(BarL,1.0)+"-"+NumToStr(GetChartID(),1.0);SellL = LastValue(Sell);
ShortVar = StaticVarGetText(Name()+"-Short");ShortVar1 = Name()+"-Short-"+NumToStr(BarL,1.0)+"-"+NumToStr(GetChartID(),1.0);ShortL = LastValue(Short);
CoverVar = StaticVarGetText(Name()+"-Cover");CoverVar1 = Name()+"-Cover-"+NumToStr(BarL,1.0)+"-"+NumToStr(GetChartID(),1.0);CoverL = LastValue(Cover);
if (BuyL AND BuyVar != BuyVar1 AND Sym != ""){brd = CreateStaticObject("pibridge.Bridge");brd.PlaceOrder (Exch,TrdSym,StrLeft(Sym,10),"LONG",1,Qty,0,TrdPrice,0,ORdType,ProdType,ClientId,Val);}
if (CoverL AND CoverVar != CoverVar1 AND Sym != ""){brd = CreateStaticObject("pibridge.Bridge");brd.PlaceOrder (Exch,TrdSym,StrLeft(Sym,10),"EXIT SHORT",1,Qty,0,TrdPrice,0,ORdType,ProdType,ClientId,Val);}
if (SellL AND SellVar != SellVar1 AND Sym != ""){brd = CreateStaticObject("pibridge.Bridge");brd.PlaceOrder (Exch,TrdSym,StrLeft(Sym,10),"EXIT LONG",2,Qty,0,TrdPrice,0,ORdType,ProdType,ClientId,Val);}
if (ShortL AND ShortVar != ShortVar1 AND Sym != ""){brd = CreateStaticObject("pibridge.Bridge");brd.PlaceOrder (Exch,TrdSym,StrLeft(Sym,10),"SHORT",2,Qty,0,TrdPrice,0,ORdType,ProdType,ClientId,Val);}
display = ParamToggle("Display Symbol Details","Yes|No",1);if(display==1){GfxTextOut("SYMBOL: " + sym,5,50);GfxTextOut("TRADE SYMBOL: " + Trdsym,5,70);GfxTextOut("EXCH: " + Exch,5,90);GfxTextOut("CLIENT ID: " + Clientid,5,110);GfxTextOut("PROD TYPE: " + prodtype,5,130);GfxTextOut("ORDER TYPE: " + ORdtype,5,150);GfxTextOut("QTY: " + WriteVal(Qty,1.0),5,170);}
if (sym == ""){GfxSelectFont( "Lucida Fax", 24, 700, False );GfxTextOut("Symbol Details Not Found in Text File",(pxw/2)-330,pxh/2);}
if ((sym != "" AND Exch == "NFO" AND StrRight(TrdSym,3)!= "FUT") OR (sym != "" AND Exch == "NSE" AND StrRight(TrdSym,2)!= "EQ") OR (sym != "" AND Exch == "MCX" AND StrRight(TrdSym,3)!= "FUT"))
{GfxSelectFont( "Lucida Fax", 24, 700, False );GfxTextOut("Trade Symbol MisMatch Check Symbol List File",(pxw/2)-370,pxh/2);}
Bridge = ParamTrigger("To Check Pi Bridge Connectivity !","Press Here");if (Bridge){brd = CreateStaticObject("pibridge.Bridge");}
Resetvar = ParamTrigger("To Reset Static Variables !","Press Here");if (ResetVar){StaticVarRemove("*");}DelSymbol = ParamTrigger("To Delete SymbolList File !","Press Here");if (DelSymbol){SymbolList = fopen( "SymbolList.txt", "w");	
if (SymbolList){fputs( "AmibrokerSymbol,TradeSymbol,Exchange,Qty,ClientID,OrderType,ProductType,Validity"+ "\n" +"EXAMPLE-I,EXAMPLE15MAYFUT,NFO,1,ABCD01,L,MIS,DAY" + "\n" , SymbolList );fclose(SymbolList);}}
_SECTION_END();
2 Likes

Hi Anita,
If the above is your Full code Then, U have not defined Buy and Sell Variable in your code.So You’ll never get signal and orders never fire to Pi. What Your code does is Just Scaning all Tickers in the Database and Filter out those Tickers/Stocks whose Day High / Day Low is Equal to the Day Opening Price.

U may Comment your Requirement in Plain English,So that We Can Code your Strategy to Get Buy/Sell Signals.