[HELP] CCI code

nac

Well-Known Member
#1
This is the code I tried to figure out by browsing for codes online.

_SECTION_BEGIN("CCI");
periods = Param( "Periods", 20, 2, 200, 1 );
Plot( CCI( periods ), _DEFAULT_NAME(), ParamColor( "Color", colorCycle ), ParamStyle("Style") );
Centre = 0;
Plot(Centre, "" , colorWhite, styleNoLabel | styleDashed ) ;
N=CCI(periods);
PlotOHLC (N,N,0,N, "", IIf (N>0,colorGreen,colorRed),styleCloud);

_SECTION_END();


As you can see in this snapshot first point above zero is red. Going by the code it should be green, right? And this is the same case with first point below zero is green, but it supposed to be red. How to get it right? I mean above zero, cloud colour should be green and below zero cloud colour should be red.
 
#2
Using cloud this is the best you can do:
Code:
_SECTION_BEGIN("CCI");
     periods = Param( "Periods", 20, 2, 200, 1 );
     N = CCI( periods );
     PositiveN = IIf( N > 0, N, Null );
     NegativeN = IIf( N < 0, N, Null );
    
     Plot( PositiveN, _DEFAULT_NAME(), colorLime, styleLine, Null, Null, 0, 0, 2 );
     Plot( NegativeN, _DEFAULT_NAME(), colorRed, styleLine, Null, Null, 0, 0, 2 );
    
     PlotGrid( 0, ParamColor( "O-Level Grid Color", colorWhite ), 1 );
     PlotOHLC( PositiveN, PositiveN, 0, PositiveN, "", ColorRGB( 0, 88, 0 ), styleNoLabel | styleCloud );
     PlotOHLC( NegativeN, 0, NegativeN, NegativeN, "", ColorRGB( 88, 0, 0 ), styleNoLabel | styleCloud );
_SECTION_END();
Alternatively, since you are plotting an Oscillator, you also might consider:
Code:
_SECTION_BEGIN("CCI");
     periods = Param( "Periods", 20, 2, 200, 1 );
     N = CCI( periods );
     clrN = IIf( N > 0, colorLime, colorRed );
     Plot( N, _DEFAULT_NAME(), clrN, styleHistogram, Null, Null, 0, 0, 5 );
     PlotGrid( 0, ParamColor( "O-Level Grid Color", colorWhite ), 1 );
_SECTION_END();
And if you still want continuous Cloud-like Plot, then you might also consider:
Code:
_SECTION_BEGIN( "CCI" );
     periods = Param( "Periods", 20, 2, 200, 1 );
     N = CCI( periods );
    
     PlotGrid( 0, ParamColor( "O-Level Grid Color", colorWhite ), 8, 1, False );
     SetGradientFill( colorGreen, colorRed, 0, GetChartBkColor() );
     Plot( N, _DEFAULT_NAME(), ParamColor( "CCI LineColor", colorAqua ), styleLine | styleGradient, Null, Null, 0, -1  );
_SECTION_END();
More information on Using graph styles, colors, titles and parameters in Indicators
 

travi

Well-Known Member
#3
This is the code I tried to figure out by browsing for codes online.





As you can see in this snapshot first point above zero is red. Going by the code it should be green, right? And this is the same case with first point below zero is green, but it supposed to be red. How to get it right? I mean above zero, cloud colour should be green and below zero cloud colour should be red.
When you try and plot +ve and -ve values with the same function, the lines connecting them when color changes will not auto change at 0 because it doesnt know that.

When you say N>0, it will start with Green and continue that way.
Is it logical enough ? Amibroker is doing what its told to do.

If you want a clean output, then you can plot it in two parts instead.

See this, very neat and tidy as well and will do exactly what you want.

Code:
periods = Param( "Periods", 20, 2, 200, 1 );
Centre = 0;
Plot(Centre, "" , colorWhite, styleNoLabel | styleDashed ) ;
N = CCI( periods );
NL = LowestVisibleValue( N );
NH = HighestVisibleValue( N );

PlotOHLC (N, N, 0, N, "", colorGreen,styleCloud|styleClipMinMax, NL, 0);
PlotOHLC (N, N, 0, N, "", colorRed  ,styleCloud|styleClipMinMax, 0, NH);
1541398387882.png
 

travi

Well-Known Member
#4
And if you want to remove +80 to -80 noise for eg.

1541398799396.png


You can change the 0 starting with 80 and -80 like this:
Code:
PlotOHLC (N, N, 0, N , "", colorGreen, styleCloud | styleClipMinMax, NL, 80);
PlotOHLC (N, N, 0, N, "", colorRed  ,styleCloud | styleClipMinMax, -80, NH);
 

Similar threads

Broker Special Offers

Intraday Higher Leverage

Save up to 90% in brokerage and get higher leverage for intraday trades.

Name:Phone:
Email:City:
State:
Are you a day trader?