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

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



PureBytes Links

Trading Reference Links

Hi David,

thank you very much for your help. 

In fact I did see the code posted by Eric Tangen and tried to modify it but I've not been able to get what I'm after.

I've tried your modifications too but - unless I did something wrong - they don't give exactly the classical trend definition.

I have at least two problems. The first is to define a new trend. It should start (an uptrend, for example) when - while being in downtrend - it makes a new high and from then on it should keep doing higher highs and higher lows.

The second problem is to avoid calling a new trend when the market moves sideway but the prices make incosequential highs and lows.

I've not been able to reach any good framework beside the two steps below and the definition of the two latest highs and lows with which trying to apply the classical rules. I've tried to add other steps but it seems I miss the very programming competence to reach any result.


percent		= Param("Percent move", 3, 0.5, 10, 0.5);
lastTrough1	= Trough(L, percent, 1);
lastTrough2	= Trough(L, percent, 2);
lastPeak1	= Peak(H, percent, 1);
lastPeak2	= Peak(H, percent, 2);
barsSinceTrough1 = TroughBars(L, percent, 1);
barsSinceTrough2 = TroughBars(L, percent, 2);
barsSincePeak1	  = PeakBars(H, percent, 1);
barsSincePeak2	  = PeakBars(H, percent, 2);

for(i = 1; i < BarCount; i++)
{

	if(barsSinceTrough1[i] > barsSincePeak1[i])  // breakdown
	{
		if(C[i] < lastTrough1[i])
			color[i] = colorRed;
	}


	if(barsSinceTrough1[i] < barsSincePeak1[i])  // breakout
	{
		if(C[i] > lastPeak1[i])
			color[i] = colorBlue;
	}

}

Plot(C, Name(), color, styleBar);




--- In amibroker@xxxxxxxxxxxxxxx, "dbw451" <dbw451@xxx> wrote:
>
> 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.3/693 - Release Date: 2/19/2007 5:01 PM