Download MetaTrader 5

how to creat indicator with other priod??

To add comments, please log in or register
Find out how to install MetaTrader on Mac OS
okwh
1631
okwh 2012.09.13 12:03 

 I used indicator with other priod not current period,but no data received,why and how?

void OnInit()

{
....
   Ext1Handle=iCustom(NULL,PERIOD_CURRENT,"xxxx",SlowEMA1);
   Ext2Handle=iCustom(NULL,PERIOD_M5,"xxxx",SlowEMA1);
   Ext3Handle=iCustom(NULL,PERIOD_M15,"xxxx",SlowEMA1);


.....
} 


int OnCalculate()
{
......
   int calculated=BarsCalculated(Ext1Handle);
   int calculated=BarsCalculated(Ext2Handle);
   int calculated=BarsCalculated(Ext3Handle); ////not calculated????
....

CopyBuffer(Ext1Handle,0,0,to_copy,Ext1);
CopyBuffer(Ext2Handle,0,0,to_copy,Ext2);
CopyBuffer(Ext3Handle,0,0,to_copy,Ext3);

......
}

at 1M period,  Ext1Handle , Ext2Handle are OK, but  Ext3Handle with other period not calculated, sometime   Ext2Handle  also not calculated.

report in expert log window is    2012.09.13 17:57:28         Not all data of Ext3Handle is calculated (5001bars ). Error0

mo data for other period ?????? 

Maybe current period can not change!

Is It possible to change the indicators handel's period dynamic  inside int OnCalculate()????

Valerii Mazurenko
3485
Valerii Mazurenko 2012.09.13 15:52  
DxdCn:

 I used indicator with other priod not current period,but no data received,why and how?

at 1M period,  Ext1Handle , Ext2Handle are OK, but  Ext3Handle with other period not calculated, sometime   Ext2Handle  also not calculated.

report in expert log window is    2012.09.13 17:57:28         Not all data of Ext3Handle is calculated (5001bars ). Error0

mo data for other period ?????? 

Maybe current period can not change!

Is It possible to change the indicators handel's period dynamic  inside int OnCalculate()????

Check result of CopyXXX in code of your indicator.

if timeframe is different from current - first call of CopyXXX is only starting the process of building the bars and returning result will be less 0. After building process finish, call CopyXXX will return count of copied bars.

When requesting data from the indicator, if requested timeseries are not yet built or they need to be downloaded from the server, 
the function will immediately return -1, 
but the process of downloading/building will be initiated.

 

okwh
1631
okwh 2012.09.13 16:58  

Thanks.

I fond it why,  CopyBuffer only copy from start-index of src-buffer to same star-index of dst-buffer, so need a middle-buffer to tranfer data through ArrayAopy. 

Still another peroblem need to resolve:

 

 ENUM_TIMEFRAMES ,tf,tf1; 

 

if I use below code with variable tf and tf2 as period,  the threehandle  all are  PERIOD_CURRENT in runtime. 

Ext1Handle=iCustom(NULL,PERIOD_CURRENT,"xxxx",SlowEMA1);
Ext2Handle=iCustom(NULL,tf,"xxxx",SlowEMA1);
Ext3Handle=iCustom(NULL,tf1,"xxxx",SlowEMA1);

 

below codes work OK, but this can not change with  changing current period.

   Ext1Handle=iCustom(NULL,PERIOD_CURRENT,"xxxx",SlowEMA1);
   Ext2Handle=iCustom(NULL,PERIOD_M5,"xxxx",SlowEMA1);
   Ext3Handle=iCustom(NULL,PERIOD_M15,"xxxx",SlowEMA1);

Heinz Traub
314
Heinz Traub 2012.09.13 17:47  
DxdCn:

Hi,

Sounds like you're not setting the values of tf and tf1 at all or the lines setting them are inside an IF statement that never gets executed. Make sure of the last one. Could you please post that part of the code?

okwh
1631
okwh 2012.09.17 11:40  

Below is code

ENUM_TIMEFRAMES tf0,tf,tf1;
void OnInit()
  {
.................
tf0 = PERIOD_CURRENT;
  switch (PERIOD_CURRENT)
  {
     case PERIOD_M1:   tf =PERIOD_M5;tf1 =PERIOD_M15; break;
      case PERIOD_M5:   tf =PERIOD_M15; tf1 =PERIOD_H1;break;
      case PERIOD_M15:   tf =PERIOD_H1;tf1 =PERIOD_H4;break;
      case PERIOD_M30:   tf =PERIOD_H2;tf1 =PERIOD_H8;  break;
      case PERIOD_H1:   tf =PERIOD_H4; tf1 =PERIOD_H12;break;
      case PERIOD_H4:   tf =PERIOD_H12;  tf1 =PERIOD_D1; break;
      case PERIOD_D1:   tf =PERIOD_D1;  tf1 =PERIOD_W1;  break;
  }
//--- get MA's handles

   Ext1Handle=iCustom(NULL,PERIOD_CURRENT,"xxxx",SlowEMA1);
   Ext2Handle=iCustom(NULL,PERIOD_M5,"xxxx",SlowEMA1);
   Ext3Handle=iCustom(NULL,PERIOD_M15,"xxxx",SlowEMA1);
//below worked error! 
// Ext1Handle=iCustom(NULL,PERIOD_CURRENT,"xxxx",SlowEMA1);
// Ext2Handle=iCustom(NULL,tf,"xxxx",SlowEMA1); 
// Ext3Handle=iCustom(NULL,tf1,"xxxx",SlowEMA1);
............

I want use variables as period parameter,but not work,

now only    such codes can work :

   Ext2Handle=iCustom(NULL,PERIOD_M5,"xxxx",SlowEMA1);
   Ext3Handle=iCustom(NULL,PERIOD_M15,"xxxx",SlowEMA1); 

I am transfer my indicators from MQL4 to MQL5.

referre:

https://www.mql5.com/en/forum/102908/page33

 https://c.mql5.com/mql4/forum/2012/04/3PeriodEUR_small.png

Did you see such a picture? - MQL4 forum
  • www.mql5.com
Did you see such a picture? - MQL4 forum
To add comments, please log in or register