//Author : Ranjicgnr
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
LBClickB =IIf(ExRem(Buy11,Sell11),1,0);
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 LBClickB;
if (BuyButtonClick=1)
{
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);
}
}
LBClickS=IIf(ExRem(Sell11,Buy11),1,0);
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 LBClickS;
if (SellButtonClick=1)
{
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() );