can any one correct this afl

#1
dear all can any one correct this afl code which i find from a web it very useful for nifty thanks

_SECTION_BEGIN("DTS");
Plot( Volume, _DEFAULT_NAME(), IIf( C > O, ParamColor("Up Color", colorGreen ), ParamColor("Down Color", colorRed ) ), ParamStyle( "Style", styleHistogram | styleThick, maskHistogram ) );
_SECTION_END();







_SECTION_BEGIN("DTS Ticker");
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",100,100,1000,1000);
y=Param(" yposn",0,40,1000,1);

GfxSelectSolidBrush( colorPink );
GfxSelectPen( colorBlack, 2 );
if ( NewPeriod )
{
GfxSelectSolidBrush( colorBlack );
GfxSelectPen( colorBlack, 2 );
Say( "New candle" );
}
GfxRoundRect( x+55, y+17, x-4, y-2, 0, 0 );
GfxSetBkMode(1);
GfxSelectFont( "Arial", 9, 700, False );
GfxSetTextColor( colorBlack );
GfxTextOut( "" +SecsToGo+" / "+NumToStr( TimeFrame, 1.0 ), x, y );
_SECTION_END();





// The main program ....

Plot(Close, "Price", -1, styleCandle);

sname = Name();

pfId = Param("1. Portfolio Number?", -1, -1, 255, 1);
per = Param("2. EMA period?", 13, 2, 200, 1);
doSl = Param("3. Plot as Stop/Loss?", 1, 0, 1, 1);

bi = BarIndex(); // This gets the start and end bars of a range
startIx = BeginValue(bi) - bi[0];
endIx = EndValue(bi) - bi[0];
if (endIx < startIx)
endIx = startIx;
if (startIx == 0)
startIx = -1;

emaArr = EMA(Close, per); // Calculate EMA array data
sstop = GP_CreateStop(emaArr, sname, pfId, startIx); // Turn into trailing stop

if (startIx > 0) { // Remove any data before start in EMA array
for (i = 0; i < startIx; i++)
emaArr = -1e10;
}
if (endIx < BarCount-1) { // Remove any data after end in EMA and stop arrays
for (i = endIx+1; i < BarCount; i++) {
sstop = -1e10;
emaArr = -1e10;
}
}

Sells = 0; // Generate sell array
if (doSl)
Sells = Cross(sstop, Close);

buyStr = "";

pfId = GP_pfIdUsed;
dummy = -1e10;
if ((pfId >= 0 OR startIx > 0) AND doSl) { // Plot proper trailing stop
if (startIx <= 0) {
buyDate = GP_GetBuyDate(sname, pfId);
buyQty = GP_GetBuyQty(sname, pfId);
BuyPrice = GP_GetBuyPrice(sname, pfId);

tgain = GP_GetGain(sname, pfId, endIx, 0);
pgain = GP_GetGain(sname, pfId, endIx, 1) * 100;

dates = DateNum();
yy = int(buyDate / 10000) + 1900;
mm = int((buyDate % 10000) / 100);
dd = buyDate % 100;
watchName = CategoryGetName(categoryWatchlist, pfId);

bpStr = StrFormat("(Gain = $%1.2f, ", tgain); // Format display string
if (frac(tgain*100))
bpStr = StrFormat("(Gain = $%1.3f, ", tgain);
if (tgain > 0)
bpStr = bpStr + "+";
buyStr = watchName + StrFormat(" - %g/%g/%04g, %1.0f @ $%1.2f = $%1.2f ", dd, mm, yy, BuyQty, BuyPrice, BuyPrice*buyQty)
+ bpStr + StrFormat("%1.2f%%), ", pgain);

Plot(dummy, buyStr, colorBlue, styleNoLine); // Plot nothing to display this text
}
Plot(sstop, "(" + WriteVal(per, 1.0) + ")", colorBlue, styleNoLine);
if (startIx <= 0) //
PlotShapes(IIf(pfId >= 0 AND dates==buyDate, shapeUpTriangle, shapeNone), colorBlue, Graph0, 0);
}
else //
Plot(emaArr, "(" + WriteVal(per, 1.0) + ")", colorBlue, styleNoLine);
_SECTION_END();



period = Param("Period", 150, 1, 2400, 1);
mult = Param("Multiplier", 4, 1.1, 20.0, 0.1); //
showPrice = ParamToggle("Show Price","No|yes",1);
showArrows = ParamToggle("Show Arrows","No|yes",1);
showRibbon = ParamToggle("Show Ribbon","No|yes",1);
GraphXSpace = 1;
f=ATR(period);
VS[0] = Close[0];
trend[0] = 0;
HighC[0]=0;
Lowc[0]=0;
for( i = period+1; i < BarCount; i++ )
{vs = vs[i-1];
trend = trend[i-1];
highC = HighC[i-1];
lowc = lowc[i-1];
if ((trend>=0) && ( C <VS ))
{
trend =-1;
HighC = C;
lowc = C;
}

if ((trend<=0) && (C >VS))
{
trend=1;
HighC = C;
lowc = C;
}

if (trend==-1)
{
if (C<lowc) lowc = C;
VS= lowc+ (mult*f);
}


if (trend==1)
{
if (C>HighC) HighC = C;
VS= HighC-(mult*f);
}

}

Buy=Cross(Trend,0);
Sell=Cross(0, Trend);
Short = Sell;
Cover = Buy;

if (ShowPrice) Plot(Close,"Close",colorBlue,styleCandle);
Plot(VS, "DTS MAGIC",IIf(trend==1,colorDarkYellow,colorDarkYellow ),styleNoLine);

shape = Buy * shapeHollowUpTriangle + Sell* shapeHollowDownTriangle;
if (ShowArrows) PlotShapes( shape, IIf( Buy, colorLime, colorYellow ), 0, IIf( Buy, Low-f, High+f));
a = Buy * shapeHollowUpTriangle;
b = Sell* shapeHollowDownTriangle;

shape = Buy * shapeUpArrow + Sell* shapeDownArrow;
if (ShowArrows) PlotShapes( shape, IIf( Buy, colorLime, colorYellow ), 0, IIf( Buy, Low-f, High+f));
a = Buy * shapeUpArrow;
b = Sell* shapeDownArrow;
Title =
"\\c25"+" [ MASTER ] "+
"\\c11 "+Interval(2)+" chart "+
"\\c34 "+FullName()+" "+
"\\. Stop = "+VS+" "+
"\n";
SetChartBkGradientFill( ParamColor("BgTop", colorBlack),
ParamColor("BgBottom", colorBlack),ParamColor("titleblock",colorBlack));



_SECTION_BEGIN("DTS TRADING SYSTEM");
_N(Title = "{{NAME}} - {{INTERVAL}} {{DATE}}: "+_DEFAULT_NAME()+" : {{OHLCX}} "
+"\n"+EncodeColor(colorYellow));





_SECTION_BEGIN("DTS BALANCE");
sw = E_TSKPSWINGLINE(High,Low,Close);
Plot( tskp_swmean, _DEFAULT_NAME(), ParamColor( "Color", colorYellow ), ParamStyle("Style",style=styleNoLine, mask=maskDefault) );
_SECTION_END();



_SECTION_BEGIN("DTS TRADING ZONES");
//----
DayH = TimeFrameGetPrice("H", inDaily, -1);// yesterdays high
DayL = TimeFrameGetPrice("L", inDaily, -1);//low
DayC = TimeFrameGetPrice("C", inDaily, -1);//close
DayO = TimeFrameGetPrice("O", inDaily);// current day open
HiDay = TimeFrameGetPrice("H", inDaily);
LoDay = TimeFrameGetPrice("L", inDaily);
TimeFrameSet( inDaily );


R6 = (DayH / DayL) * DayC * 1.002;
R5 = (DayH / DayL) * DayC;
R4 = (((DayH / DayL) + 0.83) / 1.83) * DayC;
R3 = ( ( (DayH / DayL) + 2.66) / 3.66) * DayC;
R2 = ( ( (DayH / DayL) + 4.5) / 5.5) * DayC;
R1 = ( ( (DayH / DayL) + 10) / 11) * DayC;

S1 = (2- ( ( (DayH / DayL) + 10) / 11)) * DayC;
S2 = (2-( (DayH / DayL) + 4.5) / 5.5) * DayC;
S3 = (2-(( DayH / DayL) + 2.66) / 3.66) * DayC;
S4 = (2-( (DayH / DayL) + 0.83) / 1.83) * DayC;
S5 = (2-( DayH / DayL)) * DayC;
S6 = (2-( DayH / DayL)) * DayC * 0.998;


ASPR = MA( ( ( ( DayH - DayL ) * 0.5 ) + DayC ) , 1 );
ASPS = MA( ( ( DayC - ( DayH - DayL ) * 0.5 ) ) , 1 );
style = styleDots + styleThick ;
ASPRColor = colorBlack ;

//Plot(ASPR, "ASPR", colorBlack, style);
//Plot(ASPS, "ASPS", colorBlack, style);

Plot(R1, "",colorBlack,style|styleNoLabel);
Plot(S1, "",colorBlack,style|styleNoLabel);

Shadowcolor = ParamColor("Shadow",ColorRGB(40,0,0));
Shadowcolor1 = ParamColor("Shadow1",colorDarkGrey);
Shadowcolor2 = ParamColor("Shadow2",ColorRGB(0,36,0));

style = styleDots | styleThick + styleNoRescale ;
rcolor = colorCustom13;
scolor = colorGreen;
Plot(R5, "",colorPaleBlue,style);
Plot(S5, "",colorPaleBlue,style);


PlotOHLC( 0, R4 , R3 , R3 , "", IIf(R4 > R3 ,Shadowcolor,colorBlack), styleCloud | styleNoLabel);
PlotOHLC( 0, R2 , S2 , S2 , "", IIf(R2 > S2 ,Shadowcolor1,colorBlack), styleCloud | styleNoLabel);
PlotOHLC( 0, s3 , s4 , s4 , "", IIf(S3 > S4 ,Shadowcolor2,colorBlack), styleCloud | styleNoLabel);
 
#3
_SECTION_BEGIN("DTS ");
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",100,100,1000,1000);
y=Param(" yposn",0,40,1000,1);

GfxSelectSolidBrush( colorPink );
GfxSelectPen( colorBlack, 2 );
if ( NewPeriod )
{
GfxSelectSolidBrush( colorBlack );
GfxSelectPen( colorBlack, 2 );
Say( "New candle" );
}
GfxRoundRect( x+55, y+17, x-4, y-2, 0, 0 );
GfxSetBkMode(1);
GfxSelectFont( "Arial", 9, 700, False );
GfxSetTextColor( colorBlack );
GfxTextOut( "" +SecsToGo+" / "+NumToStr( TimeFrame, 1.0 ), x, y );
_SECTION_END();





// The main program ....

Plot(Close, "Price", -1, styleCandle);

sname = Name();

pfId = Param("1. Portfolio Number?", -1, -1, 255, 1);
per = Param("2. EMA period?", 13, 2, 200, 1);
doSl = Param("3. Plot as Stop/Loss?", 1, 0, 1, 1);

bi = BarIndex(); // This gets the start and end bars of a range
startIx = BeginValue(bi) - bi[0];
endIx = EndValue(bi) - bi[0];
if (endIx < startIx)
endIx = startIx;
if (startIx == 0)
startIx = -1;

emaArr = EMA(Close, per); // Calculate EMA array data
//sstop = GP_CreateStop(emaArr, sname, pfId, startIx); // Turn into trailing stop

if (startIx > 0) { // Remove any data before start in EMA array
for (i = 0; i < startIx; i++)
emaArr = -1e10;
}
if (endIx < BarCount-1) { // Remove any data after end in EMA and stop arrays
for (i = endIx+1; i < BarCount; i++) {
sstop = -1e10;
emaArr = -1e10;
}
}

Sells = 0; // Generate sell array
if (doSl)
//Sells = Cross(sstop, Close);

buyStr = "";

//pfId = GP_pfIdUsed;
dummy = -1e10;
if ((pfId >= 0 OR startIx > 0) AND doSl) { // Plot proper trailing stop
if (startIx <= 0) {
//buyDate = Cross(sname, pfId);
//SSbuyQty = GP_GetBuyQty(sname, pfId);
BuyPrice = Cross(sname, pfId);

//tgain = GP_GetGain(sname, pfId, endIx, 0);
//pgain = GP_GetGain(sname, pfId, endIx, 1) * 100;

dates = DateNum();
yy = int(buyDate / 10000) + 1900;
mm = int((buyDate % 10000) / 100);
dd = buyDate % 100;
watchName = CategoryGetName(categoryWatchlist, pfId);

bpStr = StrFormat("(Gain = $%1.2f, ", tgain); // Format display string
if (frac(tgain*100))
bpStr = StrFormat("(Gain = $%1.3f, ", tgain);
if (tgain > 0)
bpStr = bpStr + "+";
buyStr = watchName + StrFormat(" - %g/%g/%04g, %1.0f @ $%1.2f = $%1.2f ", dd, mm, yy, BuyQty, BuyPrice, BuyPrice*buyQty)
+ bpStr + StrFormat("%1.2f%%), ", pgain);

Plot(dummy, buyStr, colorBlue, styleNoLine); // Plot nothing to display this text
}
Plot(sstop, "(" + WriteVal(per, 1.0) + ")", colorBlue, styleNoLine);
if (startIx <= 0) //
PlotShapes(IIf(pfId >= 0 AND dates==buyDate, shapeUpTriangle, shapeNone), colorBlue, Graph0, 0);
}
else //
Plot(emaArr, "(" + WriteVal(per, 1.0) + ")", colorBlue, styleNoLine);
_SECTION_END();



period = Param("Period", 150, 1, 2400, 1);
mult = Param("Multiplier", 4, 1.1, 20.0, 0.1); //
showPrice = ParamToggle("Show Price","No|yes",1);
showArrows = ParamToggle("Show Arrows","No|yes",1);
showRibbon = ParamToggle("Show Ribbon","No|yes",1);
GraphXSpace = 1;
f=ATR(period);
VS[0] = Close[0];
trend[0] = 0;
HighC[0]=0;
Lowc[0]=0;
for( i = period+1; i < BarCount; i++ )
{vs = vs[i-1];
trend = trend[i-1];
highC = HighC[i-1];
lowc = lowc[i-1];
if ((trend>=0) && ( C <VS ))
{
trend =-1;
HighC = C;
lowc = C;
}

if ((trend<=0) && (C >VS))
{
trend=1;
HighC = C;
lowc = C;
}

if (trend==-1)
{
if (C<lowc) lowc = C;
VS= lowc+ (mult*f);
}


if (trend==1)
{
if (C>HighC) HighC = C;
VS= HighC-(mult*f);
}

}

Buy=Cross(Trend,0);
Sell=Cross(0, Trend);
Short = Sell;
Cover = Buy;

if (ShowPrice) Plot(Close,"Close",colorBlue,styleCandle);
//Plot(VS, "DTS MAGIC",IIf(trend==1,colorDarkYellow,colorDarkYello w ),styleNoLine);

shape = Buy * shapeHollowUpTriangle + Sell* shapeHollowDownTriangle;
if (ShowArrows) PlotShapes( shape, IIf( Buy, colorLime, colorYellow ), 0, IIf( Buy, Low-f, High+f));
a = Buy * shapeHollowUpTriangle;
b = Sell* shapeHollowDownTriangle;

shape = Buy * shapeUpArrow + Sell* shapeDownArrow;
if (ShowArrows) PlotShapes( shape, IIf( Buy, colorLime, colorYellow ), 0, IIf( Buy, Low-f, High+f));
a = Buy * shapeUpArrow;
b = Sell* shapeDownArrow;
Title =
"\\c25"+" [ MASTER ] "+
"\\c11 "+Interval(2)+" chart "+
"\\c34 "+FullName()+" "+
"\\. Stop = "+VS+" "+
"\n";
SetChartBkGradientFill( ParamColor("BgTop", colorBlack),
ParamColor("BgBottom", colorBlack),ParamColor("titleblock",colorBlack));



_SECTION_BEGIN("DTS TRADING SYSTEM");
_N(Title = "{{NAME}} - {{INTERVAL}} {{DATE}}: "+_DEFAULT_NAME()+" : {{OHLCX}} "
+"\n"+EncodeColor(colorYellow));





_SECTION_BEGIN("DTS BALANCE");
//sw = E_TSKPSWINGLINE(High,Low,Close);
//Plot( //_DEFAULT_NAME(), ParamColor( "Color", colorYellow ), styleLine) );
_SECTION_END();



_SECTION_BEGIN("DTS TRADING ZONES");
//----
DayH = TimeFrameGetPrice("H", inDaily, -1);// yesterdays high
DayL = TimeFrameGetPrice("L", inDaily, -1);//low
DayC = TimeFrameGetPrice("C", inDaily, -1);//close
DayO = TimeFrameGetPrice("O", inDaily);// current day open
HiDay = TimeFrameGetPrice("H", inDaily);
LoDay = TimeFrameGetPrice("L", inDaily);
TimeFrameSet( inDaily );


R6 = (DayH / DayL) * DayC * 1.002;
R5 = (DayH / DayL) * DayC;
R4 = (((DayH / DayL) + 0.83) / 1.83) * DayC;
R3 = ( ( (DayH / DayL) + 2.66) / 3.66) * DayC;
R2 = ( ( (DayH / DayL) + 4.5) / 5.5) * DayC;
R1 = ( ( (DayH / DayL) + 10) / 11) * DayC;

S1 = (2- ( ( (DayH / DayL) + 10) / 11)) * DayC;
S2 = (2-( (DayH / DayL) + 4.5) / 5.5) * DayC;
S3 = (2-(( DayH / DayL) + 2.66) / 3.66) * DayC;
S4 = (2-( (DayH / DayL) + 0.83) / 1.83) * DayC;
S5 = (2-( DayH / DayL)) * DayC;
S6 = (2-( DayH / DayL)) * DayC * 0.998;


ASPR = MA( ( ( ( DayH - DayL ) * 0.5 ) + DayC ) , 1 );
ASPS = MA( ( ( DayC - ( DayH - DayL ) * 0.5 ) ) , 1 );
style = styleDots + styleThick ;
ASPRColor = colorBlack ;

//Plot(ASPR, "ASPR", colorBlack, style);
//Plot(ASPS, "ASPS", colorBlack, style);

Plot(R1, "",colorBlack,style|styleNoLabel);
Plot(S1, "",colorBlack,style|styleNoLabel);

Shadowcolor = ParamColor("Shadow",ColorRGB(40,0,0));
Shadowcolor1 = ParamColor("Shadow1",colorDarkGrey);
Shadowcolor2 = ParamColor("Shadow2",ColorRGB(0,36,0));

style = styleDots | styleThick + styleNoRescale ;
rcolor = colorCustom13;
scolor = colorGreen;
Plot(R5, "",colorPaleBlue,style);
Plot(S5, "",colorPaleBlue,style);


PlotOHLC( 0, R4 , R3 , R3 , "", IIf(R4 > R3 ,Shadowcolor,colorBlack), styleCloud | styleNoLabel);
PlotOHLC( 0, R2 , S2 , S2 , "", IIf(R2 > S2 ,Shadowcolor1,colorBlack), styleCloud | styleNoLabel);
PlotOHLC( 0, s3 , s4 , s4 , "", IIf(S3 > S4 ,Shadowcolor2,colorBlack), styleCloud | styleNoLabel);
 
#5
dear hrishi ji pls correct this afl also thanks i can not correct below afl code thansk


































































_SECTION_BEGIN("Price");
SetChartOptions(0,chartShowArrows|chartShowDates);
_N(Title = StrFormat("{{Name}} - {{Interval}} {{Date}} Open %g, Hi %g, Lo %g, Close %g (%.1f%%) Vol " +WriteVal( V, 1.0 ) +" {{VALUES}}", O, H, L, C, SelectedValue( ROC( C, 1 )) ));

trendup = MACD(12,26) > Signal(12,26,9), colorBlue, colorWhite);
trendcolor = IIf(MACD(12,26) < 0 < Signal(12,26,9), colorRed, trendup);
Plot( C, "Close", trendcolor, styleBar | styleThick );

//RSIup = RSI(7) >
//RSIdown = RSI(7) < 30;

sp = Param( "RSI Period", 7, 1, 100 );
r = RSI( sp );
RSIup = r > 70;
RSIdown = r < 30;



_SECTION_BEGIN("Small Triggers");
p1 = Param("TL 1 Periods", 20, 5, 50, 1);
p2 = Param("TL 2 Periods", 5, 3, 25, 1);
TL1 = LinearReg(C, p1);
TL2 = EMA(TL1, p2);
Col1 = IIf(TL1 > TL2, ParamColor("TL Up Colour", colorBrightGreen), ParamColor("TL Dn Colour", colorCustom12));
Plot(TL1, "TriggerLine 1", Col1, styleLine|styleThick|styleNoLabel);
Plot(TL2, "TriggerLine 2", Col1, styleLine|styleThick|styleNoLabel);
_SECTION_END();


SetChartOptions(0,chartShowArrows|chartShowDates);

NewDay = Day()!= Ref(Day(), -1);
DH = HHV( H, NewDay);
DL = LLV(L, NewDay);
Plot(DH,"DAY HIGH",colorOrange,ParamStyle("Style"),0,0,0);
Plot(DL,"DAY LOW",colorPaleGreen,ParamStyle("Style"),0,0,0);
R1=((DH-DL)*0.33)+DL;
R2=((DH-DL)*0.66)+DL;
Plot(R1,"BEARISH BELOW",colorYellow,styleDashed,0,0,0);
Plot(R2,"BULLISH ABOVE",colorTurquoise,styleDashed,0,0,0);

accel = Param("Acceleration", 0.02, 0, 1, 0.001);
mx = Param("Max. acceleration", 0.2, 0, 1, 0.001);

F_SAR = SAR(accel,mx);

colordots = IIf(F_SAR < L,colorGreen,IIf(F_SAR> H,colorRed,colorWhite));

Buy = Cross(C,F_SAR); Buy = Ref(Buy,-1); BuyPrice = O;
Sell = Cross(F_SAR,C); Sell = Ref(Sell,-1); SellPrice = O;




PlotOHLC( Open, High, Low, Close, "", colorLime, styleBar| styleThick );



_SECTION_BEGIN("trailstops");
EntrySignal = C > ( LLV( L, 20 ) + 2 * ATR( 10 ) );
ExitSignal = C < ( HHV( H, 20 ) - 2 * ATR( 10 ) );
Color = IIf( EntrySignal, colorBlue, IIf( ExitSignal, colorOrange, colorGrey50 ));
TrailStop = HHV( C - 2 * ATR(10), 15 );
ProfitTaker = EMA( H, 13 ) + 2 * ATR(10);

/* plot price chart and stops */
Plot( TrailStop, "Trailing stop", colorGold, styleThick | styleLine );
Plot( C, "Price", color, styleBar );

/* plot color ribbon */
Plot( 2, "", Color, styleArea | styleOwnScale | styleNoLabel, -0.1, 50 );


_SECTION_BEGIN("GFX EMA");
procedure Plotlinewidth(pvalue,ptitle,pcolor,pstyle,pmin,pmax,pxshift,plinewidth,pshowdate)
{
local pvalue,ptitle,pcolor,pstyle,pmin,pmax,pxshift,plinewidth,ppenstyle,pshowdate;
local Miny,Maxy; local Lvb,fvb; local pxwidth,pxheight; local TotalBars,axisarea; local i,x,y;
if(plinewidth>0 && Status("action") == 1 && (pstyle & styleLine==styleLine)){
GfxSetOverlayMode(0);
Miny=Status("axisminy"); Maxy=Status("axismaxy");
lvb=Status("lastvisiblebar"); fvb=Status("firstvisiblebar");
pxwidth=Status("pxwidth"); pxheight=Status("pxheight");
TotalBars=Lvb-fvb; xaxisarea=56;
if(pshowdate)yaxisarea=10;
else
yaxisarea=0; i=0;
x=5+i*(pxwidth-xaxisarea-10)/( TotalBars+1);
y=5+yaxisarea+(pvalue[i+fvb]-Miny)*(pxheight-yaxisarea-10)/(Maxy-Miny);
GfxMoveTo(x,pxheight - y);
for(i=1; i<TotalBars AND i<(BarCount-fvb); i++)

/* **********************************

Code to automatically identify pivots


PlotOHLC(Open, High, Low, Close,

"BIdx = " + BarIndex() +

"\n" + "O = " + O + "\n"+"H = "+ H + "\n"+"L = " + L

+ "\n"+"C ",

colorBlack, styleBar);

GraphXSpace=7;

// -- Create 0-initialized arrays the size of barcount

aHPivs = H - H;

aLPivs = L - L;

// -- More for future use, not necessary for basic plotting

aHPivHighs = H - H;

aLPivLows = L - L;

aHPivIdxs = H - H;

aLPivIdxs = L - L;

nHPivs = 0;

nLPivs = 0;

lastHPIdx = 0;

lastLPIdx = 0;

lastHPH = 0;

lastLPL = 0;

curPivBarIdx = 0;

// -- looking back from the current bar, how many bars

// back were the hhv and llv values of the previous

// n bars, etc.?

aHHVBars = HHVBars(H, nBars);

aLLVBars = LLVBars(L, nBars);

aHHV = HHV(H, nBars);

aLLV = LLV(L, nBars);

// -- Would like to set this up so pivots are calculated back from

// last visible bar to make it easy to "go back" and see the pivots

// this code would find. However, the first instance of

// _Trace output will show a value of 0

aVisBars = Status("barvisible");

nLastVisBar = LastValue(Highest(IIf(aVisBars, BarIndex(), 0)));

_TRACE("Last visible bar: " + nLastVisBar);

// -- Initialize value of curTrend

curBar = (BarCount-1);

curTrend = "";

if (aLLVBars[curBar] <

aHHVBars[curBar]) {

curTrend = "D";

}

else {

curTrend = "U";

}

// -- Loop through bars. Search for

// entirely array-based approach

// in future version

for (i=0; i<farback; i++) {

curBar = (BarCount - 1) - i;

// -- Have we identified a pivot? If trend is down...

if (aLLVBars[curBar] < aHHVBars[curBar]) {

// ... and had been up, this is a trend change

if (curTrend == "U") {

curTrend = "D";

// -- Capture pivot information

curPivBarIdx = curBar - aLLVBars[curBar];

aLPivs[curPivBarIdx] = 1;

aLPivLows[nLPivs] = L[curPivBarIdx];

aLPivIdxs[nLPivs] = curPivBarIdx;

nLPivs++;

}

// -- or current trend is up

} else {

if (curTrend == "D") {

curTrend = "U";

curPivBarIdx = curBar - aHHVBars[curBar];

aHPivs[curPivBarIdx] = 1;

aHPivHighs[nHPivs] = H[curPivBarIdx];

aHPivIdxs[nHPivs] = curPivBarIdx;

nHPivs++;

}

// -- If curTrend is up...else...

}

// -- loop through bars

}

// -- Basic attempt to add a pivot this logic may have missed

// -- OK, now I want to look at last two pivots. If the most

// recent low pivot is after the last high, I could

// still have a high pivot that I didn't catch

// -- Start at last bar

curBar = (BarCount-1);

candIdx = 0;

candPrc = 0;

lastLPIdx = aLPivIdxs[0];

lastLPL = aLPivLows[0];

lastHPIdx = aHPivIdxs[0];

lastHPH = aHPivHighs[0];

if (lastLPIdx > lastHPIdx) {

// -- Bar and price info for candidate pivot

candIdx = curBar - aHHVBars[curBar];

candPrc = aHHV[curBar];

if (

lastHPH < candPrc AND

candIdx > lastLPIdx AND

candIdx < curBar) {


// -- OK, we'll add this as a pivot...

aHPivs[candIdx] = 1;

// ...and then rearrange elements in the

// pivot information arrays

for (j=0; j<nHPivs; j++) {

aHPivHighs[nHPivs-j] = aHPivHighs[nHPivs-

(j+1)];

aHPivIdxs[nHPivs-j] = aHPivIdxs[nHPivs-(j+1)];

}

aHPivHighs[0] = candPrc ;

aHPivIdxs[0] = candIdx;

nHPivs++;

}

} else {


// -- Bar and price info for candidate pivot

candIdx = curBar - aLLVBars[curBar];

candPrc = aLLV[curBar];

if (

lastLPL > candPrc AND

candIdx > lastHPIdx AND

candIdx < curBar) {


// -- OK, we'll add this as a pivot...



nLPivs++;

}


+ WriteVal(ValueWhen(BarIndex()==aHPivIdxs[k],

DateTime(), 1), formatDateTime)

+ ", " + aHPivHighs[k]);

}

*/

// -- OK, let's plot the pivots using arrows

PlotShapes(

IIf(aHPivs==1, shapeHollowDownArrow, shapeNone), colorRed, 0,

High, Offset=-15);

PlotShapes(

IIf(aLPivs==1, shapeHollowUpArrow , shapeNone), colorBrightGreen, 0,

Low, Offset=-15);
_SECTION_END();

_SECTION_BEGIN("Dots Color");
acc = Param("Acceleration", 0.01, 0, 1, 0.001 );
accm = Param("Max. acceleration", 0.1, 0, 1, 0.001 );
myColor = IIf (C > SAR( acc, accm ) , colorGreen , colorRed);
Plot( SAR( acc, accm ), _DEFAULT_NAME(), myColor , ParamStyle("Style", styleDots |styleThick | styleNoLine, maskDefault | styleDots | styleThick | styleNoLine ) );
_SECTION_END();

_SECTION_BEGIN("OsSetting");

Ovos = ParamToggle("Display_OVOS", "No|Yes", 0);
OBSetting=Param("Setting",40,1,500,1);
Bline = StochD(OBSetting);
Oversold=Bline<=30;
Overbought=Bline>=85;

if(Ovos)
{
PlotShapes (IIf(Oversold, shapeHollowSmallCircle, shapeNone) ,38, layer = 0, yposition = haLow, offset = -8 );
PlotShapes (IIf(Overbought, shapeHollowSmallCircle, shapeNone) ,colorBrown, layer = 0, yposition = haHigh, offset = 7 );
}



//////////////////////////////////////////////////////////////////////////////////////////////////////////

_SECTION_BEGIN("Magnified Market Price");
FS=Param("Font Size",30,30,100,1);
GfxSelectFont("Arial", FS, 700, italic = False, underline = False, True );
GfxSetBkMode( colorWhite );
GfxSetTextColor( ParamColor("Color",colorBlue) );
Hor=Param("Horizontal Position",200,800,800,800);
Ver=Param("Vertical Position",50,27,27,27);

_SECTION_END();

///////////////////////////////////////////////////////////////////////////////



for(i=BarCount-1;i>1;i--)
{
if(Buy == 1)
{
entry = C;
sig = "BUY";
sl = s5d;

}
Offset = 20;
Clr = IIf(sig == "BUY", colorLime, colorRed);
ssl = IIf(bars == BarCount-1, s5d[BarCount-1], Ref(s5d, -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( 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;


}
//////////////////////////////////////////////////////////////////////////////////////////////////////////
 
#7
pls correct this afl also thanks i can not correct below afl code thansk
Sorry
I tried to correct it, but couldnt.
May be someone can do it.


































































_SECTION_BEGIN("Price");
SetChartOptions(0,chartShowArrows|chartShowDates);
_N(Title = StrFormat("{{Name}} - {{Interval}} {{Date}} Open %g, Hi %g, Lo %g, Close %g (%.1f%%) Vol " +WriteVal( V, 1.0 ) +" {{VALUES}}", O, H, L, C, SelectedValue( ROC( C, 1 )) ));

trendup = MACD(12,26) > Signal(12,26,9), colorBlue, colorWhite);
trendcolor = IIf(MACD(12,26) < 0 < Signal(12,26,9), colorRed, trendup);
Plot( C, "Close", trendcolor, styleBar | styleThick );

//RSIup = RSI(7) >
//RSIdown = RSI(7) < 30;

sp = Param( "RSI Period", 7, 1, 100 );
r = RSI( sp );
RSIup = r > 70;
RSIdown = r < 30;



_SECTION_BEGIN("Small Triggers");
p1 = Param("TL 1 Periods", 20, 5, 50, 1);
p2 = Param("TL 2 Periods", 5, 3, 25, 1);
TL1 = LinearReg(C, p1);
TL2 = EMA(TL1, p2);
Col1 = IIf(TL1 > TL2, ParamColor("TL Up Colour", colorBrightGreen), ParamColor("TL Dn Colour", colorCustom12));
Plot(TL1, "TriggerLine 1", Col1, styleLine|styleThick|styleNoLabel);
Plot(TL2, "TriggerLine 2", Col1, styleLine|styleThick|styleNoLabel);
_SECTION_END();


SetChartOptions(0,chartShowArrows|chartShowDates);

NewDay = Day()!= Ref(Day(), -1);
DH = HHV( H, NewDay);
DL = LLV(L, NewDay);
Plot(DH,"DAY HIGH",colorOrange,ParamStyle("Style"),0,0,0);
Plot(DL,"DAY LOW",colorPaleGreen,ParamStyle("Style"),0,0,0);
R1=((DH-DL)*0.33)+DL;
R2=((DH-DL)*0.66)+DL;
Plot(R1,"BEARISH BELOW",colorYellow,styleDashed,0,0,0);
Plot(R2,"BULLISH ABOVE",colorTurquoise,styleDashed,0,0,0);

accel = Param("Acceleration", 0.02, 0, 1, 0.001);
mx = Param("Max. acceleration", 0.2, 0, 1, 0.001);

F_SAR = SAR(accel,mx);

colordots = IIf(F_SAR < L,colorGreen,IIf(F_SAR> H,colorRed,colorWhite));

Buy = Cross(C,F_SAR); Buy = Ref(Buy,-1); BuyPrice = O;
Sell = Cross(F_SAR,C); Sell = Ref(Sell,-1); SellPrice = O;




PlotOHLC( Open, High, Low, Close, "", colorLime, styleBar| styleThick );



_SECTION_BEGIN("trailstops");
EntrySignal = C > ( LLV( L, 20 ) + 2 * ATR( 10 ) );
ExitSignal = C < ( HHV( H, 20 ) - 2 * ATR( 10 ) );
Color = IIf( EntrySignal, colorBlue, IIf( ExitSignal, colorOrange, colorGrey50 ));
TrailStop = HHV( C - 2 * ATR(10), 15 );
ProfitTaker = EMA( H, 13 ) + 2 * ATR(10);

/* plot price chart and stops */
Plot( TrailStop, "Trailing stop", colorGold, styleThick | styleLine );
Plot( C, "Price", color, styleBar );

/* plot color ribbon */
Plot( 2, "", Color, styleArea | styleOwnScale | styleNoLabel, -0.1, 50 );


_SECTION_BEGIN("GFX EMA");
procedure Plotlinewidth(pvalue,ptitle,pcolor,pstyle,pmin,pmax,pxshift,plinewidth,pshowdate)
{
local pvalue,ptitle,pcolor,pstyle,pmin,pmax,pxshift,plinewidth,ppenstyle,pshowdate;
local Miny,Maxy; local Lvb,fvb; local pxwidth,pxheight; local TotalBars,axisarea; local i,x,y;
if(plinewidth>0 && Status("action") == 1 && (pstyle & styleLine==styleLine)){
GfxSetOverlayMode(0);
Miny=Status("axisminy"); Maxy=Status("axismaxy");
lvb=Status("lastvisiblebar"); fvb=Status("firstvisiblebar");
pxwidth=Status("pxwidth"); pxheight=Status("pxheight");
TotalBars=Lvb-fvb; xaxisarea=56;
if(pshowdate)yaxisarea=10;
else
yaxisarea=0; i=0;
x=5+i*(pxwidth-xaxisarea-10)/( TotalBars+1);
y=5+yaxisarea+(pvalue[i+fvb]-Miny)*(pxheight-yaxisarea-10)/(Maxy-Miny);
GfxMoveTo(x,pxheight - y);
for(i=1; i<TotalBars AND i<(BarCount-fvb); i++)

/* **********************************

Code to automatically identify pivots


PlotOHLC(Open, High, Low, Close,

"BIdx = " + BarIndex() +

"\n" + "O = " + O + "\n"+"H = "+ H + "\n"+"L = " + L

+ "\n"+"C ",

colorBlack, styleBar);

GraphXSpace=7;

// -- Create 0-initialized arrays the size of barcount

aHPivs = H - H;

aLPivs = L - L;

// -- More for future use, not necessary for basic plotting

aHPivHighs = H - H;

aLPivLows = L - L;

aHPivIdxs = H - H;

aLPivIdxs = L - L;

nHPivs = 0;

nLPivs = 0;

lastHPIdx = 0;

lastLPIdx = 0;

lastHPH = 0;

lastLPL = 0;

curPivBarIdx = 0;

// -- looking back from the current bar, how many bars

// back were the hhv and llv values of the previous

// n bars, etc.?

aHHVBars = HHVBars(H, nBars);

aLLVBars = LLVBars(L, nBars);

aHHV = HHV(H, nBars);

aLLV = LLV(L, nBars);

// -- Would like to set this up so pivots are calculated back from

// last visible bar to make it easy to "go back" and see the pivots

// this code would find. However, the first instance of

// _Trace output will show a value of 0

aVisBars = Status("barvisible");

nLastVisBar = LastValue(Highest(IIf(aVisBars, BarIndex(), 0)));

_TRACE("Last visible bar: " + nLastVisBar);

// -- Initialize value of curTrend

curBar = (BarCount-1);

curTrend = "";

if (aLLVBars[curBar] <

aHHVBars[curBar]) {

curTrend = "D";

}

else {

curTrend = "U";

}

// -- Loop through bars. Search for

// entirely array-based approach

// in future version

for (i=0; i<farback; i++) {

curBar = (BarCount - 1) - i;

// -- Have we identified a pivot? If trend is down...

if (aLLVBars[curBar] < aHHVBars[curBar]) {

// ... and had been up, this is a trend change

if (curTrend == "U") {

curTrend = "D";

// -- Capture pivot information

curPivBarIdx = curBar - aLLVBars[curBar];

aLPivs[curPivBarIdx] = 1;

aLPivLows[nLPivs] = L[curPivBarIdx];

aLPivIdxs[nLPivs] = curPivBarIdx;

nLPivs++;

}

// -- or current trend is up

} else {

if (curTrend == "D") {

curTrend = "U";

curPivBarIdx = curBar - aHHVBars[curBar];

aHPivs[curPivBarIdx] = 1;

aHPivHighs[nHPivs] = H[curPivBarIdx];

aHPivIdxs[nHPivs] = curPivBarIdx;

nHPivs++;

}

// -- If curTrend is up...else...

}

// -- loop through bars

}

// -- Basic attempt to add a pivot this logic may have missed

// -- OK, now I want to look at last two pivots. If the most

// recent low pivot is after the last high, I could

// still have a high pivot that I didn't catch

// -- Start at last bar

curBar = (BarCount-1);

candIdx = 0;

candPrc = 0;

lastLPIdx = aLPivIdxs[0];

lastLPL = aLPivLows[0];

lastHPIdx = aHPivIdxs[0];

lastHPH = aHPivHighs[0];

if (lastLPIdx > lastHPIdx) {

// -- Bar and price info for candidate pivot

candIdx = curBar - aHHVBars[curBar];

candPrc = aHHV[curBar];

if (

lastHPH < candPrc AND

candIdx > lastLPIdx AND

candIdx < curBar) {


// -- OK, we'll add this as a pivot...

aHPivs[candIdx] = 1;

// ...and then rearrange elements in the

// pivot information arrays

for (j=0; j<nHPivs; j++) {

aHPivHighs[nHPivs-j] = aHPivHighs[nHPivs-

(j+1)];

aHPivIdxs[nHPivs-j] = aHPivIdxs[nHPivs-(j+1)];

}

aHPivHighs[0] = candPrc ;

aHPivIdxs[0] = candIdx;

nHPivs++;

}

} else {


// -- Bar and price info for candidate pivot

candIdx = curBar - aLLVBars[curBar];

candPrc = aLLV[curBar];

if (

lastLPL > candPrc AND

candIdx > lastHPIdx AND

candIdx < curBar) {


// -- OK, we'll add this as a pivot...



nLPivs++;

}


+ WriteVal(ValueWhen(BarIndex()==aHPivIdxs[k],

DateTime(), 1), formatDateTime)

+ ", " + aHPivHighs[k]);

}

*/

// -- OK, let's plot the pivots using arrows

PlotShapes(

IIf(aHPivs==1, shapeHollowDownArrow, shapeNone), colorRed, 0,

High, Offset=-15);

PlotShapes(

IIf(aLPivs==1, shapeHollowUpArrow , shapeNone), colorBrightGreen, 0,

Low, Offset=-15);
_SECTION_END();

_SECTION_BEGIN("Dots Color");
acc = Param("Acceleration", 0.01, 0, 1, 0.001 );
accm = Param("Max. acceleration", 0.1, 0, 1, 0.001 );
myColor = IIf (C > SAR( acc, accm ) , colorGreen , colorRed);
Plot( SAR( acc, accm ), _DEFAULT_NAME(), myColor , ParamStyle("Style", styleDots |styleThick | styleNoLine, maskDefault | styleDots | styleThick | styleNoLine ) );
_SECTION_END();

_SECTION_BEGIN("OsSetting");

Ovos = ParamToggle("Display_OVOS", "No|Yes", 0);
OBSetting=Param("Setting",40,1,500,1);
Bline = StochD(OBSetting);
Oversold=Bline<=30;
Overbought=Bline>=85;

if(Ovos)
{
PlotShapes (IIf(Oversold, shapeHollowSmallCircle, shapeNone) ,38, layer = 0, yposition = haLow, offset = -8 );
PlotShapes (IIf(Overbought, shapeHollowSmallCircle, shapeNone) ,colorBrown, layer = 0, yposition = haHigh, offset = 7 );
}



//////////////////////////////////////////////////////////////////////////////////////////////////////////

_SECTION_BEGIN("Magnified Market Price");
FS=Param("Font Size",30,30,100,1);
GfxSelectFont("Arial", FS, 700, italic = False, underline = False, True );
GfxSetBkMode( colorWhite );
GfxSetTextColor( ParamColor("Color",colorBlue) );
Hor=Param("Horizontal Position",200,800,800,800);
Ver=Param("Vertical Position",50,27,27,27);

_SECTION_END();

///////////////////////////////////////////////////////////////////////////////



for(i=BarCount-1;i>1;i--)
{
if(Buy == 1)
{
entry = C;
sig = "BUY";
sl = s5d;

}
Offset = 20;
Clr = IIf(sig == "BUY", colorLime, colorRed);
ssl = IIf(bars == BarCount-1, s5d[BarCount-1], Ref(s5d, -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( 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;


}
//////////////////////////////////////////////////////////////////////////////////////////////////////////[/QUOTE]
 
#10
Sorry
I tried to correct it, but couldnt.
May be someone can do it.
here is the corrected code



_SECTION_BEGIN("Price");
SetChartOptions(0,chartShowArrows|chartShowDates);
_N(Title = StrFormat("{{Name}} - {{Interval}} {{Date}} Open %g, Hi %g, Lo %g, Close %g (%.1f%%) Vol " +WriteVal( V, 1.0 ) +" {{VALUES}}", O, H, L, C, SelectedValue( ROC( C, 1 )) ));

//trendup = MACD(12,26) > Signal(12,26,9), colorBlue, colorWhite);
trendup = MACD(12,26) > Signal(12,26,9);

trendcolor = IIf(MACD(12,26) < 0 < Signal(12,26,9), colorRed, trendup);
Plot( C, "Close", trendcolor, styleBar | styleThick );

//RSIup = RSI(7) >
//RSIdown = RSI(7) < 30;

sp = Param( "RSI Period", 7, 1, 100 );
r = RSI( sp );
RSIup = r > 70;
RSIdown = r < 30;



_SECTION_BEGIN("Small Triggers");
p1 = Param("TL 1 Periods", 20, 5, 50, 1);
p2 = Param("TL 2 Periods", 5, 3, 25, 1);
TL1 = LinearReg(C, p1);
TL2 = EMA(TL1, p2);
Col1 = IIf(TL1 > TL2, ParamColor("TL Up Colour", colorBrightGreen), ParamColor("TL Dn Colour", colorCustom12));
Plot(TL1, "TriggerLine 1", Col1, styleLine|styleThick|styleNoLabel);
Plot(TL2, "TriggerLine 2", Col1, styleLine|styleThick|styleNoLabel);
_SECTION_END();


SetChartOptions(0,chartShowArrows|chartShowDates);

NewDay = Day()!= Ref(Day(), -1);
DH = HHV( H, NewDay);
DL = LLV(L, NewDay);
Plot(DH,"DAY HIGH",colorOrange,ParamStyle("Style"),0,0,0);
Plot(DL,"DAY LOW",colorPaleGreen,ParamStyle("Style"),0,0,0);
R1=((DH-DL)*0.33)+DL;
R2=((DH-DL)*0.66)+DL;
Plot(R1,"BEARISH BELOW",colorYellow,styleDashed,0,0,0);
Plot(R2,"BULLISH ABOVE",colorTurquoise,styleDashed,0,0,0);

accel = Param("Acceleration", 0.02, 0, 1, 0.001);
mx = Param("Max. acceleration", 0.2, 0, 1, 0.001);

F_SAR = SAR(accel,mx);

colordots = IIf(F_SAR < L,colorGreen,IIf(F_SAR> H,colorRed,colorWhite));

Buy = Cross(C,F_SAR); Buy = Ref(Buy,-1); BuyPrice = O;
Sell = Cross(F_SAR,C); Sell = Ref(Sell,-1); SellPrice = O;




PlotOHLC( Open, High, Low, Close, "", colorLime, styleBar| styleThick );



_SECTION_BEGIN("trailstops");
EntrySignal = C > ( LLV( L, 20 ) + 2 * ATR( 10 ) );
ExitSignal = C < ( HHV( H, 20 ) - 2 * ATR( 10 ) );
Color = IIf( EntrySignal, colorBlue, IIf( ExitSignal, colorOrange, colorGrey50 ));
TrailStop = HHV( C - 2 * ATR(10), 15 );
ProfitTaker = EMA( H, 13 ) + 2 * ATR(10);

/* plot price chart and stops */
Plot( TrailStop, "Trailing stop", colorGold, styleThick | styleLine );
Plot( C, "Price", color, styleBar );

/* plot color ribbon */
Plot( 2, "", Color, styleArea | styleOwnScale | styleNoLabel, -0.1, 50 );


_SECTION_BEGIN("GFX EMA");
procedure Plotlinewidth(pvalue,ptitle,pcolor,pstyle,pmin,pmax,pxshift,plinewidth,pshowdate)
{
local pvalue,ptitle,pcolor,pstyle,pmin,pmax,pxshift,plinewidth,ppenstyle,pshowdate;
local Miny,Maxy; local Lvb,fvb; local pxwidth,pxheight; local TotalBars,axisarea; local i,x,y;
if(plinewidth>0 && Status("action") == 1 && (pstyle & styleLine==styleLine)){
GfxSetOverlayMode(0);
Miny=Status("axisminy"); Maxy=Status("axismaxy");
lvb=Status("lastvisiblebar"); fvb=Status("firstvisiblebar");
pxwidth=Status("pxwidth"); pxheight=Status("pxheight");
TotalBars=Lvb-fvb; xaxisarea=56;
if(pshowdate)yaxisarea=10;
else
yaxisarea=0; i=0;
x=5+i*(pxwidth-xaxisarea-10)/( TotalBars+1);
y=5+yaxisarea+(pvalue[i+fvb]-Miny)*(pxheight-yaxisarea-10)/(Maxy-Miny);
GfxMoveTo(x,pxheight - y);
for(i=1; i<TotalBars AND i<(BarCount-fvb); i++)

/* **********************************

Code to automatically identify pivots


PlotOHLC(Open, High, Low, Close,

"BIdx = " + BarIndex() +

"\n" + "O = " + O + "\n"+"H = "+ H + "\n"+"L = " + L

+ "\n"+"C ",

colorBlack, styleBar);

GraphXSpace=7;

// -- Create 0-initialized arrays the size of barcount

aHPivs = H - H;

aLPivs = L - L;

// -- More for future use, not necessary for basic plotting

aHPivHighs = H - H;

aLPivLows = L - L;

aHPivIdxs = H - H;

aLPivIdxs = L - L;

nHPivs = 0;

nLPivs = 0;

lastHPIdx = 0;

lastLPIdx = 0;

lastHPH = 0;

lastLPL = 0;

curPivBarIdx = 0;

// -- looking back from the current bar, how many bars

// back were the hhv and llv values of the previous

// n bars, etc.?

aHHVBars = HHVBars(H, nBars);

aLLVBars = LLVBars(L, nBars);

aHHV = HHV(H, nBars);

aLLV = LLV(L, nBars);

// -- Would like to set this up so pivots are calculated back from

// last visible bar to make it easy to "go back" and see the pivots

// this code would find. However, the first instance of

// _Trace output will show a value of 0

aVisBars = Status("barvisible");

nLastVisBar = LastValue(Highest(IIf(aVisBars, BarIndex(), 0)));

_TRACE("Last visible bar: " + nLastVisBar);

// -- Initialize value of curTrend

curBar = (BarCount-1);

curTrend = "";

if (aLLVBars[curBar] <

aHHVBars[curBar]) {

curTrend = "D";

}

else {

curTrend = "U";

}

// -- Loop through bars. Search for

// entirely array-based approach

// in future version

for (i=0; i<farback; i++) {

curBar = (BarCount - 1) - i;

// -- Have we identified a pivot? If trend is down...

if (aLLVBars[curBar] < aHHVBars[curBar]) {

// ... and had been up, this is a trend change

if (curTrend == "U") {

curTrend = "D";

// -- Capture pivot information

curPivBarIdx = curBar - aLLVBars[curBar];

aLPivs[curPivBarIdx] = 1;

aLPivLows[nLPivs] = L[curPivBarIdx];

aLPivIdxs[nLPivs] = curPivBarIdx;

nLPivs++;

}

// -- or current trend is up

} else {

if (curTrend == "D") {

curTrend = "U";

curPivBarIdx = curBar - aHHVBars[curBar];

aHPivs[curPivBarIdx] = 1;

aHPivHighs[nHPivs] = H[curPivBarIdx];

aHPivIdxs[nHPivs] = curPivBarIdx;

nHPivs++;

}

// -- If curTrend is up...else...

}

// -- loop through bars

}

// -- Basic attempt to add a pivot this logic may have missed

// -- OK, now I want to look at last two pivots. If the most

// recent low pivot is after the last high, I could

// still have a high pivot that I didn't catch

// -- Start at last bar

curBar = (BarCount-1);

candIdx = 0;

candPrc = 0;

lastLPIdx = aLPivIdxs[0];

lastLPL = aLPivLows[0];

lastHPIdx = aHPivIdxs[0];

lastHPH = aHPivHighs[0];

if (lastLPIdx > lastHPIdx) {

// -- Bar and price info for candidate pivot

candIdx = curBar - aHHVBars[curBar];

candPrc = aHHV[curBar];

if (

lastHPH < candPrc AND

candIdx > lastLPIdx AND

candIdx < curBar) {


// -- OK, we'll add this as a pivot...

aHPivs[candIdx] = 1;

// ...and then rearrange elements in the

// pivot information arrays

for (j=0; j<nHPivs; j++) {

aHPivHighs[nHPivs-j] = aHPivHighs[nHPivs-

(j+1)];

aHPivIdxs[nHPivs-j] = aHPivIdxs[nHPivs-(j+1)];

}

aHPivHighs[0] = candPrc ;

aHPivIdxs[0] = candIdx;

nHPivs++;

}

} else {


// -- Bar and price info for candidate pivot

candIdx = curBar - aLLVBars[curBar];

candPrc = aLLV[curBar];

if (

lastLPL > candPrc AND

candIdx > lastHPIdx AND

candIdx < curBar) {


// -- OK, we'll add this as a pivot...



nLPivs++;

}


+ WriteVal(ValueWhen(BarIndex()==aHPivIdxs[k],

DateTime(), 1), formatDateTime)

+ ", " + aHPivHighs[k]);

}

*/

// -- OK, let's plot the pivots using arrows

PlotShapes(

IIf(aHPivs==1, shapeHollowDownArrow, shapeNone), colorRed, 0,

High, Offset=-15);

PlotShapes(

IIf(aLPivs==1, shapeHollowUpArrow , shapeNone), colorBrightGreen, 0,

Low, Offset=-15);
_SECTION_END();

_SECTION_BEGIN("Dots Color");
acc = Param("Acceleration", 0.01, 0, 1, 0.001 );
accm = Param("Max. acceleration", 0.1, 0, 1, 0.001 );
myColor = IIf (C > SAR( acc, accm ) , colorGreen , colorRed);
Plot( SAR( acc, accm ), _DEFAULT_NAME(), myColor , ParamStyle("Style", styleDots |styleThick | styleNoLine, maskDefault | styleDots | styleThick | styleNoLine ) );
_SECTION_END();

_SECTION_BEGIN("OsSetting");

Ovos = ParamToggle("Display_OVOS", "No|Yes", 0);
OBSetting=Param("Setting",40,1,500,1);
Bline = StochD(OBSetting);
Oversold=Bline<=30;
Overbought=Bline>=85;

if(Ovos)
{
PlotShapes (IIf(Oversold, shapeHollowSmallCircle, shapeNone) ,38, layer = 0, yposition = haLow, offset = -8 );
PlotShapes (IIf(Overbought, shapeHollowSmallCircle, shapeNone) ,colorBrown, layer = 0, yposition = haHigh, offset = 7 );
}



//////////////////////////////////////////////////////////////////////////////////////////////////////////

_SECTION_BEGIN("Magnified Market Price");
FS=Param("Font Size",30,30,100,1);
GfxSelectFont("Arial", FS, 700, italic = False, underline = False, True );
GfxSetBkMode( colorWhite );
GfxSetTextColor( ParamColor("Color",colorBlue) );
Hor=Param("Horizontal Position",200,800,800,800);
Ver=Param("Vertical Position",50,27,27,27);

_SECTION_END();

///////////////////////////////////////////////////////////////////////////////



for(i=BarCount-1;i>1;i--)
{
if(Buy == 1)
{
entry = C;
sig = "BUY";
sl = s5d;

}
Offset = 20;
Clr = IIf(sig == "BUY", colorLime, colorRed);
ssl = IIf(bars == BarCount-1, s5d[BarCount-1], Ref(s5d, -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( 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;


hope it works
 

Similar threads

Trade in Rs 20, No more % brokerage

Name:Phone:
Email:City:
State:
Are you a day trader?