[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[amibroker] Swing Chart and TrendLines



PureBytes Links

Trading Reference Links

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;



------------------------------------

**** IMPORTANT PLEASE READ ****
This group is for the discussion between users only.
This is *NOT* technical support channel.

TO GET TECHNICAL SUPPORT send an e-mail directly to 
SUPPORT {at} amibroker.com

TO SUBMIT SUGGESTIONS please use FEEDBACK CENTER at
http://www.amibroker.com/feedback/
(submissions sent via other channels won't be considered)

For NEW RELEASE ANNOUNCEMENTS and other news always check DEVLOG:
http://www.amibroker.com/devlog/

Yahoo! Groups Links

<*> To visit your group on the web, go to:
    http://groups.yahoo.com/group/amibroker/

<*> Your email settings:
    Individual Email | Traditional

<*> To change settings online go to:
    http://groups.yahoo.com/group/amibroker/join
    (Yahoo! ID required)

<*> To change settings via email:
    mailto:amibroker-digest@xxxxxxxxxxxxxxx 
    mailto:amibroker-fullfeatured@xxxxxxxxxxxxxxx

<*> To unsubscribe from this group, send an email to:
    amibroker-unsubscribe@xxxxxxxxxxxxxxx

<*> Your use of Yahoo! Groups is subject to:
    http://docs.yahoo.com/info/terms/