Ask! - page 176

 

PS: just to remind - the 3rd parameter in iCustom() call is the indicator name. First parameter is the symbol and the 2nd parameter is the desired time frame

mladen:
Do it like this:
array[0]=iClose("EURUSD",0,0); [/PHP]

and so on. That way array will be filled with close prices for symbols you select. If you are using a custom indicator then the form is the following :

[PHP]array[0]=iCustom("EURUSD",0,"indicator name",0,0);
 

MLaden

I am calling a custom indicator using icustom in a loop for several pairs. I can see on the experts tab that the indicator gets unloaded and then reloaded for the next pair. Does this mean that the iCustom call is recalculating the values for the entire maximum bars in the chart each time it is loaded? Also if you call it for Bar N and then Bar N+1 as separate successive calls does the second call require complete recalculation? And finally, if the successive calls are for different buffers, does each get recalculated.

I recall that you said that each iCustom call spawns a separate instance, so my presumption is that each gets recalculated in its entirety.

Thanks for the response,

Tzuman

 

Tzuman,

Metatrader creates a new instance of indicator for each new set of parameter values (exception are buffer number and index).

An example - the following two calls :

iCustom(NULL,0,"name",1,0,0);

iCustom(NULL,0,"name",2,0,0);

will create two instances of an indicator (even if you use for example "n" instead of 1 and 2 and assign different values to n before a new call to iCustom(), it will create separate instances. That is why some adaptive indicators can not be written using iCustom() but it must be done in a form of functions)

Now that is about instances. But if the indicator is loaded and then unloaded it is usually a problem with parameters (the unloading part usually indicates that). If parameters types do not match then it will do the "load - unload" stunt. Check if by accident some of the parameters passed to iCustom is not the expected type (or some of the parameters are accidentally omitted and that could cause that parameters types mix up).

Tzuman:
MLaden

I am calling a custom indicator using icustom in a loop for several pairs. I can see on the experts tab that the indicator gets unloaded and then reloaded for the next pair. Does this mean that the iCustom call is recalculating the values for the entire maximum bars in the chart each time it is loaded? Also if you call it for Bar N and then Bar N+1 as separate successive calls does the second call require complete recalculation? And finally, if the successive calls are for different buffers, does each get recalculated.

I recall that you said that each iCustom call spawns a separate instance, so my presumption is that each gets recalculated in its entirety.

Thanks for the response,

Tzuman
 

I did not want to interrupt your recent discussions

please have a look to this new thread

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

 

As I see, mrtools solved it already

MaaTini:
I did not want to interrupt your recent discussions

please have a look to this new thread

https://www.mql5.com/en/forum/182212
 
mladen:
Tzuman,

Metatrader creates a new instance of indicator for each new set of parameter values (exception are buffer number and index).

An example - the following two calls :

iCustom(NULL,0,"name",1,0,0);

iCustom(NULL,0,"name",2,0,0);

will create two instances of an indicator (even if you use for example "n" instead of 1 and 2 and assign different values to n before a new call to iCustom(), it will create separate instances. That is why some adaptive indicators can not be written using iCustom() but it must be done in a form of functions)

Now that is about instances. But if the indicator is loaded and then unloaded it is usually a problem with parameters (the unloading part usually indicates that). If parameters types do not match then it will do the "load - unload" stunt. Check if by accident some of the parameters passed to iCustom is not the expected type (or some of the parameters are accidentally omitted and that could cause that parameters types mix up).

Thanks so much for the explanation. I assumed that the load/unload was caused by the Symbol changing on each iteration of the loop so it had to load all new data values,

e.g. iCustom("EURUSD",0,"name" ,1,0,0); & iCustom("GBPUSD",0,name" ,1,0,0);

I will carefully check the parameters but I have proceeded to write my own MA average functions with some plagiarism. Just looking at the processor utilization in the Task Manager, it looks like my cpu usage has decreased by 90-95%. I'm happy

 

hello guru im newbie in coding can you help me in "stop opening multiple order when takeprofit hit" i try code like this but not working. could you help me please.

static datetime closeT;

for(int a=OrdersHistoryTotal()-1; a>=0; a--) {if(OrderSelect(a,SELECT_BY_POS,MODE_HISTORY)==true) {if(OrderMagicNumber()==magic && OrderSymbol()==symb && closeT<OrderCloseTime()) { closeT=OrderCloseTime(); if((buy==true || sell==true) && closeT==Time[0]){buy=false; sell=false;} } } }

 

thank you mladen, i will try your code.

 
RBarias:
hello guru im newbie in coding can you help me in "stop opening multiple order when takeprofit hit" i try code like this but not working. could you help me please.

staticdatetime closeT;

for(int a=OrdersHistoryTotal()-1; a>=0; a--) {if(OrderSelect(a,SELECT_BY_POS,MODE_HISTORY)==true) {if(OrderMagicNumber()==magic && OrderSymbol()==symb && closeT<OrderCloseTime()) { closeT=OrderCloseTime(); if((buy==true || sell==true) && closeT==Time[0]){buy=false; sell=false;} } } }

You can try something like this (it will check if the last closed order is closed on a current bar and if a take profit was hit) :

datetime closeT= 0;

int ticket=-1;

for(int a=OrdersHistoryTotal()-1; a>=0; a--)

{

if(OrderSelect(a,SELECT_BY_POS,MODE_HISTORY))

if(OrderMagicNumber()==magic && OrderSymbol()==symb && closeT<OrderCloseTime())

{

closeT=OrderCloseTime();

ticket=OrderTicket();

}

}

if (ticket>-1)

{

OrderSelect(ticket,SELECT_BY_TICKET,MODE_HISTORY);

if(iBarShift(symb,0,closeT)==0 && OrderClosePrice()==OrderTakeProfit())

{

buy =false;

sell=false;

}

}
 

Hi mladen,

Your Symbols.mq4 script worked perfectly in MT4 build 509, but it throws a file error in build 636 (when opening symbols.raw).

Would you kindly share an updated version for MT4 build 636?

Thank you very much in advance.

Regards,

Timo.

Reason: