Double CCI with line and histogram for MT5

fxwalb

Master Trader
Dec 18, 2009
31
0
62
Hi to all and a happy New Year.


Here is the code of an indicator,which should display a line of a CCI value, just like the standard CCI indicator and additionally the histogram of a second CCI value.
For this histogram four colors should be used for values between 0 and 100, above hundred, between 0 and -100 and below -100.

Unfortunatly the histogram does not show up. So there must be a bug in the code. Is anybody with better codning skills (like me newbee) able to find it?

best regards
 

Attachments

  • CCI_double.mq5
    5.4 KB · Views: 122

Enivid

Administrator
Staff member
Nov 30, 2008
19,240
1,507
144
Odesa
www.earnforex.com
You have the part for the histogram commented in the code, so it can't work at all. Apart from that you have several important errors in the code: division by zero on line 100, incorrect value for the PlotIndexSetInteger() function for histogram, wrong color setting for histogram, etc.
 

fxwalb

Master Trader
Dec 18, 2009
31
0
62
You have the part for the histogram commented in the code, so it can't work at all. Apart from that you have several important errors in the code: division by zero on line 100, incorrect value for the PlotIndexSetInteger() function for histogram, wrong color setting for histogram, etc.

Thanks for your reply.

How can I get info where the line 100 is?
 

fxwalb

Master Trader
Dec 18, 2009
31
0
62
You can see the line number in the status bar of the MQL Editor.

OK Thanks I found it.

Here is a new version for CCI Histogram which shows bars already, but the display is chaotic. Can you give me a hint, where mistakes are in this code?
 

Attachments

  • CCI_Histogram_simple.mq5
    2.9 KB · Views: 65

Enivid

Administrator
Staff member
Nov 30, 2008
19,240
1,507
144
Odesa
www.earnforex.com
Hmmm... When you attach the indicator to a chart it really displays wrong colors, but if you recompile it, while it's attached, it's redrawn properly. Maybe that's a bug. Try asking the MQL5 support about it.
 

fxwalb

Master Trader
Dec 18, 2009
31
0
62
Hmmm... When you attach the indicator to a chart it really displays wrong colors, but if you recompile it, while it's attached, it's redrawn properly. Maybe that's a bug. Try asking the MQL5 support about it.

What's the proper email address for the MQL support?
 

intraforex

Active Trader
Jan 6, 2010
21
0
42
italy
Not exactly, but it looks similar. Do you have the code?
Yes,thi is the code only histogram.
1)Add the code (CCI_HISTO.mql5), to chart
2)Insert in indicator (CCI_HIsto) separate windows one CCI indicator standard at 14 period.
3)Insert in indicator (CCI_HIsto) separate windows one CCI indicator standard at 7 period.

I think you see that my programming is not perfect but it works :rolleyes:
I would want to improve the CCI inserting other instructions: you can help?
Thanks
 

Attachments

  • CCI_HISTO.mq5
    5.1 KB · Views: 60

Enivid

Administrator
Staff member
Nov 30, 2008
19,240
1,507
144
Odesa
www.earnforex.com

fxwalb

Master Trader
Dec 18, 2009
31
0
62
I am not sure that you can insert text labels into the separate indicator window.


ObjectCreate(0, "myobject_name", OBJ_LABEL, 1, 0, 0);

This expression should create the object in the indicator window, but this feature is not working (yet).
 

Enivid

Administrator
Staff member
Nov 30, 2008
19,240
1,507
144
Odesa
www.earnforex.com
How can I assign to a variable the price of the close of a candle or bar ?
thanks.
In indicator's event handler OnCalculate() you have an access to array Close[], so you can just write:

double a = Close[0];

to assign the close value of the latest candle (the first if it's not set as tiemseries) to variable "a".
 

intraforex

Active Trader
Jan 6, 2010
21
0
42
italy
Someone helps me with this simple indicator?
Arrow Green when MA1>MA2
Arrow Red when MA1<MA2
MQL5:
#property copyright "2009, MetaQuotes Software Corp."
#property link      "http://www.mql5.com"
#property version   "1.00"
#property indicator_separate_window
 
#property indicator_buffers 2
#property indicator_plots  2
 
#property indicator_label1  "ARROW1"
#property indicator_type1   DRAW_ARROW
#property indicator_style1  STYLE_SOLID
#property indicator_color1  Green
#property indicator_width1  1
 
#property indicator_label2  "ARROW2"
#property indicator_type2   DRAW_ARROW
#property indicator_style2  STYLE_SOLID
#property indicator_color2  Red
#property indicator_width2  1
//--- input parameters
 
double  MA1;
double  MA2;
double Arrow1[];
double Arrow2[];
 
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int OnInit()
  {
//--- indicator buffers mapping
 SetIndexBuffer(0,Arrow1,INDICATOR_DATA);
 SetIndexBuffer(1,Arrow2,INDICATOR_DATA);
 //--- indicator name
IndicatorSetString(INDICATOR_SHORTNAME,"TEST");
 
//---- OnInit done
MA1=iMA(Symbol(),0,34,0,MODE_EMA,PRICE_CLOSE);
MA2=iMA(Symbol(),0,10,0,MODE_EMA,PRICE_CLOSE);
//---
   return(0);
  }
//+------------------------------------------------------------------+
//| Custom indicator iteration function                              |
//+------------------------------------------------------------------+
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[])
  {
//---
 
 int i ;
  for(i=1;i<=rates_total;i--);
 
 if (MA2>MA1);
     {Arrow1[i]; }
 
 if (MA2<MA1);
    {Arrow2[i]; }  
 
//--- return value of prev_calculated for next call
   return(rates_total);
  }
//+------------------------------------------------------------------+
Where is error ? :confused:
thanks to all
 
Last edited by a moderator:

Enivid

Administrator
Staff member
Nov 30, 2008
19,240
1,507
144
Odesa
www.earnforex.com
1. With iMA() function you get only indicator handle, not the buffer. You should copy the buffer to get the actual vales:

MQL5:
  double MA1Buffer[];
   CopyBuffer(MA1, 0, 0, rates_total, MA1Buffer);
  double MA2Buffer[];
   CopyBuffer(MA2, 0, 0, rates_total, MA2Buffer);

Do this inside your OnCalculate() handler.

2. Then you need compare the buffer values rather than handles when determining the arrow. You also need to give your arrow buffers the actual values rather than just stating them:
MQL5:
 if (MA2Buffer[i]>MA1MABuffer[i]);
     {Arrow1[i] = MA2Buffer[i]; }
 
 if (MA2Buffer[i]<MA1Buffer[i]);
    {Arrow2[i] = MA2Buffer[i]; }

3. When you have this working you may want to modify this code to draw arrows only on MA cross, not on all bars, but I don't know if that's relevant for you.
 
Last edited: