Author Topic: Elliot Wave  (Read 7986 times)

Ceurami

  • Guest
Elliot Wave
« on: September 21, 2010, 06:33:08 am »
Hi,

Could someone help me with this code?
This code spreads very wide on a chart and I dont know if it's capable for intraday charts?
Maybe the code has to break in seperate codes?
Please help, because it looks very interesting....

Thanks in advanced,

Maurice

Code: [Select]
// 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[i] = LastHigh[i-1];
LastLow[i] = LastLow[i-1];
if (Up[i])
{
Valid[i] = True;
if (DownSignal[i])
{
//Sequence of 2 Up Fractals. Validate only the higher one.
Valid[i] = H[i] >= H[LastHighIndex];
Valid[LastHighIndex] = H[LastHighIndex] > H[i];
}
LastHigh[i] = Max(H[i], H[LastHighIndex ]);
LastHighIndex = i;
}

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

LastLow[i] = Min(L[i], 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[i] = State[i-1];
if (Maxi[i])
{
State[i] = 1;//down
}

if (Mini[i])
{
State[i] = 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();
« Last Edit: September 21, 2010, 07:40:41 pm by administrator »

administrator

  • Administrator
  • Full Member
  • *****
  • Posts: 200
    • View Profile
Re: Elliot Wave
« Reply #1 on: September 21, 2010, 07:39:05 pm »
Hello

You need to plot the following code in one pane:
Code: [Select]
//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 )
    );

And the following code in another pane:
Code: [Select]
// 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();

/* 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[i] = LastHigh[i-1];
    LastLow[i] = LastLow[i-1];

    if ( Up[i] )
    {
        Valid[i] = True;

        if ( DownSignal[i] )
        {
//Sequence of 2 Up Fractals. Validate only the higher one.
            Valid[i] = H[i] >= H[LastHighIndex];
            Valid[LastHighIndex] = H[LastHighIndex] > H[i];
        }

        LastHigh[i] = Max( H[i], H[LastHighIndex ] );

        LastHighIndex = i;
    }

    if ( Down[i] )
    {
        Valid[i] = True;

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

        LastLow[i] = Min( L[i], 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[i] = State[i-1];
if (Maxi[i])
{
State[i] = 1;//down
}

if (Mini[i])
{
State[i] = 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();

About using it intraday I don't see any problem with that.

Ceurami

  • Guest
Re: Elliot Wave
« Reply #2 on: September 22, 2010, 03:51:20 am »
Hi Administrator,

Thank you very, very much  :)

Wow, this is really something else on the Elliot fractals.
This is what I'm really looking a long time for.
Those fractals on the (macd) TRIX indicator are superdelicious-MARVELOUS!!!!!!!!!! :P

Thanks again!

Greetings,

Maurice

Ceurami

  • Guest
Re: Elliot Wave
« Reply #3 on: September 22, 2010, 07:09:59 am »
Hi Moderator,

I'm only using this part of the code:

Code: [Select]
//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[i] = LastHigh[i-1];
LastLow[i] = LastLow[i-1];
if (Up[i])
{
Valid[i] = True;
if (DownSignal[i])
{
//Sequence of 2 Up Fractals. Validate only the higher one.
Valid[i] = H[i] >= H[LastHighIndex];
Valid[LastHighIndex] = H[LastHighIndex] > H[i];
}
LastHigh[i] = Max(H[i], H[LastHighIndex ]);
LastHighIndex = i;
}

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

LastLow[i] = Min(L[i], 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[i] = State[i-1];
if (Maxi[i])
{
State[i] = 1;//down
}

if (Mini[i])
{
State[i] = 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();

Is it possible to add a alert-sound? Only for the orange (down-fractals) and the blue (up-fractals)

Like this:


AlertIf( "SOUND C:\\Windows\\Media\\Chord.wav", "Audio alert", 2 );
AlertIf( "SOUND C:\\Windows\\Media\\Ding.wav", "Audio alert", 2 );

Thank you very much in advanced,

Maurice

mahesh.aranake

  • Newbie
  • *
  • Posts: 15
    • View Profile
Re: Elliot Wave
« Reply #4 on: September 22, 2010, 08:02:13 am »
How to copy paste codes after selecting? They give empty windows if done from this site - can there be any copy paste friendly format?

Ceurami

  • Guest
Re: Elliot Wave
« Reply #5 on: September 22, 2010, 10:04:48 am »
Hi mahesh.aranake,

Try my code from 11:09....  :)

Greetings,

Maurice

administrator

  • Administrator
  • Full Member
  • *****
  • Posts: 200
    • View Profile
Re: Elliot Wave
« Reply #6 on: September 22, 2010, 08:40:40 pm »
For alerts try the following code:

Code: [Select]
//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[i] = LastHigh[i-1];
LastLow[i] = LastLow[i-1];
if (Up[i])
{
Valid[i] = True;
if (DownSignal[i])
{
//Sequence of 2 Up Fractals. Validate only the higher one.
Valid[i] = H[i] >= H[LastHighIndex];
Valid[LastHighIndex] = H[LastHighIndex] > H[i];
}
LastHigh[i] = Max(H[i], H[LastHighIndex ]);
LastHighIndex = i;
}

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

LastLow[i] = Min(L[i], 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);

AlertIf(Down AND (ValidLow OR ZeroValid), "SOUND C:\\Windows\\Media\\Chord.wav", "Audio alert", 2);
AlertIf(Up AND (ValidHigh OR ZeroValid), "SOUND C:\\Windows\\Media\\Ding.wav", "Audio alert", 2);
//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[i] = State[i-1];
if (Maxi[i])
{
State[i] = 1;//down
}

if (Mini[i])
{
State[i] = 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();

mahesh I put the code in the indicator pasties section of the site: http://www.wisestocktrader.com/indicatorpasties/84-elliot-wave
« Last Edit: September 22, 2010, 08:42:35 pm by administrator »

Ceurami

  • Guest
Re: Elliot Wave
« Reply #7 on: September 23, 2010, 08:34:27 am »
Hi could someone help me with the "trending ribbon" in this code?
I would like to change it in:

Code: [Select]
_SECTION_BEGIN("trending ribbon");
uptrend=MACD (12,26,4) > MACD (12,26,9) AND > 0;
downtrend=MACD (12,26,4) < MACD (12,26,9) AND < 0;


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


This gives failures. I don't know the solution for this  :(

See picture to explane:




Thanks,

Maurice

administrator

  • Administrator
  • Full Member
  • *****
  • Posts: 200
    • View Profile
Re: Elliot Wave
« Reply #8 on: September 23, 2010, 07:33:42 pm »
Hello

Code was a bit incorrect but easy to fix:

Code: [Select]
_SECTION_BEGIN("trending ribbon");
uptrend = MACD(12,26) > Signal(12,26,9) AND MACD(12,26) < 0;
downtrend =MACD(12,26) < Signal(12,26,9) AND MACD(12,26) > 0;


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

That should do the trick.

Ceurami

  • Guest
Re: Elliot Wave
« Reply #9 on: September 24, 2010, 03:19:23 am »
Hi administrator,

Thank you, but it's not quit what I meant.
If you could help me 1 more time with this ribbon, that would be great!
Both the MACD (12,26,4) and the (MACD 12,26,9) have a exponential MA (EMA) right?
So, too make the ribbon easier. I think it could be:

EMA (4) > EMA (9) = uptrend ( So, they cross eachother)
EMA (4) < EMA (9) = downtrend

I've tried it myself, but it won't work out :-(

Thank you,

Maurice

administrator

  • Administrator
  • Full Member
  • *****
  • Posts: 200
    • View Profile
Re: Elliot Wave
« Reply #10 on: September 24, 2010, 04:41:35 am »
Hello

Don't know why it didn't work for you but take a look at the following code it is very similar to the previous version.

Code: [Select]
_SECTION_BEGIN("trending ribbon");
uptrend = EMA(C, 4) > EMA(C, 9);
downtrend =EMA(C, 4) < EMA(C, 9);

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