Help in buy and sell for this afl in pi-bridge, not working when running bar replay

I am unable to get the buy and sell signal in the pi-bridge when trying for live semiauto mode.

Please let me know whether there is mistake in below code or if it is working good for you please guide me how to do so?

/*
AMibroker Settings:
Tools -->> Preferences -->> Intraday -->> Tick "Align Minute Bars to Regular Market Hours"
Tools -->> Preferences -->> Intraday -->> Select “Start Time Of Interval”

Tools -->> Preferences -->> Colors -->>
UpCandleStick = Bright Green
Down CandleStick = Red
Axis(Line) = White
Axis (Text) = White
BackGround = Black

Tools -->> Preferences -->> Axis/Grids -->>
UnTick All Boxes (Around 6 Boxes)

Instructions to Use This Pi Bridge.

  1. This AFL contains both Sample Trading System and Pi Bridge
    First check this AFL with sample trading system to ensure the working of this AFL
    Replace the sample trading system with yours.Make sure U enter the Trading system inside the marked space in the AFL
    Ur System may have many lines of code…No restriction

2.Open a Blank Chart and Drag & Drop this AFL on the Chart

3.Now Go to Your Amibroker Directory, You will find a file Named "SymbolList.txt"
You Have to type all details of all Tickers as per the example given in the Text File.One line per symbol
In Amibroker Symbol - Ticker Name As it is in Amibroker Ex:- NIFTY-I
In TradeSymbol - Type the TradeSymbol as Exactly as it is in Pi Ex:- NIFTY15MAYFUT , ACC-EQ
In Exchange - NFO OR NSE OR MCX
In Qty - if it is Future than type No of Lots to Trade(NOT Lot Size),if it is Equity than Qty To Trade
In ClientId - Type Your Client Id
In OrderType - L OR MKT
In ProductType - MIS OR NRML OR CNC
In Validity - DAY
You Can Simply CopyPaste the Entire Line AND Change Amibroker Symbol & Trade Symbol.Most of the Time Rest all is Common.

4.U Can Check the Pi Bridge Connectivity from parameter window.
U Can check the function of AFL by BarReplay.Best time interval for BarReplay is 5min…U Can use any interval

Troubleshooting:
If Orders are not shown in Generated Alerts Window on Pi or Pi Bridge is not Working.
Then Follow the Below Steps to Make it work

1.Ensure that Amibroker is installed in C:\Program Files\Amibroker Directory
If U are Using 64bit os then Create a Empty Amiboker Folder in C:\Program Files\ & Amiboker may be installed in C:\Program Files (x86)\Amibroker
2.Ensure Pi & Pi Bridge is installed and U are enabled for Pi and Pi Bridge
3.Ensure pibridge.net.dll file is present in amibroker directory
4.U must first start Pi and then Amibroker…If u opened amibroker first and then pi…then Just close and reopen Amibroker only
5.In Pi–>> User Settings under PiBridge Tab Select - Live Semi Automatic
6.Ensure in Ur AFL u have correctly mentioned Exchange,ClientId,TradeSymbol,Symbol,Qty,OrderType,ProductType,Validity
7.Use this AFL to check the Function Again
8.Fired Orders will be available in Generated Alerts Window on Pi

*/
//----------------------------------------------------------------------------------------------------------------\
_SECTION_BEGIN(“Sample Trading System”);
SetChartOptions(0,chartShowArrows|chartShowDates);
Plot( C, “Close”, colorDefault, styleNoTitle | styleCandle);
_N(Title = StrFormat("{{NAME}} - {{INTERVAL}} {{DATE}} Open %g, Hi %g, Lo %g, Close %g {{VALUES}}", O, H, L, C ));
Buy=Sell=Short=Cover=0;//Donot Delete this Line

//-----Your Trading System Starts Here-----\
//----Sample Trading System Replace it with your Own----\

PrH1 = HHV(H,30);
PrL1 = LLV(L,30);

PrH2 = HHV(H,15);
PrL2 = LLV(L,15);

Buy = Cross(C,Ref(PrH1,-1));
Short = Cross(Ref(PrL1,-1),C);
Buy = ExRem(Buy,Short);
Short = ExRem(Short,Buy);

Cover = Cross(C,Ref(PrH2,-1));
Sell = Cross(Ref(PrL2,-1),C);
Sell = ExRem(Sell,Buy);
Cover = ExRem(Cover,Short);

PlotShapes(IIf(Buy, shapeUpArrow, shapeNone),colorGreen, 0,L, Offset=-25);
PlotShapes(IIf(Short, shapeDownArrow, shapeNone),colorRed, 0,H, Offset=-25);
PlotShapes(IIf(Cover, shapeSmallUpTriangle, shapeNone),colorBlue, 0,L, Offset=-45);
PlotShapes(IIf(Sell, shapeSmallDownTriangle, shapeNone),colorOrange, 0,H, Offset=-45);
//-----Your Trading System Ends Here-----\

_SECTION_END();

_SECTION_BEGIN(“PiBridge_Choks”);
EnableScript(“vbscript”);
AmiPath = fdir( “C:\Program Files (x86)\Amibroker\Broker.exe”, 1 );
if (AmiPath==""){Path = “C:\Program Files\Amibroker\”;Sys = “Bit32”; }else {Path = “C:\Program Files (x86)\Amibroker\”;Sys = “Bit64”;}
GfxSetBkMode(0);
GfxSetTextColor( colorWhite );
/*ClientId = “DS4000”;
TrdSymbol = “ICICIBANKAUG15FUT”;
Symbol = “ICICIBANK-I”;
Qty = “25”;
Exch =“NFO”;
PType = “MIS”;
OType = “MKT”; */
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=“ICICIBANK-I”;
TrdSym=“ICICIBANKAUG15FUT”;

Exch=“NFO”;
ClientId=“DS4000”;
ORdType=“MKT”;
ProdType=“MIS”;
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 );
}
DT = LastValue(DateNum(),1);
TT = LastValue(TimeNum(),1);
if (ORdType == “L”)TrdPrice = LastValue(C,1);
else TrdPrice = 0;
BuyVar = StaticVarGetText(Name()+"-Buy");
BuyVar1 = Name()+"-Buy-"+NumToStr(DT,1.0)+"-"+NumToStr(TT,1.0)+"-"+NumToStr(GetChartID(),1.0);
BuyL = LastValue(Buy);
SellVar = StaticVarGetText(Name()+"-Sell");
SellVar1 = Name()+"-Sell-"+NumToStr(DT,1.0)+"-"+NumToStr(TT,1.0)+"-"+NumToStr(GetChartID(),1.0);
SellL = LastValue(Sell);
ShortVar = StaticVarGetText(Name()+"-Short");
ShortVar1 = Name()+"-Short-"+NumToStr(DT,1.0)+"-"+NumToStr(TT,1.0)+"-"+NumToStr(GetChartID(),1.0);
ShortL = LastValue(Short);
CoverVar = StaticVarGetText(Name()+"-Cover");
CoverVar1 = Name()+"-Cover-"+NumToStr(DT,1.0)+"-"+NumToStr(TT,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);
StaticVarSetText(Name()+"-Buy",BuyVar1);
}
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);
StaticVarSetText(Name()+"-Cover",CoverVar1);
}
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);
StaticVarSetText(Name()+"-Sell",SellVar1);
}
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);StaticVarSetText(Name()+"-Short",ShortVar1);
}
GfxSelectFont( “Lucida Fax”, 8.5, 700, False );
GfxSetTextColor( colorGold );
GfxTextOut(“Coded by Choks”,(pxw/2)-50,pxh-40);
GfxTextOut(“Mail Ur Feedback to [email protected]”,(pxw/2)-130,pxh-30);
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);
}}
OpFolder = ParamTrigger(“To Open Amibroker Directory!”,“Press Here”);
<%
On Error Resume Next
OpFolder = AFL(“OpFolder”)
sys = AFL(“Sys”)
if OpFolder = 1 AND sys = “Bit32” then
CreateObject(“Shell.Application”).Open(“C:\Program Files\Amibroker”)
elseif OpFolder = 1 AND sys = “Bit64” then
CreateObject(“Shell.Application”).Open(“C:\Program Files (x86)\Amibroker”)
else
end if
%>

_SECTION_END();

Regards,

Sangeetha

Use the below modified AFL for the order firing from amibroker to pi

---\\
_SECTION_BEGIN("Sample Trading System");
 Buy=Sell=Short=Cover=0;
SetChartOptions(0,chartShowArrows|chartShowDates);
Plot( C, "Close", colorDefault, styleNoTitle | styleCandle); 
_N(Title = StrFormat("{{NAME}} - {{INTERVAL}} {{DATE}} Open %g, Hi %g, Lo %g, Close %g  {{VALUES}}", O, H, L, C ));
Buy=Sell=Short=Cover=0;//Donot Delete this Line

//-----Your Trading System Starts Here-----\\
//----Sample Trading System Replace it with your Own----\\

PrH1 = HHV(H,30);
PrL1 = LLV(L,30);

PrH2 = HHV(H,15);
PrL2 = LLV(L,15);

Buy = Cross(C,Ref(PrH1,-1));
Short = Cross(Ref(PrL1,-1),C);
Buy = ExRem(Buy,Short);
Short = ExRem(Short,Buy);

Cover = Cross(C,Ref(PrH2,-1));
Sell = Cross(Ref(PrL2,-1),C);
Sell = ExRem(Sell,Buy);
Cover = ExRem(Cover,Short);

PlotShapes(IIf(Buy, shapeUpArrow, shapeNone),colorGreen, 0,L, Offset=-25);
PlotShapes(IIf(Short, shapeDownArrow, shapeNone),colorRed, 0,H, Offset=-25);
PlotShapes(IIf(Cover, shapeSmallUpTriangle, shapeNone),colorBlue, 0,L, Offset=-45);
PlotShapes(IIf(Sell, shapeSmallDownTriangle, shapeNone),colorOrange, 0,H, Offset=-45);
//-----Your Trading System Ends Here-----\\

_SECTION_END();

_SECTION_BEGIN("PiBridge_Choks");
 Buy=Sell=Short=Cover=0;
EnableScript("vbscript");
AmiPath = fdir( "C:\\Program Files (x86)\\Amibroker\\Broker.exe", 1 );
if (AmiPath==""){Path = "C:\\Program Files\\Amibroker\\";Sys = "Bit32"; }else {Path = "C:\\Program Files (x86)\\Amibroker\\";Sys = "Bit64";}
GfxSetBkMode(0);
GfxSetTextColor( colorWhite );
/*ClientId = "DS4000";
TrdSymbol = "ICICIBANKAUG15FUT";
Symbol = "ICICIBANK-I";
Qty = "25";
Exch ="NFO";
PType = "MIS";
OType = "MKT"; */
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="ICICIBANK-I";
TrdSym="ICICIBANKAUG15FUT";

Exch="NFO";
ClientId="DS4000";
ORdType="MKT";
ProdType="MIS";
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 );
}
DT = LastValue(DateNum(),1);
TT = LastValue(TimeNum(),1);
if (ORdType == "L")TrdPrice = LastValue(C,1);
else TrdPrice = 0;
BuyVar = StaticVarGetText(Name()+"-Buy");
BuyVar1 = Name()+"-Buy-"+NumToStr(DT,1.0)+"-"+NumToStr(TT,1.0)+"-"+NumToStr(GetChartID(),1.0);
BuyL = LastValue(Buy);
SellVar = StaticVarGetText(Name()+"-Sell");
SellVar1 = Name()+"-Sell-"+NumToStr(DT,1.0)+"-"+NumToStr(TT,1.0)+"-"+NumToStr(GetChartID(),1.0);
SellL = LastValue(Sell);
ShortVar = StaticVarGetText(Name()+"-Short");
ShortVar1 = Name()+"-Short-"+NumToStr(DT,1.0)+"-"+NumToStr(TT,1.0)+"-"+NumToStr(GetChartID(),1.0);
ShortL = LastValue(Short);
CoverVar = StaticVarGetText(Name()+"-Cover");
CoverVar1 = Name()+"-Cover-"+NumToStr(DT,1.0)+"-"+NumToStr(TT,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);
StaticVarSetText(Name()+"-Buy",BuyVar1);
}
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);
StaticVarSetText(Name()+"-Cover",CoverVar1);
}
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);
StaticVarSetText(Name()+"-Sell",SellVar1);
}
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);StaticVarSetText(Name()+"-Short",ShortVar1);
}
GfxSelectFont( "Lucida Fax", 8.5, 700, False );
GfxSetTextColor( colorGold );
GfxTextOut("Coded by Choks",(pxw/2)-50,pxh-40);
GfxTextOut("Mail Ur Feedback to [email protected]",(pxw/2)-130,pxh-30);
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);
}}
OpFolder = ParamTrigger("To Open Amibroker Directory!","Press Here");
<%
On Error Resume Next 
OpFolder = AFL("OpFolder")
sys = AFL("Sys")
if OpFolder = 1  AND sys = "Bit32" then
CreateObject("Shell.Application").Open("C:\Program Files\Amibroker\")
elseif OpFolder = 1  AND sys = "Bit64" then
CreateObject("Shell.Application").Open("C:\Program Files (x86)\Amibroker\")
else
end if
%>

_SECTION_END();

_SECTION_BEGIN("PiBridge_Zerodha");

EnableScript("vbscript");AmiPath = fdir( "C:\\Program Files (x86)\\Amibroker\\Broker.exe", 1 );
if (AmiPath==""){Path = "C:\\Program Files\\Amibroker\\";Sys = "Bit32"; }else {Path = "C:\\Program Files (x86)\\Amibroker\\";Sys = "Bit64";}
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 );}
DT = LastValue(DateNum(),1);TT = LastValue(TimeNum(),1);if (ORdType == "L")TrdPrice = LastValue(C,1);else TrdPrice = 0;
BuyVar = StaticVarGetText(Name()+"-Buy");BuyVar1 = Name()+"-Buy-"+NumToStr(DT,1.0)+"-"+NumToStr(TT,1.0)+"-"+NumToStr(GetChartID(),1.0);BuyL = LastValue(Buy);
SellVar = StaticVarGetText(Name()+"-Sell");SellVar1 = Name()+"-Sell-"+NumToStr(DT,1.0)+"-"+NumToStr(TT,1.0)+"-"+NumToStr(GetChartID(),1.0);SellL = LastValue(Sell);
ShortVar = StaticVarGetText(Name()+"-Short");ShortVar1 = Name()+"-Short-"+NumToStr(DT,1.0)+"-"+NumToStr(TT,1.0)+"-"+NumToStr(GetChartID(),1.0);ShortL = LastValue(Short);
CoverVar = StaticVarGetText(Name()+"-Cover");CoverVar1 = Name()+"-Cover-"+NumToStr(DT,1.0)+"-"+NumToStr(TT,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);}
GfxSelectFont( "Lucida Fax", 8.5, 700, False );GfxSetTextColor( colorGold );GfxTextOut("SREENI AFL",(pxw/2)-50,pxh-40);GfxTextOut("ZERODHA",(pxw/2)-130,pxh-30);
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);}}
OpFolder = ParamTrigger("To Open Amibroker Directory!","Press Here");
<%
On Error Resume Next 
OpFolder = AFL("OpFolder")
sys = AFL("Sys")
if OpFolder = 1  AND sys = "Bit32" then
CreateObject("Shell.Application").Open("C:\Program Files\Amibroker\")
elseif OpFolder = 1  AND sys = "Bit64" then
CreateObject("Shell.Application").Open("C:\Program Files (x86)\Amibroker\")
else
end if
%>

_SECTION_END();

Hi…

U can refer the below Link…for Order Placement…in Pi From AmiBroker

http://tradingqna.com/12703/amibroker-bridge

Just Ignore the PiBridge code which you are Using Now…as it is complex and was coded during the starting of Pi…I converted those complex code into a dll for easy use…Please refer the above Link.

1 Like

Hi Choks,
Its really awesome explanation reply from you. The step by step details are good with the screenshot. Great work. Keep up. It makes easier the work and time consuming.
The pop up alerts are also good info for the trader rather than blankly placing in the generated alerts.
Nice work.
Regards,
Sangeetha

Hi All,

Exe posted in The Link (http://tradingqna.com/12703/amibroker-bridge) Not Working Now.
Could you Re- Post the link of exe.

Hi Sangeetha,

Are you using code posted by AlgoGeek??

Thanks

HI AlgoGreek,

Could you let me know where to update your code (update it with your inline comments in AFL) for NSE Equity for TCS(for Example).

Also, file Format of Symbolist.txt , orderlog.txt etc?

im trying to enble pi bridge trial , but link not working

My requirement is

  1. In live market (9.15 to 3.30) when Volume goes to 500000 in FO NSE Stock then I want to alert in PI screener

I can not make this coding in PI

Pl Help

Thanks
Somnath Roy