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