virtualcredit

Active Trader
Apr 21, 2009
3
0
32
Very nice, thanks!

It seems that the code of this indicator is not complete or some parts was removed: IE "double dSellBuffer[]" is declared but never used...

Any suggestions?
 

Enivid

Administrator
Staff member
Nov 30, 2008
19,212
1,504
144
Odesa
www.earnforex.com
Very nice, thanks!

It seems that the code of this indicator is not complete or some parts was removed: IE "double dSellBuffer[]" is declared but never used...

Any suggestions?
Initially it was used to mark the exit points on the chart, but I guess they were excessive for this indicator as the arrows themselves are enough for that.
 

fxwalb

Master Trader
Dec 18, 2009
31
0
62
The CCI Arrows indicator was updated and is now available for MetaTrader 5.

Seems that there is also a bug in MT5 regarding the arrow width.
If you use the indicator alone the width is correct, together with other indicators the width is always small and cannot changed.
 

fxwalb

Master Trader
Dec 18, 2009
31
0
62
I tried to plot the current CCI value on the chart with this method
...
ObjectCreate(0, "myCCInow", OBJ_LABEL, 0, 0, 0);
ObjectSetString(0, "myCCInow", OBJPROP_TEXT,"CCI @ "+DoubleToString(myCCInow,1));
ObjectSetString(0, "myCCInow", OBJPROP_FONT, font_face);
ObjectSetInteger(0, "myCCInow", OBJPROP_FONTSIZE, font_size);
ObjectSetInteger(0, "myCCInow", OBJPROP_COLOR, White);
ObjectSetInteger(0, "myCCInow", OBJPROP_CORNER, corner);
ObjectSetInteger(0, "myCCInow", OBJPROP_XDISTANCE, 1+distance_x);
ObjectSetInteger(0, "myCCInow", OBJPROP_YDISTANCE, 1+distance_y);
..

unfortunatly it does not return a value which makes sense. Is there a bug in code?
 

fxwalb

Master Trader
Dec 18, 2009
31
0
62
Do you see the value on the chart, but it doesn't make sense? What kind of values do you see?
There are displayed various switching values, which do not match the current true readings of the standard CCI indicator in MT5.
The arrows are displayed correctly though when the zero-line is crossed.

If I do the same in MT4, it works correctly.
 

Enivid

Administrator
Staff member
Nov 30, 2008
19,212
1,504
144
Odesa
www.earnforex.com
I can't say much without seeing a screenshot, but I see 2 potential problems in your code:

1. If you call that code in OnCalculate() function then you create an object each tick. Do you delete it each tick? It's better to create it only once and then only change the displayed value.

2. You have a variable containing current CCI value and the object with the same name - myCCInow. Ideally that shouldn't be a problem, but maybe it's the cause?
 

fxwalb

Master Trader
Dec 18, 2009
31
0
62
I can't say much without seeing a screenshot, but I see 2 potential problems in your code:

1. If you call that code in OnCalculate() function then you create an object each tick. Do you delete it each tick? It's better to create it only once and then only change the displayed value.

2. You have a variable containing current CCI value and the object with the same name - myCCInow. Ideally that shouldn't be a problem, but maybe it's the cause?

Thanks for the advice. I changed the name of the objact and the position of the inserted code, it's now inside on the OnCalculate but directly above the

...
return(rates_total);
...

line.

Works now properly as far as I see it.
 

Enivid

Administrator
Staff member
Nov 30, 2008
19,212
1,504
144
Odesa
www.earnforex.com
I think that you can greatly reduce the indicator's load by placing this part of the code in the OnInit() function:

ObjectCreate(0, "myCCInow", OBJ_LABEL, 0, 0, 0);
ObjectSetString(0, "myCCInow", OBJPROP_FONT, font_face);
ObjectSetInteger(0, "myCCInow", OBJPROP_FONTSIZE, font_size);
ObjectSetInteger(0, "myCCInow", OBJPROP_COLOR, White);
ObjectSetInteger(0, "myCCInow", OBJPROP_CORNER, corner);
ObjectSetInteger(0, "myCCInow", OBJPROP_XDISTANCE, 1+distance_x);
ObjectSetInteger(0, "myCCInow", OBJPROP_YDISTANCE, 1+distance_y);

And this one leave in the OnCalculate():

ObjectSetString(0, "myCCInow", OBJPROP_TEXT,"CCI @ "+DoubleToString(myCCInow,1));
 

fxwalb

Master Trader
Dec 18, 2009
31
0
62
I think that you can greatly reduce the indicator's load by placing this part of the code in the OnInit() function:

ObjectCreate(0, "myCCInow", OBJ_LABEL, 0, 0, 0);
ObjectSetString(0, "myCCInow", OBJPROP_FONT, font_face);
ObjectSetInteger(0, "myCCInow", OBJPROP_FONTSIZE, font_size);
ObjectSetInteger(0, "myCCInow", OBJPROP_COLOR, White);
ObjectSetInteger(0, "myCCInow", OBJPROP_CORNER, corner);
ObjectSetInteger(0, "myCCInow", OBJPROP_XDISTANCE, 1+distance_x);
ObjectSetInteger(0, "myCCInow", OBJPROP_YDISTANCE, 1+distance_y);

And this one leave in the OnCalculate():

ObjectSetString(0, "myCCInow", OBJPROP_TEXT,"CCI @ "+DoubleToString(myCCInow,1));


Yes, you are right, this is even better.
Thanks.
 

fxwalb

Master Trader
Dec 18, 2009
31
0
62
is it possible to get the arrows from the calculation based on another timeframe.

i.e. can I have access to CCI values of other timeframes by writing

int myCCI = iCCI(NULL,TimeFrame, CCI_Period, PRICE_TYPICAL);


?????
 

fxwalb

Master Trader
Dec 18, 2009
31
0
62
Yes, why not?

Thanks for the reply

I tried a multitimeframeversion of this indicator

my code is as follows

//+------------------------------------------------------------------+
//| CCI Arrows |
//| Copyright © 2009, EarnForex |
//| http://www.earnforex.com/ |
//+------------------------------------------------------------------+
#property copyright "Copyright © 2009, EarnForex"
#property link "http://www.earnforex.com"
#property version "1.01"
#property description "CCI Arrows - direct trading signals based on CCI indicator."
#property description "Displays red and blue arrows for Short and Long signals."

#property indicator_chart_window
#property indicator_buffers 2
#property indicator_plots 2

#property indicator_color1 Red
#property indicator_type1 DRAW_ARROW
#property indicator_style1 STYLE_SOLID
#property indicator_width1 5

#property indicator_color2 Lime
#property indicator_type2 DRAW_ARROW
#property indicator_style2 STYLE_SOLID
#property indicator_width2 5



input ENUM_TIMEFRAMES TimeFrame = PERIOD_H4;
input double Arrow_Offset=20.0;


input double UpLevel=100;
input double DnLevel=-100;


double myCCInow;

double dUpCCIBuffer[];
double dDownCCIBuffer[];

input int CCI_Period = 21; //This value sets the CCI Period Used, The default is 21

int myCCI;
double CCIBuffer[];
double mtf_CCIBuffer[];



//+------------------------------------------------------------------+
//| Custom indicator initialization function |
//+------------------------------------------------------------------+

void OnInit()
{
IndicatorSetString(INDICATOR_SHORTNAME, "CCI_Arrows(" + IntegerToString(CCI_Period) + ")");

//---- indicator buffers mapping

SetIndexBuffer(0, dUpCCIBuffer, INDICATOR_DATA);
SetIndexBuffer(1, dDownCCIBuffer, INDICATOR_DATA);

//---- drawing settings


PlotIndexSetInteger(0, PLOT_ARROW, 115);//233
// PlotIndexSetInteger(0, PLOT_ARROW_SHIFT, -Arrow_Offset);
PlotIndexSetString(0, PLOT_LABEL, "CCI Buy");

PlotIndexSetInteger(1, PLOT_ARROW, 115);//234
// PlotIndexSetInteger(1, PLOT_ARROW_SHIFT, Arrow_Offset);
PlotIndexSetString(1, PLOT_LABEL, "CCI Sell");



myCCI = iCCI(NULL,TimeFrame, CCI_Period, PRICE_TYPICAL);

}

//+------------------------------------------------------------------+
//| Custom CCI Arrows |
//+------------------------------------------------------------------+
int OnCalculate(const int rates_total,
const int prev_calculated,
const datetime &time[],
const double &open[],
const double &High[],
const double &Low[],
const double &close[],
const long &tick_volume[],
const long &volume[],
const int &spread[])



{

//--------------------
datetime TimeArray[];


CopyTime(Symbol(), TimeFrame, 0, rates_total, TimeArray);
int shift, limit, y;

if(BarsCalculated(myCCI) < rates_total) return(0);

//--- we can copy not all data
int to_copy;
if(prev_calculated > rates_total || prev_calculated < 0) {
to_copy = rates_total;
}
else {
to_copy = rates_total-prev_calculated;
if(prev_calculated > 0)
to_copy++;
}

if(CopyBuffer(myCCI, 0, 0, rates_total, mtf_CCIBuffer) <= 0) {
Print("Getting MA buff failed! Error", GetLastError());
return(0);
}

for(int i=0, y=0; i<limit; i++) {
if (time < TimeArray[y])
y++;

CCIBuffer = mtf_CCIBuffer[y];

}


//--------------------


ArraySetAsSeries(High, true);
ArraySetAsSeries(Low, true);


for (int i = rates_total; i > 1; i--)
{
dUpCCIBuffer[rates_total - i + 1] = 0;
dDownCCIBuffer[rates_total - i + 1] = 0;

myCCInow = CCIBuffer[rates_total - i + 1];

double myCCI2 = CCIBuffer[rates_total - i]; //CCI One bar ago

//---

if (myCCInow >= 0) //is going long
{
if((myCCInow > 0) && (myCCI2 < 0)) //did it cross from below 50
{
dUpCCIBuffer[rates_total - i + 1] = Low - 2 * _Point*Arrow_Offset; //
}
}

if (myCCInow < 0) //is going short
{
if((myCCInow < 0) && (myCCI2 > 0)) //did it cross from above 50
{
dDownCCIBuffer[rates_total - i + 1] = High + 2 * _Point*Arrow_Offset; //
}
}
}

//-----
return(rates_total);
}



The result is as shown in the picture.
Is there a mistake in my code?
 

Attachments

  • 2010-02-07 10.35.jpg
    2010-02-07 10.35.jpg
    79.3 KB · Views: 133