Couldn't find the answer myself. Fixing the Woodies CCI. Need Help!

 

Hi all,

I'm new to this MQL4 programming. I'm trying to build an indicator for Woodies CCI. I know there are many on them out there but they have something need to be fix. It's about the trend. For some people it maybe small but not for me. In Woodies CCI, trend play important role.

In Woodies, the trend is established when 6 bars (minimum) or more, printed on the same side. It's either above the zero line, or below the zero line.

Here is an example from Linuxser indicator, CCI_Woodies_Lnx_v4. This is an uptrend chart.

Bar 1 to 4 : No trend

Bar 5 : Warning that trend might change

Bar 6 and so on : Trend bar.

Okay, take a look at this chart. It is from USDCAD, 15M timeframe, 27 & 28 June 07'.

This chart is a downtrend chart. It should start at B (1,2,3,4,5,6. forget the 7) and not before it. Why? Because before B (1,2,3,4,5,6), the requirement for an established trend was not fulfilled. There are 4 gray bars, 1 yellow bar and that's it. There is no 6th bar. Now look at A. A shows an established trend where it meet the requirement. 4 gray bars, a yellow bar and continue by red bars. Take a look at C, we know that there is no trend as there is no 6th bar. So, A is wrong. A should not be a new establishment of a trend because C does not change the trend. It should be a trend continuation which mean, the bar will still be red after CCI line goes below zero line. This is the problem of the Woodies CCI indicator in MT4.

Now, this is the chart when I change the trend period to 6 as told by Linuxser

Look at C & A. It is now correct but look at B. Before B is now continuation of the previous trend - Uptrend. Then B is a new trend in establish. How ever, the trend is now established when the 7th bar is printed. B in this chart should be like A in the previous chart where trend is established on the 6th bar.

I'm trying to fix this but due to lack of experience and knowledge of MQL4, I'm unable to fix it.

Below is the CCI code.

int start() {

int limit, i, trendCCI, entryCCI;

int counted_bars = IndicatorCounted();

static datetime prevtime = 0;

//---- check for possible errors

if(counted_bars < 0) return(-1);

//---- last counted bar will be recounted

if(counted_bars > 0) counted_bars--;

limit=Bars;//-counted_bars;

SetIndexDrawBegin(0,Bars-CountBars);

SetIndexDrawBegin(1,Bars-CountBars);

SetIndexDrawBegin(2,Bars-CountBars);

SetIndexDrawBegin(3,Bars-CountBars);

SetIndexDrawBegin(4,Bars-CountBars);

SetIndexDrawBegin(5,Bars-CountBars);

SetIndexDrawBegin(6,Bars-CountBars);

SetIndexDrawBegin(7,Bars-CountBars);

trendCCI = TrendCCI_Period;

entryCCI = EntryCCI_Period;

IndicatorShortName("[CCI: " + trendCCI + "] [TCCI: " + entryCCI + "] [per LSMA: " + LSMAPeriod + "] [Trend: " + Trend_period + "] Values CCI|TCCI:");

for(i = limit; i >= 0; i--)

{

CCINoTrend = 0;

CCITrendDown = 0;

CCITimeBar = 0;

CCITrendUp = 0;

ZeroLine = 0;

TrendCCI = iCCI(NULL, 0, trendCCI, PRICE_TYPICAL, i);

EntryCCI = iCCI(NULL, 0, entryCCI, PRICE_TYPICAL, i);

if(TrendCCI > 0 && TrendCCI < 0)

{

if (trendDown > Trend_period)

{

trendUp = 0;

}

}

if (TrendCCI > 0)

{

if (trendUp < Trend_period) //Print the grey bar

{

CCINoTrend = TrendCCI;

trendUp++;

}

if (trendUp == Trend_period) //Print the yellow bar

{

CCITimeBar = TrendCCI;

trendUp++;

}

if (trendUp > Trend_period) //Print the blue bar

{

CCITrendUp = TrendCCI;

}

}

if(TrendCCI 0)

{

if (trendUp > Trend_period)

{

trendDown = 0;

}

}

if (TrendCCI < 0)

{

if (trendDown < Trend_period) //Print the gray bar

{

CCINoTrend = TrendCCI;

trendDown++;

}

if (trendDown == Trend_period) //Print the yellow bar

{

CCITimeBar = TrendCCI;

trendDown++;

}

if (trendDown > Trend_period) //Print the red bar

{

CCITrendDown = TrendCCI;

}

}

}

[/code]

I think this code section is where I should change but my try have no luck

[code]

for(i = limit; i >= 0; i--)

{

CCINoTrend = 0;

CCITrendDown = 0;

CCITimeBar = 0;

CCITrendUp = 0;

ZeroLine = 0;

TrendCCI = iCCI(NULL, 0, trendCCI, PRICE_TYPICAL, i);

EntryCCI = iCCI(NULL, 0, entryCCI, PRICE_TYPICAL, i);

if(TrendCCI > 0 && TrendCCI < 0)

{

if (trendDown > Trend_period)

{

trendUp = 0;

}

}

if (TrendCCI > 0)

{

if (trendUp < Trend_period) //Print the grey bar

{

CCINoTrend = TrendCCI;

trendUp++;

}

if (trendUp == Trend_period) //Print the yellow bar

{

CCITimeBar = TrendCCI;

trendUp++;

}

if (trendUp > Trend_period) //Print the blue bar

{

CCITrendUp = TrendCCI;

}

}

if(TrendCCI 0)

{

if (trendUp > Trend_period)

{

trendDown = 0;

}

}

if (TrendCCI < 0)

{

if (trendDown < Trend_period) //Print the gray bar

{

CCINoTrend = TrendCCI;

trendDown++;

}

if (trendDown == Trend_period) //Print the yellow bar

{

CCITimeBar = TrendCCI;

trendDown++;

}

if (trendDown > Trend_period) //Print the red bar

{

CCITrendDown = TrendCCI;

}

}

}

Hope someone can help me fixing this indicator.

 
Files:
ghost.gif  28 kb
 
 

O.K, Good luck and enjoy your journey

Mart

 
mart-hart:
O.K, Good luck and enjoy your journey Mart

Thanks Mart.

So, how about the indicator? Can someone help me?

Reason: