Order placement from amibroker charts

Like in PI, Is it possible to place manual orders directly from the chart of amibroker??

you can not place manual orders directly from the charts of amibroker like we do in zerodha pi

1 Like

Hi  Jagadeesh

Below is the AFL to place Manual Order from Amibroker Chart.

Read the Instructions given in the AFL thoroughly.

If U face any Problem in copy/paste

Then Download the Readymade file from here and copy amibroker Formula/Custom Folder

https://drive.google.com/uc?export=download&id=0B-AWKNHhYByLWmwxSzlNMTBVZzg

Happy Trading


/*
Instructions on How to Use This AFL:-
Step1:
One time Setup
In Amibroker, 
Goto Tools -> Preferences -> Axes/Grids -> UnTick all Check Boxes (six).
Goto Tools -> Preferences -> Colors -> Axis (Line) = WhiteColor & Axis (Text) = WhiteColor & Background = BlackColor. 

Step2:
One time Setup
In Amibroker,
GoTo Analysis -> Formula Editor -> copy/Paste the Below Code and Give a name and save.Ex:- ManualPiBridge.afl
Now AFL is saved in Formulas/Custom Folder.

Step3:
One time Setup
Open a Blank Chart.
Drag and Drop the AFl on this Blank Chart
U'll See the Chart and Buttons

Step4:
One time Setup
Goto Amibroker Directory
U'll Find a text File named SymbolList.txt.
Open that File and enter the all Symbols Details as per the Format in Text File.One Line Per Symbol.
It also Contains Example Line for how to write Symbol Details.
This is onetime Process.If U add New Symbols, then only enter details for that New Symbol Only

   AmibrokerSymbol,TradeSymbol,Exchange,Qty,ClientID,OrderType,ProductType,Validity

   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 CNC
   In Validity - DAY
Step5:
Once U entered symbols Details.
Now U Can see the Symbol Details on Chart.This is to verify the Details.
If any Data is wrong, amend the text File as per requirement.
If all Details are Correct.Then Now U are Ready to place order.
if U not details for any symbol,then Buy/sell Button will not be enabled for that Symbol.


To Test the Pi Bridge

Just Press the "Test Pi Bridge" Button.
Once Pressed, Pi Bridge Red Light in Pi will become Green.
If it Not Turn Green Then.
May be one of the Following Reason
1. U first Opened Amibroker and then Pi.
In this Case Just Close and ReOpen Amibroker and 
Again Press the Button.It'l turn Green

2.U have not Installed Pi Bridge.
Download Pi Bridge from Q and Install It

3.U have not Enabled for PiBridge
Place request in Q

To Place Buy Order.

Just Press the Buy Button
Once Pressed.It'll place order to Pi as per the Symbol Details.

If Order not Fired to Pi
Then U might have entered Wrong Symbol details.
If Order not shown in Generated alert then
In Pi -> User Settings -> Pi Bridge
U might have selected Mock Trade
Change it to Live Semi Automatic Trade.

To Place Sell Order

Same as above.

This AFL will Place only one Buy and One Sell Order Per Bar.
Buttons will be Released only on the Next bar..

To test this AFL

Change time Interval to 5minute
and Bar Replay last Trading day
and practice by Placing Buy and Sell Order
But the above Procedure followed before.


To Place Buy Order

Just Press the BUY Button

*/


_SECTION_BEGIN("Manual Trading Pi Bridge");
//coded by Choks.Mail ur Feedback to tclingam1985@gmail.com
Buy=Sell=Short=Cover=0;
_N(Title = StrFormat("{{NAME}} - {{INTERVAL}} {{DATE}} Open %g, Hi %g, Lo %g, Close %g (%.1f%%) {{VALUES}}", O, H, L, C, SelectedValue( ROC( C, 1 ) ) ));
SetChartOptions (0,chartShowDates|chartShowArrows);SetChartBkColor( colorBlack ) ;SetChartBkGradientFill( colorBlack,colorBlack);Plot(Close,"Close",IIf( C > O, colorBrightGreen, IIf(C <= O,colorRed,colorBlack ) ),styleCandle|styleNoTitle);
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;
DT = LastValue(DateNum(),1);TT = LastValue(TimeNum(),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;
buttonpress = GetCursorMouseButtons() == 9;x1 = Nz( GetCursorXPosition( 1 ) );y1 = Nz( GetCursorYPosition( 1 ) );x2 = Nz( GetCursorXPosition( 1 ) );y2 = Nz( GetCursorYPosition( 1 ) );
BuyBox = x1 >  pxw-304 AND x2 < pxw-236 AND y1 > 58 AND y2 <  92;SellBox = x1 >  pxw-184 AND x2 < pxw-116 AND y1 > 58 AND y2 <  92;PiBox = x1 >  pxw-424 AND x2 < pxw-356 AND y1 > 58 AND y2 <  92;
BuyVar = StaticVarGetText(Name()+"-Buy");BuyVar1 = Name()+"-Buy-"+NumToStr(DT,1.0)+"-"+NumToStr(TT,1.0)+"-"+NumToStr(GetChartID(),1.0);
SellVar = StaticVarGetText(Name()+"-Sell");SellVar1 = Name()+"-Sell-"+NumToStr(DT,1.0)+"-"+NumToStr(TT,1.0)+"-"+NumToStr(GetChartID(),1.0);
if (buttonpress AND Buybox  AND BuyVar != BuyVar1 AND Sym != ""){brd = CreateStaticObject("pibridge.Bridge");brd.PlaceOrder (Exch,TrdSym,StrLeft(Sym,10),"BUY-MT",1,Qty,0,TrdPrice,0,ORdType,ProdType,ClientId,Val);StaticVarSetText(Name()+"-Buy",BuyVar1);}
if (buttonpress AND Sellbox AND SellVar != SellVar1 AND Sym != ""){brd = CreateStaticObject("pibridge.Bridge");brd.PlaceOrder (Exch,TrdSym,StrLeft(Sym,10),"SELL-MT",2,Qty,0,TrdPrice,0,ORdType,ProdType,ClientId,Val);StaticVarSetText(Name()+"-Sell",SellVar1);}
if (buttonpress AND pibox ){brd = CreateStaticObject("pibridge.Bridge");}
display = ParamToggle("Display Symbol Details","Yes|No",1);if(display==1){GfxSelectPen( colorRed,2 ); 
GfxSelectSolidBrush( colorOrange );GfxRectangle(3,105,200,250);GfxTextOut("SYMBOL: " + sym,5,110);GfxTextOut("TRADE SYMBOL: " + Trdsym,5,130);
GfxTextOut("EXCH: " + Exch,5,150);GfxTextOut("CLIENT ID: " + Clientid,5,170);GfxTextOut("PROD TYPE: " + prodtype,5,190);GfxTextOut("ORDER TYPE: " + ORdtype,5,210);GfxTextOut("QTY: " + WriteVal(Qty,1.0),5,230);}
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);}
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);}}
GfxSelectFont( "Lucida Fax", 8.5, 700, False );GfxSetTextColor( colorGold );GfxTextOut("Coded by Choks",(pxw/2)-50,pxh-40);GfxTextOut("Mail Ur Feedback to tclingam1985@gmail.com",(pxw/2)-130,pxh-30);
if (SellVar != SellVar1 AND Sym != "")
{GfxSetTextColor( colorWhite );GfxSelectFont( "Lucida Fax", 14, 700, False );GfxSelectPen( colorDarkRed,2 );GfxSelectSolidBrush( colorRed );GfxRectangle(pxw-200,50,pxw-100,100);GfxPolygon(pxw-200,50,pxw-100,100,pxw-100,50,pxw-200,100);GfxRectangle(pxw-184,58,pxw-116,92);GfxTextOut("SELL",pxw-174,64);}
else{GfxSetTextColor( colorGrey50 );GfxSelectFont( "Lucida Fax", 14, 700, False );GfxSelectPen( colorGrey50,2 ); GfxSelectSolidBrush( colorGrey40 );GfxRectangle(pxw-200,50,pxw-100,100);GfxPolygon(pxw-200,50,pxw-100,100,pxw-100,50,pxw-200,100);GfxRectangle(pxw-198,51,pxw-101,99);GfxTextOut("SELL",pxw-174,64);}
if (BuyVar != BuyVar1 AND Sym != "")
{GfxSetTextColor( colorWhite );GfxSelectFont( "Lucida Fax", 14, 700, False );GfxSelectPen( colorDarkGreen,2 ); GfxSelectSolidBrush( colorGreen );GfxRectangle(pxw-320,50,pxw-220,100);GfxPolygon(pxw-320,50,pxw-220,100,pxw-220,50,pxw-320,100);GfxRectangle(pxw-304,58,pxw-236,92);GfxTextOut("BUY",pxw-290,64);}
else{GfxSetTextColor( colorGrey50 );GfxSelectFont( "Lucida Fax", 14, 700, False );GfxSelectPen( colorGrey50,2 ); GfxSelectSolidBrush( colorGrey40 );GfxRectangle(pxw-320,50,pxw-220,100);GfxPolygon(pxw-320,50,pxw-220,100,pxw-220,50,pxw-320,100);GfxRectangle(pxw-318,51,pxw-221,99);GfxTextOut("BUY",pxw-290,64);}
GfxSetTextColor( colorWhite );GfxSelectFont( "Lucida Fax", 8.5, 700, False );GfxSelectPen( colorDarkBlue,2 );GfxSelectSolidBrush( colorBlue );GfxRectangle(pxw-440,50,pxw-340,100);GfxPolygon(pxw-440,50,pxw-340,100,pxw-340,50,pxw-440,100);GfxRectangle(pxw-424,58,pxw-356,92);GfxTextOut("TEST",pxw-406,60);GfxTextOut("PI BRIDGE",pxw-420,75);
GfxSetTextColor( colorBlack );GfxSelectFont( "Lucida Fax", 14, 700, False );GfxSetTextAlign(0); GfxSelectPen( colorOrange,2 ); GfxSelectSolidBrush( colorWhite );GfxRectangle(pxw-270,15,pxw-150,45);GfxTextOut(WriteVal(LastValue(C,1),1.2),pxw-250,20);
_SECTION_END();

3 Likes

Hi Jagadeesh,
It is possible to add Buy/Sell Button to amibroker Chart.
To place Order U have to simply press the respective Button.
U Can do this with AFL.
I’ll try to post the code by this week end.

Thanks alot sir… :slight_smile:

thank you so much sir…:slight_smile:

working perfectly. Thanks Choks!

Hello Sir… Thanks again for the AFL. It is highly helpful. But one help.
I want to set the background color to white and the text color to black as I have been using white background for years. Can you please tell me which parameters to change in the given AFL as I find a lot of parameters which are assigned with colorBlack and colorWhite.
Thanks in advance. :slight_smile:

Hi Jagadeesh…
I missed ur comment…
I removed the Chart Color options from the AFL…So U can set whatever the color u wish in Preferences.
Now the entire AFL is recoded and it uses dll to place order…
Download the Manual Trading AFL from…
https://drive.google.com/open?id=0B-AWKNHhYByLQVNYak9IX2FFbDg
Download the DLL’s from…
https://drive.google.com/open?id=0B-AWKNHhYByLUUhOMk5MdGppQWc
https://drive.google.com/open?id=0B-AWKNHhYByLaEplVEZuQkg2b3M
Please Go through the Below Links…


1 Like

Hi ChokS,
Many thanks for this.
When we fire BUY/SELL orders from Amibroker using the BUY/SELL buttons like this, will it generate BUY/SELL alert in Pi as in semi automatic trading and then we submit the order or it will directly place the order in Pi?
Thanks
bk

Hi Bk…
It has options for Both Manual and Auto Submit…
Please go through the Help Files…