Stock Portfolio Organizer
The ultimate porfolio management solution.
WiseTrader Toolbox
#1 Selling Amibroker Plugin featuring:
Maual Trading Control for NEST/NOW for Amibroker (AFL)
Maual Trading Control for NEST/NOW
Now we have afl available for automating the trading from NEST/NOW from a strategy using Nest Plus Plugin.
But if you want to manually take decision, what is the solution?
Looking the chart and placing a manual Buy Or Sell will take few time to place the order. By the time the trend may disappear.
This afl will provide you a control for generating Buy and Sell Signals from clicking the buttons in the chart.
Features
- You can predefine your quantity of Buy/Sell in the parameters
- You Can Enter your Client ID in the Parameters
- You can select the Buy/Sell Price from Ask price, Bid price or LTP.
- Option for Enabling Actual Trading (If Disabled, No Signals will go to NOW/NEST, But chart will generate signals.) This can be used for testing.
- Selecting the Buy/Sell as Intraday or Delivery.
Requirements.
- For Buy/Sell Price selection, use Aux1 and Aux2 for importing the Ask Bid Prices.
- Symbol in the Amibroker should be the same as present in the NEST/NOW.
- Active Nest Plus API Subscription is required (Contact Nest Plus for Details)
Usage
- Copy The Afl to Custom Afl folder of amibroker.
- Drag and drop the afl to an intraday chart blank chart.
- Enable Controls and Auto Trading Options.
- Set Lot Qty and Purchase Type.
- Type the Client ID.
- Press Buy Or Sell when you decided.
(Decisions should be based on your trading strategy. This Afl will not generate any Buy/Sell Signals automatically)
[Suggest Features For Improvement]
[NEST, NOW, Amibroker are registered products of the Respective Companies]
Screenshots
Indicator / Formula
Title = " "; _SECTION_BEGIN("MaualTradingInt1V00 "); X2 = Param("Button X Offset", 0, 0, 2000, 100); Y2 = Param("Button Y Offset", 0, 0, 2000, 100); X1 = Param("Button Size", 100, 100, 300, 50); EnableRealTimeControl = ParamList("Enable Controls", "No|Yes", 0); EnableAutoTrade = ParamList("Enable Autotrade", "No|Yes", 0); BuyPriceSelection = ParamList("Buy Price", "Bid Price|Ask Price|LTP", 0); SellPriceSelection = ParamList("Sell Price", "Ask Price|Bid Price|LTP", 0); ProductType = ParamList("Product Type", "MIS|NRML", 0); OrderType = ParamList("Order Type", "LIMIT|MARKET", 0); ClientIdValue = ParamStr("Client Id", "CLIENTID"); LotQuantity = Param("Lot Quantity", 1000, 50, 100000, 10); // Default Trade Qty. //firstflag=0; if(StaticVarGetText("firstflag")=="") { StaticVarSet("OrderNo", 0); StaticVarSet("LTPSave", 0); StaticVarSet("LTQSave", 0); StaticVarSet("VolumeTemp", 0); StaticVarSet("AskSave", 0); StaticVarSet("BidSave", 0); StaticVarSet("LastLTPColor", colorGrey40); StaticVarSet("LastLTQColor", colorGrey40); StaticVarSet("LastAskColor", colorGrey40); StaticVarSet("LastBidColor", colorGrey40); StaticVarSetText ("firstflag","0"); } if(StaticVarGetText("firstflag"+Name())=="") { StaticVarSet(("Buy_Price" + Name()), 0); StaticVarSet(("Buy_Qty" + Name()), 0); StaticVarSet(("Sell_Price" + Name()), 0); StaticVarSet(("Sell_Qty" + Name()), 0); StaticVarSet(("AvgBuy_Price" + Name()), 0); StaticVarSet(("NetBuy_Qty" + Name()), 0); StaticVarSet(("AvgSell_Price" + Name()), 0); StaticVarSet(("NetSell_Qty" + Name()), 0); StaticVarSetText("firstflag"+Name(), "0"); } if(EnableAutoTrade == "Yes" && EnableRealTimeControl == "Yes") { if(StaticVarGetText("firstflagforNest")=="") { nestplus = Null; if(IsNull(nestplus)) { nestplus = CreateStaticObject("Nest.PlusApi"); nestplus.SetObjectName("RKRAutoTrade"); } StaticVarSetText ("firstflagforNest","0"); } } TempBuyPrice = StaticVarGet(("Buy_Price" + Name())); TempSellPrice = StaticVarGet(("Sell_Price" + Name())); TempBuyQty = StaticVarGet(("Buy_Qty" + Name())); TempSellQty = StaticVarGet(("Sell_Qty" + Name())); LTPTemp = StaticVarGet("LTPSave"); LTQTemp = StaticVarGet("LTQSave"); VolumeTemp = StaticVarGet("VolumeTemp"); AskTemp = StaticVarGet("AskSave"); BidTemp = StaticVarGet("BidSave"); LTPLastTemp = LastValue(C); VolumeLastTemp = LastValue(Volume); LTQLastTemp = (VolumeLastTemp - VolumeTemp); if(LTQLastTemp < 0) { LTQLastTemp = LTQLastTemp * -1; } if(LTQLastTemp == 0) { LTQLastTemp = LTQTemp; } AskLastTemp = LastValue(Aux1); BidLastTemp = LastValue(Aux2); LTPColor = StaticVarGet("LastLTPColor"); LTQColor = StaticVarGet("LastLTQColor"); AskColor = StaticVarGet("LastAskColor"); BidColor = StaticVarGet("LastBidColor"); if(LTPTemp > LTPLastTemp) { LTPColor = colorRed; } else if(LTPTemp < LTPLastTemp) { LTPColor = ColorGreen; } if(LTQTemp > LTQLastTemp) { LTQColor = colorRed; } else if(LTQTemp < LTQLastTemp) { LTQColor = ColorGreen; } if(AskTemp > AskLastTemp) { AskColor = colorRed; } else if(AskTemp < AskLastTemp) { AskColor = ColorGreen; } if(BidTemp > BidLastTemp) { BidColor = colorRed; } else if(BidTemp < BidLastTemp) { BidColor = ColorGreen; } StaticVarSet("LastLTPColor", LTPColor); StaticVarSet("LastLTQColor", LTQColor); StaticVarSet("LastAskColor", AskColor); StaticVarSet("LastBidColor", BidColor); StaticVarSet("LTPSave", LTPLastTemp); StaticVarSet("LTQSave", LTQLastTemp); StaticVarSet("VolumeTemp", VolumeLastTemp); StaticVarSet("AskSave", AskLastTemp); StaticVarSet("BidSave", BidLastTemp); X0 = 20; Y0 = 10; procedure DrawData (Text, x1, y1, x2, y2, colorFrom, colorTo) { GfxSetOverlayMode(0); GfxSelectFont("Verdana", 8.5, 700); GfxSetBkMode(1); GfxGradientRect(x1, y1, x2, y2, colorFrom, colorTo); GfxDrawText(Text, x1, y1, x2, y2, 32|1|4|16); } GfxSetTextColor(colorWhite); NetBuyQtyDisplay = StaticVarGet(("NetBuy_Qty" + Name())); if(NetBuyQtyDisplay == 0) { BuyAvgPriceDisplay = 0; } else { BuyAvgPriceDisplay = (StaticVarGet(("AvgBuy_Price" + Name())))/(NetBuyQtyDisplay/LotQuantity); } NetSellQtyDisplay = StaticVarGet(("NetSell_Qty" + Name())); if(NetSellQtyDisplay == 0) { SellAvgPriceDisplay = 0; } else { SellAvgPriceDisplay = (StaticVarGet(("AvgSell_Price" + Name())))/(NetSellQtyDisplay/LotQuantity); } TempNetQuantity = NetBuyQtyDisplay - NetSellQtyDisplay; TempNetValue = (SellAvgPriceDisplay * NetSellQtyDisplay) - (BuyAvgPriceDisplay * NetBuyQtyDisplay); TempNetQuantityColor = colorGrey40; TempNetValueColor = colorGrey40; if(TempNetQuantity > 0) { TempNetQuantityColor = colorGreen; } else if(TempNetQuantity < 0) { TempNetQuantityColor = colorRed; } if(TempNetValue > 0) { TempNetValueColor = colorGreen; } else if(TempNetValue < 0) { TempNetValueColor = colorRed; } DrawData (Name(), X0, Y0, X0+300, Y0+20, colorGrey40, colorGrey40); DrawData (Date(), X0+305, Y0, X0+470, Y0+20, colorGrey40, colorGrey40); DrawData ("Open : " + Open, X0+475, Y0, X0+625, Y0+20, colorGrey40, colorGrey40); DrawData ("Close : " + Close, X0+630, Y0, X0+780, Y0+20, colorGrey40, colorGrey40); DrawData ("High : " + High, X0+785, Y0, X0+935, Y0+20, colorGrey40, colorGrey40); DrawData ("Low : " + Low, X0+940, Y0, X0+1090, Y0+20, colorGrey40, colorGrey40); DrawData ("Volume : " + NumToStr(Volume,1,0), X0+1095, Y0, X0+1300, Y0+20, colorGrey40, colorGrey40); DrawData ("% Change : " + NumToStr( (((C-O)*100)/O), 1.2, True), X0+1305, Y0, X0+1450, Y0+20, colorGrey40, colorGrey40); if(EnableRealTimeControl == "Yes") { DrawData ("Buy Price : " + TempBuyPrice, X0, Y0+25, X0+150, Y0+45, colorGrey40, colorGrey40); DrawData ("Buy Qty : " + TempBuyQty, X0+155 , Y0+25, X0+305, Y0+45, colorGrey40, colorGrey40); DrawData ("Sell Price : " + TempSellPrice, X0+310, Y0+25, X0+460, Y0+45, colorGrey40, colorGrey40); DrawData ("Sell Qty : " + TempSellQty, X0+465, Y0+25, X0+615, Y0+45, colorGrey40, colorGrey40); DrawData ("BuyAvgPrice : " + BuyAvgPriceDisplay, X0+620, Y0+25, X0+770, Y0+45, colorGrey40, colorGrey40); DrawData ("NetBuyQty : " + NetBuyQtyDisplay, X0+775 , Y0+25, X0+925, Y0+45, colorGrey40, colorGrey40); DrawData ("SellAvgPrice : " + SellAvgPriceDisplay, X0+930, Y0+25, X0+1080, Y0+45, colorGrey40, colorGrey40); DrawData ("NetSellQty : " + NetSellQtyDisplay, X0+1085, Y0+25, X0+1235, Y0+45, colorGrey40, colorGrey40); TempNestOredrNo = ClientIdValue + NumToStr(Now(3),1,0) + "00" + StaticVarGet("OrderNo"); DrawData ("NetQty : " + TempNetQuantity, X0+520, Y0+50, X0+670, Y0+70, TempNetQuantityColor, TempNetQuantityColor); DrawData ("NetValue : " + TempNetValue, X0+675, Y0+50, X0+900, Y0+70, TempNetValueColor, TempNetValueColor); DrawData ("Order No : " + TempNestOredrNo, X0+905, Y0+50, X0+1150, Y0+70, colorGrey40, colorGrey40); DrawData ("LTP : " + LTPLastTemp, X0, Y0+50, X0+125, Y0+70, LTPColor, LTPColor); DrawData ("LTQ : " + NumToStr(LTQLastTemp,1,0), X0+130, Y0+50, X0+255, Y0+70, LTQColor, LTQColor); DrawData ("Bid : " + BidLastTemp, X0+260, Y0+50, X0+385, Y0+70, AskColor, AskColor); DrawData ("Ask : " + AskLastTemp, X0+390, Y0+50, X0+515, Y0+70, BidColor, BidColor); } X0 = X2 + 20; Y0 = Y2 + 100; LBClick = GetCursorMouseButtons() == 9; // Click MouseX = Nz(GetCursorXPosition(1)); // MouseY = Nz(GetCursorYPosition(1)); // procedure DrawBut (Text, x1, y1, x2, y2, colorFrom, colorTo) { GfxSetOverlayMode(0); GfxSelectFont("Verdana", 9, 700); GfxSetBkMode(1); GfxGradientRect(x1, y1, x2, y2, colorFrom, colorTo); GfxDrawText(Text, x1, y1, x2, y2, 32|1|4|16); } GfxSetTextColor(colorWhite); if(EnableRealTimeControl == "Yes") { DrawBut ("Buy", X0, Y0, X0+X1, Y0+30, colorGreen, colorGreen); CursorInBuyButton = MouseX >= X0 AND MouseX <= X0+X1 AND MouseY >= Y0 AND MouseY <= Y0+30; BuyButtonClick = CursorInBuyButton AND LBClick; if (BuyButtonClick) { DrawBut("Buy", X0+X1+10, Y0, X0+X1+75, Y0+30, colorGrey40, colorGrey40); TempBuy = LastValue(DateTime()); StaticVarSet(("BuyIndex" + Name()), TempBuy); TempBuyLastQty = StaticVarGet(("NetBuy_Qty" + Name())); TempNetBuyQty = (TempBuyLastQty + LotQuantity); TempBuyLastPrice = StaticVarGet(("AvgBuy_Price" + Name())); if(BuyPriceSelection == "Bid Price") { BuyPriceValue = BidLastTemp; } else if(BuyPriceSelection == "Ask Price") { BuyPriceValue = AskLastTemp; } else { BuyPriceValue = LTPLastTemp; } if(TempBuyLastQty == 0) { TempAvgBuyPrice = BuyPriceValue; } else { TempAvgBuyPrice = (BuyPriceValue + TempBuyLastPrice); } StaticVarSet(("Buy_Price" + Name()), BuyPriceValue); StaticVarSet(("Buy_Qty" + Name()), LotQuantity); StaticVarSet(("AvgBuy_Price" + Name()), TempAvgBuyPrice); StaticVarSet(("NetBuy_Qty" + Name()), TempNetBuyQty); if(EnableAutoTrade == "Yes" && EnableRealTimeControl == "Yes") { LastOrderNo = StaticVarGet("OrderNo"); LastOrderNo++; StaticVarSet("OrderNo", LastOrderNo); TempOrderNo = ClientIdValue + NumToStr(Now(3),1,0) + "00" + LastOrderNo; TempName = Name() + "-EQ"; nestplus.PlaceOrder("BUY", TempOrderNo, "NSE", TempName, "DAY", OrderType, LotQuantity, BuyPriceValue, 0.0, 0, ProductType, ClientIdValue); } } DrawBut ("Sell", X0, Y0+40, X0+X1, Y0+70, colorRed, colorRed); CursorInSellButton = MouseX >= X0 AND MouseX <= X0+X1 AND MouseY >= Y0+40 AND MouseY <= Y0+70; SellButtonClick = CursorInSellButton AND LBClick; if (SellButtonClick) { DrawBut("Sell", X0+X1+10, Y0, X0+X1+75, Y0+30, colorGrey40, colorGrey40); TempSell = LastValue(DateTime()); StaticVarSet(("SellIndex" + Name()), TempSell); TempSellLastQty = StaticVarGet(("NetSell_Qty" + Name())); TempNetSellQty = (TempSellLastQty + LotQuantity); TempSellLastPrice = StaticVarGet(("AvgSell_Price" + Name())); if(SellPriceSelection == "Ask Price") { SellPriceValue = AskLastTemp; } else if(SellPriceSelection == "Bid Price") { SellPriceValue = BidLastTemp; } else { SellPriceValue = LTPLastTemp; } if(TempSellLastQty == 0) { TempAvgSellPrice = SellPriceValue; } else { TempAvgSellPrice = (SellPriceValue + TempSellLastPrice); } StaticVarSet(("Sell_Price" + Name()), SellPriceValue); StaticVarSet(("Sell_Qty" + Name()), LotQuantity); StaticVarSet(("AvgSell_Price" + Name()), TempAvgSellPrice); StaticVarSet(("NetSell_Qty" + Name()), TempNetSellQty); if(EnableAutoTrade == "Yes" && EnableRealTimeControl == "Yes") { LastOrderNo = StaticVarGet("OrderNo"); LastOrderNo++; StaticVarSet("OrderNo", LastOrderNo); TempOrderNo = ClientIdValue + NumToStr(Now(3),1,0) + "00" + LastOrderNo; TempName = Name() + "-EQ"; nestplus.PlaceOrder("SELL", TempOrderNo, "NSE", TempName, "DAY", OrderType, LotQuantity, SellPriceValue, 0.0, 0, ProductType, ClientIdValue); } } DrawBut ("Clear Data", X0, Y0+80, X0+X1, Y0+110, colorGrey40, colorGrey40); CursorInClearButton = MouseX >= X0 AND MouseX <= X0+X1 AND MouseY >= Y0+80 AND MouseY <= Y0+110; ClearButtonClick = CursorInClearButton AND LBClick; if (ClearButtonClick) { DrawBut("Clear", X0+X1+10, Y0, X0+X1+75, Y0+30, colorGrey40, colorGrey40); StaticVarRemove(("BuyIndex" + Name())); StaticVarRemove(("SellIndex" + Name())); StaticVarSetText("firstflag"+Name(), ""); } BuyTempData = StaticVarGet(("BuyIndex" + Name())); SellTempData = StaticVarGet(("SellIndex" + Name())); Buy = IIF(DateTime() == BuyTempData, 1, 0); Sell = IIF(DateTime() == SellTempData, 1, 0); Buyshape = Buy * shapeUpArrow; SellShape = Sell * shapeDownArrow; PlotShapes( Buyshape, colorBrightGreen, 0, Low ); PlotShapes( SellShape, colorRed, 0, High ); GraphXSpace = 5; } _SECTION_END(); _SECTION_BEGIN("Price"); SetChartOptions(0,chartShowArrows|chartShowDates); //_N(Title = StrFormat("{{NAME}} - {{INTERVAL}} {{DATE}} \nOpen : %g, Close : %g (%.1f%%) \nLow : %g, High : %g (%.1f%%) \nVolume : " +WriteVal( V, 1.0 ) +" {{VALUES}}", O, C,(((C-O)*100)/O), L, H, (((H-L)*100)/L) )); Plot( C, "Close", ParamColor("Color", colorDefault ), styleNoTitle | ParamStyle("Style") | GetPriceStyle() ); _SECTION_END(); _SECTION_BEGIN("MA"); P = ParamField("Price field",-1); Periods = Param("Periods", 10, 2, 200, 1 ); Plot( MA( P, Periods ), /*_DEFAULT_NAME()*/ "", ParamColor( "Color", colorGreen ), ParamStyle("Style", styleLine | styleNoLabel ) | styleNoRescale ); _SECTION_END(); _SECTION_BEGIN("EMA"); P = ParamField("Price field",-1); Periods = Param("Periods", 30, 2, 300, 1, 10 ); Plot( EMA( P, Periods ), /*_DEFAULT_NAME()*/ "", ParamColor( "Color", colorOrange ), ParamStyle("Style", styleLine | styleNoLabel) | styleNoRescale ); _SECTION_END(); _SECTION_BEGIN("Long MA"); P = ParamField("Price field",-1); Periods = Param("Periods", 45, 2, 400, 1 ); Plot( MA( P, Periods ), /*_DEFAULT_NAME()*/ "", ParamColor( "Color", colorYellow ), ParamStyle("Style", styleLine | styleNoLabel ) | styleNoRescale ); _SECTION_END(); _SECTION_BEGIN("BBands"); P = ParamField("Price field",-1); Periods = Param("Periods", 15, 2, 100, 1 ); Width = Param("Width", 2, 0, 10, 0.05 ); Color = ParamColor("Color", colorLightGrey ); Color = ColorBlend( Color, GetChartBkColor(), 0.5 ); Style = ParamStyle("Style", styleLine | styleNoLabel ) | styleNoRescale;; Plot( bbt = BBandTop( P, Periods, Width ), /*"BBTop" + _PARAM_VALUES()*/ "", Color, Style ); Plot( bbb = BBandBot( P, Periods, Width ), /*"BBBot" + _PARAM_VALUES()*/ "", Color, Style ); PlotOHLC( bbt, bbt, bbb, bbb, "", ColorBlend( Color, GetChartBkColor(), 0.7 ), styleNoLabel | styleCloud | styleNoRescale, Null, Null, Null, -1 ); _SECTION_END(); _SECTION_BEGIN("Volume"); Color = ParamColor("Color", ColorRGB( 128, 128, 192 ) ); Plot( Volume, /*_DEFAULT_NAME()*/"", ColorBlend( Color, GetChartBkColor(), 0.2 ), styleNoTitle | ParamStyle( "Style", styleHistogram | styleOwnScale | styleThick | styleNoLabel, maskHistogram ), 2 ); _SECTION_END();
15 comments
Leave Comment
Please login here to leave a comment.
Back
thanks for sharing the code
but it has errors
StaticVarSet(“OrderNo”, 0, 1);
StaticVarSet(“LTPSave”, LTPLastTemp, 1);
error is too many arguments I am using amibroker 5.6
from the help of amibroker user guide
StaticVarSet( ’’varname’’, value ) RETURNS NUMBER
Sets the value of static variable. Returns 1 on success 0 on failure.
if you correct this or give a solution it will be helpful
thanks
I am using Amibroker 5.9 and the code is not giving any error. If possible, update the Amibroker to the latest version.
Else try deleting the last parameter on the StaticVarSet statement. You should do this for all the StaticVarSet function.
Eg:
StaticVarSet(“OrderNo”, 0, 1); → StaticVarSet(“OrderNo”, 0);
Thanks for sharing the code, ranjicgnr. Is it possible to automate the trades fully, adding this code to my existing afl which gives Buy/Sell? If yes, what r the changes to be made to your afl?
Hai aroonsankar.
Yes. You can fully automate the trades. You have to add your code in the beginning of my code. Then replace the button check condition with your yor Buy/Sell condition check. ie [if (BuyButtonClick)& if (SellButtonClick) ]
I will post a new afl with manual and auto buy options. It may take some time.
Thanks Ranji for your prompt reply. Your Afl was much awaited one by many traders. Waiting more build-up.
Dear ranji sir,
when you post kindly post afl compatible with 5.7 version as this buy botton not working in 5.7 version, throwing some error.
Kindly consider this when you post the new afl
Thank you and regards
Srini
Dear Srini,
Thanks for testing afl. But i have tested with Amibroker 5.7 version also. The buttons are working for me. Check are you selected Yes for Enable AutoTrade. If you enabled this, you should need a NEST PLUS API subscription from your broker/omnisys and the NEST/NOW trader must be opened and logged in. Else this will give an error. Error may be “COM object handle is null”.
Use “AutoTrade Control For NEST/NOW” instead of this. That is an updated version.
dear ranji sir,
I need your mail id to contact you or your no for my strategy framework to associate with company.
My Mail ID is ranjicgnr@gmail.com
dear ranjicgnr,
i’m getting an error ‘COM object variable is not initialized or has invalid type(valid COM object handle is required)’. I have enabled NEST PLUS API subscription.Is that another Nest Plus Api DEALER required to run this afl?
Dear Ranjith
I can’t able to plungin your Afl. How to plugin?
For detailed help, mail me.
ranjicgnr@gmail.com
Hi,
Anyone got this working for NFO kindly post the modified code. Keep getting error ‘COM object variable is not initialized or has invalid type(valid COM object handle is required)’. Using Trial ami 5.9, and GDFl datafeed , Tried reinstallation of ami, as suggested by someone else in the forum with no luck. Strangely the GDFL plugin works fine.
Thanks in advance
Both the Manual and Auto afl are not working for me
for manual iam getting the below error
COM object variable is not initialized or has invalid type(valid COM object handle is required)
For Auto i am getting below error when i try to enable controls
Ln:541,Col:46
Error51.
Array subscript has null value. Subscript must be within 0…BarCount-1 range.