Simple Coding Help - No Promise.

trash

Well-Known Member
hello,

Secondly as for the reason why m2 is not recognized is because you have a loop there and m2 is true only when i == 2! So during iteration when "i" is lower than 2 then there is no m2 var. In order to remove error you would have to add

I'm using loop less than 3 , 2 is already within loop.
for( i = 1; i < 3; i++ )


if i use if ( i == 2 )
What if i use
VarSet( "M" + i, TimeFrameExpand( up, i*in1Second , expandPoint ) );

Within 1 minute i have to write if ( i == 2 ) ,.....if if ( i == 60 )
for each condition ..
if i am writing between 10 seconds to 30 seconds between then I have to write
i == 10 to ..... i ==29, i ==30


And this one VarGet("M2") of your most recent code is completely wrong (subscript within varget string).

but don't VarGet("M2") represent 2 number under candle, then why it can't print _m


{


yes Firstvisiblebar,Lastvisiblebar can be used, but it doesn't help plot _m ..


Listen, if you wanna talk to me then use understandable English and proper style of posting. I'm not going to decipher your handwriting every time. Also you should avoid arguing about what is right or wrong with someone knowing better how to code. Rather listen and apply. You don't need conditions such as if ( i == ... ) at all the same way as you don't need varset/varget here. It's all unnecessary overhead.
 

LOVEENAJYOTHI

Well-Known Member
I wont do for you anything when i see this post.
Because, Your are like same person on the other tread, you request something, but want the code expert to do all the work from head to tail.

your case, must go and find the code for you.
Why not you to and present the code here, and describe properly how
to be done so save time for the code expert.


I also got a lot work to do.
Sorry. I think too complicated for me. Not interested.
Didn't get who u r referring to ,
Pasting below 3 AFLs where Buttons are created on chart.
My Request is not for any full AFL, rather i need ur expert advise/ Guidance.

My Requirement;
Buy1=BuyCondition;
Buy2= PressBuyButton;
Buy=Buy1 OR Buy2;

Need coding guidance to PressBuyButton which if pressed, should trigger a Buy signal on Chart/Scan/Explore as a Valid Buy condition and the Signal should Remain permanently or atleast till the close of Amibroker.

Thanx n Rgrds


Code:
Title = "";
formulaName = "Control Panel";
GfxSetBkMode(1);
GfxSelectFont("Verdana", 18, 700, italic=False);
GfxSetTextColor(colorBrightGreen);
GfxTextOut(FormulaName, 20, 10);

_SECTION_BEGIN("Control Panel");
// Base point - Left Up Corner
X0 = Param ("X - Left Up Corner",   20,   4,  200, 10);
Y0 = Param ("Y - Right Up Corner",   120,  40, 200, 10);

// --- Button pressed
LBClick = GetCursorMouseButtons() == 9;	// Click
MouseX  = Nz(GetCursorXPosition(1));		// 
MouseY  = Nz(GetCursorYPosition(1));		// 

// --- Button Draw
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);

// Button Begin
DrawBut ("Begin", X0, Y0, X0+170, Y0+30, colorGrey40, colorGrey40);
CursorInResetBut = MouseX >= X0 AND MouseX <= X0+170 AND MouseY >= Y0 AND MouseY <= Y0+30;
ResetPressed = CursorInResetBut AND LBClick;
if (ResetPressed) 
{ 
StaticVarSet ("RS", 1);      
StaticVarSet ("AutoOn",  0); 
StaticVarSet ("AutoOff", 1); 
StaticVarSet ("SMKT",    0); 
StaticVarSet ("BMKT",    0);
StaticVarSet ("CLPOS",   0);
StaticVarSet ("CANC",    0);
StaticVarSet ("ExpOn",   0); 
StaticVarSet ("ExpOff",  1);
}

// Button Auto on
DrawBut ("Auto on", X0, Y0+40, X0+170, Y0+70, colorDarkGreen, colorDarkGreen);
CursorInAutoOnBut = MouseX >= X0 AND MouseX <= X0+170 AND MouseY >= Y0+40 AND MouseY <= Y0+70;
AutoOnPressed = CursorInAutoOnBut AND LBClick;
if (AutoOnPressed) 
{ 
StaticVarSet ("RS", 0);
StaticVarSet ("AutoOn",  1);
StaticVarSet ("AutoOff", 0);
StaticVarSet ("SMKT",    0); 
StaticVarSet ("BMKT",    0);
StaticVarSet ("CLPOS",   0);
StaticVarSet ("CANC",    0);
}

// Button Auto off
DrawBut ("Auto off", X0, Y0+80, X0+170, Y0+110, colorDarkRed, colorDarkRed);
CursorInAutoOffBut = MouseX >= X0 AND MouseX <= X0+170 AND MouseY >= Y0+80 AND MouseY <= Y0+110;
AutoOffPressed = CursorInAutoOffBut AND LBClick;
if (AutoOffPressed) 
{ 
StaticVarSet ("RS", 0);
StaticVarSet ("AutoOn",  0); 
StaticVarSet ("AutoOff", 1);
StaticVarSet ("SMKT",    0); 
StaticVarSet ("BMKT",    0);
StaticVarSet ("CLPOS",   0);
StaticVarSet ("CANC",    0);
}

// Button Sell Market
DrawBut ("Sell Market", X0, Y0+130, X0+170, Y0+180, colorRed, colorRed);
CursorInSMKTBut = MouseX >= X0 AND MouseX <= X0+170 AND MouseY >= Y0+130 AND MouseY <= Y0+180;
SMKTPressed = CursorInSMKTBut AND LBClick;
if ( SMKTPressed AND StaticVarGet ("AutoOff")==1  AND StaticVarGet ("ExpOn")==1 )
{ 
StaticVarSet ("RS", 0);
StaticVarSet ("SMKT",  1);
StaticVarSet ("BMKT",  0);
StaticVarSet ("CLPOS", 0);
StaticVarSet ("CANC",  0);
}

// Button Buy Market
DrawBut ("Buy Market", X0, Y0+190, X0+170, Y0+240, colorLime, colorLime);
CursorInBMKTBut = MouseX >= X0 AND MouseX <= X0+170 AND MouseY >= Y0+190 AND MouseY <= Y0+240;
BMKTPressed = CursorInBMKTBut AND LBClick;
if ( BMKTPressed AND StaticVarGet ("AutoOff")==1  AND StaticVarGet ("ExpOn")==1 )
{ 
StaticVarSet ("RS", 0);
StaticVarSet ("SMKT",  0); 
StaticVarSet ("BMKT",  1);
StaticVarSet ("CLPOS", 0);
StaticVarSet ("CANC",  0);
}

// Button Close Position
DrawBut ("Close Position", X0, Y0+250, X0+170, Y0+300, colorGrey40, colorGrey40);
CursorInCloseBut = MouseX >= X0 AND MouseX <= X0+170 AND MouseY >= Y0+250 AND MouseY <= Y0+300;
ClosePressed = CursorInCloseBut AND LBClick;
if ( ClosePressed AND StaticVarGet ("AutoOff")==1  AND StaticVarGet ("ExpOn")==1 )
{ 
StaticVarSet ("RS", 0);
StaticVarSet ("SMKT",  0); 
StaticVarSet ("BMKT",  0);
StaticVarSet ("CLPOS", 1);
StaticVarSet ("CANC",  0);
}

// Button Cancel All Orders
DrawBut ("Cancel All Orders", X0, Y0+310, X0+170, Y0+360, colorGrey40, colorGrey40);
CursorInCancelBut = MouseX >= X0 AND MouseX <= X0+170 AND MouseY >= Y0+310 AND MouseY <= Y0+360;
CancelPressed = CursorInCancelBut AND LBClick;
if ( CancelPressed AND StaticVarGet ("AutoOff")==1 AND StaticVarGet ("ExpOn")==1 )
{ 
StaticVarSet ("RS", 0);
StaticVarSet ("SMKT",  0); 
StaticVarSet ("BMKT",  0);
StaticVarSet ("CLPOS", 0);
StaticVarSet ("CANC",  1);
}

// Button Export On
DrawBut ("Export On", X0, Y0+380, X0+170, Y0+410, colorDarkGreen, colorDarkGreen);
CursorInExpOnBut = MouseX >= X0 AND MouseX <= X0+170 AND MouseY >= Y0+380 AND MouseY <= Y0+410;
ExpOnPressed = CursorInExpOnBut AND LBClick;
if ( ExpOnPressed )
{ 
StaticVarSet ("RS", 0);
StaticVarSet ("ExpOn",  1);
StaticVarSet ("ExpOff", 0); 
}

// Button Export Off
DrawBut("Export Off", X0, Y0+420, X0+170, Y0+450, colorDarkRed, colorDarkRed);
CursorInExpOffBut = MouseX >= X0 AND MouseX <= X0+170 AND MouseY >= Y0+420 AND MouseY <= Y0+450;
ExpOffPressed = CursorInExpOffBut AND LBClick;
if ( ExpOffPressed )
{ 
StaticVarSet ("RS", 0);
StaticVarSet ("ExpOn", 0); 
StaticVarSet ("ExpOff",1);
StaticVarSet ("SMKT",  0); 
StaticVarSet ("BMKT",  0);
StaticVarSet ("CLPOS", 0);
StaticVarSet ("CANC",  0);
}

if(StaticVarGet("RS")==1)			{DrawBut("", X0+180, Y0,     X0+210, Y0+30,  colorGrey40, colorGrey40);		}// RS=1			
if(StaticVarGet("AutoOn")==1)	{DrawBut("", X0+180, Y0+40,  X0+210, Y0+70,  colorDarkGreen, colorDarkGreen);}// AutoOn		
if(StaticVarGet("AutoOff")==1)	{DrawBut("", X0+180, Y0+80,  X0+210, Y0+110, colorDarkRed, colorDarkRed);	}// AutoOff	
if(StaticVarGet("SMKT")==1)		{DrawBut("", X0+180, Y0+130, X0+210, Y0+180, colorRed, colorRed);				}// SMKT			
if(StaticVarGet("BMKT")==1)		{DrawBut("", X0+180, Y0+190, X0+210, Y0+240, colorLime, colorLime);			}// BMKT			
if(StaticVarGet("CLPOS")==1)		{DrawBut("", X0+180, Y0+250, X0+210, Y0+300, colorGrey40, colorGrey40);		}// CLPOS		
if(StaticVarGet("CANC")==1)		{DrawBut("", X0+180, Y0+310, X0+210, Y0+360, colorGrey40, colorGrey40);		}// CANC			
if(StaticVarGet("ExpOn")==1)		{DrawBut("", X0+180, Y0+380, X0+210, Y0+410, colorDarkGreen, colorDarkGreen);}// ExpOn		
if(StaticVarGet("ExpOff")==1)	{DrawBut("", X0+180, Y0+420, X0+210, Y0+450, colorDarkRed, colorDarkRed);		}// ExpOff		

_SECTION_END();




Code:
Title = " ";
_SECTION_BEGIN("RKR_AutoTrade1V00 ");

EnableRealTimeControl = ParamList("Enable Controls", "No|Yes", 0);
EnableStrategy = ParamList("Enable Strategy", "No|Yes", 0);
StrategyType = ParamList("StrategyType", "Long/Short|Long|Short", 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.
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);
ParamList("Written By", "Ranjith K R");
ParamList("e-mail ID", "[email protected]");
Buy = 0;
Sell = 0;
Short = 0;
Cover = 0;

if(EnableStrategy == "Yes")
{
/*~~~~~~~~~~~~~~~~AutoTrade Strategy~~~~~~~~~~~~~~~~~~~~~~*/
/*
You Have to replace the below code with your strategy
Strictly don't use the bellow Buy/Sell code for real Trading
*/
/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/

Buy = Cross(MACD(12, 26), Signal(12, 26, 9));
Sell = Cross(Signal(12, 26, 9), MACD(12, 26));

Short = Cross(Signal(12, 26, 9), MACD(12, 26));
Cover = Cross(MACD(12, 26), Signal(12, 26, 9));

/*~~~~~~~~~~~~~~~End Of AutoTrade Strategy~~~~~~~~~~~~~~~~*/
}


if(EnableAutoTrade == "Yes" && EnableRealTimeControl == "Yes")
{
	if(StaticVarGetText("firstflagforNest")=="")
	{
		nestplus = Null;
		if(IsNull(nestplus))
		{
			nestplus = CreateStaticObject("Nest.PlusApi");
			nestplus.SetObjectName("RKRAutoTrade");
		}
		StaticVarSetText ("firstflagforNest","0", 1);
	}
	
}

X0 = 20;
Y0 = 10;
procedure DashBoard (Text, x1, y1, x2, y2, colorFrom, colorTo)
{
	GfxSetOverlayMode(0);
	GfxSelectFont("Segoe UI", 8.5, 500);
	GfxSetBkMode(1);
	GfxGradientRect(x1, y1, x2, y2, colorFrom, colorTo);
	GfxDrawText(Text, x1, y1, x2, y2, 32|0|4|16);
}
GfxSetTextColor(colorWhite);

DashBoard (" Strategy: " + EnableStrategy, X0, Y0, X0+150, Y0+13, colorGrey40, colorGrey40);
DashBoard (" Strategy Type: " + StrategyType, X0, Y0+13, X0+150, Y0+26, colorGrey40, colorGrey40);
DashBoard (" Auto Trade: " + EnableAutoTrade, X0, Y0+26, X0+150, Y0+38, colorGrey40, colorGrey40);
DashBoard (" Buy Price: " + BuyPriceSelection, X0, Y0+38, X0+150, Y0+50, colorGrey40, colorGrey40);
DashBoard (" Sell Price: " + SellPriceSelection, X0, Y0+50, X0+150, Y0+62, colorGrey40, colorGrey40);
DashBoard (" Product Type: " + ProductType, X0, Y0+62, X0+150, Y0+75, colorGrey40, colorGrey40);
DashBoard (" Order Type: " + OrderType, X0, Y0+75, X0+150, Y0+88, colorGrey40, colorGrey40);
DashBoard ("", X0+1, Y0+88, X0+149, Y0+89, colorRed, colorRed);
GfxSetTextColor(colorAqua);
DashBoard (" Written By: Ranjith K R", X0, Y0+89, X0+150, Y0+105, colorBlack, colorBlack);

X0 = 180;
Y0 = 10;
procedure DrawData (Text, x1, y1, x2, y2, colorFrom, colorTo)
{
	GfxSetOverlayMode(0);
	GfxSelectFont("Segoe UI", 8.5, 600);
	GfxSetBkMode(1);
	GfxGradientRect(x1, y1, x2, y2, colorFrom, colorTo);
	GfxDrawText(Text, x1, y1, x2, y2, 32|0|4|16);
}
GfxSetTextColor(colorWhite);
DrawData (" " + Name(), X0, Y0, X0+200, Y0+15, colorGrey40, colorGrey40);
DrawData (" " + Date(), X0+205, Y0, X0+360, Y0+15, colorGrey40, colorGrey40);
DrawData (" Open : " + Open, X0+365, Y0, X0+505, Y0+15, colorGrey40, colorGrey40);
DrawData (" Close : " + Close, X0+510, Y0, X0+650, Y0+15, colorGrey40, colorGrey40);
DrawData (" High : " + High, X0+655, Y0, X0+795, Y0+15, colorGrey40, colorGrey40);
DrawData (" Low : " + Low, X0+800, Y0, X0+940, Y0+15, colorGrey40, colorGrey40);
DrawData (" Volume : " + NumToStr(Volume,1,0), X0+945, Y0, X0+1100, Y0+15, colorGrey40, colorGrey40);
DrawData (" % Change : " + NumToStr( (((C-O)*100)/O), 1.2, True), X0+1105, Y0, X0+1235, Y0+15, colorGrey40, colorGrey40);

if(StaticVarGetText("firstflag")=="")
{
	StaticVarSet("OrderNo", 0);
	
	StaticVarSetText ("firstflag","0");
}

if(StaticVarGetText("firstflag"+Name())=="")
{
	StaticVarSet(("BuyIndex" + Name()), 0);
	StaticVarSet(("BuyCount" + Name()), 0);
	StaticVarSet(("BuyFlag"  + Name()), 0);
	StaticVarSet(("BuyPrice"  + Name()), 0);
	StaticVarSet(("BuyQty"  + Name()), 0);
	
	StaticVarSet(("SellIndex" + Name()), 0);
	StaticVarSet(("SellCount" + Name()), 0);
	StaticVarSet(("SellFlag"  + Name()), 0);
	StaticVarSet(("SellPrice"  + Name()), 0);
	StaticVarSet(("SellQty"  + Name()), 0);
	
	StaticVarSet(("ShortIndex" + Name()), 0);
	StaticVarSet(("ShortCount" + Name()), 0);
	StaticVarSet(("ShortFlag"  + Name()), 0);
	StaticVarSet(("ShortPrice"  + Name()), 0);
	StaticVarSet(("ShortQty"  + Name()), 0);
	
	StaticVarSet(("CoverIndex" + Name()), 0);
	StaticVarSet(("CoverCount" + Name()), 0);
	StaticVarSet(("CoverFlag"  + Name()), 0);
	StaticVarSet(("CoverPrice"  + Name()), 0);
	StaticVarSet(("CoverQty"  + Name()), 0);
	
	StaticVarSet("LTPSave" + Name(), 0);
	StaticVarSet("LTQSave" + Name(), 0);
	StaticVarSet("VolumeTemp" + Name(), 0);
	StaticVarSet("AskSave" + Name(), 0);
	StaticVarSet("BidSave" + Name(), 0);
	
	StaticVarSet("LastLTPColor" + Name(), colorGrey40);
	StaticVarSet("LastLTQColor" + Name(), colorGrey40);
	StaticVarSet("LastAskColor" + Name(), colorGrey40);
	StaticVarSet("LastBidColor" + Name(), colorGrey40);
	
	StaticVarSetText("firstflag"+Name(), "0");
}

CurrentAskPrice = LastValue(Aux1);
CurrentBidPrice = LastValue(Aux2);
CurrentTradedPrice = LastValue(C);
CurrentVolume = LastValue(Volume);

if(BuyPriceSelection == "Bid Price")
{
	BuyPriceValue = CurrentBidPrice;
}
else if(BuyPriceSelection == "Ask Price")
{
	BuyPriceValue = CurrentAskPrice;
}
else
{
	BuyPriceValue = CurrentTradedPrice;
}

if(SellPriceSelection == "Ask Price")
{
	SellPriceValue = CurrentAskPrice;
}
else if(SellPriceSelection == "Bid Price")
{
	SellPriceValue = CurrentBidPrice;
}
else
{
	SellPriceValue = CurrentTradedPrice;
}

LTPTemp = StaticVarGet("LTPSave" + Name());
LTQTemp = StaticVarGet("LTQSave" + Name());
VolumeTemp = StaticVarGet("VolumeTemp" + Name());
AskTemp = StaticVarGet("AskSave" + Name());
BidTemp = StaticVarGet("BidSave" + Name());

CurrentLTQ = (CurrentVolume - VolumeTemp);

if(CurrentLTQ < 0)
{
	CurrentLTQ = CurrentLTQ * -1;
}

if(CurrentLTQ == 0)
{
	CurrentLTQ = LTQTemp;
}

LTPColor = StaticVarGet("LastLTPColor" + Name());
LTQColor = StaticVarGet("LastLTQColor" + Name());
AskColor = StaticVarGet("LastAskColor" + Name());
BidColor = StaticVarGet("LastBidColor" + Name());


if(LTPTemp > CurrentTradedPrice)
{
	LTPColor = colorRed;
}
else if(LTPTemp < CurrentTradedPrice)
{
	LTPColor = ColorGreen;
}

if(LTQTemp > CurrentLTQ)
{
	LTQColor = colorRed;
}
else if(LTQTemp < CurrentLTQ)
{
	LTQColor = ColorGreen;
}

if(AskTemp > CurrentAskPrice)
{
	AskColor = colorRed;
}
else if(AskTemp < CurrentAskPrice)
{
	AskColor = ColorGreen;
}

if(BidTemp > CurrentBidPrice)
{
	BidColor = colorRed;
}
else if(BidTemp < CurrentBidPrice)
{
	BidColor = ColorGreen;
}

StaticVarSet("LastLTPColor" + Name(), LTPColor);
StaticVarSet("LastLTQColor" + Name(), LTQColor);
StaticVarSet("LastAskColor" + Name(), AskColor);
StaticVarSet("LastBidColor" + Name(), BidColor);

StaticVarSet("LTPSave" + Name(), CurrentTradedPrice);
StaticVarSet("LTQSave" + Name(), CurrentLTQ);
StaticVarSet("VolumeTemp" + Name(), CurrentVolume);
StaticVarSet("AskSave" + Name(), CurrentAskPrice);
StaticVarSet("BidSave" + Name(), CurrentBidPrice);


X0 = X2 + 20;
Y0 = Y2 + 120;
LBClick = GetCursorMouseButtons() == 9;	// Click
MouseX  = Nz(GetCursorXPosition(1));		// 
MouseY  = Nz(GetCursorYPosition(1));		//

NumPad0 = GetAsyncKeyState(96) < 0;
NumPad4 = GetAsyncKeyState(100) < 0;
NumPad5 = GetAsyncKeyState(101) < 0;
NumPad7 = GetAsyncKeyState(103) < 0;
NumPad8 = GetAsyncKeyState(104) < 0;

procedure DrawBut (Text, x1, y1, x2, y2, colorFrom, colorTo)
{
	GfxSetOverlayMode(0);
	GfxSelectFont("Segoe UI", 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 || NumPad7 )
	{
		TempBuy = Buy;
		Buy = IIf((DateTime() == LastValue(DateTime())) || (TempBuy == True), True, False);
	}

	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 || NumPad8)
	{
		TempSell = Sell;
		Sell = IIf((DateTime() == LastValue(DateTime())) || (TempSell == True), True, False);
	}
	
	DrawBut ("Short", X0, Y0+80, X0+X1, Y0+110, colorOrange, colorOrange);
	CursorInShortButton = MouseX >= X0 AND MouseX <= X0+X1 AND MouseY >= Y0+80 AND MouseY <= Y0+110;
	ShortButtonClick = CursorInShortButton AND LBClick;
	if (ShortButtonClick || NumPad4)
	{
		TemShort = Short;
		Short = IIf((DateTime() == LastValue(DateTime())) || (TemShort == True), True, False);
	}

	DrawBut ("Cover", X0, Y0+120, X0+X1, Y0+150, colorTurquoise, colorTurquoise);
	CursorInCoverButton = MouseX >= X0 AND MouseX <= X0+X1 AND MouseY >= Y0+120 AND MouseY <= Y0+150;
	CoverButtonClick = CursorInCoverButton AND LBClick;
	if (CoverButtonClick || NumPad5)
	{
		TempCover = Cover;
		Cover = IIf((DateTime() == LastValue(DateTime())) || (TempCover == True), True, False);
	}

	DrawBut ("Clear Data", X0, Y0+160, X0+X1, Y0+190, colorGrey40, colorGrey40);
	CursorInClearButton = MouseX >= X0 AND MouseX <= X0+X1 AND MouseY >= Y0+160 AND MouseY <= Y0+190;
	ClearButtonClick = CursorInClearButton AND LBClick;
	if (ClearButtonClick || NumPad0 ) 
	{ 
		DrawBut("Clear", X0+X1+10, Y0, X0+X1+75, Y0+30,  colorGrey40, colorGrey40);

		StaticVarSetText("firstflag"+Name(), "");
	}
	
	//TempBuy = Buy;
	TempBuy = IIf((DateTime() == LastValue(DateTime())) && (LastValue(Buy) == True), True, False);
	BuyTempData = StaticVarGet("BuyIndex" + Name());
	TempCount = StaticVarGet("BuyCount" + Name());
	BuyPrevTemp = 0;
	for(i = 0; i <= TempCount; i++)
	{
		BuyPrevTemp = BuyPrevTemp | (IIF(DateTime() == BuyTempData[i], True, False));
	}
	Buy = IIF(((BuyPrevTemp == True) || (TempBuy == True)), True, False);
	
	//TempSell = Sell;
	TempSell = IIf((DateTime() == LastValue(DateTime())) && (LastValue(Sell) == True), True, False);
	SellTempData = StaticVarGet("SellIndex" + Name());
	TempCount = StaticVarGet("SellCount" + Name());
	SellPrevTemp = 0;
	for(i = 0; i <= TempCount; i++)
	{
		SellPrevTemp = SellPrevTemp | (IIF(DateTime() == SellTempData[i], True, False));
	}
	TempCount = StaticVarGet("BuyCount" + Name());
	Sell = IIF((TempCount > 0) && ((SellPrevTemp == True) || (TempSell == True)), True, False);
	
	//TempShort = Short;
	TempShort = IIf((DateTime() == LastValue(DateTime())) && (LastValue(Short) == True), True, False);
	ShortTempData = StaticVarGet("ShortIndex" + Name());
	TempCount = StaticVarGet("ShortCount" + Name());
	ShortPrevTemp = 0;
	for(i = 0; i <= TempCount; i++)
	{
		ShortPrevTemp = ShortPrevTemp | (IIF(DateTime() == ShortTempData[i], True, False));
	}
	Short = IIF(((ShortPrevTemp == True) || (TempShort == True)), True, False);
	
	//TempCover = Cover;
	TempCover = IIf((DateTime() == LastValue(DateTime())) && (LastValue(Cover) == True), True, False);
	CoverTempData = StaticVarGet("CoverIndex" + Name());
	TempCount = StaticVarGet("CoverCount" + Name());
	CoverPrevTemp = 0;
	for(i = 0; i <= TempCount; i++)
	{
		CoverPrevTemp = CoverPrevTemp | (IIF(DateTime() == CoverTempData[i], True, False));
	}
	TempCount = StaticVarGet("ShortCount" + Name());
	Cover = IIF((TempCount > 0) && ((CoverPrevTemp == True) || (TempCover == True)), True, False);
	
}

if(StrategyType == "Long")
{
	Short = 0;
	Cover = 0;
}
else if(StrategyType == "Short")
{
	Buy = 0;
	Sell = 0;
}

Buy = ExRem( Buy, Sell );
Sell = ExRem( Sell, Buy );

Short = ExRem( Short, Cover );
Cover = ExRem( Cover, Short );

Buyshape = Buy * shapeUpArrow;
SellShape = Sell * shapeDownArrow;
PlotShapes( Buyshape, colorBrightGreen, 0, Low );
PlotShapes( SellShape, colorRed, 0, High );

Shortshape = Short * shapeDownArrow;
CoverShape = Cover * shapeUpArrow;
PlotShapes( Shortshape, colorOrange, 0, High, -30);
PlotShapes( CoverShape, colorTurquoise, 0, Low, -30 );

GraphXSpace = 5;
	
	
if(EnableRealTimeControl == "Yes")
{
	if((LastValue(Buy) == True) && (StaticVarGet(("BuyFlag" + Name())) != LastValue(DateTime())))
	{
		StaticVarSet(("BuyFlag" + Name()), LastValue(DateTime()));
		DrawBut("Buy", X0+X1+10, Y0, X0+X1+75, Y0+30,  colorGrey40, colorGrey40);
		TempCount = StaticVarGet("BuyCount" + Name());
		TempIndex = StaticVarGet("BuyIndex" + Name());
		TempPrice = StaticVarGet("BuyPrice"  + Name());
		TempQty = StaticVarGet("BuyQty"  + Name());
		TempIndex[TempCount] = LastValue(DateTime());
		TempPrice[TempCount] = BuyPriceValue;
		TempQty[TempCount] = LotQuantity;
		TempCount++;
		StaticVarSet("BuyCount" + Name(), TempCount);
		StaticVarSet(("BuyIndex" + Name()), TempIndex);
		StaticVarSet(("BuyPrice" + Name()), TempPrice);
		StaticVarSet(("BuyQty" + Name()), TempQty);
		
		if(EnableAutoTrade == "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);
		}
	}

	if((LastValue(Sell) == True) && (StaticVarGet(("SellFlag" + Name())) != LastValue(DateTime())))
	{
		StaticVarSet(("SellFlag" + Name()), LastValue(DateTime()));
		DrawBut("Sell", X0+X1+10, Y0, X0+X1+75, Y0+30,  colorGrey40, colorGrey40);
		TempCount = StaticVarGet("SellCount" + Name());
		TempIndex = StaticVarGet("SellIndex" + Name());
		TempPrice = StaticVarGet("SellPrice"  + Name());
		TempQty = StaticVarGet("SellQty"  + Name());
		TempIndex[TempCount] = LastValue(DateTime());
		TempPrice[TempCount] = SellPriceValue;
		TempQty[TempCount] = LotQuantity;
		TempCount++;
		StaticVarSet("SellCount" + Name(), TempCount);
		StaticVarSet(("SellIndex" + Name()), TempIndex);
		StaticVarSet(("SellPrice" + Name()), TempPrice);
		StaticVarSet(("SellQty" + Name()), TempQty);
		
		if(EnableAutoTrade == "Yes")
		{
			LastOrderNo = StaticVarGet("OrderNo");
			LastOrderNo++;
			StaticVarSet("OrderNo", LastOrderNo, 1);
			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);
		}
	}
	
	if((LastValue(Short) == True) && (StaticVarGet(("ShortFlag" + Name())) != LastValue(DateTime())))
	{
		StaticVarSet(("ShortFlag" + Name()), LastValue(DateTime()));
		DrawBut("Short", X0+X1+10, Y0, X0+X1+75, Y0+30,  colorGrey40, colorGrey40);
		TempCount = StaticVarGet("ShortCount" + Name());
		TempIndex = StaticVarGet("ShortIndex" + Name());
		TempPrice = StaticVarGet("ShortPrice"  + Name());
		TempQty = StaticVarGet("ShortQty"  + Name());
		TempIndex[TempCount] = LastValue(DateTime());
		TempPrice[TempCount] = SellPriceValue;
		TempQty[TempCount] = LotQuantity;
		TempCount++;
		StaticVarSet("ShortCount" + Name(), TempCount);
		StaticVarSet(("ShortIndex" + Name()), TempIndex);
		StaticVarSet(("ShortPrice" + Name()), TempPrice);
		StaticVarSet(("ShortQty" + Name()), TempQty);
		
		if(EnableAutoTrade == "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);
		}
	}

	if((LastValue(Cover) == True) && (StaticVarGet(("CoverFlag" + Name())) != LastValue(DateTime())))
	{
		StaticVarSet(("CoverFlag" + Name()), LastValue(DateTime()));
		DrawBut("Cover", X0+X1+10, Y0, X0+X1+75, Y0+30,  colorGrey40, colorGrey40);
		TempCount = StaticVarGet("CoverCount" + Name());
		TempIndex = StaticVarGet("CoverIndex" + Name());
		TempPrice = StaticVarGet("CoverPrice"  + Name());
		TempQty = StaticVarGet("CoverQty"  + Name());
		TempIndex[TempCount] = LastValue(DateTime());
		TempPrice[TempCount] = BuyPriceValue;
		TempQty[TempCount] = LotQuantity;
		TempCount++;
		StaticVarSet("CoverCount" + Name(), TempCount);
		StaticVarSet(("CoverIndex" + Name()), TempIndex);
		StaticVarSet(("CoverPrice" + Name()), TempPrice);
		StaticVarSet(("CoverQty" + Name()), TempQty);
		
		if(EnableAutoTrade == "Yes")
		{
			LastOrderNo = StaticVarGet("OrderNo");
			LastOrderNo++;
			StaticVarSet("OrderNo", LastOrderNo, 1);
			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);
		}
	}
}
	
X0 = 180;
Y0 = 30;

if(EnableRealTimeControl == "Yes")
{
	TotPrice = 0;
	TotQty = 0;
	TotVal = 0;
	TempPriceArray = StaticVarGet("BuyPrice" + Name());
	TempQtyArray = StaticVarGet("BuyQty" + Name());
	TempCount = StaticVarGet("BuyCount" + Name());
	for(i = 0; i < TempCount; i++)
	{
		TotPrice = TotPrice + TempPriceArray[i];
		TotQty = TotQty + TempQtyArray[i];
		TotVal = TotVal + TempPriceArray[i] * TempQtyArray[i];
	}
	if(TempCount == 0)
	{
		AvgBuyPrice = 0;
		LastBuyPrice = 0;
		LastBuyQty = 0;
	}
	else
	{
		AvgBuyPrice = (TotPrice / TempCount);
		LastBuyPrice = TempPriceArray[(TempCount - 1)];
		LastBuyQty = NumToStr(TempQtyArray[(TempCount - 1)], 1, 0);
	}
	TotBuyQty = NumToStr(TotQty, 1, 0);
	NetBuyQty = TotQty;
	NetBuyValue = TotVal;
	
	TotPrice = 0;
	TotQty = 0;
	TotVal = 0;
	TempPriceArray = StaticVarGet("SellPrice" + Name());
	TempQtyArray = StaticVarGet("SellQty" + Name());
	TempCount = StaticVarGet("SellCount" + Name());
	for(i = 0; i < TempCount; i++)
	{
		TotPrice = TotPrice + TempPriceArray[i];
		TotQty = TotQty + TempQtyArray[i];
		TotVal = TotVal + TempPriceArray[i] * TempQtyArray[i];
	}
	if(TempCount == 0)
	{
		AvgSellPrice = 0;
		LastSellPrice = 0;
		LastSellQty = 0;
	}
	else
	{
		AvgSellPrice = (TotPrice / TempCount);
		LastSellPrice = TempPriceArray[(TempCount - 1)];
		LastSellQty = NumToStr(TempQtyArray[(TempCount - 1)], 1, 0);
	}
	TotSellQty = NumToStr(TotQty, 1, 0);
	NetSellQty = TotQty;
	NetSellValue = TotVal;
	
	TotPrice = 0;
	TotQty = 0;
	TotVal = 0;
	TempPriceArray = StaticVarGet("ShortPrice" + Name());
	TempQtyArray = StaticVarGet("ShortQty" + Name());
	TempCount = StaticVarGet("ShortCount" + Name());
	for(i = 0; i < TempCount; i++)
	{
		TotPrice = TotPrice + TempPriceArray[i];
		TotQty = TotQty + TempQtyArray[i];
		TotVal = TotVal + TempPriceArray[i] * TempQtyArray[i];
	}
	if(TempCount == 0)
	{
		AvgShortPrice = 0;
		LastShortPrice = 0;
		LastShortQty = 0;
	}
	else
	{
		AvgShortPrice = (TotPrice / TempCount);
		LastShortPrice = TempPriceArray[(TempCount - 1)];
		LastShortQty = NumToStr(TempQtyArray[(TempCount - 1)], 1, 0);
	}
	TotShortQty = NumToStr(TotQty, 1, 0);
	NetShortQty = TotQty;
	NetShortValue = TotVal;
	
	TotPrice = 0;
	TotQty = 0;
	TotVal = 0;
	TempPriceArray = StaticVarGet("CoverPrice" + Name());
	TempQtyArray = StaticVarGet("CoverQty" + Name());
	TempCount = StaticVarGet("CoverCount" + Name());
	for(i = 0; i < TempCount; i++)
	{
		TotPrice = TotPrice + TempPriceArray[i];
		TotQty = TotQty + TempQtyArray[i];
		TotVal = TotVal + TempPriceArray[i] * TempQtyArray[i];
	}
	if(TempCount == 0)
	{
		AvgCoverPrice = 0;
		LastCoverPrice = 0;
		LastCoverQty = 0;
	}
	else
	{
		AvgCoverPrice = (TotPrice / TempCount);
		LastCoverPrice = TempPriceArray[(TempCount - 1)];
		LastCoverQty = NumToStr(TempQtyArray[(TempCount - 1)], 1, 0);
	}
	TotCoverQty = NumToStr(TotQty, 1, 0);
	NetCoverQty = TotQty;
	NetCoverValue = TotVal;
	
	NetQty = NetSellQty - NetBuyQty + NetShortQty - NetCoverQty;
	NetValue = NetSellValue - NetBuyValue + NetShortValue - NetCoverValue;
	
	NetQuantityColor = colorGrey40;
	NetValueColor = colorGrey40;

	if(NetQty > 0)
	{
		NetQuantityColor = colorRed;
		NetValueColor = colorRed;
	}
	else if(NetQty < 0)
	{
		NetQuantityColor = colorGreen;
		NetValueColor = colorGreen;
	}
	else if(NetQty == 0)
	{
		if(NetValue > 0)
		{
			NetValueColor = colorGreen;
		}
		else if(NetValue < 0)
		{
			NetValueColor = colorRed;
		}
	}
	
	DrawData (" AvgBuyPr: " + AvgBuyPrice, X0, Y0, X0+150, Y0+15, colorGrey40, colorGrey40);
	DrawData (" TotBuyQty: " + TotBuyQty, X0+155 , Y0, X0+305, Y0+15, colorGrey40, colorGrey40);
	DrawData (" AvgSellPr: " + AvgSellPrice, X0+310, Y0, X0+460, Y0+15, colorGrey40, colorGrey40);
	DrawData (" TotSellQty: " + TotSellQty, X0+465, Y0, X0+615, Y0+15, colorGrey40, colorGrey40);
	DrawData (" AvgShortPr: " + AvgShortPrice, X0+620, Y0, X0+770, Y0+15, colorGrey40, colorGrey40);
	DrawData (" TotShortQty: " + TotShortQty, X0+775 , Y0, X0+925, Y0+15, colorGrey40, colorGrey40);
	DrawData (" AvgCoverPr: " + AvgCoverPrice, X0+930, Y0, X0+1080, Y0+15, colorGrey40, colorGrey40);
	DrawData (" TotCoverQty: " + TotCoverQty, X0+1085, Y0, X0+1235, Y0+15, colorGrey40, colorGrey40);
	
	Y0 = 50;
	
	DrawData (" LastBuyPr: " + LastBuyPrice, X0, Y0, X0+150, Y0+15, colorGrey40, colorGrey40);
	DrawData (" LastBuyQty: " + LastBuyQty, X0+155 , Y0, X0+305, Y0+15, colorGrey40, colorGrey40);
	DrawData (" LastSellPr: " + LastSellPrice, X0+310, Y0, X0+460, Y0+15, colorGrey40, colorGrey40);
	DrawData (" LastSellQty: " + LastSellQty, X0+465, Y0, X0+615, Y0+15, colorGrey40, colorGrey40);
	DrawData (" LastShortPr: " + LastShortPrice, X0+620, Y0, X0+770, Y0+15, colorGrey40, colorGrey40);
	DrawData (" LastShortQty: " + LastShortQty, X0+775 , Y0, X0+925, Y0+15, colorGrey40, colorGrey40);
	DrawData (" LastCoverPr: " + LastCoverPrice, X0+930, Y0, X0+1080, Y0+15, colorGrey40, colorGrey40);
	DrawData (" LastCoverQty: " + LastCoverQty, X0+1085, Y0, X0+1235, Y0+15, colorGrey40, colorGrey40);
	
	Y0 = 70;
	
	DrawData (" LTP : " + CurrentTradedPrice, X0, Y0, X0+125, Y0+15, LTPColor, LTPColor);
	DrawData (" LTQ : " + NumToStr(CurrentLTQ,1,0), X0+130, Y0, X0+255, Y0+15, LTQColor, LTQColor);
	DrawData (" Bid : " + CurrentBidPrice, X0+260, Y0, X0+385, Y0+15, AskColor, AskColor);
	DrawData (" Ask : " + CurrentAskPrice, X0+390, Y0, X0+515, Y0+15, BidColor, BidColor);
	
	NestOredrNo = ClientIdValue + NumToStr(Now(3),1,0) + "00" + StaticVarGet("OrderNo");
	DrawData (" NetQty : " + NetQty, X0+520, Y0, X0+670, Y0+15, NetQuantityColor, NetQuantityColor);
	DrawData (" NetValue : " + NetValue, X0+675, Y0, X0+900, Y0+15, NetValueColor, NetValueColor);
	DrawData (" Order No : " + NestOredrNo, X0+905, Y0, X0+1150, Y0+15, colorGrey40, colorGrey40);
	
}

_SECTION_END();

// ~~~~~~~~~~~~~~~~ Quote Display Draw ~~~~~~~~~~~~~~~~~//

_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();



Code:
_SECTION_BEGIN("Manual Trading Pi Bridge");
//coded by Choks.Mail ur Feedback to [email protected]
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 [email protected]",(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();
 
I'm not going to decipher your handwriting every time. Also you should avoid arguing about what is right or wrong with someone knowing better how to code. Rather listen and apply. You don't need conditions such as if ( i == ... ) at all the same way as you don't need varset/varget here. It's all unnecessary overhead.
I've edited that post in english that you do understand.
if i argue, i might have said , what if i decipher your Punctuation?

You don't have to decipher it .
Asking question is not arguing , why do you take it as an argument?

Yes, i got your mean, but condition could differ. it could be condition mixed with (OR , AND ) operator or it could be in some other way ..
 
Last edited:

KelvinHand

Well-Known Member
Didn't get who u r referring to ,
Pasting below 3 AFLs where Buttons are created on chart.
My Request is not for any full AFL, rather i need ur expert advise/ Guidance.

My Requirement;
Buy1=BuyCondition;
Buy2= PressBuyButton;
Buy=Buy1 OR Buy2;

Need coding guidance to PressBuyButton which if pressed, should trigger a Buy signal on Chart/Scan/Explore as a Valid Buy condition and the Signal should Remain permanently or atleast till the close of Amibroker.

Thanx n Rgrds


Code:
Title = "";
formulaName = "Control Panel";
GfxSetBkMode(1);
GfxSelectFont("Verdana", 18, 700, italic=False);
GfxSetTextColor(colorBrightGreen);
GfxTextOut(FormulaName, 20, 10);

_SECTION_BEGIN("Control Panel");
// Base point - Left Up Corner
X0 = Param ("X - Left Up Corner",   20,   4,  200, 10);
Y0 = Param ("Y - Right Up Corner",   120,  40, 200, 10);

// --- Button pressed
LBClick = GetCursorMouseButtons() == 9;	// Click
MouseX  = Nz(GetCursorXPosition(1));		// 
MouseY  = Nz(GetCursorYPosition(1));		// 

// --- Button Draw
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);

// Button Begin
DrawBut ("Begin", X0, Y0, X0+170, Y0+30, colorGrey40, colorGrey40);
CursorInResetBut = MouseX >= X0 AND MouseX <= X0+170 AND MouseY >= Y0 AND MouseY <= Y0+30;
ResetPressed = CursorInResetBut AND LBClick;
if (ResetPressed) 
{ 
StaticVarSet ("RS", 1);      
StaticVarSet ("AutoOn",  0); 
StaticVarSet ("AutoOff", 1); 
StaticVarSet ("SMKT",    0); 
StaticVarSet ("BMKT",    0);
StaticVarSet ("CLPOS",   0);
StaticVarSet ("CANC",    0);
StaticVarSet ("ExpOn",   0); 
StaticVarSet ("ExpOff",  1);
}

// Button Auto on
DrawBut ("Auto on", X0, Y0+40, X0+170, Y0+70, colorDarkGreen, colorDarkGreen);
CursorInAutoOnBut = MouseX >= X0 AND MouseX <= X0+170 AND MouseY >= Y0+40 AND MouseY <= Y0+70;
AutoOnPressed = CursorInAutoOnBut AND LBClick;
if (AutoOnPressed) 
{ 
StaticVarSet ("RS", 0);
StaticVarSet ("AutoOn",  1);
StaticVarSet ("AutoOff", 0);
StaticVarSet ("SMKT",    0); 
StaticVarSet ("BMKT",    0);
StaticVarSet ("CLPOS",   0);
StaticVarSet ("CANC",    0);
}

// Button Auto off
DrawBut ("Auto off", X0, Y0+80, X0+170, Y0+110, colorDarkRed, colorDarkRed);
CursorInAutoOffBut = MouseX >= X0 AND MouseX <= X0+170 AND MouseY >= Y0+80 AND MouseY <= Y0+110;
AutoOffPressed = CursorInAutoOffBut AND LBClick;
if (AutoOffPressed) 
{ 
StaticVarSet ("RS", 0);
StaticVarSet ("AutoOn",  0); 
StaticVarSet ("AutoOff", 1);
StaticVarSet ("SMKT",    0); 
StaticVarSet ("BMKT",    0);
StaticVarSet ("CLPOS",   0);
StaticVarSet ("CANC",    0);
}

// Button Sell Market
DrawBut ("Sell Market", X0, Y0+130, X0+170, Y0+180, colorRed, colorRed);
CursorInSMKTBut = MouseX >= X0 AND MouseX <= X0+170 AND MouseY >= Y0+130 AND MouseY <= Y0+180;
SMKTPressed = CursorInSMKTBut AND LBClick;
if ( SMKTPressed AND StaticVarGet ("AutoOff")==1  AND StaticVarGet ("ExpOn")==1 )
{ 
StaticVarSet ("RS", 0);
StaticVarSet ("SMKT",  1);
StaticVarSet ("BMKT",  0);
StaticVarSet ("CLPOS", 0);
StaticVarSet ("CANC",  0);
}

// Button Buy Market
DrawBut ("Buy Market", X0, Y0+190, X0+170, Y0+240, colorLime, colorLime);
CursorInBMKTBut = MouseX >= X0 AND MouseX <= X0+170 AND MouseY >= Y0+190 AND MouseY <= Y0+240;
BMKTPressed = CursorInBMKTBut AND LBClick;
if ( BMKTPressed AND StaticVarGet ("AutoOff")==1  AND StaticVarGet ("ExpOn")==1 )
{ 
StaticVarSet ("RS", 0);
StaticVarSet ("SMKT",  0); 
StaticVarSet ("BMKT",  1);
StaticVarSet ("CLPOS", 0);
StaticVarSet ("CANC",  0);
}

// Button Close Position
DrawBut ("Close Position", X0, Y0+250, X0+170, Y0+300, colorGrey40, colorGrey40);
CursorInCloseBut = MouseX >= X0 AND MouseX <= X0+170 AND MouseY >= Y0+250 AND MouseY <= Y0+300;
ClosePressed = CursorInCloseBut AND LBClick;
if ( ClosePressed AND StaticVarGet ("AutoOff")==1  AND StaticVarGet ("ExpOn")==1 )
{ 
StaticVarSet ("RS", 0);
StaticVarSet ("SMKT",  0); 
StaticVarSet ("BMKT",  0);
StaticVarSet ("CLPOS", 1);
StaticVarSet ("CANC",  0);
}

// Button Cancel All Orders
DrawBut ("Cancel All Orders", X0, Y0+310, X0+170, Y0+360, colorGrey40, colorGrey40);
CursorInCancelBut = MouseX >= X0 AND MouseX <= X0+170 AND MouseY >= Y0+310 AND MouseY <= Y0+360;
CancelPressed = CursorInCancelBut AND LBClick;
if ( CancelPressed AND StaticVarGet ("AutoOff")==1 AND StaticVarGet ("ExpOn")==1 )
{ 
StaticVarSet ("RS", 0);
StaticVarSet ("SMKT",  0); 
StaticVarSet ("BMKT",  0);
StaticVarSet ("CLPOS", 0);
StaticVarSet ("CANC",  1);
}

// Button Export On
DrawBut ("Export On", X0, Y0+380, X0+170, Y0+410, colorDarkGreen, colorDarkGreen);
CursorInExpOnBut = MouseX >= X0 AND MouseX <= X0+170 AND MouseY >= Y0+380 AND MouseY <= Y0+410;
ExpOnPressed = CursorInExpOnBut AND LBClick;
if ( ExpOnPressed )
{ 
StaticVarSet ("RS", 0);
StaticVarSet ("ExpOn",  1);
StaticVarSet ("ExpOff", 0); 
}

// Button Export Off
DrawBut("Export Off", X0, Y0+420, X0+170, Y0+450, colorDarkRed, colorDarkRed);
CursorInExpOffBut = MouseX >= X0 AND MouseX <= X0+170 AND MouseY >= Y0+420 AND MouseY <= Y0+450;
ExpOffPressed = CursorInExpOffBut AND LBClick;
if ( ExpOffPressed )
{ 
StaticVarSet ("RS", 0);
StaticVarSet ("ExpOn", 0); 
StaticVarSet ("ExpOff",1);
StaticVarSet ("SMKT",  0); 
StaticVarSet ("BMKT",  0);
StaticVarSet ("CLPOS", 0);
StaticVarSet ("CANC",  0);
}

if(StaticVarGet("RS")==1)			{DrawBut("", X0+180, Y0,     X0+210, Y0+30,  colorGrey40, colorGrey40);		}// RS=1			
if(StaticVarGet("AutoOn")==1)	{DrawBut("", X0+180, Y0+40,  X0+210, Y0+70,  colorDarkGreen, colorDarkGreen);}// AutoOn		
if(StaticVarGet("AutoOff")==1)	{DrawBut("", X0+180, Y0+80,  X0+210, Y0+110, colorDarkRed, colorDarkRed);	}// AutoOff	
if(StaticVarGet("SMKT")==1)		{DrawBut("", X0+180, Y0+130, X0+210, Y0+180, colorRed, colorRed);				}// SMKT			
if(StaticVarGet("BMKT")==1)		{DrawBut("", X0+180, Y0+190, X0+210, Y0+240, colorLime, colorLime);			}// BMKT			
if(StaticVarGet("CLPOS")==1)		{DrawBut("", X0+180, Y0+250, X0+210, Y0+300, colorGrey40, colorGrey40);		}// CLPOS		
if(StaticVarGet("CANC")==1)		{DrawBut("", X0+180, Y0+310, X0+210, Y0+360, colorGrey40, colorGrey40);		}// CANC			
if(StaticVarGet("ExpOn")==1)		{DrawBut("", X0+180, Y0+380, X0+210, Y0+410, colorDarkGreen, colorDarkGreen);}// ExpOn		
if(StaticVarGet("ExpOff")==1)	{DrawBut("", X0+180, Y0+420, X0+210, Y0+450, colorDarkRed, colorDarkRed);		}// ExpOff		

_SECTION_END();




Code:
Title = " ";
_SECTION_BEGIN("RKR_AutoTrade1V00 ");

EnableRealTimeControl = ParamList("Enable Controls", "No|Yes", 0);
EnableStrategy = ParamList("Enable Strategy", "No|Yes", 0);
StrategyType = ParamList("StrategyType", "Long/Short|Long|Short", 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.
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);
ParamList("Written By", "Ranjith K R");
ParamList("e-mail ID", "[email protected]");
Buy = 0;
Sell = 0;
Short = 0;
Cover = 0;

if(EnableStrategy == "Yes")
{
/*~~~~~~~~~~~~~~~~AutoTrade Strategy~~~~~~~~~~~~~~~~~~~~~~*/
/*
You Have to replace the below code with your strategy
Strictly don't use the bellow Buy/Sell code for real Trading
*/
/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/

Buy = Cross(MACD(12, 26), Signal(12, 26, 9));
Sell = Cross(Signal(12, 26, 9), MACD(12, 26));

Short = Cross(Signal(12, 26, 9), MACD(12, 26));
Cover = Cross(MACD(12, 26), Signal(12, 26, 9));

/*~~~~~~~~~~~~~~~End Of AutoTrade Strategy~~~~~~~~~~~~~~~~*/
}


if(EnableAutoTrade == "Yes" && EnableRealTimeControl == "Yes")
{
	if(StaticVarGetText("firstflagforNest")=="")
	{
		nestplus = Null;
		if(IsNull(nestplus))
		{
			nestplus = CreateStaticObject("Nest.PlusApi");
			nestplus.SetObjectName("RKRAutoTrade");
		}
		StaticVarSetText ("firstflagforNest","0", 1);
	}
	
}

X0 = 20;
Y0 = 10;
procedure DashBoard (Text, x1, y1, x2, y2, colorFrom, colorTo)
{
	GfxSetOverlayMode(0);
	GfxSelectFont("Segoe UI", 8.5, 500);
	GfxSetBkMode(1);
	GfxGradientRect(x1, y1, x2, y2, colorFrom, colorTo);
	GfxDrawText(Text, x1, y1, x2, y2, 32|0|4|16);
}
GfxSetTextColor(colorWhite);

DashBoard (" Strategy: " + EnableStrategy, X0, Y0, X0+150, Y0+13, colorGrey40, colorGrey40);
DashBoard (" Strategy Type: " + StrategyType, X0, Y0+13, X0+150, Y0+26, colorGrey40, colorGrey40);
DashBoard (" Auto Trade: " + EnableAutoTrade, X0, Y0+26, X0+150, Y0+38, colorGrey40, colorGrey40);
DashBoard (" Buy Price: " + BuyPriceSelection, X0, Y0+38, X0+150, Y0+50, colorGrey40, colorGrey40);
DashBoard (" Sell Price: " + SellPriceSelection, X0, Y0+50, X0+150, Y0+62, colorGrey40, colorGrey40);
DashBoard (" Product Type: " + ProductType, X0, Y0+62, X0+150, Y0+75, colorGrey40, colorGrey40);
DashBoard (" Order Type: " + OrderType, X0, Y0+75, X0+150, Y0+88, colorGrey40, colorGrey40);
DashBoard ("", X0+1, Y0+88, X0+149, Y0+89, colorRed, colorRed);
GfxSetTextColor(colorAqua);
DashBoard (" Written By: Ranjith K R", X0, Y0+89, X0+150, Y0+105, colorBlack, colorBlack);

X0 = 180;
Y0 = 10;
procedure DrawData (Text, x1, y1, x2, y2, colorFrom, colorTo)
{
	GfxSetOverlayMode(0);
	GfxSelectFont("Segoe UI", 8.5, 600);
	GfxSetBkMode(1);
	GfxGradientRect(x1, y1, x2, y2, colorFrom, colorTo);
	GfxDrawText(Text, x1, y1, x2, y2, 32|0|4|16);
}
GfxSetTextColor(colorWhite);
DrawData (" " + Name(), X0, Y0, X0+200, Y0+15, colorGrey40, colorGrey40);
DrawData (" " + Date(), X0+205, Y0, X0+360, Y0+15, colorGrey40, colorGrey40);
DrawData (" Open : " + Open, X0+365, Y0, X0+505, Y0+15, colorGrey40, colorGrey40);
DrawData (" Close : " + Close, X0+510, Y0, X0+650, Y0+15, colorGrey40, colorGrey40);
DrawData (" High : " + High, X0+655, Y0, X0+795, Y0+15, colorGrey40, colorGrey40);
DrawData (" Low : " + Low, X0+800, Y0, X0+940, Y0+15, colorGrey40, colorGrey40);
DrawData (" Volume : " + NumToStr(Volume,1,0), X0+945, Y0, X0+1100, Y0+15, colorGrey40, colorGrey40);
DrawData (" % Change : " + NumToStr( (((C-O)*100)/O), 1.2, True), X0+1105, Y0, X0+1235, Y0+15, colorGrey40, colorGrey40);

if(StaticVarGetText("firstflag")=="")
{
	StaticVarSet("OrderNo", 0);
	
	StaticVarSetText ("firstflag","0");
}

if(StaticVarGetText("firstflag"+Name())=="")
{
	StaticVarSet(("BuyIndex" + Name()), 0);
	StaticVarSet(("BuyCount" + Name()), 0);
	StaticVarSet(("BuyFlag"  + Name()), 0);
	StaticVarSet(("BuyPrice"  + Name()), 0);
	StaticVarSet(("BuyQty"  + Name()), 0);
	
	StaticVarSet(("SellIndex" + Name()), 0);
	StaticVarSet(("SellCount" + Name()), 0);
	StaticVarSet(("SellFlag"  + Name()), 0);
	StaticVarSet(("SellPrice"  + Name()), 0);
	StaticVarSet(("SellQty"  + Name()), 0);
	
	StaticVarSet(("ShortIndex" + Name()), 0);
	StaticVarSet(("ShortCount" + Name()), 0);
	StaticVarSet(("ShortFlag"  + Name()), 0);
	StaticVarSet(("ShortPrice"  + Name()), 0);
	StaticVarSet(("ShortQty"  + Name()), 0);
	
	StaticVarSet(("CoverIndex" + Name()), 0);
	StaticVarSet(("CoverCount" + Name()), 0);
	StaticVarSet(("CoverFlag"  + Name()), 0);
	StaticVarSet(("CoverPrice"  + Name()), 0);
	StaticVarSet(("CoverQty"  + Name()), 0);
	
	StaticVarSet("LTPSave" + Name(), 0);
	StaticVarSet("LTQSave" + Name(), 0);
	StaticVarSet("VolumeTemp" + Name(), 0);
	StaticVarSet("AskSave" + Name(), 0);
	StaticVarSet("BidSave" + Name(), 0);
	
	StaticVarSet("LastLTPColor" + Name(), colorGrey40);
	StaticVarSet("LastLTQColor" + Name(), colorGrey40);
	StaticVarSet("LastAskColor" + Name(), colorGrey40);
	StaticVarSet("LastBidColor" + Name(), colorGrey40);
	
	StaticVarSetText("firstflag"+Name(), "0");
}

CurrentAskPrice = LastValue(Aux1);
CurrentBidPrice = LastValue(Aux2);
CurrentTradedPrice = LastValue(C);
CurrentVolume = LastValue(Volume);

if(BuyPriceSelection == "Bid Price")
{
	BuyPriceValue = CurrentBidPrice;
}
else if(BuyPriceSelection == "Ask Price")
{
	BuyPriceValue = CurrentAskPrice;
}
else
{
	BuyPriceValue = CurrentTradedPrice;
}

if(SellPriceSelection == "Ask Price")
{
	SellPriceValue = CurrentAskPrice;
}
else if(SellPriceSelection == "Bid Price")
{
	SellPriceValue = CurrentBidPrice;
}
else
{
	SellPriceValue = CurrentTradedPrice;
}

LTPTemp = StaticVarGet("LTPSave" + Name());
LTQTemp = StaticVarGet("LTQSave" + Name());
VolumeTemp = StaticVarGet("VolumeTemp" + Name());
AskTemp = StaticVarGet("AskSave" + Name());
BidTemp = StaticVarGet("BidSave" + Name());

CurrentLTQ = (CurrentVolume - VolumeTemp);

if(CurrentLTQ < 0)
{
	CurrentLTQ = CurrentLTQ * -1;
}

if(CurrentLTQ == 0)
{
	CurrentLTQ = LTQTemp;
}

LTPColor = StaticVarGet("LastLTPColor" + Name());
LTQColor = StaticVarGet("LastLTQColor" + Name());
AskColor = StaticVarGet("LastAskColor" + Name());
BidColor = StaticVarGet("LastBidColor" + Name());


if(LTPTemp > CurrentTradedPrice)
{
	LTPColor = colorRed;
}
else if(LTPTemp < CurrentTradedPrice)
{
	LTPColor = ColorGreen;
}

if(LTQTemp > CurrentLTQ)
{
	LTQColor = colorRed;
}
else if(LTQTemp < CurrentLTQ)
{
	LTQColor = ColorGreen;
}

if(AskTemp > CurrentAskPrice)
{
	AskColor = colorRed;
}
else if(AskTemp < CurrentAskPrice)
{
	AskColor = ColorGreen;
}

if(BidTemp > CurrentBidPrice)
{
	BidColor = colorRed;
}
else if(BidTemp < CurrentBidPrice)
{
	BidColor = ColorGreen;
}

StaticVarSet("LastLTPColor" + Name(), LTPColor);
StaticVarSet("LastLTQColor" + Name(), LTQColor);
StaticVarSet("LastAskColor" + Name(), AskColor);
StaticVarSet("LastBidColor" + Name(), BidColor);

StaticVarSet("LTPSave" + Name(), CurrentTradedPrice);
StaticVarSet("LTQSave" + Name(), CurrentLTQ);
StaticVarSet("VolumeTemp" + Name(), CurrentVolume);
StaticVarSet("AskSave" + Name(), CurrentAskPrice);
StaticVarSet("BidSave" + Name(), CurrentBidPrice);


X0 = X2 + 20;
Y0 = Y2 + 120;
LBClick = GetCursorMouseButtons() == 9;	// Click
MouseX  = Nz(GetCursorXPosition(1));		// 
MouseY  = Nz(GetCursorYPosition(1));		//

NumPad0 = GetAsyncKeyState(96) < 0;
NumPad4 = GetAsyncKeyState(100) < 0;
NumPad5 = GetAsyncKeyState(101) < 0;
NumPad7 = GetAsyncKeyState(103) < 0;
NumPad8 = GetAsyncKeyState(104) < 0;

procedure DrawBut (Text, x1, y1, x2, y2, colorFrom, colorTo)
{
	GfxSetOverlayMode(0);
	GfxSelectFont("Segoe UI", 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 || NumPad7 )
	{
		TempBuy = Buy;
		Buy = IIf((DateTime() == LastValue(DateTime())) || (TempBuy == True), True, False);
	}

	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 || NumPad8)
	{
		TempSell = Sell;
		Sell = IIf((DateTime() == LastValue(DateTime())) || (TempSell == True), True, False);
	}
	
	DrawBut ("Short", X0, Y0+80, X0+X1, Y0+110, colorOrange, colorOrange);
	CursorInShortButton = MouseX >= X0 AND MouseX <= X0+X1 AND MouseY >= Y0+80 AND MouseY <= Y0+110;
	ShortButtonClick = CursorInShortButton AND LBClick;
	if (ShortButtonClick || NumPad4)
	{
		TemShort = Short;
		Short = IIf((DateTime() == LastValue(DateTime())) || (TemShort == True), True, False);
	}

	DrawBut ("Cover", X0, Y0+120, X0+X1, Y0+150, colorTurquoise, colorTurquoise);
	CursorInCoverButton = MouseX >= X0 AND MouseX <= X0+X1 AND MouseY >= Y0+120 AND MouseY <= Y0+150;
	CoverButtonClick = CursorInCoverButton AND LBClick;
	if (CoverButtonClick || NumPad5)
	{
		TempCover = Cover;
		Cover = IIf((DateTime() == LastValue(DateTime())) || (TempCover == True), True, False);
	}

	DrawBut ("Clear Data", X0, Y0+160, X0+X1, Y0+190, colorGrey40, colorGrey40);
	CursorInClearButton = MouseX >= X0 AND MouseX <= X0+X1 AND MouseY >= Y0+160 AND MouseY <= Y0+190;
	ClearButtonClick = CursorInClearButton AND LBClick;
	if (ClearButtonClick || NumPad0 ) 
	{ 
		DrawBut("Clear", X0+X1+10, Y0, X0+X1+75, Y0+30,  colorGrey40, colorGrey40);

		StaticVarSetText("firstflag"+Name(), "");
	}
	
	//TempBuy = Buy;
	TempBuy = IIf((DateTime() == LastValue(DateTime())) && (LastValue(Buy) == True), True, False);
	BuyTempData = StaticVarGet("BuyIndex" + Name());
	TempCount = StaticVarGet("BuyCount" + Name());
	BuyPrevTemp = 0;
	for(i = 0; i <= TempCount; i++)
	{
		BuyPrevTemp = BuyPrevTemp | (IIF(DateTime() == BuyTempData[i], True, False));
	}
	Buy = IIF(((BuyPrevTemp == True) || (TempBuy == True)), True, False);
	
	//TempSell = Sell;
	TempSell = IIf((DateTime() == LastValue(DateTime())) && (LastValue(Sell) == True), True, False);
	SellTempData = StaticVarGet("SellIndex" + Name());
	TempCount = StaticVarGet("SellCount" + Name());
	SellPrevTemp = 0;
	for(i = 0; i <= TempCount; i++)
	{
		SellPrevTemp = SellPrevTemp | (IIF(DateTime() == SellTempData[i], True, False));
	}
	TempCount = StaticVarGet("BuyCount" + Name());
	Sell = IIF((TempCount > 0) && ((SellPrevTemp == True) || (TempSell == True)), True, False);
	
	//TempShort = Short;
	TempShort = IIf((DateTime() == LastValue(DateTime())) && (LastValue(Short) == True), True, False);
	ShortTempData = StaticVarGet("ShortIndex" + Name());
	TempCount = StaticVarGet("ShortCount" + Name());
	ShortPrevTemp = 0;
	for(i = 0; i <= TempCount; i++)
	{
		ShortPrevTemp = ShortPrevTemp | (IIF(DateTime() == ShortTempData[i], True, False));
	}
	Short = IIF(((ShortPrevTemp == True) || (TempShort == True)), True, False);
	
	//TempCover = Cover;
	TempCover = IIf((DateTime() == LastValue(DateTime())) && (LastValue(Cover) == True), True, False);
	CoverTempData = StaticVarGet("CoverIndex" + Name());
	TempCount = StaticVarGet("CoverCount" + Name());
	CoverPrevTemp = 0;
	for(i = 0; i <= TempCount; i++)
	{
		CoverPrevTemp = CoverPrevTemp | (IIF(DateTime() == CoverTempData[i], True, False));
	}
	TempCount = StaticVarGet("ShortCount" + Name());
	Cover = IIF((TempCount > 0) && ((CoverPrevTemp == True) || (TempCover == True)), True, False);
	
}

if(StrategyType == "Long")
{
	Short = 0;
	Cover = 0;
}
else if(StrategyType == "Short")
{
	Buy = 0;
	Sell = 0;
}

Buy = ExRem( Buy, Sell );
Sell = ExRem( Sell, Buy );

Short = ExRem( Short, Cover );
Cover = ExRem( Cover, Short );

Buyshape = Buy * shapeUpArrow;
SellShape = Sell * shapeDownArrow;
PlotShapes( Buyshape, colorBrightGreen, 0, Low );
PlotShapes( SellShape, colorRed, 0, High );

Shortshape = Short * shapeDownArrow;
CoverShape = Cover * shapeUpArrow;
PlotShapes( Shortshape, colorOrange, 0, High, -30);
PlotShapes( CoverShape, colorTurquoise, 0, Low, -30 );

GraphXSpace = 5;
	
	
if(EnableRealTimeControl == "Yes")
{
	if((LastValue(Buy) == True) && (StaticVarGet(("BuyFlag" + Name())) != LastValue(DateTime())))
	{
		StaticVarSet(("BuyFlag" + Name()), LastValue(DateTime()));
		DrawBut("Buy", X0+X1+10, Y0, X0+X1+75, Y0+30,  colorGrey40, colorGrey40);
		TempCount = StaticVarGet("BuyCount" + Name());
		TempIndex = StaticVarGet("BuyIndex" + Name());
		TempPrice = StaticVarGet("BuyPrice"  + Name());
		TempQty = StaticVarGet("BuyQty"  + Name());
		TempIndex[TempCount] = LastValue(DateTime());
		TempPrice[TempCount] = BuyPriceValue;
		TempQty[TempCount] = LotQuantity;
		TempCount++;
		StaticVarSet("BuyCount" + Name(), TempCount);
		StaticVarSet(("BuyIndex" + Name()), TempIndex);
		StaticVarSet(("BuyPrice" + Name()), TempPrice);
		StaticVarSet(("BuyQty" + Name()), TempQty);
		
		if(EnableAutoTrade == "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);
		}
	}

	if((LastValue(Sell) == True) && (StaticVarGet(("SellFlag" + Name())) != LastValue(DateTime())))
	{
		StaticVarSet(("SellFlag" + Name()), LastValue(DateTime()));
		DrawBut("Sell", X0+X1+10, Y0, X0+X1+75, Y0+30,  colorGrey40, colorGrey40);
		TempCount = StaticVarGet("SellCount" + Name());
		TempIndex = StaticVarGet("SellIndex" + Name());
		TempPrice = StaticVarGet("SellPrice"  + Name());
		TempQty = StaticVarGet("SellQty"  + Name());
		TempIndex[TempCount] = LastValue(DateTime());
		TempPrice[TempCount] = SellPriceValue;
		TempQty[TempCount] = LotQuantity;
		TempCount++;
		StaticVarSet("SellCount" + Name(), TempCount);
		StaticVarSet(("SellIndex" + Name()), TempIndex);
		StaticVarSet(("SellPrice" + Name()), TempPrice);
		StaticVarSet(("SellQty" + Name()), TempQty);
		
		if(EnableAutoTrade == "Yes")
		{
			LastOrderNo = StaticVarGet("OrderNo");
			LastOrderNo++;
			StaticVarSet("OrderNo", LastOrderNo, 1);
			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);
		}
	}
	
	if((LastValue(Short) == True) && (StaticVarGet(("ShortFlag" + Name())) != LastValue(DateTime())))
	{
		StaticVarSet(("ShortFlag" + Name()), LastValue(DateTime()));
		DrawBut("Short", X0+X1+10, Y0, X0+X1+75, Y0+30,  colorGrey40, colorGrey40);
		TempCount = StaticVarGet("ShortCount" + Name());
		TempIndex = StaticVarGet("ShortIndex" + Name());
		TempPrice = StaticVarGet("ShortPrice"  + Name());
		TempQty = StaticVarGet("ShortQty"  + Name());
		TempIndex[TempCount] = LastValue(DateTime());
		TempPrice[TempCount] = SellPriceValue;
		TempQty[TempCount] = LotQuantity;
		TempCount++;
		StaticVarSet("ShortCount" + Name(), TempCount);
		StaticVarSet(("ShortIndex" + Name()), TempIndex);
		StaticVarSet(("ShortPrice" + Name()), TempPrice);
		StaticVarSet(("ShortQty" + Name()), TempQty);
		
		if(EnableAutoTrade == "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);
		}
	}

	if((LastValue(Cover) == True) && (StaticVarGet(("CoverFlag" + Name())) != LastValue(DateTime())))
	{
		StaticVarSet(("CoverFlag" + Name()), LastValue(DateTime()));
		DrawBut("Cover", X0+X1+10, Y0, X0+X1+75, Y0+30,  colorGrey40, colorGrey40);
		TempCount = StaticVarGet("CoverCount" + Name());
		TempIndex = StaticVarGet("CoverIndex" + Name());
		TempPrice = StaticVarGet("CoverPrice"  + Name());
		TempQty = StaticVarGet("CoverQty"  + Name());
		TempIndex[TempCount] = LastValue(DateTime());
		TempPrice[TempCount] = BuyPriceValue;
		TempQty[TempCount] = LotQuantity;
		TempCount++;
		StaticVarSet("CoverCount" + Name(), TempCount);
		StaticVarSet(("CoverIndex" + Name()), TempIndex);
		StaticVarSet(("CoverPrice" + Name()), TempPrice);
		StaticVarSet(("CoverQty" + Name()), TempQty);
		
		if(EnableAutoTrade == "Yes")
		{
			LastOrderNo = StaticVarGet("OrderNo");
			LastOrderNo++;
			StaticVarSet("OrderNo", LastOrderNo, 1);
			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);
		}
	}
}
	
X0 = 180;
Y0 = 30;

if(EnableRealTimeControl == "Yes")
{
	TotPrice = 0;
	TotQty = 0;
	TotVal = 0;
	TempPriceArray = StaticVarGet("BuyPrice" + Name());
	TempQtyArray = StaticVarGet("BuyQty" + Name());
	TempCount = StaticVarGet("BuyCount" + Name());
	for(i = 0; i < TempCount; i++)
	{
		TotPrice = TotPrice + TempPriceArray[i];
		TotQty = TotQty + TempQtyArray[i];
		TotVal = TotVal + TempPriceArray[i] * TempQtyArray[i];
	}
	if(TempCount == 0)
	{
		AvgBuyPrice = 0;
		LastBuyPrice = 0;
		LastBuyQty = 0;
	}
	else
	{
		AvgBuyPrice = (TotPrice / TempCount);
		LastBuyPrice = TempPriceArray[(TempCount - 1)];
		LastBuyQty = NumToStr(TempQtyArray[(TempCount - 1)], 1, 0);
	}
	TotBuyQty = NumToStr(TotQty, 1, 0);
	NetBuyQty = TotQty;
	NetBuyValue = TotVal;
	
	TotPrice = 0;
	TotQty = 0;
	TotVal = 0;
	TempPriceArray = StaticVarGet("SellPrice" + Name());
	TempQtyArray = StaticVarGet("SellQty" + Name());
	TempCount = StaticVarGet("SellCount" + Name());
	for(i = 0; i < TempCount; i++)
	{
		TotPrice = TotPrice + TempPriceArray[i];
		TotQty = TotQty + TempQtyArray[i];
		TotVal = TotVal + TempPriceArray[i] * TempQtyArray[i];
	}
	if(TempCount == 0)
	{
		AvgSellPrice = 0;
		LastSellPrice = 0;
		LastSellQty = 0;
	}
	else
	{
		AvgSellPrice = (TotPrice / TempCount);
		LastSellPrice = TempPriceArray[(TempCount - 1)];
		LastSellQty = NumToStr(TempQtyArray[(TempCount - 1)], 1, 0);
	}
	TotSellQty = NumToStr(TotQty, 1, 0);
	NetSellQty = TotQty;
	NetSellValue = TotVal;
	
	TotPrice = 0;
	TotQty = 0;
	TotVal = 0;
	TempPriceArray = StaticVarGet("ShortPrice" + Name());
	TempQtyArray = StaticVarGet("ShortQty" + Name());
	TempCount = StaticVarGet("ShortCount" + Name());
	for(i = 0; i < TempCount; i++)
	{
		TotPrice = TotPrice + TempPriceArray[i];
		TotQty = TotQty + TempQtyArray[i];
		TotVal = TotVal + TempPriceArray[i] * TempQtyArray[i];
	}
	if(TempCount == 0)
	{
		AvgShortPrice = 0;
		LastShortPrice = 0;
		LastShortQty = 0;
	}
	else
	{
		AvgShortPrice = (TotPrice / TempCount);
		LastShortPrice = TempPriceArray[(TempCount - 1)];
		LastShortQty = NumToStr(TempQtyArray[(TempCount - 1)], 1, 0);
	}
	TotShortQty = NumToStr(TotQty, 1, 0);
	NetShortQty = TotQty;
	NetShortValue = TotVal;
	
	TotPrice = 0;
	TotQty = 0;
	TotVal = 0;
	TempPriceArray = StaticVarGet("CoverPrice" + Name());
	TempQtyArray = StaticVarGet("CoverQty" + Name());
	TempCount = StaticVarGet("CoverCount" + Name());
	for(i = 0; i < TempCount; i++)
	{
		TotPrice = TotPrice + TempPriceArray[i];
		TotQty = TotQty + TempQtyArray[i];
		TotVal = TotVal + TempPriceArray[i] * TempQtyArray[i];
	}
	if(TempCount == 0)
	{
		AvgCoverPrice = 0;
		LastCoverPrice = 0;
		LastCoverQty = 0;
	}
	else
	{
		AvgCoverPrice = (TotPrice / TempCount);
		LastCoverPrice = TempPriceArray[(TempCount - 1)];
		LastCoverQty = NumToStr(TempQtyArray[(TempCount - 1)], 1, 0);
	}
	TotCoverQty = NumToStr(TotQty, 1, 0);
	NetCoverQty = TotQty;
	NetCoverValue = TotVal;
	
	NetQty = NetSellQty - NetBuyQty + NetShortQty - NetCoverQty;
	NetValue = NetSellValue - NetBuyValue + NetShortValue - NetCoverValue;
	
	NetQuantityColor = colorGrey40;
	NetValueColor = colorGrey40;

	if(NetQty > 0)
	{
		NetQuantityColor = colorRed;
		NetValueColor = colorRed;
	}
	else if(NetQty < 0)
	{
		NetQuantityColor = colorGreen;
		NetValueColor = colorGreen;
	}
	else if(NetQty == 0)
	{
		if(NetValue > 0)
		{
			NetValueColor = colorGreen;
		}
		else if(NetValue < 0)
		{
			NetValueColor = colorRed;
		}
	}
	
	DrawData (" AvgBuyPr: " + AvgBuyPrice, X0, Y0, X0+150, Y0+15, colorGrey40, colorGrey40);
	DrawData (" TotBuyQty: " + TotBuyQty, X0+155 , Y0, X0+305, Y0+15, colorGrey40, colorGrey40);
	DrawData (" AvgSellPr: " + AvgSellPrice, X0+310, Y0, X0+460, Y0+15, colorGrey40, colorGrey40);
	DrawData (" TotSellQty: " + TotSellQty, X0+465, Y0, X0+615, Y0+15, colorGrey40, colorGrey40);
	DrawData (" AvgShortPr: " + AvgShortPrice, X0+620, Y0, X0+770, Y0+15, colorGrey40, colorGrey40);
	DrawData (" TotShortQty: " + TotShortQty, X0+775 , Y0, X0+925, Y0+15, colorGrey40, colorGrey40);
	DrawData (" AvgCoverPr: " + AvgCoverPrice, X0+930, Y0, X0+1080, Y0+15, colorGrey40, colorGrey40);
	DrawData (" TotCoverQty: " + TotCoverQty, X0+1085, Y0, X0+1235, Y0+15, colorGrey40, colorGrey40);
	
	Y0 = 50;
	
	DrawData (" LastBuyPr: " + LastBuyPrice, X0, Y0, X0+150, Y0+15, colorGrey40, colorGrey40);
	DrawData (" LastBuyQty: " + LastBuyQty, X0+155 , Y0, X0+305, Y0+15, colorGrey40, colorGrey40);
	DrawData (" LastSellPr: " + LastSellPrice, X0+310, Y0, X0+460, Y0+15, colorGrey40, colorGrey40);
	DrawData (" LastSellQty: " + LastSellQty, X0+465, Y0, X0+615, Y0+15, colorGrey40, colorGrey40);
	DrawData (" LastShortPr: " + LastShortPrice, X0+620, Y0, X0+770, Y0+15, colorGrey40, colorGrey40);
	DrawData (" LastShortQty: " + LastShortQty, X0+775 , Y0, X0+925, Y0+15, colorGrey40, colorGrey40);
	DrawData (" LastCoverPr: " + LastCoverPrice, X0+930, Y0, X0+1080, Y0+15, colorGrey40, colorGrey40);
	DrawData (" LastCoverQty: " + LastCoverQty, X0+1085, Y0, X0+1235, Y0+15, colorGrey40, colorGrey40);
	
	Y0 = 70;
	
	DrawData (" LTP : " + CurrentTradedPrice, X0, Y0, X0+125, Y0+15, LTPColor, LTPColor);
	DrawData (" LTQ : " + NumToStr(CurrentLTQ,1,0), X0+130, Y0, X0+255, Y0+15, LTQColor, LTQColor);
	DrawData (" Bid : " + CurrentBidPrice, X0+260, Y0, X0+385, Y0+15, AskColor, AskColor);
	DrawData (" Ask : " + CurrentAskPrice, X0+390, Y0, X0+515, Y0+15, BidColor, BidColor);
	
	NestOredrNo = ClientIdValue + NumToStr(Now(3),1,0) + "00" + StaticVarGet("OrderNo");
	DrawData (" NetQty : " + NetQty, X0+520, Y0, X0+670, Y0+15, NetQuantityColor, NetQuantityColor);
	DrawData (" NetValue : " + NetValue, X0+675, Y0, X0+900, Y0+15, NetValueColor, NetValueColor);
	DrawData (" Order No : " + NestOredrNo, X0+905, Y0, X0+1150, Y0+15, colorGrey40, colorGrey40);
	
}

_SECTION_END();

// ~~~~~~~~~~~~~~~~ Quote Display Draw ~~~~~~~~~~~~~~~~~//

_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();



Code:
_SECTION_BEGIN("Manual Trading Pi Bridge");
//coded by Choks.Mail ur Feedback to [email protected]
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 [email protected]",(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();
OK. Will look at it, but no promise.
Week day very busy. only weekend might got some time.

Let see whether any code expert will do it before me.
God bless you.
 

KelvinHand

Well-Known Member
In fact you only need 13 lines of code no matter how many time frames you want to cover. Thirteen.

Hi Trash,

Let me put it this way, they are not as good as you that will know how to complete the code in 13 lines. I can understand your high standard and your proud of yourself.

If you are willing to transfer your know how to show them how you do the 13 lines, it will be very grateful to learn from you. But if not - then i think become show-off to other.

No point doing this here & there.

Thank you & best regards...KH
 
I want to learn,

Example;
There are 3 indicator in my system afl

indicator1 , indicator2 , indicator3


For Buy=Any two indicator buy signal ,

For sell=Any two indicator sell signal ,

how to write buy sell rules?

thank you
 

extremist

Well-Known Member
Ridiculous. Why would I want to show something to guys who do not even pay respect to the actual AmiBroker developer in the first place and ignoramuses who do not want to listen anyway but just want to grab stuff like drug addicts. And for the record I have shown many things already... thousands and thousands of things. You don't have to tell me what I have to show. I do not owe anything to anyone!

As for this specific case I have told already what to do! And the picture is just shown to those special case bunglers and their famous "But this is not possible in AmiBroker..." whining. They should rather get up from bed finally and start to learn something first then afterwards they can start to talk while sleeping.
Respect is a virtue which is not compelled. It is to be Earned .
you reap what you sow.
You do something worthy to earn respect and you will get it.
but begging....:D
 
I want to learn,
Example;
There are 3 indicator in my system afl
indicator1 , indicator2 , indicator3
For Buy=Any two indicator buy signal ,
For sell=Any two indicator sell signal ,
how to write buy sell rules?
thank you

Lets say u have 3 conditions (based on your 3 indis) with 2 states each (Long/Short)

UP_Con1, UP_Con2. UP_Con3

DN_Con1, DN_Con2, DN_Con3

now combine them like this

Buy = UP_Con1 and UP_Con2 or UP_Con1 and UP_Con3 or UP_Con2 and UP_Con3;
Short = DN_Con1 and DN_Con2 or DN_Con1 and DN_Con3 or DN_Con2 and DN_Con3;


Happy :)
 
Hello

I have a question

Did Tj or any other moderator personally invite us to come here and participate?

We all come here out of our own wish, we stay here and contribute in our own way, as it fulfills some of our needs . . . .

It may not be possible to solve everyone's queries but we definitely have a place to raise them.

We all choose to be here, no one is forcing us to do that, once again we all come here as it fulfills some of our needs

However it's nobody Else's business to say what that need can/should be,
if it is a genuine need to help others, or it is to just show off,
or even a lack affection/friends in real life, its everyone's personal call . . .

The forum is for traders, trying to learn/help from other traders

We should all try to make this a Happy place. :thumb:

Take what helps you, contribute where you can, and just ignore what you don't like ;)


Cheers


Happy :)
 

Similar threads