intraday Buy & Sell signal with trailing Stoploss

#42
Hello Dear,
The alf which requires you the code is as follows

_SECTION_BEGIN("MA Diff");
T=26;
KMA=((C-MA(C,T))/MA(C,T))*100;
Graph0=KMA;
Graph0Style=2+4;
Graph0BarColor=IIf(KMA>0,5,4);
GraphXSpace=5;

_SECTION_END();

_SECTION_BEGIN("Price");
SetChartOptions(0,chartShowArrows|chartShowDates);
Plot( C, "Close", ParamColor("Color", colorBlack ), styleNoTitle | ParamStyle("Style") | GetPriceStyle() );
_SECTION_END();

//------------------------------------------------------------------------------

_SECTION_BEGIN("ZIG-ZAG");
P = ParamField( "Price field" );
change = Param("% change",5,0.1,25,0.1);
_SECTION_END();

_SECTION_BEGIN("EMA");
P = ParamField("Price field",-1);
Periods = Param("Periods", 15, 2, 300, 1, 10 );
_SECTION_END();

_SECTION_BEGIN("MACD Exploration");
r1 = Param( "Fast avg", 12, 2, 200, 1 );
r2 = Param( "Slow avg", 26, 2, 200, 1 );
r3 = Param( "Signal avg", 9, 2, 200, 1 );
Z=Param("zig",1,0,10,0.1);


Cond1 = Cross(MACD(r1,r2),Signal(r1,r2,r3));

Cond3 = Zig(C,z)>Ref(Zig(C,z),-4);
Buy = Cond1 AND Cond3;

Cond4 = Cross(Signal(r1,r2,r3),MACD(r1,r2));

Cond6 = Zig(C,z)<Ref(Zig(C,z),-4);
Sell = Cond4 AND Cond6;
Trigger = WriteIf(Buy, "Buy", "") + WriteIf(Sell, "Sell", "");

_N(Title = StrFormat("{{NAME}} {{DATE}} {{INTERVAL}}: O=%1.2f, H=%1.2f, L=%1.2f, C=%1.2f, V=%1.0f\n{{VALUES}}", O, H, L, C, V));

BG = IIf(Buy, colorPaleGreen, IIf(Sell, colorRose, colorDefault));
FG = IIf(Buy, colorDarkGreen, IIf(Sell, colorDarkRed, colorDefault));

if(Status("action") == actionIndicator)
{
Plot(C, "", colorGrey50, styleBar);
//PlotShapes(IIf(Buy, shapeCircle, shapeNone),colorBlue, 0,L, Offset=-60);
//PlotShapes(IIf(Sell, shapeCircle, shapeNone),colorBlue, 0,H, Offset=-30);

}

//------------------------------------------------------------------------------------------------
if(Status("action") == actionExplore)

Filter = Buy OR Sell;
SetOption("NoDefaultColumns", True);

AddTextColumn(Name(), "Symbol", 77, FG, BG, 120);
AddColumn(DateTime(), "Date", formatDateTime, FG, BG, 100);
AddColumn(TimeNum() ,"Time",1);
AddColumn( C, "Close", 1.3 );
AddColumn( H, "High", 1.3 );
AddColumn(V, "Volume");
AddColumn(Ref(V,-1),"P-Vol");
AddColumn(V/Ref(V,-1)*100,"Increase in Vol");
AddColumn( Buy, "Buy", 1 );
AddColumn( Sell, "Sell", 1 );

shape = Buy * shapeHollowUpTriangle + Sell * shapeHollowDownTriangle;

PlotShapes( shape, IIf( Buy, colorBlue, colorBlue ), 0, IIf( Buy, Low, High ) );

GraphXSpace = 7;

GraphXSpace = 7;
_SECTION_END();

_SECTION_BEGIN("EMA3");
P = ParamField("Price field",-1);
Periods = Param("Periods", 15, 2, 300, 1, 10 );
_SECTION_END();


_SECTION_BEGIN("Background text");
C13=Param("fonts",20,10,30,1 );
C14=Param("left-right",2.1,1.0,5.0,0.1 );
C15=Param("up-down",12,1,20,1 );
Miny = Status("axisminy");
Maxy = Status("axismaxy");
lvb = Status("lastvisiblebar");
fvb = Status("firstvisiblebar");
pxwidth = Status("pxwidth");
pxheight = Status("pxheight");
GfxSetBkMode(transparent=1);
GfxSetOverlayMode(1);
GfxSelectFont("Tahoma", Status("pxheight")/C13 );
GfxSetTextAlign( 6 );
GfxSetTextColor( ColorRGB (217,217,213));
GfxTextOut( Name(), Status("pxwidth")/C14, Status("pxheight")/C15 );
GfxSelectFont("Tahoma", Status("pxheight")/C13*0.5 );
GfxSetTextColor( ColorRGB (255,255,255));
GfxTextOut( "DG", Status("pxwidth")/C14, Status("pxheight")/C15*2.5 );
GfxSelectFont("Tahoma", Status("pxheight")/C13*0.5 );
GfxSetTextColor( ColorRGB (255,255,255));
GfxTextOut( "DG", Status("pxwidth")/C14, Status("pxheight")/C15*4 );
GfxSelectFont("MS Sans Serif", 10, 500, False, False, 0);
//Second phase starts Here

_SECTION_BEGIN("Trading");
//SetChartBkColor(ParamColor("Outer panel color ",colorLightYellow));
SetChartBkColor(ParamColor("BackGround Color", colorBlack));
pShowtradeLines = ParamToggle("Show Trade Lines", "No|Yes", 1);
pShowMarkers = ParamToggle("Show Markers", "No|Yes", 1);
synch=ParamToggle("Synchronize buy/short with foreign index", "No|Yes", 1);
Volmin=Param("Volume minimum",5000,0,10000000,50);
Volmax=Param("Volume maximum",1000000,0,10000000,50);
priceRL=Param("Price Range Min",150,1,20000,1);
priceRH=Param("Price Range Max",3000,1,20000,1);
PercChangemin=Param("Percentage Change Min set", -25, -100, 100, 0.1);
PercChangemax=Param("Percentage Change Max set", 25, -100, 100, 0.1);
PerctakeProfit=Param("Take Profit Percent Set",0.6,0.3,30,0.1);
PercStoploss=Param("StopLoss Percent Set",0.25,0.2,5,0.1);

PlotOHLC(Open,High,Low,Close,"",colorWhite,styleCandle);
Bars = 0;
xpdh = 90;

{
Plot_Range = (TimeNum() >= 85500 AND TimeNum()<= 153500) AND (DateNum()==LastValue(DateNum()));
FH_Range = (TimeNum() >= 085500 AND TimeNum()<= 093000) AND (DateNum()==LastValue(DateNum()));

FH_Prices = High * FH_Range;
FH_Marker = BarsSince(FH_Range>0);

Num_Bars = 36000 / Interval(1);

TimeFrameSet(inDaily);
TOP_ = Open;
PDH_ = Ref(High,-1);
PDL_ = Ref(Low,-1);
PDO_ = Ref(Open,-1);
PDC_ = Ref(Close,-1);
PDM_ = (PDH_+PDL_)/2;
TimeFrameRestore();

isAll = True;
isRth = TimeNum() >= 085400 AND TimeNum() <= 093000;
isdRth = TimeNum() >= 085400 AND TimeNum() <= 160000;

aRthL = IIf(isRth, L, 1000000);
aRthH = IIf(isdRth, H, Null);
aRthLd = IIf(isdRth, L, 1000000);

TOP = TimeFrameExpand(TOP_,inDaily,expandFirst);
PDH = TimeFrameExpand(PDH_,inDaily,expandFirst);
PDL = TimeFrameExpand(PDL_,inDaily,expandFirst);
PDO = TimeFrameExpand(PDO_,inDaily,expandFirst);
PDC = TimeFrameExpand(PDC_,inDaily,expandFirst);
PDM = TimeFrameExpand(PDM_,inDaily,expandFirst);
FHH = Ref(HHV(High*FH_Range,Num_Bars),-FH_Marker);
FHL = TimeFrameCompress( aRthL, inDaily, compressLow );
FHL = TimeFrameExpand( FHL, inDaily, expandFirst );
DayH = TimeFrameCompress( aRthH, inDaily, compressHigh );
DayH = TimeFrameExpand( DayH, inDaily, expandFirst );
DayL = TimeFrameCompress( aRthLd, inDaily, compressLow );
DayL = TimeFrameExpand( DayL, inDaily, expandFirst );


FC1=((PDH-PDL)*0.433);
FC2=((PDH-PDL)*0.7666);
FC3=((PDH-PDL)*1.355);
FC4=(FHH-FHL);

A=IIf((FC4<=FC1+PDH*0.005),FC1,0);
B=IIf((FC4<=FC2+PDH*0.005 AND FC4>FC1+PDH*0.005),FC2,0);
Cl=IIf((FC4<=FC3 AND FC4>FC2+PDH*0.005),FC3,0);
AF=(A+B+Cl);

//foreign
_SECTION_BEGIN ("foreign Index bar graph");
Vr=ParamList("Index",List = "^NSEI,^NSEBANK,^CNXIT,^NSMIDCP,RELIANCE.NS,SBIN.N S",0);
SetForeign(Vr);
HaC =(O+H+L+C)/4;
HaO = AMA( Ref( HaC, -1 ), 0.5 );
HaH = Max( H, Max( HaC, HaO) );
HaL = Min( L, Min( HaC, HaO) );
BG3=HHV(LLV(HaL,4)+ATR(4),8);
BR3=LLV(HHV(HaH ,4)-ATR(4),8);
co = IIf(Hac>BG3 ,colorBrightGreen,IIf(Hac < BR3,colorRed,colorGrey50));
Plot(4, "", Co,styleArea+styleOwnScale | styleNoLabel, -1, 100);
RestorePriceArrays();
_SECTION_END();

BuyPrice=(DayL+AF);
BuyTP1=(BuyPrice+(BuyPrice*(PerctakeProfit/100)));
BuyTP2=(C>=BuyTP1);
SellPrice=(DayH-AF);
SellTP1=(SellPrice-(SellPrice*(PerctakeProfit/100)));
SellTP2=(C<=SellTP1);
percchange=(((C-TOP)/TOP)*100);
Vol=(V>=Volmin AND V<=Volmax);
Percentage=(percchange>=PercChangemin AND percchange<=PercChangemax);
prc=(C>=priceRL AND C<=priceRH);
BuyStop1=(BuyPrice-(BuyPrice*(PercStoploss/100)));
BuyStop2=IIf((BuyStop1<=SellPrice) AND SellPrice<=BuyPrice,SellPrice,BuyStop1);
SellStop1=(SellPrice+(SellPrice*(PercStoploss/100)));
SellStop2=IIf((SellStop1>=BuyPrice) AND SellPrice<=BuyPrice, BuyPrice,SellStop1);

BuyStop=IIf((Buy AND NOT BuyTP2),BuyStop2,Null);
BuyTP=IIf(Buy AND NOT BuyStop,BuyTP2,Null);

Bars = BarsSince(TimeNum() >= 85400 AND TimeNum() < 092900);
x0 = BarCount-LastValue(Bars);
x1 = BarCount-1;
TOP_Line = LineArray(x0,LastValue(TOP),x1,LastValue(TOP),0);
PDH_Line = LineArray(x0,LastValue(PDH),x1,LastValue(PDH),0);
PDL_Line = LineArray(x0,LastValue(PDL),x1,LastValue(PDL),0);
PDC_Line = LineArray(x0,LastValue(PDC),x1,LastValue(PDC),0);
PDM_Line = LineArray(x0,LastValue(PDM),x1,LastValue(PDM),0);
FHH_Line = LineArray(x0,LastValue(FHH),x1,LastValue(FHH),0);
FHL_Line = LineArray(x0,LastValue(FHL),x1,LastValue(FHL),0);
BuyPriceline=LineArray(x0,LastValue(BuyPrice),x1,LastValue(BuyPrice),0);
BuyStopline=LineArray(x0,LastValue(BuyStop2),x1,LastValue(BuyStop2),0);
BuyTPline=LineArray(x0,LastValue(BuyTP1),x1,LastValue(BuyTP1),0);
SellPriceline=LineArray(x0,LastValue(SellPrice),x1 ,LastValue(SellPrice),0);
SellStopline=LineArray(x0,LastValue(SellStop2),x1, LastValue(SellStop2),0);
SellTPline=LineArray(x0,LastValue(SellTP1),x1,LastValue(SellTP1),0);
DayHline=LineArray(x0,LastValue(DayH),x1,LastValue (DayH),0);
DayLline=LineArray(x0,LastValue(DayL),x1,LastValue (DayL),0);


Plot(IIf(pShowtradeLines,BuyStopline,Null),"BuySto p",colorBrightGreen,styleDots|styleNoRescale| styleNoLine);
Plot(IIf(pShowtradeLines,SellPriceline,Null),"Shor t Here",colorRed,styleDots|styleNoRescale);
//PlotShapes(IIf(pShowMarkers AND Buy, shapeHollowUpArrow, Null), colorDarkGreen, 0,L,Offset=-30);

if( Status("action") == actionIndicator )
(
Title = EncodeColor(colorWhite)+ "Trading System" + " - " + Name() + " - " + EncodeColor(colorYellow)+ Interval(2) + EncodeColor(colorYellow) +
" - " + Date() +" - "+ EncodeColor(colorYellow) + "-Open="+WriteVal(O,1) + EncodeColor(colorYellow) + "- High= "+ WriteVal(H,1)+ EncodeColor(colorYellow) + "- Low= "+ WriteVal(L,1)+ EncodeColor(colorYellow) + "- Close= "+ WriteVal(C,1)+ EncodeColor(colorYellow) + "- Vol= "+ WriteVal(V,1)+("\n")
+WriteIf(Percchange, " % Change = "+(Percchange)+" ","")+" Previous DayHigh="+WriteVal(PDH,1)+", Previous DayLow="+WriteVal(PDL,1)+", Today High="+WriteVal(DayH,1)+", Todays Low="+WriteVal(DayL,1)+
WriteIf(Hac>BG3,EncodeColor(colorBrightGreen)+"+Up ",
WriteIf(Hac<BR3,EncodeColor(colorRed)+"-Down",EncodeColor(colorLightYellow)+"< Flat >")));

GfxSetOverlayMode( mode = 0 );
GfxSelectPen( colorLightBlue, 3 );
GfxSelectSolidBrush( colorLightYellow );
GfxRoundRect( 20, 55, 180, 175, 15, 15 );
GfxSetBkMode(1);
GfxSelectFont( "Arial", 10, 700, False );
GfxSetTextColor( colorBrown );
GfxSetTextAlign(0);
GfxTextOut( WriteIf(SellPrice, "TRP level: "+(SellPrice),""), 30, 60);
GfxTextOut( WriteIf(BuyPrice, "Buy Above: "+(BuyPrice),""), 30, 75);
GfxTextOut( WriteIf(BuyStop2, "Long SL: "+(BuyStop2),""), 30, 90);
GfxTextOut( WriteIf(BuyTP1 , "Long Target 1: "+(BuyTP1),""), 30, 105);
GfxTextOut( WriteIf(SellPrice, "Sell Below: "+(SellPrice),""), 30, 120);
GfxTextOut( WriteIf(SellStop2, "Short SL: "+(SellStop2),""), 30, 135);
GfxTextOut( WriteIf(SellTP1, "Short Target: "+(SellTP1),""), 30, 150);

AddColumn(V,"Volume",1.0);
AddColumn(Percchange,"Change %",1.2);
AddColumn(BuyPrice,"Buy at",1.2);
AddColumn(BuyStop,"Buy Stop at",1.2);
AddColumn(BuyTP1,"Buy Profit at",1.2);
AddColumn(SellPrice,"Short at",1.2);
AddColumn(SellTP1,"Short profit at",1.2);

}

_SECTION_END();

_SECTION_BEGIN("short signal");
HaClose=(O+H+L+C)/4;
HaOpen = AMA( Ref( HaClose, -1 ), 0.5 );
HaHigh = Max( H, Max( HaClose, HaOpen ) );
HaLow = Min( L, Min( HaClose, HaOpen ) );
BG2=HHV(LLV(Low,4)+ATR(4),8);
BR2=LLV(HHV(High,4)-ATR(4),8);
SetBarFillColor( IIf(O <C, colorSeaGreen,colorOrange) );
k = Optimize("K",Param("K",1.75,1,5,0.25),1,5,0.25);
Per= Optimize("atr",Param("atr",10,3,30,1),3,30,1);
j=HaClose;
nm= (H-L);
rfsctor = WMA(nm, PER);
revers = K * rfsctor;
Trend = 1;
NW[0] = 0;
for(i = 1; i < BarCount; i++)
{
if(Trend[i-1] == 1)
{
if(j < NW[i-1])
{
Trend = -1;
NW = j + Revers;
}
else
{
Trend = 1;
if((j - Revers) > NW[i-1])
{
NW = j - Revers;
}
else
{
NW = NW[i-1];
}
}
}
if(Trend[i-1] == -1)
{
if(j > NW[i-1])
{
Trend = 1;
NW = j - Revers;
}
else
{
Trend = -1;
if((j + Revers) < NW[i-1])
{
NW = j + Revers;
}
else
{
NW = NW[i-1];
}
}
}
}

Plot(NW, "", IIf(Trend == 1, 6, 4), 4);

Buy=Cross(j,nw);
Short=Cross(nw,j);
Sell=Cross(nw,j);
Cover=Cross(j,nw);
Buy=ExRem(Buy,Sell);
Sell=ExRem(Sell,Buy);
Short=ExRem(Short,Cover);
Cover=ExRem(Cover,Short);
//dist = 1.5*ATR(15);
for( i = 0; i < BarCount; i++ )
{
if( Buy ) PlotText( "Buy@" + O[ i ], i, L[ i ]-Trend, colorDarkBlue, colorYellow );
if( Sell ) PlotText( "Sell@" +H[ i ], i-4, L[ i ]+Trend, colorRed, colorYellow );
}

PlotShapes(IIf(Buy, shapeUpArrow, shapeNone),colorWhite, 0,halow,-30);
PlotShapes(IIf(Sell, shapeHollowDownTriangle, shapeNone),colorWhite, 0,hahigh,-15);
PlotShapes(IIf(Cover, shapeHollowUpTriangle, shapeNone),colorWhite, 0,halow,-15);
PlotShapes(IIf(Short, shapeDownArrow, shapeNone),colorWhite, 0,hahigh,-30);
//-----------end--------------
 
#44
Re: intraday AFL

//This formula works good in amibroker 5.50 version

_SECTION_BEGIN("Stupid Functions");

function HAI_F1(no)
{
res=HHV(H,no);
sup=LLV(L,no);
avd=IIf(C>Ref(res,-1),1,IIf(C<Ref(sup,-1),-1,0));
avn=ValueWhen(avd!=0,avd,1);
return (IIf(avn==1,sup,res));
}

function HAI_F2(no)
{
return (Cross(C,HAI_F1(no)));
}

function HAI_F3(no)
{
return (Cross(HAI_F1(no),C));
}

function HAI_F4(no)
{
prev=AMA2(C,1,0);
d=IIf(C>Ref(Max(Max(H,Ref(H,-20)),Max(Ref(H,-10),Ref(H,-15))),-1),Min(Min(L,Ref(L,-20)),Min(Ref(L,-10),Ref(L,-15))),
IIf(C<Ref(Min(Min(L,Ref(L,-20)),Min(Ref(L,-10),Ref(L,-15))),-1),Max(Max(H,Ref(H,-20)),Max(Ref(H,-10),Ref(H,-15))),PREV));
a=Cross(Close,d);
b=Cross(d,Close);
return (IIf(BarsSince(a)<BarsSince(b),1,0));
}

function HAI_F5(no)
{
state = HAI_F4(no);
s=state>Ref(state,-1);
ss=state<Ref(state,-1);
return (state==Ref(state,-1));
}


function HAI_F6(p,n,s,m)
{
return (PDI(p)>MDI(n)AND Signal(s)<MACD(m));
}

function HAI_F7(p,n,s,m)
{
return (MDI(n)>PDI(p)AND Signal(s)>MACD(m));
}


_SECTION_END();

//http://jackpottrade.forumotion.in/t152-intradayaflcom-amibroker-formula


_SECTION_BEGIN("Swing");

no = 22;
sloss = HAI_F1(no);
a = HAI_F2(no);
b = HAI_F3(no);
state = HAI_F4(no);
sss = HAI_F5(no);
uptrend = HAI_F6(20,10,29,22);
downtrend = HAI_F7(20,10,29,13);

style = a * styleStaircase + b * styleStaircase;
PlotShapes(a,style, IIf(a,colorGreen,colorRed), 0, IIf(a,Low,High));
_SECTION_END();

col=IIf(state == 1 ,51,IIf(state ==0,4,1));
Plot(C,"",Col,64);
PlotShapes( shapeUpArrow * a, colorGreen,0,L);
PlotShapes( shapeDownArrow * b, colorRed,0,H);

Filter = a OR b OR sss ;
AddColumn(C,"close",1.2);
AddColumn( IIf( a, 66,1 ), "buy", formatChar, 1, bkcolor =IIf (a,colorYellow, colorPink ));
AddColumn( IIf( b, 83,1 ), "sell", formatChar, 1, bkcolor =IIf (b,colorPink, colorYellow ));
AddColumn( IIf( sss, 87,1 ), "wait", formatChar, 1, bkcolor =IIf (sss,colorYellow, colorRed ));

_SECTION_BEGIN("");
_N(Title = EncodeColor(colorWhite) + "{{NAME}} - {{INTERVAL}} {{DATE}} " );
_SECTION_END();

_SECTION_BEGIN("Intraday AFL System");
Buy = a;
Sell = b;

PlotShapes(IIf(Buy, shapeSquare, shapeNone),colorGreen, 0, L, Offset=-30);
PlotShapes(IIf(Buy, shapeSquare, shapeNone),colorLime, 0, L, Offset=-40);
PlotShapes(IIf(Buy, shapeUpArrow, shapeNone),colorWhite, 0,L, Offset=-35);
PlotShapes(IIf(Sell, shapeSquare, shapeNone),colorRed, 0, H, Offset=30);
PlotShapes(IIf(Sell, shapeSquare, shapeNone),colorOrange, 0,H, Offset=40);
PlotShapes(IIf(Sell, shapeDownArrow, shapeNone),colorWhite, 0,H, Offset=-35);

dist = ATR(20);
for (i=0; i<BarCount; i++) {
if ( Buy )
PlotText("Buy:" + O[ i ], i, L[ i ]-3*dist, colorGreen);
if ( Sell )
PlotText("Sell:" + O[ i ], i, H[ i ]+3*dist, colorRed);
}
_SECTION_END();

_SECTION_BEGIN("Trend");

Plot( 2, /* defines the height of the ribbon in percent of pane width */"ribbon",
IIf( uptrend, colorGreen, IIf( downtrend, colorRed, 0 )), /* choose color */
styleOwnScale|styleArea|styleNoLabel, -0.5, 100 );
_SECTION_END();

//d = Close > Ref( ChandelierHL(ATR(3),20), -1);
//e =Close < Ref( ChandelierHL(ATR(3),20), -1);
//f = Close < Ref( ChandelierHL(ATR(3),20), -1);
//g = Close > Ref( ChandelierHL(ATR(3),20), -1);

Buy = a AND uptrend ;
Short = b AND downtrend ;
Sell = b AND downtrend ;
Cover = a AND uptrend;

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

Filter=Buy OR Sell;
Filter= Cover OR Short;

AddColumn( Buy, "Buy", 1);
AddColumn(Sell, "Sell", 1);
AddColumn(Close,"Close",1.2);
AddColumn(Volume,"Volume",1.0);

// Plot the Buy and Sell arrows.
shape = Buy * shapeUpArrow + Sell * shapeDownArrow;
PlotShapes(shape, IIf(Buy,colorGreen,colorRed), 0, IIf(Buy,Low,High));

//Plot(sloss,"Swing",colorYellow,styleStaircase);

//SetChartBkGradientFill( ParamColor("BgTop", ColorRGB( 172,172,172 )),

//ParamColor("BgBottom", ColorRGB( 172,172,172 )),ParamColor("titleblock",ColorRGB( 172,172,172 )));
//Alerts
AlertIf( Buy, "SOUND C:\\Windows\\Media\\tada.wav", "Buy",1,1+2+4+8);
AlertIf( Short, "SOUND C:\\Windows\\Media\\notify.wav", "Short",2,1+2+4+8);

GraphXSpace = 5;

/* -------------------------------------------------------------------------------------- */

SetChartBkColor(colorDarkOliveGreen = 46);
SetChartOptions(0,chartShowArrows|chartShowDates);

/* -------------------------------------------------------------------------------------- */

////////////////////////////////////////////////////////////////////////////////////////////////
messageboard = ParamToggle("Message Board","Show|Hide",0);
showsl = ParamToggle("Stop Loss Line", "Show|Hide", 0);

style = a * styleStaircase + b * styleStaircase;

PlotShapes(a,style, IIf(a,colorGreen,colorRed), 0, IIf(a,Low,High));
if (showsl == 0) Plot(sloss,"Stop Loss",colorCustom14,styleDots);
exitlong = Cross(sloss, H);
PlotShapes(exitlong * shapeNone, colorBlack,0,H,-10);
exitshort = Cross(L, sloss);
PlotShapes(exitshort * shapeNone, colorBlack,0,L,-15);

Buy = exitshort;
Sell = exitlong;
//Short = Sell;
//Cover = Buy;
Buy = ExRem(Buy,Sell);
Sell = ExRem(Sell,Buy);
//Short = ExRem(Short, Cover);
//Cover = ExRem(Cover, Short);
AlertIf( Buy, "", "BUY @ " + C, 1 );
AlertIf( Sell, "", "SELL @ " + C, 2 );

for (i=BarCount-1; i>1; i--) {
if (Buy == 1) {
entry = O;
sig = "BUY";
sl = sloss;
tar1 = entry + (entry * .0040);
tar2 = entry + (entry * .0085);
tar3 = entry + (entry * .0179);
bars = i;
i = 0;
}
if (Sell == 1) {
sig = "SELL";
entry = O;
sl = sloss;
tar1 = entry - (entry * .0040);
tar2 = entry - (entry * .0085);
tar3 = entry - (entry * .0212);
bars = i;
i = 0;
}
}

Offset = 20;
Clr = IIf(sig == "BUY", colorLime, colorRed);
ssl = IIf(bars == BarCount-1, sloss[BarCount-1], Ref(sloss, -1));
sl = ssl[BarCount-1];

printf("Last " + sig + " Signal came " + (BarCount-bars) + " bars ago");
printf("\n" + sig + " @ : " + entry + "\nStop Loss : " + sl + " (" + WriteVal(IIf(sig == "SELL",entry-sl,sl-entry), 2.2) + ")"+ "\nTarget_1 : " + tar1 + "\nTarget_2 : " + tar2 + "\nTarget_3 : " + tar3);
printf("\nCurrent P/L : " + WriteVal(IIf(sig == "BUY",(C-entry),(entry-C)),2.2));

if (messageboard == 0) {
GfxSelectFont( "Tahoma", 13, 100 );
GfxSetBkMode( 1 );
GfxSetTextColor( colorWhite );

if (sig =="BUY")
GfxSelectSolidBrush( colorGreen ); // this is the box background color
else
GfxSelectSolidBrush( colorRed ); // this is the box background color

pxHeight = Status( "pxchartheight" ) ;
xx = Status( "pxchartwidth");
Left = 1100;
width = 310;
x = 05;
x2 = 200;

y = Status( "pxchartheight" );

GfxSelectPen( colorGreen, 1); // broader color
GfxRoundRect( x, y - 143, x2, y , 7, 7 ) ;
GfxTextOut( ( " "), 10, y-140) ;
GfxTextOut( Name(),13,y-120);

GfxTextOut( ("" + WriteIf(sig =="BUY",sig + " @ ",sig + " @") + " : " + entry), 13, y-100);
GfxTextOut( ("Trailing SL : " + sl + " "), 13, y-80);
GfxTextOut( ("TGT:1 : " + tar1), 13, y -60);
GfxTextOut( ("TGT:2 : " + tar2), 13,y-40);
GfxTextOut( ("Current P/L : " + WriteVal(IIf(sig == "BUY",(C-entry),(entry-C)),2.2)), 13, y-20);;
}
 
#45
Re: nifty plus AFL

_SECTION_BEGIN("Price Chart");
bgTop = ParamColor("BgTop", colorDarkBlue);
bgBot = ParamColor("BgBottom", colorDarkBlue);
SetChartBkGradientFill( bgTop ,bgBot,colorDarkGreen);
pStyle = ParamList("Price Style", "Candle|Solid Candle|Bar|Line|Heikin-Ashi",2);
cBull = ParamColor("Price Bull", colorBrightGreen);
CBear = ParamColor("Price Bear", colorRed);
cLine = ParamColor("Price Line", colorOrange);

SetChartOptions(0,chartShowArrows|chartShowDates);
_N(Title = StrFormat("{{NAME}}- {{INTERVAL}} {{DATE}} O= %g, H= %g, L= %g, C= %g (%.1f%%) V= " +WriteVal( V, 1.0 ) +"\n{{VALUES}}", O, H, L, C,

SelectedValue( ROC( C, 1 )) ));

ThisStyle = styleCandle;
ThisTitle = "";

_O=O; _C=C; _H=H; _L=L;

ThisColor = IIf( _C>_O, cBull, IIf(_C<_O, CBear, CLine));


switch (pStyle )
{

case "Solid Candle":
SetBarFillColor( ThisColor );
break;


case "Bar":
ThisStyle = styleBar;
break;

case "Line":
ThisStyle = styleLine;
ThisColor = cLine;
break;


case "Heikin-Ashi":
_C = (O+H+L+C)/4;
_O = AMA( Ref( _C, -1 ), 0.5 );
_H = Max( H, Max( _C, _O ) );
_L = Min( L, Min( _C, _O ) );

ThisColor = IIf(_C >= _O,CBull, CBear);
SetBarFillColor( ThisColor );

ThisColor = IIf(_C >= _O,cLine, cLine);
ThisTitle = "Heikin-Ashi";
break;

default:
SetBarFillColor( ThisColor );
ThisColor = cLine;

break;

}

PlotOHLC( _O, _H, _L, _C, ThisTitle, ThisColor, ThisStyle);
GraphXSpace = 8;

_SECTION_END();



_SECTION_BEGIN("BandStop");
Length=Param("Length",20, 2); // Bollinger Bands Period
Deviation=Param("Deviation",2);
// Deviation was 2
MoneyRisk=Param("Money Risk", 1);

LineStyle=ParamToggle("Display line mode", "No|Yes", 1); // Display line mode: 0-no,1-yes
cUpTrendLine = ParamColor("UpTrendLine", colorGreen);
cDnTrendLine = ParamColor("DownTrendLine", colorRed);

// Offset Factor
TurnedUp=Nz(StaticVarGet("TurnedUp"));
TurnedDown=Nz(StaticVarGet("TurnedDown"));
SoundON = ParamToggle("Sound","Off|On",1);


procedure CalcTrend_proc(bbtop,bbbot,Length,MoneyRisk,SoundON,TurnedUp,TurnedDown)
{
global UpTrendLine;
global DownTrendLine;
global smax;
global smin;

UpTrendLine=Null;
DownTrendLine=Null;
smax=Null;
smin=Null;
trend=0;


for (i=Length+1; i<BarCount; i++)
{
smax=bbtop;
smin=bbbot;
if (C>smax[i-1]) trend=1;
if (C<smin[i-1]) trend=-1;
if(trend>0 && smin<smin[i-1]) smin=smin[i-1];
if(trend<0 && smax>smax[i-1]) smax=smax[i-1];
bsmax=smax+0.5*(MoneyRisk-1)*(smax-smin);
bsmin=smin-0.5*(MoneyRisk-1)*(smax-smin);
if(trend>0 && bsmin<bsmin[i-1]) bsmin=bsmin[i-1];
if(trend<0 && bsmax>bsmax[i-1]) bsmax=bsmax[i-1];
if (trend>0)
{
UpTrendLine=bsmin;
if (SoundON==True && !TurnedUp && i==BarCount-1 && IsEmpty(UpTrendLine[i-1]))
{
Say("Bollinger Bands going Up");
TurnedUp=StaticVarSet("TurnedUp",1);
TurnedDown=StaticVarSet("TurnedDown",0);

}
}

if (trend<0)
{
DownTrendLine=bsmax;
if (SoundON==True && !TurnedDown && i==BarCount-1 && IsEmpty(DownTrendLine[i-1]))
{

TurnedUp=StaticVarSet("TurnedUp",0);
TurnedDown=StaticVarSet("TurnedDown",1);
}
} //if (trend<0)
} //for
} //procedure

bbtop=BBandTop(C,Length,Deviation);
bbbot=BBandBot(C,Length,Deviation);

CalcTrend_proc(bbtop,bbbot,Length,MoneyRisk,SoundON,TurnedUp,TurnedDown);
UpTrendSigNal=UpTrendLine AND IsEmpty(Ref(UpTrendLine,-1));
DownTrendSigNal=DownTrendLine AND IsEmpty(Ref(DownTrendLine,-1));

DisplayStyle = styleNoLabel|styleDots|styleNoTitle;
if(LineStyle == 0) DisplayStyle |= styleNoLine;


Plot(UpTrendLine,"UPTRENDLINE",cUpTrendLine,DisplayStyle);
Plot(DownTrendLine,"DOWNTRENDLINE",cDnTrendLine,DisplayStyle) ;

PlotShapes(IIf(UpTrendSignal,shapeCircle,shapeNone ),cUpTrendLine,0,bbbot,0);
PlotShapes(IIf(DownTrendSignal,shapeCircle,shapeNone),cDnTrendLine,0,bbtop,0);
_SECTION_END();
_SECTION_BEGIN("Signal Panel");

no=10;
res=HHV(H,no);
sup=LLV(L,no);
avd=IIf(C>Ref(res,-1),1,IIf(C<Ref(sup,-1),-1,0));
avn=ValueWhen(avd!=0,avd,1);
s5d=IIf(avn==1,sup,res);

showsl = ParamToggle("Stop Loss Line", "Show|Hide", 0);
if (showsl == 1)
{Plot(s5d,"Stop Loss",colorCustom14,styleDots);}

exitlong = Cross(s5d, H);
PlotShapes(exitlong * shapeNone, colorBlack,0,H,-10);
exitshort = Cross(L, s5d);
PlotShapes(exitshort * shapeNone, colorBlack,0,L,-15);

Buy = exitshort;
Sell = exitlong;
//Short = Sell;
//Cover = Buy;
Buy = ExRem(Buy,Sell);
Sell = ExRem(Sell,Buy);
//Short = ExRem(Short, Cover);
//Cover = ExRem(Cover, Short);
AlertIf( Buy, "", "BUY @ " + C, 1 );
AlertIf( Sell, "", "SELL @ " + C, 2 );

for(i=BarCount-1;i>1;i--)
{
if(Buy == 1)
{
entry = C;
sig = "BUY";
sl = s5d;
tar1 = entry + (entry * .0050);
tar2 = entry + (entry * .0092);
tar3 = entry + (entry * .0179);

bars = i;
i = 0;
}
if(Sell == 1)
{
sig = "SELL";
entry = C;
sl = s5d;
tar1 = entry - (entry * .0050);
tar2 = entry - (entry * .0112);
tar3 = entry - (entry * .0212);


bars = i;
i = 0;
}
}
Offset = 20;
Clr = IIf(sig == "BUY", colorLime, colorRed);
ssl = IIf(bars == BarCount-1, s5d[BarCount-1], Ref(s5d, -1));
sl = ssl[BarCount-1];

Plot(LineArray(bars-Offset, tar1, BarCount, tar1,1), "", Clr, styleLine|styleDots, Null, Null, Offset);
Plot(LineArray(bars-Offset, tar2, BarCount, tar2,1), "", Clr, styleLine|styleDots, Null, Null, Offset);
Plot(LineArray(bars-Offset, tar3, BarCount, tar3,1), "", Clr, styleLine|styleDots, Null, Null, Offset);

Plot(LineArray(bars-Offset, sl, BarCount, sl,1), "", colorDarkRed, styleLine|styleLine, Null, Null, Offset);
Plot(LineArray(bars-Offset, entry, BarCount, entry,1), "", colorGreen, styleLine|styleLine, Null, Null, Offset);

for (i=bars; i <BarCount;i++)
{
PlotText(""+sig+"@"+entry, BarCount+3,entry,Null,colorGreen);
PlotText("T1@"+tar1,BarCount+3,tar1,Null,Clr);PlotText("T2@"+tar2,BarCount+3,tar2,Null,Clr);PlotText ("T3@"+tar3,BarCount+3,tar3,Null,Clr);

}

messageboard = ParamToggle("Message Board","Show|Hide",1);
if (messageboard == 1 )
{
GfxSelectFont( "Tahoma", 13, 100 );
GfxSetBkMode( 1 );
GfxSetTextColor( colorWhite );

if ( sig =="BUY")
{
GfxSelectSolidBrush( colorBlue ); // this is the box background color
}
else
{
GfxSelectSolidBrush( colorRed ); // this is the box background color
}
pxHeight = Status( "pxchartheight" ) ;
xx = Status( "pxchartwidth");
Left = 1100;
width = 310;
x = 5;
x2 = 290;

y = pxHeight;

GfxSelectPen( colorGreen, 1); // broader color
GfxRoundRect( x, y - 163, x2, y , 7, 7 ) ;
GfxTextOut( ( "Attri's Research Inc. - NIFTYPlus"),10,y-158);
GfxTextOut( (" "),27,y-160);
GfxTextOut( ("Last " + sig + " Signal came " + (BarCount-bars-1) * Interval()/60 + " mins ago"), 13, y-140) ; // The text format location
GfxTextOut( ("" + WriteIf(sig =="BUY",sig + " @ ",sig + " @") + " : " + entry), 13, y-120);
GfxTextOut( ("Trailing SL : " + sl + " (" + WriteVal(IIf(sig == "SELL",entry-sl,sl-entry), 2.2) + ")"), 13, y-100);
GfxTextOut( ("TGT:1 : " + tar1), 13, y -80);
GfxTextOut( ("TGT:2 : " + tar2), 13,y-60);
GfxTextOut( ("TGT:3 : " + tar3), 13,y-40);
GfxTextOut( ("Current P/L : " + WriteVal(IIf(sig == "BUY",(C-entry),(entry-C)),2.2)), 70, y-22);;

}
_SECTION_END();
_SECTION_BEGIN("Moving Average");

x=Param("EMA 1",20,1,200,1);
y=Param("EMA 2", 50,1,200,1);
z=Param("EMA 3",100,1,200,1);
zz=Param("EMA 4",200,1,200,1);
EMA20= EMA(C,x);
EMA50=EMA(C,y);
EMA100= EMA(C,z);
EMA200=EMA(C,zz);

SUT=EMA(C,5)>EMA20;
SDT=EMA20>EMA(C,5);
mut= EMA20>EMA50;
mdt=EMA20<EMA50;
_SECTION_END();
_SECTION_BEGIN("Mid Term Price Trend");


MPT = IIf( mut, colorGreen, IIf( mdt, colorRed, colorYellow));
Plot( 3, "", MPT, styleArea|styleOwnScale|styleNoLabel, 0, 100);

_SECTION_END();

_SECTION_BEGIN("Short Term Price Trend");

SPT = IIf( EMA(C,5)>EMA20, colorBrightGreen, IIf( EMA20>EMA(C,5), colorPink, colorYellow));
Plot( 6, "", SPT, styleArea|styleOwnScale|styleNoLabel, 0, 100);

_SECTION_END();
 
#46
Re: super trend afl

_SECTION_BEGIN("SuperTrend");
SetBarsRequired(100000,0);
GraphXSpace = 15;
SetChartOptions(0,chartShowArrows|chartShowDates);
SetChartBkColor(ParamColor("bkcolor",ColorRGB(0,0, 0)));
GfxSetBkMode(0);
GfxSetOverlayMode(1);
SetBarFillColor(IIf(C>O,ParamColor("Candle UP Color", colorGreen),IIf(C<=O,ParamColor("Candle Down Color", colorRed),colorLightGrey)));
Plot(C,"\nPrice",IIf(C>O,ParamColor("Wick UP Color", colorDarkGreen),IIf(C<=O,ParamColor("Wick Down Color", colorDarkRed),colorLightGrey)),64,0,0,0,0);

SetTradeDelays(1,1,1,1);


_N(Title = StrFormat("{{NAME}} - {{INTERVAL}} {{DATE}} Open %g, Hi %g, Lo %g, Close %g (%.1f%%) {{VALUES}}", O, H, L, C, SelectedValue( ROC( C, 1 ) ) ));

Factor=Param("Factor",2,1,10,0.1);
Pd=Param("ATR Periods",11,1,100,1);
Up=(H+L)/2+(Factor*ATR(Pd));
Dn=(H+L)/2-(Factor*ATR(Pd));
iATR=ATR(Pd);
TrendUp=TrendDown=Null;
trend[0]=1;
changeOfTrend=0;
flag=flagh=0;

for (i = 1; i <BarCount-1; i++) {
TrendUp = Null;
TrendDown = Null;

trend=1;


if (Close>Up[i-1]) {
trend=1;
if (trend[i-1] == -1) changeOfTrend = 1;

}
else if (Close<Dn[i-1]) {
trend=-1;
if (trend[i-1] == 1) changeOfTrend = 1;
}
else if (trend[i-1]==1) {
trend=1;
changeOfTrend = 0;
}
else if (trend[i-1]==-1) {
trend=-1;
changeOfTrend = 0;
}

if (trend<0 && trend[i-1]>0) {
flag=1;
}
else {
flag=0;
}

if (trend>0 && trend[i-1]<0) {
flagh=1;
}
else {
flagh=0;
}

if (trend>0 && Dn<Dn[i-1]){
Dn=Dn[i-1];
}

if (trend<0 && Up>Up[i-1])
{ Up=Up[i-1];
}

if (flag==1)
{ Up=(H+L)/2+(Factor*iATR);;
}
if (flagh==1)
{ Dn=(H+L)/2-(Factor*iATR);;
}
if (trend==1) {
TrendUp=Dn;
if (changeOfTrend == 1) {
TrendUp[i-1] = TrendDown[i-1];
changeOfTrend = 0;
}
}
else if (trend==-1) {
TrendDown=Up;
if (changeOfTrend == 1) {
TrendDown[i-1] = TrendUp[i-1];
changeOfTrend = 0;
}
}
}

Plot(TrendUp,"Trend",colorGreen);
Plot(TrendDown,"Down",colorRed);

Buy = trend==1;
Sell=trend==-1;

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


BuyPrice=ValueWhen(Buy,C);
SellPrice=ValueWhen(Sell,C);
ShortPrice=ValueWhen(Short,C);
CoverPrice=ValueWhen(Cover,C);


Title = EncodeColor(colorWhite)+ "Super Trend AFL code from www.marketcalls.in" + " - " + Name() + " - " + EncodeColor(colorRed)+ Interval(2) + EncodeColor(colorWhite) +
" - " + Date() +" - "+"\n" +EncodeColor(colorRed) +"Op-"+O+" "+"Hi-"+H+" "+"Lo-"+L+" "+
"Cl-"+C+" "+ "Vol= "+ WriteVal(V)+"\n"+
EncodeColor(colorLime)+
WriteIf (Buy , " GO LONG / Reverse Signal at "+C+" ","")+
WriteIf (Sell , " EXIT LONG / Reverse Signal at "+C+" ","")+"\n"+EncodeColor(colorYellow)+
WriteIf(Sell , "Total Profit/Loss for the Last Trade Rs."+(C-BuyPrice)+"","")+
WriteIf(Buy , "Total Profit/Loss for the Last trade Rs."+(SellPrice-C)+"","");

PlotShapes(IIf(Buy, shapeSquare, shapeNone),colorGreen, 0, L, Offset=-40);
PlotShapes(IIf(Buy, shapeSquare, shapeNone),colorLime, 0,L, Offset=-50);
PlotShapes(IIf(Buy, shapeUpArrow, shapeNone),colorWhite, 0,L, Offset=-45);
PlotShapes(IIf(Short, shapeSquare, shapeNone),colorRed, 0, H, Offset=40);
PlotShapes(IIf(Short, shapeSquare, shapeNone),colorOrange, 0,H, Offset=50);
PlotShapes(IIf(Short, shapeDownArrow, shapeNone),colorWhite, 0,H, Offset=-45);

TrendSL=IIf(trend==1,TrendUp,TrendDown);

for(i=BarCount-1;i>1;i--)
{
if(Buy == 1)
{
entry = C;
sig = "BUY";
sl = TrendSL;
tar1 = entry + (entry * .0050);
tar2 = entry + (entry * .0092);
tar3 = entry + (entry * .0179);

bars = i;
i = 0;
}
if(Sell == 1)
{
sig = "SELL";
entry = C;
sl = TrendSL;
tar1 = entry - (entry * .0050);
tar2 = entry - (entry * .0112);
tar3 = entry - (entry * .0212);


bars = i;
i = 0;
}
}
Offset = 20;
Clr = IIf(sig == "BUY", colorLime, colorRed);
ssl = IIf(bars == BarCount-1, TrendSL[BarCount-1], Ref(TrendSL, -1));
sl = ssl[BarCount-1];


Plot(LineArray(bars-Offset, tar1, BarCount, tar1,1), "", Clr, styleLine|styleDots, Null, Null, Offset);
Plot(LineArray(bars-Offset, tar2, BarCount, tar2,1), "", Clr, styleLine|styleDots, Null, Null, Offset);
Plot(LineArray(bars-Offset, tar3, BarCount, tar3,1), "", Clr, styleLine|styleDots, Null, Null, Offset);

//Plot(LineArray(bars-Offset, sl, BarCount, sl,1), "", colorDarkRed, styleLine|styleLine, Null, Null, Offset);
//Plot(LineArray(bars-Offset, entry, BarCount, entry,1), "", colorGreen, styleLine|styleLine, Null, Null, Offset);

/*
for (i=bars; i <BarCount;i++)
{
PlotText(""+sig+"@"+entry, BarCount-5,entry,Null,colorBlue);
PlotText("T1@"+tar1,BarCount-5,tar1,Null,Clr);PlotText("T2@"+tar2,BarCount-5,tar2,Null,Clr);PlotText ("T3@"+tar3,BarCount-5,tar3,Null,Clr);

}*/

messageboard = ParamToggle("Message Board","Show|Hide",1);
if (messageboard == 1 )
{
GfxSelectFont( "Tahoma", 13, 100 );
GfxSetBkMode( 1 );
GfxSetTextColor( colorWhite );

if ( sig =="BUY")
{
GfxSelectSolidBrush( colorBlue ); // this is the box background color
}
else
{
GfxSelectSolidBrush( colorRed ); // this is the box background color
}
pxHeight = Status( "pxchartheight" ) ;
xx = Status( "pxchartwidth");
Left = 1100;
width = 310;
x = 5;
x2 = 290;

y = pxHeight;

GfxSelectPen( colorGreen, 1); // broader color
GfxRoundRect( x, y - 98, x2, y , 7, 7 ) ;
GfxTextOut( ( "Marketcalls - Supertrend"),13,y-100);
GfxTextOut( (" "),27,y-100);
GfxTextOut( ("Last " + sig + " Signal came " + (BarCount-bars-1) * Interval()/60 + " mins ago"), 13, y-80) ; // The text format location
GfxTextOut( ("" + WriteIf(sig =="BUY",sig + " @ ",sig + " @") + " : " + entry), 13, y-60);
GfxTextOut( ("Trailing SL : " + Ref(TrendSL,-1) + " (" + WriteVal(IIf(sig == "SELL",entry-sl,sl-entry), 2.2) + ")"), 13, y-40);
/*GfxTextOut( ("TGT:1 : " + tar1), 13, y -80);
GfxTextOut( ("TGT:2 : " + tar2), 13,y-60);
GfxTextOut( ("TGT:3 : " + tar3), 13,y-40);*/
GfxTextOut( ("Current P/L : " + WriteVal(IIf(sig == "BUY",(C-entry),(entry-C)),2.2)), 13, y-22);;




//Magfied Market Price
FS=Param("Font Size",30,11,100,1);
GfxSelectFont("Times New Roman", FS, 700, True );
GfxSetBkMode( colorWhite );
GfxSetTextColor( ParamColor("Color",colorGreen) );
Hor=Param("Horizontal Position",940,1,1200,1);
Ver=Param("Vertical Position",12,1,830,1);
GfxTextOut(""+C, Hor , Ver );
YC=TimeFrameGetPrice("C",inDaily,-1);
DD=Prec(C-YC,2);
xx=Prec((DD/YC)*100,2);
GfxSelectFont("Times New Roman", 11, 700, True );
GfxSetBkMode( colorBlack );
GfxSetTextColor(ParamColor("Color",colorYellow) );
GfxTextOut(""+DD+" ("+xx+"%)", Hor , Ver+45 );

}

_SECTION_END();

_SECTION_BEGIN("Time Left");
function GetSecondNum()
{
Time = Now( 4 );
Seconds = int( Time % 100 );
Minutes = int( Time / 100 % 100 );
Hours = int( Time / 10000 % 100 );
SecondNum = int( Hours * 60 * 60 + Minutes * 60 + Seconds );
return SecondNum;
}
RequestTimedRefresh( 1 );
TimeFrame = Interval();
SecNumber = GetSecondNum();
Newperiod = SecNumber % TimeFrame == 0;
SecsLeft = SecNumber - int( SecNumber / TimeFrame ) * TimeFrame;
SecsToGo = TimeFrame - SecsLeft;

x=Param("xposn",50,0,1000,1);
y=Param("yposn",380,0,1000,1);

GfxSelectSolidBrush( ColorRGB( 230, 230, 230 ) );
GfxSelectPen( ColorRGB( 230, 230, 230 ), 2 );
if ( NewPeriod )
{
GfxSelectSolidBrush( colorYellow );
GfxSelectPen( colorYellow, 2 );
Say( "New period" );
}
//GfxRoundRect( x+45, y+40, x-3, y-2, 0, 0 );
//GfxSetBkMode(1);
GfxSelectFont( "Arial", 14, 700, False );
GfxSetTextColor( colorRed );
GfxTextOut( "Time Left :"+SecsToGo+"", x, y );
_SECTION_END();

_SECTION_BEGIN("Movint trand Surrogate");
mtOpen = LinearReg( Open, 20 ); // calculate moving trend from open
mtHigh = LinearReg( High, 20 ); // calculate moving trend from open
mtLow = LinearReg( Low, 20 ); // calculate moving trend from open
mtClose = LinearReg( Close, 20 ); // calculate moving trend from open
// plot surrogate chart
PlotOHLC( mtOpen, mtHigh, mtLow, mtClose, "Surrogate", colorBlack, styleCandle );
*
*
_SECTION_END();
 
#47
Re: Buy sell nifty AFL

_SECTION_BEGIN("MA Diff");
T=26;
KMA=((C-MA(C,T))/MA(C,T))*100;
Graph0=KMA;
Graph0Style=2+4;
Graph0BarColor=IIf(KMA>0,5,4);
GraphXSpace=5;

_SECTION_END();

_SECTION_BEGIN("Price");
SetChartOptions(0,chartShowArrows|chartShowDates);
Plot( C, "Close", ParamColor("Color", colorBlack ), styleNoTitle | ParamStyle("Style") | GetPriceStyle() );
_SECTION_END();

//------------------------------------------------------------------------------

_SECTION_BEGIN("ZIG-ZAG");
P = ParamField( "Price field" );
change = Param("% change",5,0.1,25,0.1);
_SECTION_END();

_SECTION_BEGIN("EMA");
P = ParamField("Price field",-1);
Periods = Param("Periods", 15, 2, 300, 1, 10 );
_SECTION_END();

_SECTION_BEGIN("MACD Exploration");
r1 = Param( "Fast avg", 12, 2, 200, 1 );
r2 = Param( "Slow avg", 26, 2, 200, 1 );
r3 = Param( "Signal avg", 9, 2, 200, 1 );
Z=Param("zig",1,0,10,0.1);


Cond1 = Cross(MACD(r1,r2),Signal(r1,r2,r3));

Cond3 = Zig(C,z)>Ref(Zig(C,z),-4);
Buy = Cond1 AND Cond3;

Cond4 = Cross(Signal(r1,r2,r3),MACD(r1,r2));

Cond6 = Zig(C,z)<Ref(Zig(C,z),-4);
Sell = Cond4 AND Cond6;
Trigger = WriteIf(Buy, "Buy", "") + WriteIf(Sell, "Sell", "");

_N(Title = StrFormat("{{NAME}} {{DATE}} {{INTERVAL}}: O=%1.2f, H=%1.2f, L=%1.2f, C=%1.2f, V=%1.0f\n{{VALUES}}", O, H, L, C, V));

BG = IIf(Buy, colorPaleGreen, IIf(Sell, colorRose, colorDefault));
FG = IIf(Buy, colorDarkGreen, IIf(Sell, colorDarkRed, colorDefault));

if(Status("action") == actionIndicator)
{
Plot(C, "", colorGrey50, styleBar);
//PlotShapes(IIf(Buy, shapeCircle, shapeNone),colorBlue, 0,L, Offset=-60);
//PlotShapes(IIf(Sell, shapeCircle, shapeNone),colorBlue, 0,H, Offset=-30);

}

//------------------------------------------------------------------------------------------------
if(Status("action") == actionExplore)

Filter = Buy OR Sell;
SetOption("NoDefaultColumns", True);

AddTextColumn(Name(), "Symbol", 77, FG, BG, 120);
AddColumn(DateTime(), "Date", formatDateTime, FG, BG, 100);
AddColumn(TimeNum() ,"Time",1);
AddColumn( C, "Close", 1.3 );
AddColumn( H, "High", 1.3 );
AddColumn(V, "Volume");
AddColumn(Ref(V,-1),"P-Vol");
AddColumn(V/Ref(V,-1)*100,"Increase in Vol");
AddColumn( Buy, "Buy", 1 );
AddColumn( Sell, "Sell", 1 );

shape = Buy * shapeHollowUpTriangle + Sell * shapeHollowDownTriangle;

PlotShapes( shape, IIf( Buy, colorBlue, colorBlue ), 0, IIf( Buy, Low, High ) );

GraphXSpace = 7;

GraphXSpace = 7;
_SECTION_END();

_SECTION_BEGIN("EMA3");
P = ParamField("Price field",-1);
Periods = Param("Periods", 15, 2, 300, 1, 10 );
_SECTION_END();


_SECTION_BEGIN("Background text");
C13=Param("fonts",20,10,30,1 );
C14=Param("left-right",2.1,1.0,5.0,0.1 );
C15=Param("up-down",12,1,20,1 );
Miny = Status("axisminy");
Maxy = Status("axismaxy");
lvb = Status("lastvisiblebar");
fvb = Status("firstvisiblebar");
pxwidth = Status("pxwidth");
pxheight = Status("pxheight");
GfxSetBkMode(transparent=1);
GfxSetOverlayMode(1);
GfxSelectFont("Tahoma", Status("pxheight")/C13 );
GfxSetTextAlign( 6 );
GfxSetTextColor( ColorRGB (217,217,213));
GfxTextOut( Name(), Status("pxwidth")/C14, Status("pxheight")/C15 );
GfxSelectFont("Tahoma", Status("pxheight")/C13*0.5 );
GfxSetTextColor( ColorRGB (103,103,103));
GfxTextOut( "", Status("pxwidth")/C14, Status("pxheight")/C15*2.5 );
GfxSelectFont("Tahoma", Status("pxheight")/C13*0.5 );
GfxSetTextColor( ColorRGB (103,103,103));
GfxTextOut( "", Status("pxwidth")/C14, Status("pxheight")/C15*4 );
GfxSelectFont("MS Sans Serif", 10, 500, False, False, 0);
//Second phase starts Here
//File: BHS Chart
_SECTION_BEGIN("Trading");
//SetChartBkColor(ParamColor("Outer panel color ",colorLightYellow));
SetChartBkColor(ParamColor("BackGround Color", colorBlack));
pShowtradeLines = ParamToggle("Show Trade Lines", "No|Yes", 1);
pShowMarkers = ParamToggle("Show Markers", "No|Yes", 1);
synch=ParamToggle("Synchronize buy/short with foreign index", "No|Yes", 1);
Volmin=Param("Volume minimum",5000,0,10000000,50);
Volmax=Param("Volume maximum",1000000,0,10000000,50);
priceRL=Param("Price Range Min",150,1,20000,1);
priceRH=Param("Price Range Max",3000,1,20000,1);
PercChangemin=Param("Percentage Change Min set", -25, -100, 100, 0.1);
PercChangemax=Param("Percentage Change Max set", 25, -100, 100, 0.1);
PerctakeProfit=Param("Take Profit Percent Set",0.6,0.3,30,0.1);
PercStoploss=Param("StopLoss Percent Set",0.25,0.2,5,0.1);

PlotOHLC(Open,High,Low,Close,"",colorWhite,styleCandle);
Bars = 0;
xpdh = 90;

{
Plot_Range = (TimeNum() >= 85500 AND TimeNum()<= 153500) AND (DateNum()==LastValue(DateNum()));
FH_Range = (TimeNum() >= 085500 AND TimeNum()<= 093000) AND (DateNum()==LastValue(DateNum()));

FH_Prices = High * FH_Range;
FH_Marker = BarsSince(FH_Range>0);

Num_Bars = 36000 / Interval(1);

TimeFrameSet(inDaily);
TOP_ = Open;
PDH_ = Ref(High,-1);
PDL_ = Ref(Low,-1);
PDO_ = Ref(Open,-1);
PDC_ = Ref(Close,-1);
PDM_ = (PDH_+PDL_)/2;
TimeFrameRestore();

isAll = True;
isRth = TimeNum() >= 085400 AND TimeNum() <= 093000;
isdRth = TimeNum() >= 085400 AND TimeNum() <= 160000;

aRthL = IIf(isRth, L, 1000000);
aRthH = IIf(isdRth, H, Null);
aRthLd = IIf(isdRth, L, 1000000);

TOP = TimeFrameExpand(TOP_,inDaily,expandFirst);
PDH = TimeFrameExpand(PDH_,inDaily,expandFirst);
PDL = TimeFrameExpand(PDL_,inDaily,expandFirst);
PDO = TimeFrameExpand(PDO_,inDaily,expandFirst);
PDC = TimeFrameExpand(PDC_,inDaily,expandFirst);
PDM = TimeFrameExpand(PDM_,inDaily,expandFirst);
FHH = Ref(HHV(High*FH_Range,Num_Bars),-FH_Marker);
FHL = TimeFrameCompress( aRthL, inDaily, compressLow );
FHL = TimeFrameExpand( FHL, inDaily, expandFirst );
DayH = TimeFrameCompress( aRthH, inDaily, compressHigh );
DayH = TimeFrameExpand( DayH, inDaily, expandFirst );
DayL = TimeFrameCompress( aRthLd, inDaily, compressLow );
DayL = TimeFrameExpand( DayL, inDaily, expandFirst );


FC1=((PDH-PDL)*0.433);
FC2=((PDH-PDL)*0.7666);
FC3=((PDH-PDL)*1.355);
FC4=(FHH-FHL);

A=IIf((FC4<=FC1+PDH*0.005),FC1,0);
B=IIf((FC4<=FC2+PDH*0.005 AND FC4>FC1+PDH*0.005),FC2,0);
Cl=IIf((FC4<=FC3 AND FC4>FC2+PDH*0.005),FC3,0);
AF=(A+B+Cl);

//foreign
_SECTION_BEGIN ("foreign Index bar graph");
Vr=ParamList("Index",List = "^NSEI,^NSEBANK,^CNXIT,^NSMIDCP,RELIANCE.NS,SBIN.NS",0);
SetForeign(Vr);
HaC =(O+H+L+C)/4;
HaO = AMA( Ref( HaC, -1 ), 0.5 );
HaH = Max( H, Max( HaC, HaO) );
HaL = Min( L, Min( HaC, HaO) );
BG3=HHV(LLV(HaL,4)+ATR(4),8);
BR3=LLV(HHV(HaH ,4)-ATR(4),8);
co = IIf(Hac>BG3 ,colorBrightGreen,IIf(Hac < BR3,colorRed,colorGrey50));
Plot(4, "", Co,styleArea+styleOwnScale | styleNoLabel, -1, 100);
RestorePriceArrays();
_SECTION_END();

BuyPrice=(DayL+AF);
BuyTP1=(BuyPrice+(BuyPrice*(PerctakeProfit/100)));
BuyTP2=(C>=BuyTP1);
SellPrice=(DayH-AF);
SellTP1=(SellPrice-(SellPrice*(PerctakeProfit/100)));
SellTP2=(C<=SellTP1);
percchange=(((C-TOP)/TOP)*100);
Vol=(V>=Volmin AND V<=Volmax);
Percentage=(percchange>=PercChangemin AND percchange<=PercChangemax);
prc=(C>=priceRL AND C<=priceRH);
BuyStop1=(BuyPrice-(BuyPrice*(PercStoploss/100)));
BuyStop2=IIf((BuyStop1<=SellPrice) AND SellPrice<=BuyPrice,SellPrice,BuyStop1);
SellStop1=(SellPrice+(SellPrice*(PercStoploss/100)));
SellStop2=IIf((SellStop1>=BuyPrice) AND SellPrice<=BuyPrice, BuyPrice,SellStop1);

BuyStop=IIf((Buy AND NOT BuyTP2),BuyStop2,Null);
BuyTP=IIf(Buy AND NOT BuyStop,BuyTP2,Null);

Bars = BarsSince(TimeNum() >= 85400 AND TimeNum() < 092900);
x0 = BarCount-LastValue(Bars);
x1 = BarCount-1;
TOP_Line = LineArray(x0,LastValue(TOP),x1,LastValue(TOP),0);
PDH_Line = LineArray(x0,LastValue(PDH),x1,LastValue(PDH),0);
PDL_Line = LineArray(x0,LastValue(PDL),x1,LastValue(PDL),0);
PDC_Line = LineArray(x0,LastValue(PDC),x1,LastValue(PDC),0);
PDM_Line = LineArray(x0,LastValue(PDM),x1,LastValue(PDM),0);
FHH_Line = LineArray(x0,LastValue(FHH),x1,LastValue(FHH),0);
FHL_Line = LineArray(x0,LastValue(FHL),x1,LastValue(FHL),0);
BuyPriceline=LineArray(x0,LastValue(BuyPrice),x1,LastValue(BuyPrice),0);
BuyStopline=LineArray(x0,LastValue(BuyStop2),x1,LastValue(BuyStop2),0);
BuyTPline=LineArray(x0,LastValue(BuyTP1),x1,LastValue(BuyTP1),0);
SellPriceline=LineArray(x0,LastValue(SellPrice),x1,LastValue(SellPrice),0);
SellStopline=LineArray(x0,LastValue(SellStop2),x1,LastValue(SellStop2),0);
SellTPline=LineArray(x0,LastValue(SellTP1),x1,LastValue(SellTP1),0);
DayHline=LineArray(x0,LastValue(DayH),x1,LastValue(DayH),0);
DayLline=LineArray(x0,LastValue(DayL),x1,LastValue(DayL),0);


Plot(IIf(pShowtradeLines,BuyStopline,Null),"BuyStop",colorBrightGreen,styleDots|styleNoRescale| styleNoLine);
Plot(IIf(pShowtradeLines,SellPriceline,Null),"Short Here",colorRed,styleDots|styleNoRescale);
//PlotShapes(IIf(pShowMarkers AND Buy, shapeHollowUpArrow, Null), colorDarkGreen, 0,L,Offset=-30);

if( Status("action") == actionIndicator )
(
Title = EncodeColor(colorWhite)+ "Trading System" + " - " + Name() + " - " + EncodeColor(colorYellow)+ Interval(2) + EncodeColor(colorYellow) +
" - " + Date() +" - "+ EncodeColor(colorYellow) + "-Open="+WriteVal(O,1) + EncodeColor(colorYellow) + "- High= "+ WriteVal(H,1)+ EncodeColor(colorYellow) + "- Low= "+ WriteVal(L,1)+ EncodeColor(colorYellow) + "- Close= "+ WriteVal(C,1)+ EncodeColor(colorYellow) + "- Vol= "+ WriteVal(V,1)+("\n")
+WriteIf(Percchange, " % Change = "+(Percchange)+" ","")+" Previous DayHigh="+WriteVal(PDH,1)+", Previous DayLow="+WriteVal(PDL,1)+", Today High="+WriteVal(DayH,1)+", Todays Low="+WriteVal(DayL,1)+
WriteIf(Hac>BG3,EncodeColor(colorBrightGreen)+"+Up",
WriteIf(Hac<BR3,EncodeColor(colorRed)+"-Down",EncodeColor(colorLightYellow)+"< Flat >")));

GfxSetOverlayMode( mode = 0 );
GfxSelectPen( colorLightBlue, 3 );
GfxSelectSolidBrush( colorLightYellow );
GfxRoundRect( 20, 55, 180, 175, 15, 15 );
GfxSetBkMode(1);
GfxSelectFont( "Arial", 10, 700, False );
GfxSetTextColor( colorBrown );
GfxSetTextAlign(0);
GfxTextOut( WriteIf(SellPrice, "TRP level: "+(SellPrice),""), 30, 60);
GfxTextOut( WriteIf(BuyPrice, "Buy Above: "+(BuyPrice),""), 30, 75);
GfxTextOut( WriteIf(BuyStop2, "Long SL: "+(BuyStop2),""), 30, 90);
GfxTextOut( WriteIf(BuyTP1 , "Long Target 1: "+(BuyTP1),""), 30, 105);
GfxTextOut( WriteIf(SellPrice, "Sell Below: "+(SellPrice),""), 30, 120);
GfxTextOut( WriteIf(SellStop2, "Short SL: "+(SellStop2),""), 30, 135);
GfxTextOut( WriteIf(SellTP1, "Short Target: "+(SellTP1),""), 30, 150);

AddColumn(V,"Volume",1.0);
AddColumn(Percchange,"Change %",1.2);
AddColumn(BuyPrice,"Buy at",1.2);
AddColumn(BuyStop,"Buy Stop at",1.2);
AddColumn(BuyTP1,"Buy Profit at",1.2);
AddColumn(SellPrice,"Short at",1.2);
AddColumn(SellTP1,"Short profit at",1.2);

}

_SECTION_END();

_SECTION_BEGIN("short signal");
HaClose=(O+H+L+C)/4;
HaOpen = AMA( Ref( HaClose, -1 ), 0.5 );
HaHigh = Max( H, Max( HaClose, HaOpen ) );
HaLow = Min( L, Min( HaClose, HaOpen ) );
BG2=HHV(LLV(Low,4)+ATR(4),8);
BR2=LLV(HHV(High,4)-ATR(4),8);
SetBarFillColor( IIf(O <C, colorSeaGreen,colorOrange) );
k = Optimize("K",Param("K",1.75,1,5,0.25),1,5,0.25);
Per= Optimize("atr",Param("atr",10,3,30,1),3,30,1);
j=HaClose;
nm= (H-L);
rfsctor = WMA(nm, PER);
revers = K * rfsctor;
Trend = 1;
NW[0] = 0;
for(i = 1; i < BarCount; i++)
{
if(Trend[i-1] == 1)
{
if(j < NW[i-1])
{
Trend = -1;
NW = j + Revers;
}
else
{
Trend = 1;
if((j - Revers) > NW[i-1])
{
NW = j - Revers;
}
else
{
NW = NW[i-1];
}
}
}
if(Trend[i-1] == -1)
{
if(j > NW[i-1])
{
Trend = 1;
NW = j - Revers;
}
else
{
Trend = -1;
if((j + Revers) < NW[i-1])
{
NW = j + Revers;
}
else
{
NW = NW[i-1];
}
}
}
}

Plot(NW, "", IIf(Trend == 1, 6, 4), 4);

Buy=Cross(j,nw);
Short=Cross(nw,j);
Sell=Cross(nw,j);
Cover=Cross(j,nw);
Buy=ExRem(Buy,Sell);
Sell=ExRem(Sell,Buy);
Short=ExRem(Short,Cover);
Cover=ExRem(Cover,Short);
//dist = 1.5*ATR(15);
for( i = 0; i < BarCount; i++ )
{
if( Buy ) PlotText( "Buy@" + O[ i ], i, L[ i ]-Trend, colorDarkBlue, colorYellow );
if( Sell ) PlotText( "Sell@" +H[ i ], i-4, L[ i ]+Trend, colorRed, colorYellow );
}

PlotShapes(IIf(Buy, shapeUpArrow, shapeNone),colorWhite, 0,halow,-30);
PlotShapes(IIf(Sell, shapeHollowDownTriangle, shapeNone),colorWhite, 0,hahigh,-15);
PlotShapes(IIf(Cover, shapeHollowUpTriangle, shapeNone),colorWhite, 0,halow,-15);
PlotShapes(IIf(Short, shapeDownArrow, shapeNone),colorWhite, 0,hahigh,-30);
//-----------end--------------

_SECTION_BEGIN("han candle");
SetChartOptions(0,chartShowArrows | chartShowDates);

HaClose = (O + H + L + C)/4;
HaOpen = AMA( Ref( HaClose, -1 ), 0.5 );
HaHigh = Max( H, Max( HaClose, HaOpen ) );
HaLow = Min( L, Min( HaClose, HaOpen ) );
xDiff = (HaHigh - Halow) * 10000;
barcolor = IIf(HaClose >= HaOpen,colorGreen,colorRed);
PlotOHLC( HaOpen, HaHigh, HaLow, HaClose, "", barcolor, styleCandle );
_SECTION_END();
 
#48
can u solve this afl for me. PLZ


_SECTION_BEGIN("MAD");
T=80;
KMA=((C-MA(C,T))/MA(C,T))*100;
Graph0=KMA;
Graph0BarColor=IIf(KMA>0,5,4);

cx=Param("cxposn",810,0,1200,1);
cy=Param("cyposn",37,0,1000,1);

GfxSetBkColor(ColorRGB(200,50,100));
GfxSelectFont( "Bodoni MT",22,98, False);
GfxSetTextColor( colorYellow);
GfxTextOut("LTP. "+C+" ", cx, cy );
_SECTION_END();


_SECTION_BEGIN("Name");
GfxSetOverlayMode(1);
GfxSelectFont("Tahoma", Status("pxheight")/20);
GfxSetTextAlign( 6 );
GfxSetTextColor( ColorHSB( 10, 300, 20 ) );
GfxSetBkMode(0);
GfxTextOut( Name(), Status("pxwidth")/2, Status("pxheight")/20 );


_SECTION_BEGIN("Time Left");
function GetSecondNum()
{
Time = Now( 4 );
Seconds = int( Time % 100 );
Minutes = int( Time / 100 % 100 );
Hours = int( Time / 10000 % 100 );
SecondNum = int( Hours * 60 * 60 + Minutes * 60 + Seconds );
return SecondNum;
}
RequestTimedRefresh( 1 );
TimeFrame = Interval();
SecNumber = GetSecondNum();
Newperiod = SecNumber % TimeFrame == 0;
SecsLeft = SecNumber - int( SecNumber / TimeFrame ) * TimeFrame;
SecsToGo = TimeFrame - SecsLeft;

x=Param("xposn",300,0,1000,1);
y=Param("yposn",50,0,1000,1);

GfxSelectSolidBrush( ColorRGB( 230, 230, 230 ) );
GfxSelectPen( ColorRGB( 223, 100, 230 ), 3 );
if ( NewPeriod )
{
GfxSelectSolidBrush( colorYellow );
GfxSelectPen( colorYellow, 2 );
//Say( "New period" );
}
GfxRoundRect( x+135, y+538, x+265, y+512, 0,0 );
GfxSetBkMode(1);
GfxSelectFont( "Arial", 14, 800, False );
GfxSetTextColor( colorBlack );
GfxTextOut( "Timeleft"+" : "+NumToStr( SecsToGo, 1.0 ), x+200, y+515 );
_SECTION_END();

_SECTION_END();


_SECTION_BEGIN("mo");

mo();

_SECTION_END();

_SECTION_BEGIN("BS-Text");

ABC=SS_C1();
CD=SS_C2();

AA = SS_A1();
BB = SS_B1();

pos = 4.9*ATR(5);
for( i = 0; i < BarCount; i++ ) {
if( ABC ) PlotText( "BUY * STOCKXRAY @\n" +AA, i, Low - pos, colorAqua, Offset=-10 );

if( CD ) PlotText( "SELL * STOCKXRAY @\n" + BB, i, Low + pos, colorRose, Offset=-10 );
}

_SECTION_END();

_SECTION_BEGIN("ADX");
range = Param("ADX Periods", 7, 2, 200, 1 );
Col_adx = IIf(ADX(range) > Ref(ADX(range),-1) AND ADX(range) > 20,colorBlue, colorGrey40);
em = Param("EMA Of ADX",3,1,20,1);
p = EMA(PDI(range),em);
m = EMA(MDI(range),em);

//Plot( ADX(range), _DEFAULT_NAME(), Col_adx , ParamStyle("ADX style", styleThick ) );
btp = BBandTop( P, 5, 0.4 );
bbp = BBandBot( P, 5, 0.4 );
btm = BBandTop( m, 5, 0.4 );
bbm = BBandBot( m, 5, 0.4 );
//Plot(btp , "" , colorDarkGreen, styleDashed );
//Plot(bbp , "" , colorDarkGreen, styleDashed );
//Plot( btm, "" , colorDarkRed, styleDashed );
//Plot( bbm, "" , colorDarkRed, styleDashed );
Col_p = IIf(p > btp, colorBrightGreen,colorDarkGreen);
Col_m = IIf(m > btm,colorRed,colorDarkRed);
//Plot( p, "+DI", Col_p, styleDots );
//Plot( M, "-DI", Col_m, styleDots );

Buy = ADX(range) > MDI(range) AND PDI(range) > MDI(range);
Sell = ADX(range) > PDI(range) AND MDI(range) > PDI(range);
Buy_sell = IIf(Buy,colorGreen,IIf(Sell,colorRed,colorBlack));
trend = IIf(col_p==colorBrightGreen,colorBrightGreen,IIf(c ol_m==colorRed,colorRed,IIf(PDI(range) > MDI(range),colorDarkGreen,colorDarkRed)));
//Plot(6, "", Buy_sell, styleOwnScale| styleArea|styleNoLabel,-0.5,100);

_SECTION_END();

_SECTION_BEGIN("B");
SetChartBkColor(colorPaleBlue);
Buy_p = p > btp OR m < bbm;
Buy_p1 =p > btp AND m < bbm;
Sell_m = m > btm OR p < bbp;
Sell_m1 = m > btm AND p < bbp;




bs = IIf(O>bb,colorBrightGreen,IIf(O<aa,colorRed,IIf(Bu y_p AND Sell_m,colorWhite,IIf(Buy_p,colorBlue,IIf(Sell_m,c olorPink,colorBlack)))));



HaClose =EMA((O+H+L+C)/4,3);
HaOpen = AMA( Ref( HaClose, -1 ), 0.5 );
HaHigh = Max( H, Max( HaClose, HaOpen ) );
HaLow = Min( L, Min( HaClose, HaOpen ) );
PlotOHLC( HaOpen, HaHigh, HaLow, HaClose,"" , bs, styleCandle| styleNoLabel );
_SECTION_END();


_SECTION_BEGIN("MSG");

SS_Mo();
E30 = SS_E1();
F30 = SS_E2();
GO=(CD+(E30*0.0038));
JO=(ABC-(E30*0.0038));
so=(CD+(E30*0.0055));
PO=(ABC-(E30*0.0055));

ABC=SS_C1();
CD=SS_C2();

messageboard = ParamToggle("","",0);
exitlong = CD;

exitshort = ABC;



BT1 = SS_BT1();
BT2 = SS_BT2();
BT3 = SS_BT3();
BT4 = SS_BT4();

ST1 = SS_ST1();
ST2 = SS_ST2();
ST3 = SS_ST3();
ST4 = SS_ST4();


for(i=BarCount-1;i>1;i--)
{
if(ABC == 1)
{
BT11 = BT1;
BT22 = BT2;
BT33 = BT3;
BT44 = BT4;
entry = AA;
sig = "ABC";

tar1 = BT11;
tar2 = BT22;
tar3 = BT33;
tar4 = BT44;

bars = i;
i = 0;
}
if(CD == 1)
{
sig = "CD";


ST11 = ST1;
ST22 = ST2;
ST33 = ST3;
ST44 = ST4;
entry = BB;

tar1 = ST11;
tar2 = ST22;
tar3 = ST33;
tar4 = ST44;

bars = i;
i = 0;
}
}
Offset = 20;
Clr = IIf(sig == "ABC", colorBlue,colorDarkRed);


Plot(LineArray(bars-Offset, tar1, BarCount, tar1,1), "", Clr, styleLine, Null, Null, Offset);
Plot(LineArray(bars-Offset, tar2, BarCount, tar2,1), "", Clr, styleLine, Null, Null, Offset);
Plot(LineArray(bars-Offset, tar3, BarCount, tar3,1), "", Clr, styleLine, Null, Null, Offset);
Plot(LineArray(bars-Offset, tar4, BarCount, tar4,1), "", Clr, styleLine, Null, Null, Offset);

for (i=bars; i <BarCount;i++)
{
//PlotText(""+sig+"@"+entry, BarCount+4,entry,Null,colorBlue);
PlotText("T1*"+tar1,BarCount+4,tar1,Null,Clr);
PlotText("T2* "+tar2,BarCount+4,tar2,Null,Clr);
PlotText ("LT1* "+tar3,BarCount+4,tar3,Null,Clr);
PlotText ("LT2* "+tar4,BarCount+4,tar4,Null,Clr);

}


printf("Last " + sig + " Signal came " + (BarCount-bars) + " bars ago");
printf("\n" + sig + " @ : " + entry + "\nStop Loss : " + " (" + WriteVal(IIf(sig == "CD",entry-C,C-entry), 2.2) + ")"+ "\nTarget_1 : " + tar1 + "\nTarget_2 : " + tar2 + "\nTarget_3 : " + tar3);
printf("\nCurrent P/L : " + WriteVal(IIf(sig == "ABC",(C-entry),(entry-C)),2.2));

if (messageboard == 0 )
{
GfxSelectFont( "Tahoma", 10, 100 );
GfxSetBkMode( 1 );
GfxSetTextColor( colorWhite );

if ( sig =="ABC")
{
GfxSelectSolidBrush( colorBlue );
}
else
{
GfxSelectSolidBrush( colorRed );
}
pxHeight = Status( "pxchartheight" ) ;
xx = Status( "pxchartwidth");
Left = 1100;
width = 310;
x = 3;
x2 = 210;

y = pxHeight;

GfxSelectPen( colorWhite, 5);
GfxRoundRect( x, y - 180, x2, y -1, 80, 150 ) ;
GfxTextOut( ( " * STOCKXRAY MAGIC * "),101,y-173);
GfxSetTextColor(ColorRGB(100,300,200));
GfxTextOut( (" STOP LOSS : " + WriteVal(IIf(sig == "ABC",(E30-SO),(E30-PO)),2.1)), 90, y-117);;
GfxTextOut( (" SECURED SL # REVERSE TREND "), 105, y-100);
GfxSetTextColor( colorWhite );
GfxTextOut( ("TGT:1 : " + tar1), 101, y -82);
GfxTextOut( ("TGT:2 : " + tar2), 100,y-62);
GfxSetTextColor( colorGold );
GfxTextOut( ("LONG TGT 1 : " + tar3), 100,y-43);
GfxTextOut( ("LONG TGT 2 : " + tar4), 100,y-24);
GfxSetTextColor( colorBrightGreen );
GfxTextOut( (" CURRENT P/L : " + WriteVal(IIf(sig == "ABC",(C-entry),(entry-C)),2.1)), 90, y-155);
GfxSelectFont("Tahomabold", 10.4, 100 );
GfxSetTextColor(ColorHSB(30,4,250));
GfxTextOut( (" BEST OPPORTUNITY * " + WriteVal(IIf(sig == "ABC",(E30-GO),(E30-JO)),2.1)), 103, y-135);;
GfxSetTextColor(ColorRGB(10,250,250));
GfxTextOut( ( " Develop By "),950,y-40);
GfxSetTextColor(ColorRGB(10,250,250));
GfxTextOut( ( "* STOCKXRAY SYSTEM * "),950,y-20);
}




_SECTION_BEGIN("Breakout");
breakout = ParamToggle("BREKOUT","No|Yes",1);

PP1 = SS_PP1();
PPA1 = SS_PPA1();
PP2 = SS_PP2();
PPA2 = SS_PPA2();

Asd=IIf(breakout,PPA1,PPA2);
Lkj=IIf(breakout,PP1,PP2);

Plot(IIf(breakout,PPA1,PPA2),"Best Up",colorBlack,4+8+2048);
Plot(IIf(breakout,PP1,PP2),"Best Dn",colorBlack,4+8+2048);


_SECTION_END();


_SECTION_END();
//Plot( Volume, _DEFAULT_NAME(), ParamColor("Color", colorPink ), ParamStyle( "Style", styleHistogram | styleOwnScale | styleThick, maskHistogram ), 2 );

_SECTION_BEGIN("zone");

TimeFrameSet(60*in1Minute);
//SS_Z1

st = SS_Z1();

TimeFrameRestore(); // restore time frame to original

uptrendf=TimeFrameExpand(st , 60*in1Minute);

//downtrendf=TimeFrameExpand( downtrend, 15*in1Minute);

Colorf=TimeFrameExpand (colorGold, 60*in1Minute);

Plot( 2, "zone",IIf(O>uptrendf,colorBrightGreen,colorRed),s tyleOwnScale|styleArea|styleNoLabel,1, 100,1);
_SECTION_END();

_SECTION_BEGIN("93");
ORBHigh = SS_Z2();
ORBLow = SS_Z3();

yy=Cross(f30,ORBHigh);
tt=Cross(ORBLow,f30);

PlotShapes(shapeStar*yy,colorWhite,0,O,-20);
PlotShapes(shapeStar*tt,colorBlack,0,O,20);


ww=Cross(f30,tar2);
qq=Cross(tar2,f30);

PlotShapes(shapeHollowStar*ww,colorDarkBlue,0,L,-20);
PlotShapes(shapeHollowStar*qq,colorViolet,0,H,20);
_SECTION_END();


_SECTION_BEGIN("Volume");

cx = Param("cxposn",1000,0,1200,1);
cy = Param("cyposn", 6,0,1000,10 );

GfxSelectFont( " Arial ", 18, 98, False );
GfxSetTextColor( colorWhite );
GfxTextOut("Volume " +Volume+ "", cx-300,cy +555);


_SECTION_END();
_SECTION_BEGIN("Title");

DDayO = TimeFrameGetPrice("O", inDaily);
DHiDay = TimeFrameGetPrice("H", inDaily);
DLoDay = TimeFrameGetPrice("L", inDaily);
prvC = TimeFrameGetPrice("C", inDaily, -1);//close
Title = EncodeColor(ColorRGB(10,10,350))+"* STOCKXRAY * "+EncodeColor(colorWhite)+ Name() + ", " + Interval(2) + ", " + Date() +
EncodeColor(colorBrightGreen) + "\nO " + EncodeColor(colorBrightGreen) + O +
", H : " + H +
", L : " + L+ EncodeColor(colorOrange) +
" ~ Prev Close : " + EncodeColor(colorPink) + prvC +EncodeColor(colorGold)+
"\n Day-Open : " +DDayO + " Day-High : " +DHiDay + " Day-Low : "+ DLoDay ;




_SECTION_END();
 

Similar threads