ICustom function - page 8

 
 

take a look at the iCustom function in MQL help, it does exactly what you require

 

That's it!

Thanks!

 

iCustom

Hi there,

Sometimes the operation of an my indicators needs to be slight;y different if the indicator was run as a result of a call to iCustom as opposed to how the indicator would normally run if it was attached to a chart.

Is there a simple function or method within MQL that one can use within an indicator to determine if the indicator was explicitly run because it was attached to a chart or if the indicator was run as a result of a call to iCustom?

As a fudge I have been including a boolean parameter to my indicators called 'Custom' with a default value of false. If I make a call to iCustom to run the indicator then I set this parameter to true instead. That way I can tell within my indicator whether the indicator is running as a result of a call to iCustom.

Surely there must be some function like say IsCustom() which returns true of the indicator was run via iCustom or false otherwise.

Does anyone have an elegant, simple way of determining whether an indicator was run as a result of being called via iCustom?

Regards,

Laurence.

 

thank you all for all your help!

aj

 

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.

 

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 icustom) he 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 |

//+------------------------------------------------------------------+

int init()

{

//---- 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);

}

//+------------------------------------------------------------------+

 

this is the thread where i got the code made by Codersguru;

https://www.mql5.com/en/forum/173108

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!

At At At
 

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?

 

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!!!!

yay! its not right though, mabey worse this is strange! help me please someone... everyone is sleeping zzz zzz zzz except me!

Reason: