elliott wave

#1
hello
is it possible to have advanced get type of elliott wave marking in amibroker
is ther any formula or afl file for that if so plese do help



thanks
 
#2
Here are a few AFLs




// ELLIOT WAVE
//-- Script Start -------
Option = ParamToggle("Insert To", "Price Chart|Indicator");

pr=Param("Elliot Wave minimum % move",2, 0.001,100);

//{ Beginner Elliot Wave stuff }
EWpk=PeakBars(H,pr)==0;
EWtr=TroughBars(L,pr)==0;

//{ Intermediate Elliot Wave stuff }
zz=Zig(C,pr);
zzHi=Zig(H,pr);
zzLo=Zig(L,pr);
Avg=(zzHi+zzLo)/2;

//{ Advanced Elliot Wave stuff }
RetroSuccessSecret=IIf(EWpk,zzHi,
IIf(EWtr,zzLo,IIf(Avg>Ref(Avg,-1),H,L)));
EW=Zig(RetroSuccessSecret,pr);

//{ Plot on price chart }
if (Option==0)
Plot(EW, "EW", ParamColor("Color", colorBrown), ParamStyle("Style", styleNoLabel|styleThick));
else
{

//{ Buy/Sell Elliot Wave stuff }
EWbuy=TroughBars(EW,pr)==0;
EWsell=PeakBars(EW,pr)==0;

//{ Plot on own window }
Plot(EWbuy-EWsell, "EW2", ParamColor("Color", colorRed), ParamStyle("Style", styleNoLabel|styleThick));

}
//-- Script End -------

_SECTION_BEGIN("Colour Bar Chart");
outsidebar = H > Ref( H, -1 ) AND L < Ref( L, -1 );
insidebar = H < Ref( H, -1 ) AND L > Ref( L, -1 );
upbar = H > Ref( H, -1 ) AND L >= Ref( L, -1 );
downbar = L < Ref( L, -1 ) AND H <= Ref( H, -1 );

barcolor = IIf(outsidebar, colorBlue,
IIf(downbar, colorRed,
IIf(upbar, colorGreen,
IIf(insidebar, 11, colorBlack)
)
)
);

Title = Name() + "\\c" + barcolor + " - Color Bar Chart : " +
WriteIf(Outsidebar, "Outside Bar",
WriteIf(insidebar, "Inside Bar",
WriteIf(upbar, "Up Bar",
WriteIf(downbar, "Down Bar", "Neutral Bar")
)
)
);

Plot(Close, Title, barcolor, styleThick + styleBar);
_SECTION_END();

_SECTION_BEGIN("Background");
SetChartOptions(0,chartShowArrows|chartShowDates);
if( ParamToggle("Tooltip shows", "All Values|Only Prices" ) )
{
ToolTip=StrFormat("Open: %g\nHigh: %g\nLow: %g\nClose: %g
(%.1f%%)\nVolume: "+NumToStr( V, 1 ), O, H, L, C, SelectedValue( ROC( C, 1
)));
}

SetChartBkColor(ParamColor("Outer panel color ",colorBlack)); // color of outer border
SetChartBkGradientFill( ParamColor("Inner panel color upper half",colorDarkTeal),
ParamColor("Inner panel color lower half",colorBlack)//color of inner panel
,ParamColor("behind Text Color", colorYellow));
_SECTION_END();




//Elliot Wave [Single Loop]
_SECTION_BEGIN("Elliotwave");
X=BarIndex();
p=Param("p",5,5,30,1);
z=Zig(C,p);Plot(C,"C",2,64);
CONDP=PeakBars(C,P)==0;SP=Cum(CONDP);
EP1=ValueWhen(CONDP,C,1);TP1=ValueWhen(CONDP,X,1);
EP2=ValueWhen(CONDP,C,2);TP2=ValueWhen(CONDP,X,2);
EP3=ValueWhen(CONDP,C,3);TP3=ValueWhen(CONDP,X,3);
EP4=ValueWhen(CONDP,C,4);TP4=ValueWhen(CONDP,X,4);
CONDT=TroughBars(C,P)==0;ST=Cum(CONDT);
ET1=ValueWhen(CONDT,C,1);TT1=ValueWhen(CONDT,X,1);
ET2=ValueWhen(CONDT,C,2);TT2=ValueWhen(CONDT,X,2);
ET3=ValueWhen(CONDT,C,3);TT3=ValueWhen(CONDT,X,3);
ET4=ValueWhen(CONDT,C,4);TT4=ValueWhen(CONDT,X,4);
ET5=ValueWhen(CONDT,C,5);TT5=ValueWhen(CONDT,X,5);
// EW definition
EW8=EP3>EP4 AND EP2>EP3 AND EP2>EP1 AND ET4>ET5 AND ET3>ET2 AND
ET2>ET1 AND ET3>ET4 AND ET4>ET5 AND CONDT;
COLOR=colorWhite;
PlotShapes(shapeDigit8*EW8,color);
G=Cum(CONDP OR CONDT);
GEW=SelectedValue(ValueWhen(EW8,G));
for(n=1;n<=9;n++)
{
PlotShapes((49-(2*n-(n%2)))*(G==GEW-n AND (n%2)*CONDP+(-1+n%2)
*CONDT),Color);
}
Plot(EW8,"",colorRed,2+styleOwnScale);
Plot(z,"",colorYellow,styleThick);
Filter=EW8;// explore for all quotations
AddColumn(C,"C");
GraphXSpace=8;
_SECTION_END();

_SECTION_BEGIN("Price");
SetChartOptions(0,chartShowArrows|chartShowDates);
_N(Title = StrFormat("{{NAME}} - {{INTERVAL}} {{DATE}} Open %g, Hi %g, Lo %g, Close %g (%.1f%%) {{VALUES}}", O, H, L, C, SelectedValue( ROC( C, 1 ) ) ));
Plot( C, "Close", ParamColor("Color", colorBlack ), styleNoTitle | ParamStyle("Style") | GetPriceStyle() );
_SECTION_END();




//Elliot Wave Oscillator
hBar = EMA(C,5)- EMA(C,35);
Plot(hBar, _DEFAULT_NAME(),
IIf(hBar>=0, ParamColor("Up Color", colorGreen), ParamColor("Down Color", colorRed)),
ParamStyle( "Style", styleHistogram | styleThick, maskHistogram )
);

/* These two forms of the same indicator are designed to act as the Chandelier Exit stop loss as described by Barbara Rockefeller in
"Technical Analysis for Dummies", and is written especially for use with AmiBroker. She describes the Chandelier exit as a dataset of
"the highest high or the highest close SINCE YOUR ENTRY." To allow the Chandelier exit to stop you out gives you a couple of
average-true-ranges (ATRs) from the best price the stock has reached SINCE YOUR ENTRY.

Only *you* know when your trading rules will dictate that you enter the trade, and so my Chandelier Exit Preview here allows you to preview
the Chandelier exit series by clicking on the bar that AmiBroker’s back-test/optimize says you should buy on. If your RSI says “buy” on the
1st of June, simply overlay my Chandelier Exit formula onto your price data, and click on the bar corresponding to the 1st of June. The three
series named "Chand..." will change each time you click a different bar. Thus when you click the 1st of June bar, you get a Chandelier Exit
stop loss especially designed for buying that stock on the 1st of June. The second formula, the Chandelier Exit, is designed to fit into your
automated AmiBroker trading formulae.

Why do all this?.... 1) Adaptive trailing stops allow you to crystallize profits made. 2) The Chanderlier Exit takes into account when you
bought the stock, making it more relevant. 3) This AmiBroker version allows you to preview when it would stop you out for any bar that your
trading system tells you. 4) It can be fairly easily integrated into your automated AmiBroker back-tests and optimizations.

How to integrate it into your personal AmiBroker trading system:

Pretend your "buy" formula is simply [MA(Close, 10) > O] and your "sell" formula is [MA(Close, 10) < 0] for simplicity. Run a window with
the MA(Close, 10) graph so you can see when it crosses zero, and place another window with the price, and overlay with the Chandelier Exit
formula you wish to use. If you use Chandelier Exit Preview, simply click on each day when the MA(Close, 10) crosses zero, and the appropriate
Chandelier exit lines for the highest High and Close, and lowest Low will appear. The point of the Preview is that you can click on any day
and see how the Chandelier exit would behave :).

As for the second, Chandelier Exit formula, simply copy your "[MA(Close, 10) > O]" and use it to replace the <your "buy" criterion>. Then
go to your Sell criterion and add "OR" then copy the appropriate Graph1, Graph2 or Graph3 depending on whether your Chandelier Exit should
use the highest High (Graph1) or Close (Graph2) or lowest Low (Graph3), in the form of "OR Cross(Graph1, Close)". If you wish to optimize
the "ATRPeriods" and "Multiple" paramaters, simply replace "Param" with "Optimize" and run it through the Automatic Analysis.

/* These two forms of the same indicator are designed to act as the Chandelier Exit stop loss as described by Barbara Rockefeller in
"Technical Analysis for Dummies", and is written especially for use with AmiBroker. She describes the Chandelier exit as a dataset of
"the highest high or the highest close SINCE YOUR ENTRY." To allow the Chandelier exit to stop you out gives you a couple of
average-true-ranges (ATRs) from the best price the stock has reached SINCE YOUR ENTRY.

Only *you* know when your trading rules will dictate that you enter the trade, and so my Chandelier Exit Preview here allows you to preview
the Chandelier exit series by clicking on the bar that AmiBroker’s back-test/optimize says you should buy on. If your RSI says “buy” on the
1st of June, simply overlay my Chandelier Exit formula onto your price data, and click on the bar corresponding to the 1st of June. The three
series named "Chand..." will change each time you click a different bar. Thus when you click the 1st of June bar, you get a Chandelier Exit
stop loss especially designed for buying that stock on the 1st of June. The second formula, the Chandelier Exit, is designed to fit into your
automated AmiBroker trading formulae.

Why do all this?.... 1) Adaptive trailing stops allow you to crystallize profits made. 2) The Chanderlier Exit takes into account when you
bought the stock, making it more relevant. 3) This AmiBroker version allows you to preview when it would stop you out for any bar that your
trading system tells you. 4) It can be fairly easily integrated into your automated AmiBroker back-tests and optimizations.

How to integrate it into your personal AmiBroker trading system:

Pretend your "buy" formula is simply [MA(Close, 10) > O] and your "sell" formula is [MA(Close, 10) < 0] for simplicity. Run a window with
the MA(Close, 10) graph so you can see when it crosses zero, and place another window with the price, and overlay with the Chandelier Exit
formula you wish to use. If you use Chandelier Exit Preview, simply click on each day when the MA(Close, 10) crosses zero, and the appropriate
Chandelier exit lines for the highest High and Close, and lowest Low will appear. The point of the Preview is that you can click on any day
and see how the Chandelier exit would behave :).

As for the second, Chandelier Exit formula, simply copy your "[MA(Close, 10) > O]" and use it to replace the <your "buy" criterion>. Then
go to your Sell criterion and add "OR" then copy the appropriate Graph1, Graph2 or Graph3 depending on whether your Chandelier Exit should
use the highest High (Graph1) or Close (Graph2) or lowest Low (Graph3), in the form of "OR Cross(Graph1, Close)". If you wish to optimize
the "ATRPeriods" and "Multiple" paramaters, simply replace "Param" with "Optimize" and run it through the Automatic Analysis.



//ELLIOT Fractals
_SECTION_BEGIN("Price");
SetChartOptions(0,chartShowArrows|chartShowDates);
_N(Title = StrFormat("{{NAME}} - {{INTERVAL}} {{DATE}} Open %g, Hi %g, Lo %g, Close %g (%.1f%%) {{VALUES}}", O, H, L, C, SelectedValue( ROC( C, 1 ) ) ));
Plot( C, "Close", ParamColor("Color", colorBlack ), styleCandle
| ParamStyle("Style") | GetPriceStyle() );
// Paste the code below to your price chart somewhere and green ribbon means both
// both MACD and ADX trending up so if the red ribbon shows up the MACD and the ADX
// are both trending down.

_SECTION_BEGIN("trending ribbon");
uptrend=PDI()>MDI()AND Signal()<MACD();
downtrend=MDI()>PDI()AND Signal()>MACD();


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

_SECTION_END();

_SECTION_BEGIN("LEMA");
P = ParamField("Price field",-1);
Periods = Param("Periods", 20, 2, 200, 1, 10 );
lema = EMA (Close,Periods)+ EMA((Close-EMA(Close,Periods)),Periods);
Plot( lEMA, _DEFAULT_NAME(), ParamColor( "Color", colorCycle ),
ParamStyle("Style") );
_SECTION_END();

_SECTION_BEGIN("ELLIOTT Fractals");
/*
The basic definition of an 'up' fractal is a bar high that is both higher than the two bars immediately preceding it
and higher than the two bars immediately following it.
The lows of the bars are NOT considered in determining the up fractal progression.

If two bars in the progression have equal highs followed by two consecutive bars with lower highs,
then a total of six bars rather than the usual five bars will make up the progression.
The first High becomes the counting fractal. Reverse for 'down' fractals.

The 5 bar formation works best on Daily or longer time frame charts.For intraday data charts we often use 9 bar, 13 bar and 21 bar formations for fractal counting
*/
Up5BarFractal = Ref(H,-2) < H AND Ref(H,-1) < H AND Ref(H,1) < H AND Ref(H,2) < H;
Up6BarFractal = Ref(H,-2) < H AND Ref(H,-1) < H AND (H == Ref(H,1)) AND Ref(H,2) < H AND Ref(H,3) < H;
Down5BarFractal = Ref(L,-2) > L AND Ref(L,-1) > L AND Ref(L,1) > L AND Ref(L,2) > L;
Down6BarFractal = Ref(L,-2) > L AND Ref(L,-1) > L AND (L == Ref(L,1)) AND Ref(L,2) > L AND Ref(L,3) > L;

//TODO: More filtering: Show only troughs that are around atrough in trix(9).

PlotShapes( IIf(Down5BarFractal ,shapeSmallUpTriangle,0) ,colorBlack, 0, L,-12);
PlotShapes( IIf(Down6BarFractal ,shapeSmallUpTriangle,0) ,colorBlack, 0, L,-12);

PlotShapes( IIf(Up5BarFractal ,shapeSmallDownTriangle,0) ,colorBlack, 0, H,-12);
PlotShapes( IIf(Up6BarFractal ,shapeSmallDownTriangle,0) ,colorBlack, 0, H,-12);

Up = (Up5BarFractal OR Up6BarFractal);
Down = (Down5BarFractal OR Down6BarFractal);
//Removing false fractals:
DownSignal = Flip(Ref(Up,-1), Ref(Down,-1));
UpSignal = Flip(Ref(Down,-1), Ref(Up,-1));

LastHigh[0] = H[0];
LastLow[0] = L[0];

LastLowIndex = 0;
LastHighIndex = 0;
Valid = 0;
for (i=1; i < BarCount; i++)
{

LastHigh = LastHigh[i-1];
LastLow = LastLow[i-1];
if (Up)
{
Valid = True;
if (DownSignal)
{
//Sequence of 2 Up Fractals. Validate only the higher one.
Valid = H >= H[LastHighIndex];
Valid[LastHighIndex] = H[LastHighIndex] > H;
}
LastHigh = Max(H, H[LastHighIndex ]);
LastHighIndex = i;
}

if (Down)
{
Valid = True;
if (UpSignal)
{
//Sequence of 2 Down Fractals. Validate only the lower one.
Valid = L <= L[LastLowIndex];
Valid[LastLowIndex] = L[LastLowIndex] < L;
}

LastLow = Min(L, L[LastLowIndex]);
LastLowIndex = i;
}
}

TrixN = Trix(9);
TroughLow = Ref(TrixN, -3) > TrixN AND Ref(TrixN, -2) > TrixN AND Ref(TrixN, -1) > TrixN AND Ref(TrixN, 1) > TrixN AND Ref(TrixN, 2) > TrixN AND Ref(TrixN, 3) > TrixN;
TroughHigh = Ref(TrixN, -3) < TrixN AND Ref(TrixN, -2) < TrixN AND Ref(TrixN, -1) < TrixN AND Ref(TrixN, 1) < TrixN AND Ref(TrixN, 2) < TrixN AND Ref(TrixN, 3) < TrixN;
//TroughLow = Ref(TrixN, -2) > TrixN AND Ref(TrixN, -1) > TrixN AND Ref(TrixN, 1) > TrixN AND Ref(TrixN, 2) > TrixN;
//TroughHigh = Ref(TrixN, -2) < TrixN AND Ref(TrixN, -1) < TrixN AND Ref(TrixN, 1) < TrixN AND Ref(TrixN, 2) < TrixN;
ZeroValid = Cross(TrixN, 0) OR Cross(0, TrixN) OR Ref(Cross(TrixN, 0),1) OR Ref(Cross(0, TrixN),1);
ValidLow = TroughLow OR Ref(TroughLow, 1) OR Ref(TroughLow, 2) OR Ref(TroughLow, 3) OR Ref(TroughLow, 4);// OR Ref(TroughLow, 5));
ValidHigh = TroughHigh OR Ref(TroughHigh, 1) OR Ref(TroughHigh, 2) OR Ref(TroughHigh, 3) OR Ref(TroughHigh, 4);// OR Ref(TroughHigh, 5));

//Plot(LastHigh-10 ,"LastHigh", colorBlue, styleLine);
//Plot(LastLow-10 ,"LastLow ", colorRed, styleLine);
//Plot(Valid*5 + 10 ,"LastLow ", colorGreen, styleLine | styleThick);

//PlotShapes( IIf(Down AND Valid,shapeSmallUpTriangle,0) ,colorGreen, 0, L,-12);
//PlotShapes( IIf(Up AND Valid,shapeSmallDownTriangle,0) ,colorRed, 0, H,-12);
Maxi = Up AND (ValidHigh OR ZeroValid);
Mini = Down AND (ValidLow OR ZeroValid);
PlotShapes( IIf(Down AND (ValidLow OR ZeroValid),shapeSmallUpTriangle,0) ,colorBlue, 0, L,-12);
PlotShapes( IIf(Up AND (ValidHigh OR ZeroValid),shapeSmallDownTriangle,0) ,colorOrange, 0, H,-12);
//Plot(UpSignal*3+5,"UpSignal", colorBlue, styleLine| styleThick);
//Plot(DownSignal*3 ,"DownSignal", colorRed, styleLine| styleThick);

/*
LastMaxi = 0;
LastMini = 0;
ElliotLines = 0;
State = 0;
for (i=1; i < BarCount; i++)
{
State = State[i-1];
if (Maxi)
{
State = 1;//down
}

if (Mini)
{
State = 2;
}

}

PlotShapes(IIf(State > 0, shapeSmallCircle, 0), IIf(State == 1, colorRed, colorBlue), 0, IIf(State == 1, H, L), -5);
*/
//Line = LineArray( x0, y0, x1, y1, 1 );
//Plot( Line, "Trend line", colorBlue );

/*
Wave B
Usually 50% of Wave A
Should not exceed 75% of Wave A
Wave C
either 1 x Wave A
or 1.62 x Wave A
or 2.62 x Wave A
*/
function CorrectiveRatios(StartPrice, A, B, C, RatioDelta, Delta)
{

ALength = abs(startPrice - A); BLength = abs(A-B);
CLength = abs(B-C);

Ratio1 = BLength / CLength ;
Cond1 = Ration1 >= 0.5 - RatioDelta AND ratio1 <= 0.75 + RatioDelta;
Cond2 = abs(Clength - ALength) < Delta OR abs(Clength - 1.62 * ALength) < Delta OR abs(CLength - 2.62 * ALength) < Delta;

return Cond1 AND Cond2;
}

function ImpulseRules(StartPrice, One, Two, Three, Four, Five)
{
//Wave 2 should be beneath wave 1 start:
Cond1 = Two > StartPrice AND Two < One;
//Wave 4 - the same:
Cond2 = Four > Two AND Four < Three;
//Wave 5 should be <= wave 3
Cond3 = abs(Three-Two) >= abs(Five - Four);
//Wave 1 should be smaller than wave five, making wave 3 the biggest:
Cond4 = abs(StartPrice - One) < abs(Five - Four);
return Cond1 AND Cond2 AND Cond3 AND Cond4;
}
_SECTION_END();


Hope u find something u could use!

Regards
 
Last edited:
#9
can you guys guide me how to use this elliott wave, this is the first time i am going to use these charts.... when i see the elliott waves code...... its very confusing me...... i have amibroker with me but i dont have data provider ........ can any one of u can help
 
#10
Here are a few AFLs




// ELLIOT WAVE
//-- Script Start -------
Option = ParamToggle("Insert To", "Price Chart|Indicator");

pr=Param("Elliot Wave minimum % move",2, 0.001,100);

//{ Beginner Elliot Wave stuff }
EWpk=PeakBars(H,pr)==0;
EWtr=TroughBars(L,pr)==0;

//{ Intermediate Elliot Wave stuff }
zz=Zig(C,pr);
zzHi=Zig(H,pr);
zzLo=Zig(L,pr);
Avg=(zzHi+zzLo)/2;

//{ Advanced Elliot Wave stuff }
RetroSuccessSecret=IIf(EWpk,zzHi,
IIf(EWtr,zzLo,IIf(Avg>Ref(Avg,-1),H,L)));
EW=Zig(RetroSuccessSecret,pr);

//{ Plot on price chart }
if (Option==0)
Plot(EW, "EW", ParamColor("Color", colorBrown), ParamStyle("Style", styleNoLabel|styleThick));
else
{

//{ Buy/Sell Elliot Wave stuff }
EWbuy=TroughBars(EW,pr)==0;
EWsell=PeakBars(EW,pr)==0;

//{ Plot on own window }
Plot(EWbuy-EWsell, "EW2", ParamColor("Color", colorRed), ParamStyle("Style", styleNoLabel|styleThick));

}
//-- Script End -------

_SECTION_BEGIN("Colour Bar Chart");
outsidebar = H > Ref( H, -1 ) AND L < Ref( L, -1 );
insidebar = H < Ref( H, -1 ) AND L > Ref( L, -1 );
upbar = H > Ref( H, -1 ) AND L >= Ref( L, -1 );
downbar = L < Ref( L, -1 ) AND H <= Ref( H, -1 );

barcolor = IIf(outsidebar, colorBlue,
IIf(downbar, colorRed,
IIf(upbar, colorGreen,
IIf(insidebar, 11, colorBlack)
)
)
);

Title = Name() + "\\c" + barcolor + " - Color Bar Chart : " +
WriteIf(Outsidebar, "Outside Bar",
WriteIf(insidebar, "Inside Bar",
WriteIf(upbar, "Up Bar",
WriteIf(downbar, "Down Bar", "Neutral Bar")
)
)
);

Plot(Close, Title, barcolor, styleThick + styleBar);
_SECTION_END();

_SECTION_BEGIN("Background");
SetChartOptions(0,chartShowArrows|chartShowDates);
if( ParamToggle("Tooltip shows", "All Values|Only Prices" ) )
{
ToolTip=StrFormat("Open: %g\nHigh: %g\nLow: %g\nClose: %g
(%.1f%%)\nVolume: "+NumToStr( V, 1 ), O, H, L, C, SelectedValue( ROC( C, 1
)));
}

SetChartBkColor(ParamColor("Outer panel color ",colorBlack)); // color of outer border
SetChartBkGradientFill( ParamColor("Inner panel color upper half",colorDarkTeal),
ParamColor("Inner panel color lower half",colorBlack)//color of inner panel
,ParamColor("behind Text Color", colorYellow));
_SECTION_END();




//Elliot Wave [Single Loop]
_SECTION_BEGIN("Elliotwave");
X=BarIndex();
p=Param("p",5,5,30,1);
z=Zig(C,p);Plot(C,"C",2,64);
CONDP=PeakBars(C,P)==0;SP=Cum(CONDP);
EP1=ValueWhen(CONDP,C,1);TP1=ValueWhen(CONDP,X,1);
EP2=ValueWhen(CONDP,C,2);TP2=ValueWhen(CONDP,X,2);
EP3=ValueWhen(CONDP,C,3);TP3=ValueWhen(CONDP,X,3);
EP4=ValueWhen(CONDP,C,4);TP4=ValueWhen(CONDP,X,4);
CONDT=TroughBars(C,P)==0;ST=Cum(CONDT);
ET1=ValueWhen(CONDT,C,1);TT1=ValueWhen(CONDT,X,1);
ET2=ValueWhen(CONDT,C,2);TT2=ValueWhen(CONDT,X,2);
ET3=ValueWhen(CONDT,C,3);TT3=ValueWhen(CONDT,X,3);
ET4=ValueWhen(CONDT,C,4);TT4=ValueWhen(CONDT,X,4);
ET5=ValueWhen(CONDT,C,5);TT5=ValueWhen(CONDT,X,5);
// EW definition
EW8=EP3>EP4 AND EP2>EP3 AND EP2>EP1 AND ET4>ET5 AND ET3>ET2 AND
ET2>ET1 AND ET3>ET4 AND ET4>ET5 AND CONDT;
COLOR=colorWhite;
PlotShapes(shapeDigit8*EW8,color);
G=Cum(CONDP OR CONDT);
GEW=SelectedValue(ValueWhen(EW8,G));
for(n=1;n<=9;n++)
{
PlotShapes((49-(2*n-(n%2)))*(G==GEW-n AND (n%2)*CONDP+(-1+n%2)
*CONDT),Color);
}
Plot(EW8,"",colorRed,2+styleOwnScale);
Plot(z,"",colorYellow,styleThick);
Filter=EW8;// explore for all quotations
AddColumn(C,"C");
GraphXSpace=8;
_SECTION_END();

_SECTION_BEGIN("Price");
SetChartOptions(0,chartShowArrows|chartShowDates);
_N(Title = StrFormat("{{NAME}} - {{INTERVAL}} {{DATE}} Open %g, Hi %g, Lo %g, Close %g (%.1f%%) {{VALUES}}", O, H, L, C, SelectedValue( ROC( C, 1 ) ) ));
Plot( C, "Close", ParamColor("Color", colorBlack ), styleNoTitle | ParamStyle("Style") | GetPriceStyle() );
_SECTION_END();




//Elliot Wave Oscillator
hBar = EMA(C,5)- EMA(C,35);
Plot(hBar, _DEFAULT_NAME(),
IIf(hBar>=0, ParamColor("Up Color", colorGreen), ParamColor("Down Color", colorRed)),
ParamStyle( "Style", styleHistogram | styleThick, maskHistogram )
);

/* These two forms of the same indicator are designed to act as the Chandelier Exit stop loss as described by Barbara Rockefeller in
"Technical Analysis for Dummies", and is written especially for use with AmiBroker. She describes the Chandelier exit as a dataset of
"the highest high or the highest close SINCE YOUR ENTRY." To allow the Chandelier exit to stop you out gives you a couple of
average-true-ranges (ATRs) from the best price the stock has reached SINCE YOUR ENTRY.

Only *you* know when your trading rules will dictate that you enter the trade, and so my Chandelier Exit Preview here allows you to preview
the Chandelier exit series by clicking on the bar that AmiBrokers back-test/optimize says you should buy on. If your RSI says buy on the
1st of June, simply overlay my Chandelier Exit formula onto your price data, and click on the bar corresponding to the 1st of June. The three
series named "Chand..." will change each time you click a different bar. Thus when you click the 1st of June bar, you get a Chandelier Exit
stop loss especially designed for buying that stock on the 1st of June. The second formula, the Chandelier Exit, is designed to fit into your
automated AmiBroker trading formulae.

Why do all this?.... 1) Adaptive trailing stops allow you to crystallize profits made. 2) The Chanderlier Exit takes into account when you
bought the stock, making it more relevant. 3) This AmiBroker version allows you to preview when it would stop you out for any bar that your
trading system tells you. 4) It can be fairly easily integrated into your automated AmiBroker back-tests and optimizations.

How to integrate it into your personal AmiBroker trading system:

Pretend your "buy" formula is simply [MA(Close, 10) > O] and your "sell" formula is [MA(Close, 10) < 0] for simplicity. Run a window with
the MA(Close, 10) graph so you can see when it crosses zero, and place another window with the price, and overlay with the Chandelier Exit
formula you wish to use. If you use Chandelier Exit Preview, simply click on each day when the MA(Close, 10) crosses zero, and the appropriate
Chandelier exit lines for the highest High and Close, and lowest Low will appear. The point of the Preview is that you can click on any day
and see how the Chandelier exit would behave :).

As for the second, Chandelier Exit formula, simply copy your "[MA(Close, 10) > O]" and use it to replace the <your "buy" criterion>. Then
go to your Sell criterion and add "OR" then copy the appropriate Graph1, Graph2 or Graph3 depending on whether your Chandelier Exit should
use the highest High (Graph1) or Close (Graph2) or lowest Low (Graph3), in the form of "OR Cross(Graph1, Close)". If you wish to optimize
the "ATRPeriods" and "Multiple" paramaters, simply replace "Param" with "Optimize" and run it through the Automatic Analysis.

/* These two forms of the same indicator are designed to act as the Chandelier Exit stop loss as described by Barbara Rockefeller in
"Technical Analysis for Dummies", and is written especially for use with AmiBroker. She describes the Chandelier exit as a dataset of
"the highest high or the highest close SINCE YOUR ENTRY." To allow the Chandelier exit to stop you out gives you a couple of
average-true-ranges (ATRs) from the best price the stock has reached SINCE YOUR ENTRY.

Only *you* know when your trading rules will dictate that you enter the trade, and so my Chandelier Exit Preview here allows you to preview
the Chandelier exit series by clicking on the bar that AmiBrokers back-test/optimize says you should buy on. If your RSI says buy on the
1st of June, simply overlay my Chandelier Exit formula onto your price data, and click on the bar corresponding to the 1st of June. The three
series named "Chand..." will change each time you click a different bar. Thus when you click the 1st of June bar, you get a Chandelier Exit
stop loss especially designed for buying that stock on the 1st of June. The second formula, the Chandelier Exit, is designed to fit into your
automated AmiBroker trading formulae.

Why do all this?.... 1) Adaptive trailing stops allow you to crystallize profits made. 2) The Chanderlier Exit takes into account when you
bought the stock, making it more relevant. 3) This AmiBroker version allows you to preview when it would stop you out for any bar that your
trading system tells you. 4) It can be fairly easily integrated into your automated AmiBroker back-tests and optimizations.

How to integrate it into your personal AmiBroker trading system:

Pretend your "buy" formula is simply [MA(Close, 10) > O] and your "sell" formula is [MA(Close, 10) < 0] for simplicity. Run a window with
the MA(Close, 10) graph so you can see when it crosses zero, and place another window with the price, and overlay with the Chandelier Exit
formula you wish to use. If you use Chandelier Exit Preview, simply click on each day when the MA(Close, 10) crosses zero, and the appropriate
Chandelier exit lines for the highest High and Close, and lowest Low will appear. The point of the Preview is that you can click on any day
and see how the Chandelier exit would behave :).

As for the second, Chandelier Exit formula, simply copy your "[MA(Close, 10) > O]" and use it to replace the <your "buy" criterion>. Then
go to your Sell criterion and add "OR" then copy the appropriate Graph1, Graph2 or Graph3 depending on whether your Chandelier Exit should
use the highest High (Graph1) or Close (Graph2) or lowest Low (Graph3), in the form of "OR Cross(Graph1, Close)". If you wish to optimize
the "ATRPeriods" and "Multiple" paramaters, simply replace "Param" with "Optimize" and run it through the Automatic Analysis.



//ELLIOT Fractals
_SECTION_BEGIN("Price");
SetChartOptions(0,chartShowArrows|chartShowDates);
_N(Title = StrFormat("{{NAME}} - {{INTERVAL}} {{DATE}} Open %g, Hi %g, Lo %g, Close %g (%.1f%%) {{VALUES}}", O, H, L, C, SelectedValue( ROC( C, 1 ) ) ));
Plot( C, "Close", ParamColor("Color", colorBlack ), styleCandle
| ParamStyle("Style") | GetPriceStyle() );
// Paste the code below to your price chart somewhere and green ribbon means both
// both MACD and ADX trending up so if the red ribbon shows up the MACD and the ADX
// are both trending down.

_SECTION_BEGIN("trending ribbon");
uptrend=PDI()>MDI()AND Signal()<MACD();
downtrend=MDI()>PDI()AND Signal()>MACD();


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

_SECTION_END();

_SECTION_BEGIN("LEMA");
P = ParamField("Price field",-1);
Periods = Param("Periods", 20, 2, 200, 1, 10 );
lema = EMA (Close,Periods)+ EMA((Close-EMA(Close,Periods)),Periods);
Plot( lEMA, _DEFAULT_NAME(), ParamColor( "Color", colorCycle ),
ParamStyle("Style") );
_SECTION_END();

_SECTION_BEGIN("ELLIOTT Fractals");
/*
The basic definition of an 'up' fractal is a bar high that is both higher than the two bars immediately preceding it
and higher than the two bars immediately following it.
The lows of the bars are NOT considered in determining the up fractal progression.

If two bars in the progression have equal highs followed by two consecutive bars with lower highs,
then a total of six bars rather than the usual five bars will make up the progression.
The first High becomes the counting fractal. Reverse for 'down' fractals.

The 5 bar formation works best on Daily or longer time frame charts.For intraday data charts we often use 9 bar, 13 bar and 21 bar formations for fractal counting
*/
Up5BarFractal = Ref(H,-2) < H AND Ref(H,-1) < H AND Ref(H,1) < H AND Ref(H,2) < H;
Up6BarFractal = Ref(H,-2) < H AND Ref(H,-1) < H AND (H == Ref(H,1)) AND Ref(H,2) < H AND Ref(H,3) < H;
Down5BarFractal = Ref(L,-2) > L AND Ref(L,-1) > L AND Ref(L,1) > L AND Ref(L,2) > L;
Down6BarFractal = Ref(L,-2) > L AND Ref(L,-1) > L AND (L == Ref(L,1)) AND Ref(L,2) > L AND Ref(L,3) > L;

//TODO: More filtering: Show only troughs that are around atrough in trix(9).

PlotShapes( IIf(Down5BarFractal ,shapeSmallUpTriangle,0) ,colorBlack, 0, L,-12);
PlotShapes( IIf(Down6BarFractal ,shapeSmallUpTriangle,0) ,colorBlack, 0, L,-12);

PlotShapes( IIf(Up5BarFractal ,shapeSmallDownTriangle,0) ,colorBlack, 0, H,-12);
PlotShapes( IIf(Up6BarFractal ,shapeSmallDownTriangle,0) ,colorBlack, 0, H,-12);

Up = (Up5BarFractal OR Up6BarFractal);
Down = (Down5BarFractal OR Down6BarFractal);
//Removing false fractals:
DownSignal = Flip(Ref(Up,-1), Ref(Down,-1));
UpSignal = Flip(Ref(Down,-1), Ref(Up,-1));

LastHigh[0] = H[0];
LastLow[0] = L[0];

LastLowIndex = 0;
LastHighIndex = 0;
Valid = 0;
for (i=1; i < BarCount; i++)
{

LastHigh = LastHigh[i-1];
LastLow = LastLow[i-1];
if (Up)
{
Valid = True;
if (DownSignal)
{
//Sequence of 2 Up Fractals. Validate only the higher one.
Valid = H >= H[LastHighIndex];
Valid[LastHighIndex] = H[LastHighIndex] > H;
}
LastHigh = Max(H, H[LastHighIndex ]);
LastHighIndex = i;
}

if (Down)
{
Valid = True;
if (UpSignal)
{
//Sequence of 2 Down Fractals. Validate only the lower one.
Valid = L <= L[LastLowIndex];
Valid[LastLowIndex] = L[LastLowIndex] < L;
}

LastLow = Min(L, L[LastLowIndex]);
LastLowIndex = i;
}
}

TrixN = Trix(9);
TroughLow = Ref(TrixN, -3) > TrixN AND Ref(TrixN, -2) > TrixN AND Ref(TrixN, -1) > TrixN AND Ref(TrixN, 1) > TrixN AND Ref(TrixN, 2) > TrixN AND Ref(TrixN, 3) > TrixN;
TroughHigh = Ref(TrixN, -3) < TrixN AND Ref(TrixN, -2) < TrixN AND Ref(TrixN, -1) < TrixN AND Ref(TrixN, 1) < TrixN AND Ref(TrixN, 2) < TrixN AND Ref(TrixN, 3) < TrixN;
//TroughLow = Ref(TrixN, -2) > TrixN AND Ref(TrixN, -1) > TrixN AND Ref(TrixN, 1) > TrixN AND Ref(TrixN, 2) > TrixN;
//TroughHigh = Ref(TrixN, -2) < TrixN AND Ref(TrixN, -1) < TrixN AND Ref(TrixN, 1) < TrixN AND Ref(TrixN, 2) < TrixN;
ZeroValid = Cross(TrixN, 0) OR Cross(0, TrixN) OR Ref(Cross(TrixN, 0),1) OR Ref(Cross(0, TrixN),1);
ValidLow = TroughLow OR Ref(TroughLow, 1) OR Ref(TroughLow, 2) OR Ref(TroughLow, 3) OR Ref(TroughLow, 4);// OR Ref(TroughLow, 5));
ValidHigh = TroughHigh OR Ref(TroughHigh, 1) OR Ref(TroughHigh, 2) OR Ref(TroughHigh, 3) OR Ref(TroughHigh, 4);// OR Ref(TroughHigh, 5));

//Plot(LastHigh-10 ,"LastHigh", colorBlue, styleLine);
//Plot(LastLow-10 ,"LastLow ", colorRed, styleLine);
//Plot(Valid*5 + 10 ,"LastLow ", colorGreen, styleLine | styleThick);

//PlotShapes( IIf(Down AND Valid,shapeSmallUpTriangle,0) ,colorGreen, 0, L,-12);
//PlotShapes( IIf(Up AND Valid,shapeSmallDownTriangle,0) ,colorRed, 0, H,-12);
Maxi = Up AND (ValidHigh OR ZeroValid);
Mini = Down AND (ValidLow OR ZeroValid);
PlotShapes( IIf(Down AND (ValidLow OR ZeroValid),shapeSmallUpTriangle,0) ,colorBlue, 0, L,-12);
PlotShapes( IIf(Up AND (ValidHigh OR ZeroValid),shapeSmallDownTriangle,0) ,colorOrange, 0, H,-12);
//Plot(UpSignal*3+5,"UpSignal", colorBlue, styleLine| styleThick);
//Plot(DownSignal*3 ,"DownSignal", colorRed, styleLine| styleThick);

/*
LastMaxi = 0;
LastMini = 0;
ElliotLines = 0;
State = 0;
for (i=1; i < BarCount; i++)
{
State = State[i-1];
if (Maxi)
{
State = 1;//down
}

if (Mini)
{
State = 2;
}

}

PlotShapes(IIf(State > 0, shapeSmallCircle, 0), IIf(State == 1, colorRed, colorBlue), 0, IIf(State == 1, H, L), -5);
*/
//Line = LineArray( x0, y0, x1, y1, 1 );
//Plot( Line, "Trend line", colorBlue );

/*
Wave B
Usually 50% of Wave A
Should not exceed 75% of Wave A
Wave C
either 1 x Wave A
or 1.62 x Wave A
or 2.62 x Wave A
*/
function CorrectiveRatios(StartPrice, A, B, C, RatioDelta, Delta)
{

ALength = abs(startPrice - A); BLength = abs(A-B);
CLength = abs(B-C);

Ratio1 = BLength / CLength ;
Cond1 = Ration1 >= 0.5 - RatioDelta AND ratio1 <= 0.75 + RatioDelta;
Cond2 = abs(Clength - ALength) < Delta OR abs(Clength - 1.62 * ALength) < Delta OR abs(CLength - 2.62 * ALength) < Delta;

return Cond1 AND Cond2;
}

function ImpulseRules(StartPrice, One, Two, Three, Four, Five)
{
//Wave 2 should be beneath wave 1 start:
Cond1 = Two > StartPrice AND Two < One;
//Wave 4 - the same:
Cond2 = Four > Two AND Four < Three;
//Wave 5 should be <= wave 3
Cond3 = abs(Three-Two) >= abs(Five - Four);
//Wave 1 should be smaller than wave five, making wave 3 the biggest:
Cond4 = abs(StartPrice - One) < abs(Five - Four);
return Cond1 AND Cond2 AND Cond3 AND Cond4;
}
_SECTION_END();


Hope u find something u could use!

Regards


Hi,

Thanks for the code, I need buy sell indicators, see screen print...... wonderful code
 
Last edited:

Similar threads