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

RE: [amibroker] Coloring the chart in accordance with the trend



PureBytes Links

Trading Reference Links

The Peak and Trough function use the Zig indicator, so the peaks and valleys
are determined once price moves a predefined amount based on a percentage
specified.  Eric Tangen posted some nice code that does something similar
you want with the caveat the color change does not change until the peak or
valley is identified and it doesn't look at HHs and LLs:

 

http://www.amibroker.com/library/detail.php?id=353
<http://www.amibroker.com/library/detail.php?id=353&hilite=ZIG> &hilite=ZIG

 

If you really want HHs and LLs to determine colors, you can use this code as
your base.  The code identifies the peaks and valleys (PivotLow and
PivotHigh variables) and where the peaks and troughs are valid (Buy_Valid
and Sell_Valid variables)  You can use ValueWhen to get the Low and High
values at the pivots:

 

dSwingLowValue = ValueWhen(PivotLow, L, 1)

dSwingHighValue = ValueWhen(PivotHigh, H, 1)

 

Then you can determine your HHs and LLs:

 

bHH = dSwingHighValue > Ref(dSwingHighValue,-1);

bLH = (Ref(dSwingHighValue,-1) > dSwingHighValue) OR (PivotHigh AND
dSwingHighValue == Ref(dSwingHighValue,-1));

bLL = dSwingLowValue < Ref(dSwingLowValue,-1);

bHL = (Ref(dSwingLowValue,-1) < dSwingLowValue) OR (PivotLow AND
dSwingLowValue == Ref(dSwingLowValue,-1));

.

Then you would determine your uptrend / downtrend:

 

bUpTrend = BarsSince(bHH) > BarsSince(bHL) AND BarsSince(bLL) >
BarsSince(bHH) AND BarsSince(bLH) > BarsSince(bHH);

bDnTrend = BarsSince(bLL) > BarsSince(bLH) AND BarsSince(bHH) >
BarsSince(bLL) AND BarsSince(bHL) > BarsSince(bLL);

 

Finally, you would update Tangen's BarColor formula with the up trend and
down trend variables:

 

BarColors = 

IIf(BarsSince(Buy_Valid) < BarsSince(Sell_Valid) 

AND BarsSince(Buy_Valid)!=0 AND bUpTrend, colorGreen,

IIf(BarsSince(Sell_Valid) < BarsSince(Buy_Valid)

AND BarsSince(Sell_Valid)!=0 AND bDnTrend, colorRed, colorBlue));

 

This should work, however I personally do not use trend coloring like this.
I actually prefer Tangen's coloring scheme because when trends are defined
by HHs and LLs, too many price bars are in a trend-less mode (blue color in
this case).

 

Hope this helps.

 

Regards,

 

David

 

  _____  

From: amibroker@xxxxxxxxxxxxxxx [mailto:amibroker@xxxxxxxxxxxxxxx] On Behalf
Of jppt0k
Sent: 02/19/2007 10:06 AM
To: Amibroker Group
Subject: [amibroker] Coloring the chart in accordance with the trend

 

Hi all,

I'm trying every way to color a chart in accordance with the usual 
definition of trend (uptrend with higher highs and higher lows and 
downtrend with lower lows and lower highs) but cannot come up with 
anything that works as it should.

The idea is to obtain a chart similar to those of PowerSwings, such as 
the one attached.

I'm using the Trough and Peak functions but have reached a degree of 
convolutedness and confusion that I'm sure to stand now at the 
I-absolutely-need-help point.

Is there someone that has worked on a similar project or knows a way to 
do it?

Thanks in advance.

j

 


Content-Description: "AVG certification"
No virus found in this incoming message.
Checked by AVG Free Edition.
Version: 7.5.441 / Virus Database: 268.18.2/692 - Release Date: 2/18/2007 4:35 PM