Download MetaTrader 5
To add comments, please log in or register
Do you know that MQL5 has event handling?
Harry
267
Harry 2014.06.10 02:56 

Hi Everyone,

I write an indicator that has Entry/TP/SL buffer and it show arrow/value on chart correctly. However, it doesn't feed trading EA correctly. the EA start many positions where there is no value on the Entry buffer from the indicator. Some how it still have Entry/SL/TP.

I narrow down to 1 potential problem and let me explain it below.

Assume that each bar, there is a variable1  which can take value 0 or 1. So the time series look like that

0 0 0 1 1 1 0 0 1 1 1 0 0 0 0 11 0 0 1

Take the section underlined (1 1 1 0 0 1 1 1 0 0 0 0 1 ) for example.

I want to count the number of 0 between each series of 1. So for the data above, the first 1 blue will have a Number0[i]=2 and the last 1 in dark-red has a Number0[i]=4.

My code is below. It is quite straight forward.

I wonder if when I assign the END of series on (i+1), should it could any issue when I feed the final Number0 buffer to an EA. 

Thank you for your help.

SCFX 

 

.....
   int limit=rates_total-prev_calculated;
   if(limit<0) limit=2;

....

//--1.This marks the START of a series of 1
for(int i=1;i<limit;i++)
{  if(   iCustom(NULL,0,"series010",0,i)==1  &&
         iCustom(NULL,0,"series010",i+1)==0  )
   {start1[i]=1;}
}   

//--2.This marks the END of a series of 1 - I think this step cause trouble
for(int i=1;i<limit;i++)
{  if(   iCustom(NULL,0,"series010",0,i)==0  &&
         iCustom(NULL,0,"series010",,i+1)==1 )
   {end1[i+1]=1;}      //I think it cause trouble, the (i+1)
}   
//--3. Last step: Counting number 0
for(int i=1;i<limit && i+100<limit;i++)
{  int counting0=0;
   
   if(start1[i]==1)
   {  for(int j=i+1;j<=i+100;j++) //within the next 100 bar
      {  if(   end1[j]==1)
         {  for(int k=i;k<=j;k++)
            {  if(   iCustom(NULL,0,"series010",0,k)==0)    
               counting0=counting0+1;
            }
         }
         Number0_buffer[i]=counting0;
      break;  //exit and start finding next start1=1       
      }
   }
}


/////---- since I think the (i+1) cause trouble, I try to make it (i) but still not help

//--2.This marks the END of a series of 1
for(int i=2;i<limit;i++)
{  if(   iCustom(NULL,0,"series010",0,i)==1  &&
         iCustom(NULL,0,"series010",,i-1)==0 )
   {end1[i]=1;}      //I think it cause trouble, the (i+1)
}   
whroeder1
13602
whroeder1 2014.06.10 11:37  
scfx: it doesn't feed trading EA correctly.
   int limit=rates_total-prev_calculated;
   if(limit<0) limit=2;
:
   {  for(int j=i+1;j<=i+100;j++) //within the next 100 bar
      {  if(   end1[j]==1)
         {  for(int k=i;k<=j;k++)
            {  if(   iCustom(NULL,0,"series010",0,k)==0)   
  1. rates_total - prev_calculated comes from OnCalculate() which is only for indicators. But you state that this code is an EA
  2. If this code is in indicator, your lookback is 100, but you don't adjust limit to be below rates_total - lookback
Harry
267
Harry 2014.06.10 16:36  

Hi WHRoeder,

It is a indicator and I think that it is how it work.

Assume that the indicator starts calculating bar 1.

The section you quote should ask the indicator to go to bar 2 and check, then bar 3... bar 101.

I thought that the limit is only put requirement on i rather than on j. (the first 2 steps do not require the look back)

 

The second question is that, the last step where I calculate the number0, I look back 100 bar and I already put the condition within for() below. 

Does this count?

 

for(int i=1;i<limit && i+100<limit;i++)

 or should I put?

int limit=rates_total-prev_calculated;
   if(limit<100) limit=100;

 

 Thank you for your help.

SCFX 

/
To add comments, please log in or register