icustom question
I have been trying to make an indicator that only calls another indicator by icustom. I made this line of code;
double COG=iCustom(NULL,0,"COGpoint1",50,3000,0,true);
Ive tryed to put the line different places of the code and ive played about with the name of the double, I have been reading and reading lots of tutorials. I think that mabey i must put some thing at the start like number of buffers!? mabey it should not be a double?
as it stands i am getting errors when i compile;
'init' - comma or semicolon expected
'init' - expression on global scope not allowed
can someone please help me to understand this with any custom indicator? because I feel that the tutorials that I have read (and I beleve I have them all) have given me the line of code for icustom but it doesnt work simply by having the line on its own, I know it must be changed for each indicator but there are some things missing from the explanation.
01-02-2009, 12:31 AM
Ive had a major attempt at this Im am quite proud of myself! I got some code from Codersguru, I changed it for an indicator. lol it looks good has no errors when compiling (first time ever!!!!!) but ... it makes metatrader "not responding" when you add it to a chart.
I changed all the names of the buffers of the indicators (from val1, val2, val3, val4. to value1, value2...etc) because i figured that they were interfearing with each other as i had a better look at the code Codersguru had made (he made a code for calling supertrend with icustomhe changed the names of the buffers so i thort that must be it, but no still not responding.
//+------------------------------------------------------------------+
//| COG call.mq4 |
//| |
//| |
//+------------------------------------------------------------------+
#property indicator_separate_window
#property indicator_buffers 4
#property indicator_color1 Lime
#property indicator_color2 Red
#property indicator_color3 CLR_NONE
#property indicator_color4 CLR_NONE
//---- buffers
double value1[];
double value2[];
double value3[];
double value4[];
//+------------------------------------------------------------------+
//| Custom indicator initialization function |
//+------------------------------------------------------------------+
//---- indicators
SetIndexStyle(0,DRAW_LINE,STYLE_SOLID,1,Lime);
SetIndexBuffer(0,value1);
SetIndexStyle(1,DRAW_LINE,STYLE_SOLID,1,Red);
SetIndexBuffer(1,value2);
SetIndexStyle(2,DRAW_NONE);
SetIndexBuffer(2,value3);
SetIndexStyle(3,DRAW_NONE);
SetIndexBuffer(3,value4);
//----
return(0);
}
//+------------------------------------------------------------------+
//| Custom indicator deinitialization function |
//+------------------------------------------------------------------+
int deinit()
{
//----
//----
return(0);
}
//+------------------------------------------------------------------+
//| Custom indicator iteration function |
//+------------------------------------------------------------------+
int start()
{
int counted_bars=IndicatorCounted();
//---- check for possible errors
if (counted_bars<0) return(-1);
//---- last counted bar will be recounted
if (counted_bars>0) counted_bars--;
int pos=Bars-counted_bars;
while(pos>=0)
{
value1[pos]=iCustom(NULL,0,"COGpoint1",50,3000,0,true);
value2[pos]=iCustom(NULL,0,"COGpoint1",50,3000,0,true);
value3[pos]=iCustom(NULL,0,"COGpoint1",50,3000,0,true);
value4[pos]=iCustom(NULL,0,"COGpoint1",50,3000,0,true);
}
return(0);
}
//+------------------------------------------------------------------+
01-02-2009, 12:41 AM
bamben
Junior Member
Join Date: Nov 2008
Posts: 9
this is the thread where i got the code made by Codersguru;
iCustom function
i noticed i left a part out of my code pos at the ends and pos--;
value1[pos]=iCustom(NULL,0,"COGpoint1",50,3000,0,true,pos);
value2[pos]=iCustom(NULL,0,"COGpoint1",50,3000,0,true,pos);
value3[pos]=iCustom(NULL,0,"COGpoint1",50,3000,0,true,pos);
value4[pos]=iCustom(NULL,0,"COGpoint1",50,3000,0,true,pos);
pos--;
lets try it!
01-02-2009, 12:54 AM
bamben
Junior Member
Join Date: Nov 2008
Posts: 9
LOL LOL LOLLLLLLL hahaha! oh my god
ok I have made progress I have half my indicator on the screen (only the red part of the indicator, lol wheres the green part?) this is the first thing i have ever got to half work though i cant beleve it hahaha! does any one konw what i have done wrong?
http://i31.photobucket.com/albums/c3..._m/cogcall.jpg
#75 (permalink)
01-02-2009, 01:35 AM
bamben
Junior Member
Join Date: Nov 2008
Posts: 9
hmm i added numbers at the end 0,1,2,3 for experiment. i dont know why? but it has done something, now i have a flat red line and green!!!!
http://i31.photobucket.com/albums/c3...cogcall2-1.jpg
yay! its not right though, mabey worse this is strange! help me please someone... everyone is sleeping zzz zzz zzz except me!
01-02-2009, 01:38 AM
bamben
Junior Member
Join Date: Nov 2008
Posts: 9
Look this is what i did (in Bold):
value1[pos]=iCustom(NULL,0,"COGpoint1",50,3000,0,true,pos,0);
value2[pos]=iCustom(NULL,0,"COGpoint1",50,3000,0,true,pos,1);
value3[pos]=iCustom(NULL,0,"COGpoint1",50,3000,0,true,pos,2);
value4[pos]=iCustom(NULL,0,"COGpoint1",50,3000,0,true,pos,3);
01-02-2009, 01:40 AM
bamben
Junior Member
Join Date: Nov 2008
Posts: 9
In fact, look at my code now!
//+------------------------------------------------------------------+
//| COG call.mq4 |
//| |
//| |
//+------------------------------------------------------------------+
#property indicator_separate_window
#property indicator_buffers 4
#property indicator_color1 Lime
#property indicator_color2 Red
#property indicator_color3 CLR_NONE
#property indicator_color4 CLR_NONE
//---- buffers
double value1[];
double value2[];
double value3[];
double value4[];
//+------------------------------------------------------------------+
//| Custom indicator initialization function |
//+------------------------------------------------------------------+
int init()
{
string short_name;
//---- indicators
IndicatorBuffers(4);
SetIndexStyle(0,DRAW_LINE,STYLE_SOLID,1,Lime);
SetIndexBuffer(0,value1);
SetIndexStyle(1,DRAW_LINE,STYLE_SOLID,1,Red);
SetIndexBuffer(1,value2);
SetIndexStyle(2,DRAW_NONE);
SetIndexBuffer(2,value3);
SetIndexStyle(3,DRAW_NONE);
SetIndexBuffer(3,value4);
IndicatorDigits(Digits+2);
return(0);
}
//+------------------------------------------------------------------+
//| Custom indicator deinitialization function |
//+------------------------------------------------------------------+
int deinit()
{
//----
//----
return(0);
}
//+------------------------------------------------------------------+
//| Custom indicator iteration function |
//+------------------------------------------------------------------+
int start()
{
int counted_bars=IndicatorCounted();
//---- check for possible errors
if (counted_bars<0) return(-1);
//---- last counted bar will be recounted
if (counted_bars>0) counted_bars--;
int pos=Bars-counted_bars;
while(pos>=0)
{
value1[pos]=iCustom(NULL,0,"COGpoint1",50,3000,0,true,pos,0);
value2[pos]=iCustom(NULL,0,"COGpoint1",50,3000,0,true,pos,1);
value3[pos]=iCustom(NULL,0,"COGpoint1",50,3000,0,true,pos,2);
value4[pos]=iCustom(NULL,0,"COGpoint1",50,3000,0,true,pos,3);
pos--;
}
return(0);
}
//+------------------------------------------------------------------+
01-02-2009, 02:04 AM
bamben
Junior Member
Join Date: Nov 2008
Posts: 9
i tryed putting
value1[pos]=iCustom(NULL,0,"COGpoint1",50,3000,0,true,pos,0,0);
value2[pos]=iCustom(NULL,0,"COGpoint1",50,3000,0,true,pos,0,1);
value3[pos]=iCustom(NULL,0,"COGpoint1",50,3000,0,true,pos,0,2);
value4[pos]=iCustom(NULL,0,"COGpoint1",50,3000,0,true,pos,0,3);
now it has kept again only the red line wich is buffer 2 but it has now put higher up in the chart screen and it it still flat. crazy!?!?
01-02-2009, 02:09 AM
bamben
Junior Member
Join Date: Nov 2008
Posts: 9
ahhhhh!!!
whats so special about buffer 2???