You are on page 1of 8

_SECTION_BEGIN("Advanced Trailstop System");

///Advanced Trailing stop - www.tatechnics.in


mult=Param("multi", 2.0, 0.1, 10, 0.05);
Aper=Param("ATR period", 7, 2, 100, 1 );
atrvalue=(mult*ATR(aper));
Bs[0]=0;//=L;
L[0]=0;
C[0]=0;
for( i = 9; i < BarCount; i++ )
{
if ( L[ i ] > L[ i - 1 ] AND L[ i
L[ i ] > L[ i - 4 ] AND
L[ i ] > L[ i - 5 ] AND L[ i
L[ i ] > L[ i - 8 ] AND
L[ i ] > L[ i - 9 ] AND C[ i
{
bs[ i ] = L[ i ] - ATRvalue[
}
else
{
if ( H[ i
ND H[ i ] < H[
H[ i ]
H[ i ] < H[ i
H[ i ]
{
bs[ i ]

]
i
<
<

] > L[ i - 2 ] AND L[ i ] > L[ i - 3 ] AND


] > L[ i - 6 ] AND L[ i ] > L[ i - 7 ] AND
] > bs[ i - 1 ])
i ] ;

< H[ i - 1 ] AND H[ i ] < H[ i - 2 ] AND H[ i ] < H[ i - 3 ] A


- 4 ] AND
H[ i - 5 ] AND H[ i ] < H[ i - 6 ] AND H[ i ] < H[ i - 7 ] AND
8 ] AND
H[ i - 9 ] AND C[ i ] < bs[ i - 1 ] )

= H[ i ] + ATRvalue[ i ];

}
else
{
bs[ i ] = bs[ i - 1];
} }}
//====================================================
Mycolor=IIf(C>bs,colorLime,colorRed);
bcolor=IIf(C>bs,colorYellow,colorBlue);
PlotOHLC( Open, High, Low, Close, "", Mycolor, styleBar| styleThick );
Plot(bs,"ATS",bcolor,1|styleThick);
Buy=Cover=Cross(C,bs);
Sell=Short=Cross(bs,C);
shape=Buy*shapeUpArrow + Sell*shapeDownArrow;
PlotShapes(shapeUpArrow*Buy, colorLime, 0, L, -35 );
PlotShapes(shapeDownArrow*Sell, colorRed, 0, H, -30 );
SellPrice=ValueWhen(Sell,C,1);
BuyPrice=ValueWhen(Buy,C,1);
Long=Flip(Buy,Sell);
Shrt=Flip(Sell,Buy );
_SECTION_END();
Filter= Buy OR Sell OR Short OR Cover;
//=================TITLE========================================================
========================================
_SECTION_BEGIN("Title");
if( Status("action") == actionIndicator )
(

Title = EncodeColor(colorWhite)+ "Advanced Trailstop System " + " - " + Name()


+ " - " + EncodeColor(colorRed)+ Interval(2) + EncodeColor(colorWhite) +
" - " + Date() +" - "+"\n" +EncodeColor(colorYellow) +"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(co
lorWhite)+
WriteIf(Sell , "Total Profit/Loss for the Last Trade Rs."+(C-BuyPrice)+"","")+
WriteIf(Buy , "Total Profit/Loss for the Last trade Rs."+(SellPrice-C)+"","")+
WriteIf(Long AND NOT Buy, "Trade : Long - Entry price Rs."+(BuyPrice),"")+
WriteIf(shrt AND NOT Sell, "Trade : Short - Entry price Rs."+(SellPrice),"")+"\n
"+
WriteIf(Long AND NOT Buy, "Current Profit/Loss Rs."+(C-BuyPrice)+"","")+
WriteIf(shrt AND NOT Sell, "Current Profit/Loss Rs."+(SellPrice-C)+"",""));
_SECTION_END();

Advanced Trend Lines with S & R


Formula:
_SECTION_BEGIN("Advanced Trend Lines");
function GetXSupport(Lo, Percentage, Back)
{
return ((BarCount - 1) - LastValue(TroughBars(Lo, Percentage,Back)));
}
function GetYSupport(Lo, Percentage, Back)
{
return (LastValue(Trough(Lo, Percentage, back)));
}
function GetXResistance(Hi, Percentage, Back)
{
return ((BarCount - 1) -LastValue(PeakBars(Hi, Percentage, Back)));
}
function GetYResistance(Hi, Percentage, Back)
{
return (LastValue(Peak(Hi, Percentage, Back)));
}
function TD_Supply(P)
{
return ( P > Ref(P, 1) AND P > Ref(P, -1) AND P > Ref(C, -2));
}
function TD_Demand(P)
{
return ( P < Ref(P, 1) AND P < Ref(P, -1) AND P < Ref(C, -2));
}
////////////////////////////////////////////////////////////////////////
//Parameters
Percentage
= Param("Percentage", 1.5, 0.01, 100. ,0.01);
DrawAllLines
= ParamToggle("Draw All Lines?", "No|Yes");
Lines
= Param("Lines?", 1, 1, BarCount-2);
DrawR
= ParamList("Resistance Points", "Off|High to High|High
to Low", 1);
DrawS
= ParamList("Support Points", "Off|Low to Low|Low to Hig
h", 1);
ShowTDP
= ParamToggle("Show TD Pionts", "No|Yes", 1);
AllOrDownR
= ParamToggle("Resistance Direction", "All|Down");

AllOrUpS
= ParamToggle("Support Direction", "All|Up");
ShowSR
= ParamToggle("Show Vert S/R","No|Yes", 1);
SRPer
= Param("S/R Percentage", 3, 1);
SRBack
= Param("S/R Back", 5, 1);
str = "";
Res = Sup = 0;
Con = 1;
////////////////////////////////////////////////////////////////////////
Main = C;
Con = ConS = ConR = 1;
if(DrawS=="Low to Low")
{
Support1 = L;
Support2 = L;
}
else
{
Support1 = L;
Support2 = H;
}
if(DrawR=="High to High")
{
Resistance1 = H;
Resistance2 = H;
}
else
{
Resistance1 = H;
Resistance2 = L;
}
////////////////////////////////////////////////////////////////////////
//Plotting Area
Plot(Main, "", IIf(C>O,colorGreen, colorRed), styleBar);
if(DrawAllLines)
for(i = 2; i<=Lines+1; i++)
{
if(DrawS!="Off")
{
x0 = GetXSupport(Support1, Percentage, i);
x1 = GetXSupport(Support2, Percentage, i-1);
y0 = GetYSupport(Support1, Percentage, i);
y1 = GetYSupport(Support2, Percentage, i-1);
x = LineArray(x0, y0, x1, y1, 1);
if(AllOrUpS) ConS = StrToNum(NumToStr(y0 < y1));
if(Con AND ConS)
Plot(x, "", IIf(LastValue(C) < LastValue(x), colorBlue,c
olorLightBlue),
styleLine|styleThick);
}
if(DrawR!="Off")
{
x0 = GetXResistance(Resistance1, Percentage, i);
x1 = GetXResistance(Resistance2, Percentage, i-1);
y0 = GetYResistance(Resistance1, Percentage, i);
y1 = GetYResistance(Resistance2, Percentage, i-1);
x = LineArray(x0, y0, x1, y1, 1);
if(AllOrDownR) ConR = y0 > y1;
if(Con AND ConR)
Plot(x, "", IIf(LastValue(C) < LastValue(x), colorBlue,
colorLightBlue),

styleLine|styleThick);
}
}
else
{
if(DrawS!="Off")
{
x0 = GetXSupport(Support1, Percentage, Lines+1);
x1 = GetXSupport(Support2, Percentage, Lines);
y0 = GetYSupport(Support1, Percentage, Lines+1);
y1 = GetYSupport(Support2, Percentage, Lines);
x = LineArray(x0, y0, x1, y1, 1 );
Sup = LastValue(LinRegSlope(x, Lines+1));
if(AllOrUpS) ConS = y0 < y1;
if(Con AND ConS)
Plot(x, "", IIf(LastValue(C) < LastValue(x), colorBlue,c
olorLightBlue),
styleLine|styleThick);
}
if(DrawR!="Off")
{
x0 = GetXResistance(Resistance1, Percentage, Lines+1);
x1 = GetXResistance(Resistance2, Percentage, Lines);
y0 = GetYResistance(Resistance1, Percentage, Lines+1);
y1 = GetYResistance(Resistance2, Percentage, Lines);
x = LineArray(x0, y0, x1, y1, 1 );
Res = LastValue(LinRegSlope(x, Lines+1));
if(AllOrDownR) ConR = y0 > y1;
if(Con AND ConR)
Plot(x, "", IIf(LastValue(C) < LastValue(x), colorBlue,
colorLightBlue),
styleLine|styleThick);
}
str = "\nR Slope=("+Res+"), S Slope=("+Sup+")";
}
if(ShowTDP)
{
PlotShapes(TD_Supply(H)*shapeSmallCircle,
PlotShapes(TD_Demand(L)*shapeSmallCircle,
}
if(ShowSR)
{
for(i=1; i<=SRBack; i++)
{
x0 = GetXSupport(L, SRPer, i);
x1 = BarCount-1;
y0 = GetYSupport(L, SRPer, i);
x = LineArray(x0, y0, x1, y0, 0);
Plot(x, "", IIf(LastValue(C) > x,
styleLine|styleDashed|styleThick);
x0 = GetXResistance(H, SRPer, i);
y0 = GetYResistance(H, SRPer, i);
x = LineArray(x0, y0, x1, y0, 0);
Plot(x, "", IIf(LastValue(C) > x,
styleLine|styleDashed|styleThick);

colorRed, 0, H, H*.001);
colorGreen, 0, L, -L*.001);

colorDarkGreen, colorDarkRed),

colorDarkGreen, colorDarkRed),

}
}
Title =FullName()+" ({{NAME}})\n{{DATE}}\n"+"Open: "+O+", Hi: "+H+", Lo: "+L+",

Close: "+C+StrFormat(" (%.2f %.2f\%)", C-Ref(C, -1), SelectedValue(ROC(C,


1)))+str;
_SECTION_END();
/////////////////////////////////////////////////////////////////////////////
//
// TRO Indicators for AmiBroker
//
//
This code contains the TRO indicators for dynamic support and resistance
,
// Fibs based on the dynamic SRs, buy (and sell) zones, and the TRO slot
// machine which displays the candle colors for the day and two user defined
// timeframes (default is 5-min and 60-min). You can use the parameter screen
// to turn the indicators on and off.
//
// The dynamic support and resistance is displayed as dots above and below the
// price bars. Red is resistance and Blue is support. White dots indicate a
// possible bounce trade off the dynamic SRs. The fibs are displayed as dotted
// lines.
//
// The Buy (AND Sell) zones are displayed as colored ranges around the day's op
en
// value (which is displayed as a white line).
//
// The TRO slot machine is a 4 tiered ribbon at the bottom of the price
// chart. The bottom ribbon represents the day candle color (green is up and
// red is down). The second and third ribbons are user defined timeframes
// which also display the timeframe candle colors. The top ribbon shows sporta
tic
// blocks which represent trade triggers relating to the white dots above and
// below the price bars. A blue block is buy and a red block is sell. A trigg
er
// is only displayed if one of the user specified timeframes is pointing in the
// direction of the trigger.
//
// Compiled and written by: dbw451
//
Date: July 27, 2007
//
// Modifications: www.stockmaniacs.net
//
// Note: this code is provided as is and no representations of any kind are
// implied or made. As always, trading is at your own risk.
//
/////////////////////////////////////////////////////////////////////////////
SetChartOptions(0,chartShowArrows|chartShowDates);
_N(Title = StrFormat("{{NAME}} - {{INTERVAL}} {{DATE}} O %g, H %g, L %g, C %g (%
.1f%%) Vol " +WriteVal( V, 1.0 ) +" {{VALUES}}", O, H, L, C, SelectedValue( ROC(
C, 1 )) ));
Plot(C, "C", colorBlack, styleCandle );
SetChartBkColor(ParamColor("BackGround Color", colorDarkGrey));
// Global Variables
bDynamic_R = 0;
bDynamic_S = 0;
_SECTION_BEGIN("Toggles");

bPlotSR = ParamToggle("Dynamic SR","Off|On",True);


bPlotFib = ParamToggle("Dynamic Fibs","Off|On",False);
bPlotBZ = ParamToggle("Buy Zone","Off|On",True);
bPlotSM = ParamToggle("Slot Machine","Off|On",True);
_SECTION_END();
_SECTION_BEGIN("DynamicSR");
iPeriods = Param("Num Lookback Bars",5 ,1, 100,1);
DayValue = Day();
NewDay[0] = 1;
for( i = 1; i < BarCount; i++)
{
if (DayValue[i] == DayValue[i-1])
NewDay[i] = 0;
else
NewDay[i] = 1;
}
BarsSinceOpen = BarsSince(NewDay);
PeriodToUse = IIf (BarsSinceOpen < iPeriods, BarsSinceOpen + 1, iPeriods);
Dynamic_R = HHV(H,PeriodToUse);
Dynamic_S = LLV(L,PeriodToUse);
Dynamic_R = HHV(H,PeriodToUse);
Dynamic_S = LLV(L,PeriodToUse);
Dynamic_R = IIf(H >= Dynamic_R, H, Dynamic_R);
Dynamic_S = IIf(H <= Dynamic_S ,L,Dynamic_S);
DynamicRange = Dynamic_R - Dynamic_S;
bDynamic_R = Ref(H,-1) == Dynamic_R AND Ref(C,-1) < Ref(H,-1);
bDynamic_S = Ref(L,-1) == Dynamic_S AND Ref(C,-1) > Ref(L,-1);
if(bPlotSR) {
Plot(Dynamic_R,"DR", IIf(bDynamic_R, colorWhite, colorRed), styleDots |
styleNoLine);
Plot(Dynamic_S,"DS", IIf(bDynamic_S, colorWhite, colorBlue), styleDots |
styleNoLine);
}
fib1
fib2
fib3
fib4
fib5

=
=
=
=
=

Dynamic_S
Dynamic_S
Dynamic_S
Dynamic_S
Dynamic_S

+
+
+
+
+

.24
.38
.50
.62
.76

*
*
*
*
*

if(bPlotFib) {
Plot(fib1,"F24",
Plot(fib2,"F38",
Plot(fib3,"F50",
Plot(fib4,"F62",
Plot(fib5,"F76",
}

DynamicRange;
DynamicRange;
DynamicRange;
DynamicRange;
DynamicRange;
colorDarkGreen, styleDashed);
colorBrown, styleDashed);
colorGrey40, styleDashed);
colorDarkYellow, styleDashed);
colorDarkGreen, styleDashed);

_SECTION_END();
_SECTION_BEGIN("BuyZone");
OpenTime = Param("TimeOfOpen",91500,0,153000,500);
Points = Param("BuyZonePointsAway",5,0,50,1);
Range = Param("BuyZoneRange",3,0,50,1);
multiplier = Param("Multiplier",1,0,10000,100);
bOpenBar
: 500 is
dOpenBar
bzOpen =

= IIf(TimeNum() >= OpenTime AND TimeNum() < OpenTime+500,1,0); // note


for 5 minute timeframe
= IIf(bOpenBar==1,Open,0);
ValueWhen(bOpenBar==1,dOpenBar);

bzPoints = Points / multiplier;


bzRange = Range / multiplier;
bzLongBot = bzOpen + bzPoints;
bzLongTop = bzLongBot + bzRange;
bzShortTop = bzOpen - bzPoints;
bzShortBot = bzShortTop - bzRange;
if (bPlotBZ)
{
Plot (bzOpen,"bzOpen",colorWhite, styleStaircase | styleNoRescale);
PlotOHLC( bzLongBot,bzLongTop,bzLongBot,bzLongTop, "", colorPaleGreen, s
tyleCloud | styleNoLabel | styleNoRescale);
PlotOHLC( bzShortTop,bzShortBot,bzShortTop,bzShortBot, "", colorLightOra
nge, styleCloud | styleNoLabel | styleNoRescale);
Plot(bzLongTop,"LZtop", colorPaleGreen, styleLine | styleNoRescale);
// Plot line so value is displayed on chart axis
Plot(bzShortBot,"SZbot", colorLightOrange, styleLine | styleNoRescale);
}
_SECTION_END();
_SECTION_BEGIN("SlotMachine");
if(bPlotSM) {
Row2Minutes = Param("Row2 TimeFrame (min)",5,1,240,1);
Row3Minutes = Param("Row3 TimeFrame (min)",60,1,240,1);
Row2Time = Row2Minutes * 60;
Row3Time = Row3Minutes * 60;
TimeFrameSet(Row2Time);
btfRow2 = C > O;
TimeFrameRestore();
TimeFrameSet(Row3Time);
btfRow3 = C > O;
TimeFrameRestore();
bRow2 = TimeFrameExpand(btfRow2, Row2Time);
bRow3 = TimeFrameExpand(btfRow3, Row3Time);
bTrendTrigger = IIf((bDynamic_R AND (!bRow2 OR !bRow3)), 1, IIf((bDynami
c_S AND (bRow2 OR bRow3)), 1, 0));

Plot( 1, "Day", IIf( C > bzOpen, colorGreen, colorDarkRed), styleOwnScal


e|styleArea|styleNoLabel, -0.5, 100 );
Plot( 2, "60min", IIf( bRow3, colorBrightGreen, colorRed), styleOwnScale
|styleArea|styleNoLabel, -0.5, 100 );
Plot( 3, "5min", IIf( bRow2, colorGreen, colorDarkRed), styleOwnScale|st
yleArea|styleNoLabel, -0.5, 100 );
Plot( 4, "Trigger", IIf((bTrendTrigger AND bDynamic_S), colorBlue, IIf((
bTrendTrigger AND bDynamic_R), colorRed, colorBlack)), styleOwnScale|styleArea|s
tyleNoLabel, -0.5, 100 );
}
_SECTION_END();

Related Interests