Icustom buffer value with indicator on separate window

 

Hello everyone!

I made an EA where my custom indicator returns the buffer value to buy/sell

   IndiCustomVenda = iCustom(NULL, Indicador_TimeFrame, Nome_Indicador, Indicador_Venda, ind_shift);
   IndiCustomCompra = iCustom(NULL, Indicador_TimeFrame, Nome_Indicador, Indicador_Compra, ind_shift);

(........)

      Print("VENDA = " + IndiCustomVenda);      
      Print("COMPRA = " +IndiCustomCompra);

      if(   ( (IndiCustomVenda !=EMPTY_VALUE) && (IndiCustomVenda !=0) ) || ( (Martingale_Seguido == true) && (LossVenda > 0) )   )     
        {
         EfetuarVenda();
         LossVenda = 0;
        }

And works fine! BUT, when the indicator is on separate window, or subwindow on the chart, it always returns empty value.

So... I think the problem is that the indicator buffer is not on the "main" chart, but I can't find a way to set the icustom to "look" in the indicator window.

I'm working with mql4 for just 4 months, so my skills are very basic, and I search the forum but can't find similar problem.. So sorry in advance for the noobidity.

Pictures  and files attached

Documentation on MQL5: Constants, Enumerations and Structures / Indicator Constants / Indicators Lines
Documentation on MQL5: Constants, Enumerations and Structures / Indicator Constants / Indicators Lines
  • www.mql5.com
Some technical indicators have several buffers drawn in the chart. Numbering of indicator buffers starts with 0. When copying indicator values using the CopyBuffer() function into an array of the double type, for some indicators one may indicate the identifier of a copied buffer instead of its number.
Files:
 
Fábio Albano:

Hello everyone!

I made an EA where my custom indicator returns the buffer value to buy/sell

And works fine! BUT, when the indicator is on separate window, or subwindow on the chart, it always returns empty value.

So... I think the problem is that the indicator buffer is not on the "main" chart, but I can't find a way to set the icustom to "look" in the indicator window.

I'm working with mql4 for just 4 months, so my skills are very basic, and I search the forum but can't find similar problem.. So sorry in advance for the noobidity.

Pictures attached

Does not have anything to do with the fact if the indicator is on main chart or in separate window

Check your iCustom() parameters

 
Fábio Albano:

Why start another topic about this?

You have had an answer here.

I have deleted your duplicate topic.

 

I thought I had posted on the mql 5 forum, but now I saw how it works, sorry again..

So, why the same code works when the indicator is on the chart?


   IndiCustomVenda = iCustom(NULL, PERIOD_CURRENT, "VELAS_SEGUIDAS", 0, 0);
   IndiCustomCompra = iCustom(NULL, PERIOD_CURRENT, "VELAS_SEGUIDAS", 1, 0);



      Print("VENDA = " + IndiCustomVenda);      
      Print("COMPRA = " +IndiCustomCompra);

      if(((IndiCustomVenda !=EMPTY_VALUE) && (IndiCustomVenda !=0)) )
        {
         Print("okVenda");
        }
      if(((IndiCustomCompra !=EMPTY_VALUE) && (IndiCustomCompra !=0)) )
        {
         Print("okCompra");
        }
Files:
 

Can someone tell me what I'm doing wrong, please?

Indicator and EA attached above.

 
Fábio Albano:

Can someone tell me what I'm doing wrong, please?

Indicator and EA attached above.

Access bar 1, not 0.

And if you loop back, say, for the past 200 bars, you'll get these values correctly (I drew the vertical lines to indicate the bars it returned a value):


 

Sorry I forgot to mention, but I need to work only on the strategy tester. So by access bar, you mean the shift? (....", 0, 0);

Can you attach your modified EA so I can learn more?

Very very thank you!

 
Fábio Albano:

Sorry I forgot to mention, but I need to work only on the strategy tester. So by access bar, you mean the shift? (....", 0, 0);

Can you attach your modified EA so I can learn more?

Very very thank you!

Yes, shift.

I've only changed a few things in your function that calls iCustom() - my sole purpose was to prove that you can get values:

void TechnicalAnalysis2x11()
  {
   static datetime lastBar = 0;
   if (lastBar!=iTime(NULL,PERIOD_CURRENT,0))
   {
      for (int i=0; i<200; i++)
      {
         IndiCustomVenda = iCustom(NULL, PERIOD_CURRENT, "RSI_Divergence_indicator__1", 0, i);
         IndiCustomCompra = iCustom(NULL, PERIOD_CURRENT, "RSI_Divergence_indicator__1", 1, i);
      
         if(((IndiCustomVenda !=EMPTY_VALUE) && (IndiCustomVenda !=0)) )
            Print("Bar = ", i, ", Time = ", TimeToStr(iTime(NULL,PERIOD_CURRENT,i),TIME_MINUTES), ", Venda = ", IndiCustomVenda);

         if(((IndiCustomCompra !=EMPTY_VALUE) && (IndiCustomCompra !=0)) )
            Print("Bar = ", i, ", Time = ", TimeToStr(iTime(NULL,PERIOD_CURRENT,i),TIME_MINUTES), ",  Compra = ", IndiCustomCompra);
      }
      lastBar = iTime(NULL,PERIOD_CURRENT,0);
   }
  }
 
  1.    IndiCustomVenda = iCustom(NULL, Indicador_TimeFrame, Nome_Indicador, Indicador_Venda, ind_shift);
    
    On MT4: Unless the current chart is that specific symbol(s)/TF(s) referenced, you must handle 4066/4073 errors before accessing candle/indicator values.
              Download history in MQL4 EA - Forex Calendar - MQL4 programming forum - Page 3 #26 № 4

  2. You should encapsulate your iCustom calls to make your code self-documenting.
              Detailed explanation of iCustom - MQL4 programming forum

  3. Don't use NULL.
    • You can use NULL in place of _Symbol only in those calls that the documentation specially says you can. iHigh does, iCustom does, MarketInfo does not. OrderSend does not.
    • Don't use NULL (except for pointers where you explicitly check for it.) Use _Symbol and _Period, that is minimalist as possible and more efficient.
    • Zero is the same as PERIOD_CURRENT which means _Period. Don't hard code numbers.
    • MT4: No need for a function call with iHigh(NULL,0,s) just use the predefined arrays, i.e. High[].

  4. Fábio Albano: Can someone tell me what I'm doing wrong, please?
    Seng Joo Thio: Access bar 1, not 0.
    Agree
 
Wow! This helped me a lot! Thanks guys very much!! 
Reason: