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

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



PureBytes Links

Trading Reference Links

Oops, I forgot the trend change rule about a new high or low.  The up trend
and down trend variables that I offered just need an additional filter to
check for new highs and lows:

 

bUpTrend = C > dSwingHighValue AND BarsSince(bHH) > BarsSince(bHL) AND
BarsSince(bLL) >
BarsSince(bHH) AND BarsSince(bLH) > BarsSince(bHH);
 
bDnTrend = C < dSwingLowValue AND BarsSince(bLL) > BarsSince(bLH) AND
BarsSince(bHH) >
BarsSince(bLL) AND BarsSince(bHL) > BarsSince(bLL);

 

Your second problem is a tough issue for which I don't have a good solution.
I've tried many variations of variable zig percentages using ATR multiples,
swing lengths, etc. and have not found a good way reduce false highs and
lows produced in a range.  As a trade filter, I'll look at the swing lengths
and require the action swings to be a multiple (i.e. 1.5x to 2.0x) longer
than the reaction swing length.  If the action and reaction swing length
differences are smaller than the multiple, I assume the market is ranging.
This approach means I don't trigger a trend trade until the 3rd wave and I
miss the trend trade for the first wave of a trend change (which is usually
the largest).  In other words, I'll trade the first pullback of a new trend
confirmed by swing length differences being larger than my multiple.

 

Your code framework looks fine as long as you realize (which I'm sure you
do) that the Zig indicator (i.e. Peak/Trough) look into the future, so
values compared against them should not be used in a trading system.  I'm
pretty sure PowerSwings has a lot of logic behind it to determine the trend
changes.  I've not figured out a good approach.  Writing code for the left
hand side of the chart is never easy because usually there is a lot of
visual interpretation that's tough to codify.  I'm open to any ideas on this
topic.  With ideas, I might be able to offer suggestions on how to code.

 

Regards,

 

David

  _____  

From: amibroker@xxxxxxxxxxxxxxx [mailto:amibroker@xxxxxxxxxxxxxxx] On Behalf
Of jppt0k
Sent: 02/19/2007 12:12 PM
To: amibroker@xxxxxxxxxxxxxxx
Subject: [amibroker] Re: Coloring the chart in accordance with the trend

 

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@xxxxxxxxx <mailto:amibroker%40yahoogroups.com> ps.com,
"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.amibroke <http://www.amibroker.com/library/detail.php?id=353>
r.com/library/detail.php?id=353
> <http://www.amibroke
<http://www.amibroker.com/library/detail.php?id=353&hilite=ZIG>
r.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@xxxxxxxxx <mailto:amibroker%40yahoogroups.com> ps.com
[mailto:amibroker@xxxxxxxxx <mailto:amibroker%40yahoogroups.com> ps.com] 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