Simple Coding Help - No Promise.

extremist

Well-Known Member
Extremist,

I got your point what you are saying. No issues at all about your hard words;).
You are right that most people need everything served to them:mad:

I can see the sell signal with zoom in and out, that's not an issue.
Issue is exploration doesn't highlight this sell signal in it. It is showing only buy signals (blue triangle in red circles, refer attached chart). Also attached is the exploration chart snapshot which shows only buy signals (I have checked it and it shows no sell signal).

Hope this clears misunderstanding..




ok.....
i take back those words for u. but those goes to few others.

I try to see if i could help u. but 'm not good at explorations. but i give a shot....
and sorry if i hurt u....
 
mastermind007, sent you a pm re amibroker afl. Please reply
I did not get any PMs from you. Did you send it to me or to someone else?
 

extremist

Well-Known Member
Thanks a lot Nihal :thumb:
It is not showing sell signal. Example- check Indusind bank future chart, there is a sell signal generated as shown in chart attached.



FYI, I am using hourly chart. There is also 1 more sell signal on 19th May which is not coming in exploration results.

Thanks,
Ashish..
there was little coding mistake tht's why it was not working.
i corrected it and re posting the code bellow.
Code:
_SECTION_BEGIN("Cross Stochastic");

Graph0=50;
Graph1=90;
Graph2=10;

Plot(Graph0,"",2,1);
Plot(Graph1,"",4,1);
Plot(Graph2,"",8,1);
uptrend= IIf( StochK(17,9) > StochD(17,9,3), 1, 0 );
downtrend=IIf( StochK(17,9)<StochD(17,9,3), 1, 0 );
crossBuy=Cross(StochK(17,9),StochD(17,9,3));
crossSell=Cross(StochD(17,9,3),StochK(17,9));

 Plot( StochD(17,9,3), _DEFAULT_NAME(), colorRed , ParamStyle("Style") );

Plot( StochK(17,9), _DEFAULT_NAME(), colorBlue , ParamStyle("Style") );


Buy =  Ref(crossBuy,-2)  AND  Ref(StochD(9,5,3),-2) <20 AND Ref(uptrend,-1) AND uptrend ;
Sell = crossSell  AND StochD(9,5,3) > 50 ;

//Buy2=Cross(StochK(17,9),Graph2) ;
//Sell2=Cross(StochD(17,9,3),Graph1);
Buy2=Cross(StochK(17,9),Graph2) and StochK(17,9)>10 ;
Sell2=Cross(Graph1,StochD(17,9,3)) and StochD(17,9,3)<90;

Short=Sell;
Cover=Buy;

PlotShapes( IIf(Buy, shapeUpArrow,0) , colorGreen ,0,StochD(17,9,3),-10);
PlotShapes( IIf(Sell, shapeDownArrow,0) , colorRed ,0, StochD(17,9,3),-10);

PlotShapes( shapeSmallUpTriangle* Buy2 , colorBlue);
PlotShapes( shapeSmallDownTriangle* Sell2 ,colorRed);
Filter=1;
AddColumn(IIf(Buy2 ,Ref(c,0) ,Null),"Buy stoch ",6.2,2,29);  
AddColumn(IIf(Sell2 ,Ref(c,0),Null),"Sell stoch",6.2,2,4);

_SECTION_END();
let me know ... is it ok now....?
 
there was little coding mistake tht's why it was not working.
i corrected it and re posting the code bellow.
Code:
_SECTION_BEGIN("Cross Stochastic");

Graph0=50;
Graph1=90;
Graph2=10;

Plot(Graph0,"",2,1);
Plot(Graph1,"",4,1);
Plot(Graph2,"",8,1);
uptrend= IIf( StochK(17,9) > StochD(17,9,3), 1, 0 );
downtrend=IIf( StochK(17,9)<StochD(17,9,3), 1, 0 );
crossBuy=Cross(StochK(17,9),StochD(17,9,3));
crossSell=Cross(StochD(17,9,3),StochK(17,9));

 Plot( StochD(17,9,3), _DEFAULT_NAME(), colorRed , ParamStyle("Style") );

Plot( StochK(17,9), _DEFAULT_NAME(), colorBlue , ParamStyle("Style") );


Buy =  Ref(crossBuy,-2)  AND  Ref(StochD(9,5,3),-2) <20 AND Ref(uptrend,-1) AND uptrend ;
Sell = crossSell  AND StochD(9,5,3) > 50 ;

//Buy2=Cross(StochK(17,9),Graph2) ;
//Sell2=Cross(StochD(17,9,3),Graph1);
Buy2=Cross(StochK(17,9),Graph2) and StochK(17,9)>10 ;
Sell2=Cross(Graph1,StochD(17,9,3)) and StochD(17,9,3)<90;

Short=Sell;
Cover=Buy;

PlotShapes( IIf(Buy, shapeUpArrow,0) , colorGreen ,0,StochD(17,9,3),-10);
PlotShapes( IIf(Sell, shapeDownArrow,0) , colorRed ,0, StochD(17,9,3),-10);

PlotShapes( shapeSmallUpTriangle* Buy2 , colorBlue);
PlotShapes( shapeSmallDownTriangle* Sell2 ,colorRed);
Filter=1;
AddColumn(IIf(Buy2 ,Ref(c,0) ,Null),"Buy stoch ",6.2,2,29);  
AddColumn(IIf(Sell2 ,Ref(c,0),Null),"Sell stoch",6.2,2,4);

_SECTION_END();
let me know ... is it ok now....?
Thanks a lot Budddy:clap:
Appreciated.
 

trash

Well-Known Member
Thanks a lot Nihal :thumb:
It is not showing sell signal. Example- check Indusind bank future chart, there is a sell signal generated as shown in chart attached.



FYI, I am using hourly chart. There is also 1 more sell signal on 19th May which is not coming in exploration results.

Thanks,
Ashish..
It does not show it because this line simply is a paradox.

Code:
Sell2=Cross(StochD(17,9,3),Graph1) and StochD(17,9,3)<90;
The line above says "Show something if StochD crosses from below above 90 and if at the same time it is below 90." When should that one ever happen?
So instead it should be this way

Code:
Sell2=Cross(Graph1, StochD(17,9,3)) and StochD(17,9,3)<90;
But that one is things done twice. So this next one is just enough

Code:
Sell2=Cross(Graph1, StochD(17,9,3));
You guys should repeat in you mind what a line of code is actually doing instead of adding things that either make no sense or are just redundant and add nothing (but just useless code to additionally take care of and making entire code slower).


So we come to next bad thing in your code being the fact that your code is not effective code at all but instead been made very slow in comparison to more effective way of doing things. It has been said multiple times already ... so here is another one time being added to the previous billion ones:

If you have multiple calls of same functions with same parameters then store those functions to just one variable. It makes your code just crispy and better maintainable.
Is it so much difficult? I don't think so.

So if like in your code you have Stochk( 17, 3 ) being called 7 times then make life easier and code execution faster by storing it to i.e

myStochK = StochK( 17, 3 );

What effect you will get?
Well, as said, faster code and less work if maintaining it, debugging it and of course much better readable etc.

So now take some time today and compare your code with my more crispy version. Well it is still not perfect yet but way, way, way better than original one for sure. Also if opening both codes in editor compare execution times if you click Code check & profile in editor. Does it click on you while seeing the difference? (like 80% speed up for example)

Code:
_SECTION_BEGIN( "Cross Stochastic" );

Graph0 = 50;
Graph1 = 90;
Graph2 = 10;

myStochK = StochK( 17, 9 );
myStochD = StochD( 17, 9, 3 );
myStochD2 = StochD( 9, 5, 3 );

uptrend = myStochK > myStochD;
downtrend = myStochK < myStochD;

crossBuy = Cross( myStochK, myStochD );
crossSell = Cross( myStochD, myStochK );

Buy = Ref( crossBuy, -2 ) AND Ref( myStochD2, -2 ) < 20 AND Sum( uptrend, 2 ) == 2;
Sell = crossSell AND myStochD2 > 50;

Buy2 = Cross( myStochK, Graph2 );
Sell2 = Cross( Graph1, myStochD );

Short = Sell;
Cover = Buy;


if( Status( "action" ) == actionIndicator )
{
	Plot( myStochD, "StochD", colorRed, ParamStyle( "Style StochD" ) );
	//Plot( myStochD2, "StochD2", colorOrange, ParamStyle( "Style StochD2" ) );
	Plot( myStochK, "StochK", colorBlue, ParamStyle( "Style StochK" ) );
	
	Plot( Graph0, "", 2, 1 );
	Plot( Graph1, "", 4, 1 );
	Plot( Graph2, "", 8, 1 );

	PlotShapes( IIf( Buy, shapeUpArrow, 0 ), colorGreen, 0, myStochD, -10 );
	PlotShapes( IIf( Sell, shapeDownArrow, 0 ), colorRed, 0, myStochD, -10 );

	PlotShapes( shapeSmallUpTriangle*Buy2, colorBlue, 0, 10 );
	PlotShapes( shapeSmallDownTriangle*Sell2, colorRed, 0, 90 );
}


if( Status( "action" ) == actionExplore )
{
	Filter = buy2 OR sell2;
	SetSortColumns( 2 );
	AddColumn( IIf( Buy2, Ref( C, 0 ), Null ), "Buy stoch ", 6.2, 2, 29 );
	AddColumn( IIf( Sell2, Ref( C, 0 ), Null ), "Sell stoch", 6.2, 2, 4 );
}

_SECTION_END();
But good advices will be ignored anyway (the majority of awful codes in this forum just prove it) so carry on continuing with making things worse and (most of the time) blaming other sides of fence when trouble(s) will occur....
 

extremist

Well-Known Member
It does not show it because this line simply is a paradox.

Code:
Sell2=Cross(StochD(17,9,3),Graph1) and StochD(17,9,3)<90;
The line above says "Show something if StochD crosses from below above 90 and if at the same time it is below 90." When should that one ever happen?
So instead it should be this way

Code:
Sell2=Cross(Graph1, StochD(17,9,3)) and StochD(17,9,3)<90;
But that one is things done twice. So this next one is just enough

Code:
Sell2=Cross(Graph1, StochD(17,9,3));
You guys should repeat in you mind what a line of code is actually doing instead of adding things that either make no sense or are just redundant and add nothing (but just useless code to additionally take care of and making entire code slower).


So we come to next bad thing in your code being the fact that your code is not effective code at all but instead been made very slow in comparison to more effective way of doing things. It has been said multiple times already ... so here is another one time being added to the previous billion ones:

If you have multiple calls of same functions with same parameters then store those functions to just one variable. It makes your code just crispy and better maintainable.
Is it so much difficult? I don't think so.

So if like in your code you have Stochk( 17, 3 ) being called 7 times then make life easier and code execution faster by storing it to i.e

myStochK = StochK( 17, 3 );

What effect you will get?
Well, as said, faster code and less work if maintaining it, debugging it and of course much better readable etc.

So now take some time today and compare your code with my more crispy version. Well it is still not perfect yet but way, way, way better than original one for sure. Also if opening both codes in editor compare execution times if you click Code check & profile in editor. Does it click on you while seeing the difference? (like 80% speed up for example)

Code:
_SECTION_BEGIN( "Cross Stochastic" );

Graph0 = 50;
Graph1 = 90;
Graph2 = 10;

myStochK = StochK( 17, 9 );
myStochD = StochD( 17, 9, 3 );
myStochD2 = StochD( 9, 5, 3 );

uptrend = myStochK > myStochD;
downtrend = myStochK < myStochD;

crossBuy = Cross( myStochK, myStochD );
crossSell = Cross( myStochD, myStochK );

Buy = Ref( crossBuy, -2 ) AND Ref( myStochD2, -2 ) < 20 AND Sum( uptrend, 2 ) == 2;
Sell = crossSell AND myStochD2 > 50;

Buy2 = Cross( myStochK, Graph2 );
Sell2 = Cross( Graph1, myStochD );

Short = Sell;
Cover = Buy;


if( Status( "action" ) == actionIndicator )
{
	Plot( myStochD, "StochD", colorRed, ParamStyle( "Style StochD" ) );
	//Plot( myStochD2, "StochD2", colorOrange, ParamStyle( "Style StochD2" ) );
	Plot( myStochK, "StochK", colorBlue, ParamStyle( "Style StochK" ) );
	
	Plot( Graph0, "", 2, 1 );
	Plot( Graph1, "", 4, 1 );
	Plot( Graph2, "", 8, 1 );

	PlotShapes( IIf( Buy, shapeUpArrow, 0 ), colorGreen, 0, myStochD, -10 );
	PlotShapes( IIf( Sell, shapeDownArrow, 0 ), colorRed, 0, myStochD, -10 );

	PlotShapes( shapeSmallUpTriangle*Buy2, colorBlue, 0, 10 );
	PlotShapes( shapeSmallDownTriangle*Sell2, colorRed, 0, 90 );
}


if( Status( "action" ) == actionExplore )
{
	Filter = buy2 OR sell2;
	SetSortColumns( 2 );
	AddColumn( IIf( Buy2, Ref( C, 0 ), Null ), "Buy stoch ", 6.2, 2, 29 );
	AddColumn( IIf( Sell2, Ref( C, 0 ), Null ), "Sell stoch", 6.2, 2, 4 );
}

_SECTION_END();
But good advices will be ignored anyway (the majority of awful codes in this forum just prove it) so carry on continuing with making things worse and (most of the time) blaming other sides of fence when trouble(s) will occur....
Well thank u Trash
i learnt these basics from u yrs ago....
to keep code neat and clean.

i just copied the code . corrected it and posted it.
i didn't took the pain to fasten it.
else i keep in mind these things.

And please don't give up on us. :)
we might be slow learners but we r learning.
 
Hi guys, nice to read how this useful thread. I’m struggling with a basic set of rules which I would like to plot as a ribbon.

Uptrend:
When RSI(14) crosses 70 upward: trendribbon turns green
o When RSI(14) stays above 40 (after first passing 70): ribbon stays green
o When RSI(14 crosses 40 downward (after first passing 70): ribbon turns grey

Downtrend:
When (RSI(14) crosses 30 downward: trendribbon turns red
o When RSI(14) stays under 60 (after first passing 30 down): ribbon stays red
o When (RSI(14) crosses 60 upward (after first passing 30 down): ribbon turns grey

Can someone please help in coding an afl with these rules?
Thanks in advance!!
 
Please correct the error in this AFL

_SECTION_BEGIN("TRADE");
Title = "AUTOTRADE";
TargetBasedExit = ParamList("Target Based Exit", "No|Yes", 0);
StopLossBasedExit = ParamList("StopLoss Based Exit", "No|Yes", 0);
TargetPoints = Param("Target Points",0.00,0.00,1000000.00,0.05);
StopLossPoints = Param("StopLoss Points",0.00,0.00,1000000.00,0.05);
BuyPriceSelection = ParamList("Buy Price", "Open|High|Low|Close", 0);
SellPriceSelection = ParamList("Short Price", "Open|High|Low|Close", 0);
OrderExecution = ParamList("Order Execution", "Immediate|On Candle Completion", 0);
LotQuantity = Param("Quantity", 1, 1, 100000, 1); // Default Trade Qty.
Exchange = ParamList("Exchange", "MCX|NFO|NSE-EQ|OPTIONS|CDS", 0);
InstType = ParamList("Type", "FUTIDX|FUTSTK|FUTCOM|OPTIDX|OPTSTK", 0);
SymbolStr = ParamStr("Symbol", ""); // Symbol
Contract = ParamList("Contract", "FIRST-MONTH|SECOND-MONTH", 0);
StrikePrice = Param("If Options Enter Strike Price", 0.00,0.00,1000000.00,0.05);
CallPut = ParamList("If Options Select Call/Put", "CALL|PUT", 0);
ProductType = ParamList("Product Type", "MIS|NRML", 0);
AutoMode = ParamList("AUTO MODE", "FULLY-AUTOMATIC|SEMI-AUTOMATIC", 0);
OrderType = ParamList("Order Type", "LIMIT|MARKET", 0);
ClientIdValue = ParamStr("Client Id", "");
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);
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);

Buy = 0;
Sell = 0;
Short = 0;
Cover = 0;

SetBarsRequired( sbrAll );
RequestTimedRefresh( 1,False );

if(EnableStrategy == "Yes")
{
//Buy = LastValue(C)> 100 ;
/*~~~~~~~~~~~~~~~~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 = LastValue(C)> 100;
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")=="")
{

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


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 == "Open")
{
BuyPriceValue = LastValue(O);
}
else if(BuyPriceSelection == "High")
{
BuyPriceValue = LastValue(H);
}
else if(BuyPriceSelection == "Low")
{
BuyPriceValue = LastValue(L);
}
else
{
BuyPriceValue = CurrentTradedPrice;
}

if(SellPriceSelection == "Open")
{
SellPriceValue = LastValue(O);
}
else if(SellPriceSelection == "High")
{
SellPriceValue = LastValue(H);
}
else if(BuyPriceSelection == "Low")
{
SellPriceValue = LastValue(L);
}
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, 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, 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, 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, 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")
{
_TRACE(("BuyFlag" + Name()));

if((LastValue(Buy) == True) && (StaticVarGet(("BuyFlag" + Name())) != LastValue(DateTime())) )
{
StaticVarSet(("BuyFlag" + Name()), LastValue(DateTime()));
_TRACE(("BuyFlag1" + Name()));

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")
{
OrdInfo = Exchange + " BUY " +SymbolStr + " " + LotQuantity + " " + BuyPriceValue + " " +ProductType + " " + InstType + " " + Contract + " " + StrikePrice + " " + CallPut + " "+ AutoMode + " " + ClientIdValue;

SendOrder(1, OrdInfo);
_TRACE("Buy @" +BuyPriceValue);
}
}

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")
{
OrdInfo = Exchange + " SELL " +SymbolStr + " " + LotQuantity + " " + SellPriceValue + " " +ProductType + " " + InstType + " " + Contract + " " + StrikePrice + " " + CallPut + " "+ AutoMode + " " + ClientIdValue;
//nestplus.PlaceOrder("BUY", TempOrderNo, "NSE", TempName, "DAY", OrderType, nqty ,BuyPriceValue, 0.0, 0, ProductType, ClientIdValue);
//PopupWindow( "Buy at Price " + BuyPriceValue, "Buy",5, 600, -1, 20, 20 );
//AlertIf( Sell, "EXEC G:\\OrdPlugin.exe ", OrdInfo, 3 );
//PopupWindow( "Sell at Price " + SellPriceValue, "Buy",5, 600, -1, 20, 20 );
SendOrder(1, OrdInfo);
_TRACE("Sell @" +SellPriceValue);
}
}

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")
{
OrdInfo = Exchange + " SELL " +SymbolStr + " " + LotQuantity + " " + SellPriceValue + " " +ProductType + " " + InstType + " " + Contract + " " + StrikePrice + " " + CallPut + " "+ AutoMode + " " + ClientIdValue;
//nestplus.PlaceOrder("BUY", TempOrderNo, "NSE", TempName, "DAY", OrderType, nqty ,BuyPriceValue, 0.0, 0, ProductType, ClientIdValue);
//PopupWindow( "Buy at Price " + BuyPriceValue, "Buy",5, 600, -1, 20, 20 );
//AlertIf( Sell, "EXEC G:\\OrdPlugin.exe ", OrdInfo, 3 );
//PopupWindow( "Sell at Price " + SellPriceValue, "Buy",5, 600, -1, 20, 20 );
SendOrder(1, OrdInfo);
_TRACE("Sell @" +SellPriceValue);
}
}

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")
{
OrdInfo = Exchange + " BUY " +SymbolStr + " " + LotQuantity + " " + SellPriceValue + " " +ProductType + " " + InstType + " " + Contract + " " + StrikePrice + " " + CallPut + " "+ AutoMode + " " + ClientIdValue;
//nestplus.PlaceOrder("BUY", TempOrderNo, "NSE", TempName, "DAY", OrderType, nqty ,BuyPriceValue, 0.0, 0, ProductType, ClientIdValue);
//PopupWindow( "Buy at Price " + BuyPriceValue, "Buy",5, 600, -1, 20, 20 );
//AlertIf( Sell, "EXEC G:\\OrdPlugin.exe ", OrdInfo, 3 );
//PopupWindow( "Sell at Price " + SellPriceValue, "Buy",5, 600, -1, 20, 20 );
SendOrder(1, OrdInfo);
_TRACE("BUY @" +BuyPriceValue);
}
}
}

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;
TotQty = TotQty + TempQtyArray;
TotVal = TotVal + TempPriceArray * TempQtyArray;
}
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;
TotQty = TotQty + TempQtyArray;
TotVal = TotVal + TempPriceArray * TempQtyArray;
}
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;
TotQty = TotQty + TempQtyArray;
TotVal = TotVal + TempPriceArray * TempQtyArray;
}
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;
TotQty = TotQty + TempQtyArray;
TotVal = TotVal + TempPriceArray * TempQtyArray;
}
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();
 

Similar threads