Download MetaTrader 5
To add comments, please log in or register
Deposit to your account via PayPal
Michal Brauner
25
Michal Brauner 2014.04.16 10:27 

Hi,

I made a simple custom indicator and I'm trying to use it in my EA. But there is a problem with loading values from indicator - iCustom always returns an empty value (tester, demo). When I show graph in EA tester, indicator is showed correct.

There is OnTick method from my EA:

void OnTick()
{
   static int SRStartArrowCounter = 0;
    
   double SR_Low = iCustom(NULL, PERIOD_M15, "SR_Levels", 5, 30, 0, 0);
   double SR_High = iCustom(NULL, PERIOD_M15, "SR_Levels", 5, 30, 1, 0);
   double SR_Low_length = iCustom(NULL, PERIOD_M15, "SR_Levels", 5, 30, 6, 0);
   double SR_High_length = iCustom(NULL, PERIOD_M15, "SR_Levels", 5, 30, 7, 0);
   
   Print("SR_Low="+SR_Low+", SR_High="+SR_High);
   Print("SR_Low_length="+SR_Low_length+", SR_High_length="+SR_High_length);
   
   if ((SR_Low_length==5 && SR_High_length>=5) || (SR_High_length==5 && SR_Low_length>=5))
   {
      SRStartArrowCounter++;
      ObjectCreate("SRStartArrowCounter"+SRStartArrowCounter, OBJ_ARROW, 0, Time[0], SR_Low);
   }
}

I attached a custom indicator and there is a screen:

screen

Thanks for your answers and for your help.

Files:
Ian Venner
2583
Ian Venner 2014.04.16 18:52  

Your EA calls values from the indicator for the current bar (zero). Attach your indicator to a chart you can see it doesn't do anything on the current bar.

Some of the levels do look quite accurate although a lot of them appear to be accurate after the fact.

ffoorr
985
ffoorr 2014.04.17 10:50  

Your indicator is fasely coded, this is not good because it will draw all the indicator at each tick :

   else
   {
      start = prev_calculated - 1;//  this is bar 1 
   }
                  
   for (int i=start; i<rates_total; i++)  // from 1 to bars_total
   {  

It may work doing this :

 else
   {
      start = prev_calculated;//   
   }
                  
   for (int i=start; i<2000; i++)  // from 0 to 2000 bars
   {  
ffoorr
985
ffoorr 2014.04.17 11:11  

edit;

Your indicator is fasely coded, this is not good because it will draw all the indicator at each tick :

this is not true, but this :

Your indicator is fasely coded, this is not good because it will draw all the indicator at each bar.

So it's OK the indicator work fine, but that's why you don't have the 0 bar at iCustom as SDC told you, the indicator will draw all the indicator once par bar

ffoorr
985
ffoorr 2014.04.17 11:19  

And remember, as Métaquote says: take everything with a pinch of salt

check everything

Michal Brauner
25
Michal Brauner 2014.04.20 08:51  
SDC:

Your EA calls values from the indicator for the current bar (zero). Attach your indicator to a chart you can see it doesn't do anything on the current bar.

Some of the levels do look quite accurate although a lot of them appear to be accurate after the fact.

Thanks for your answer, I quite remade indicator and it works (didn't return an empty value).

But there were others problems with getting indicator values into EA, so I integrate indicator calculation direct into EA. It was much more easier :)

SYED NAUFAL GADDAFI
1401
SYED NAUFAL GADDAFI 2014.04.20 08:55  
micky.2:

But there were others problems with getting indicator values into EA, so I integrate indicator calculation direct into EA. It was much more easier :)


Yes, it is easier. We just want you to figure it out. XD
Michal Brauner
25
Michal Brauner 2014.04.20 08:58  
ffoorr:

Your indicator is fasely coded, this is not good because it will draw all the indicator at each tick :

It may work doing this :



Thanks for your answer, it helps me. At the end, I got inspired from example indicators and used this:

for (int i=start; i>=0; i--)

But as I wrote in my previous comment, I included indicator calculations directly into EA (not using iCustom) - looks like much easier solution :)

/
To add comments, please log in or register