It's my first post here (sorry for my poor english).

I've a problem - i want to replace the "ZigZag line" in the code of Swing Chart 
(as below) with two TrendLines - one for Peaks and the second for Troughs - 
using code as follow (sample)

UP = Peak1 + ( (Peak1-Peak2)/(PeakBars2-PeakBars1) ) * PeakBars1;
DOWN = Trough1 + ( (Trough1-Trough2) / (TroughBars2-TroughBars1) ) * 
TroughBars1;
when
Peak2 means every peak previous to Peak1 and Peak1 is every peak (from second 
peak to the last one).
Trough2 means every trough previous to Trough1 and Trough1 is every trough 
(from second trough to the last one).

Basic code for SwingChart is here

/* SWING CHART */

LookBack = Param("Look N-Bars into the Past" , 200, 0, 10000);
LookFuture = Param("Look N-Bars into the Future" , 200, 0, 10000);

SetBarsRequired( LookBack, LookFuture ); // needed for script

swingsize = Param("SwingSize", 10, 1, 100, 1);

PriceUP = ParamField("Price field UP",-1);
PriceDOWN = ParamField("Price field DOWN",-1);


HP = HHVBars( PriceUP, swingsize ) == 0;

LP = LLVBars( PriceDOWN, swingsize ) == 0;

EnableScript("jscript");

<%

result = VBArray(AFL("PriceUP")).toArray();

function TrendLine( starti, startv, endi, endv )

{

for( j = starti; j <= endi; j++ )

{

result[ j ] = startv + ( j - starti )*(endv-startv)/(endi-starti);

}

}

PriceUP = VBArray(AFL("PriceUP")).toArray();

PriceDOWN = VBArray(AFL("PriceDOWN")).toArray();

HP = VBArray(AFL("HP")).toArray();

LP = VBArray(AFL("LP")).toArray();

endi = -1;

starti = -1;

dir = 0;

for( i = PriceUP.length - 0; i >= 0; i-- )

{

if( dir == 1 && LP[ i ] )

{

TrendLine( i, PriceDOWN[ i ], endi, endv );

endi = i;

endv = PriceDOWN[ i ];

dir = -1;

}

else

if( dir == -1 && HP[ i ] )

{

TrendLine( i, PriceUP[ i ], endi, endv );

endi = i;

endv = PriceUP[ i ];

dir = 1;

}

else

if( dir == 0 && endi == -1 && LP[ i ] )

{

endi = i;

endv = PriceDOWN[ i ];

dir = -1;

}

else

if( dir == 0 && endi == -1 && HP[ i ] )

{

endi = i;

endv = PriceUP[ i ];

dir = 1;

}

}

AFL("Graph0")=result;

%>

Graph0Color=colorRed;

Graph1=Close;

Graph1Color = colorBlack;

Graph1Style=styleCandle;

Reply via email to