Get datas from own indicator

 

Hello!

I have an own indicator, and I want to use in EA the indicator's two buffers. The problem is the second buffer result is always 0. What did i do wrong?


The indicator:

//+------------------------------------------------------------------+
//|                                     PatternFounder.mq5    |
//|                                                 by Zsolt Szabó   |
//|                                                                  |
//+------------------------------------------------------------------+
#property indicator_chart_window
#property indicator_buffers 2

double min_diff_value;
int min_index;
double PatternIndexBuffer[];
double PatternPercentBuffer[];


//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int OnInit()
{
    SetIndexBuffer(0,PatternIndexBuffer,INDICATOR_DATA);
    SetIndexBuffer(1,PatternPercentBuffer,INDICATOR_DATA);
    
       
    return(INIT_SUCCEEDED);
    }

//+------------------------------------------------------------------+
//| Custom indicator iteration function                              |
//+------------------------------------------------------------------+
int OnCalculate(const int rates_total,
                const int prev_calculated,
                const datetime &time[],
                const double &open[],
                const double &high[],
                const double &low[],
                const double &close[],
                const long &tick_volume[],
                const long &volume[],
                const int &spread[])
{
    // Legkevésbé eltérő pattern azonosítása
    double pattern = 0;
    //int samest_pattern_index = -1;
    int samest_pattern_index = -1;
    int basic_index = rates_total - 2;
    
    for (int i = rates_total - 7; i >= 0; i--) // indítás az első gyertyától
    {
    
//------Pattern 1 -----------------------------------------------    
// Some other program lines with calculations...
      
////////Teljes egyezés kiszámítása______________________________________________________________________
        
        double Sample_Total_percent = Sample_1_percent;
        if (Sample_2_percent < Sample_Total_percent){Sample_Total_percent = Sample_2_percent;}
        if (Sample_3_percent < Sample_Total_percent){Sample_Total_percent = Sample_3_percent;}
        if (Sample_4_percent < Sample_Total_percent){Sample_Total_percent = Sample_4_percent;}
        if (Sample_5_percent < Sample_Total_percent){Sample_Total_percent = Sample_5_percent;}
                
        if (Sample_Total_percent > pattern){
        //pattern = Sample_Total_percent;
        pattern = NormalizeDouble(Sample_Total_percent,2);
        samest_pattern_index = i;
        }
      }
     
        
      }
      
// Rajzoljunk vonalat a legkisebb gyertyára
  if (samest_pattern_index != -1)
  {
      double y = low[samest_pattern_index] - pattern * 0.1; // draw line slightly below the low of the candle
      //double y = 1;
      datetime time_of_min_diff_bar = time[samest_pattern_index];
      ObjectCreate(0, "MyVerticalLine", OBJ_VLINE, 0, time_of_min_diff_bar, y);
      
      
      //datetime time_of_basic_bar = time[basic_index];
      //ObjectCreate(0, "BasicLine", OBJ_VLINE, 0, time_of_basic_bar, y);
      //datetime time_of_basic_bar2 = time[basic_index-1];
      //ObjectCreate(0, "BasicLine2", OBJ_VLINE, 0, time_of_basic_bar2, y);
      
      string datetime_str = TimeToString(time_of_min_diff_bar);
      //Comment(datetime_str, " Basichigh" +high[basic_index], " Pattern: "+ pattern, " samest_pattern_index: "+samest_pattern_index);
      Comment(datetime_str," Pattern: "+ pattern, " samest_pattern_index: "+samest_pattern_index);
      MessageBox((datetime_str), "Érték", MB_OK | MB_ICONINFORMATION);
      
         // Bufferek beolvasása      
         int start;
         if(prev_calculated==0)
         start=0;
         else
         start=prev_calculated-1;
         
         //--- calculate PatternIndex
         for(int j=start; j<rates_total && !IsStopped(); j++){
         PatternIndexBuffer[j]=samest_pattern_index;
         //PatternIndexBuffer[j]=pattern;
         PatternPercentBuffer[j]=pattern; 
         }    
  

      }
  
 
  
      return(rates_total);
     
    }


And this is the EA:

//+------------------------------------------------------------------+
//|                                      P Booster Lime 20220403.mq5 |
//|                                      Copyright 2023, Zsolt Szabo |
//|         https://www.youtube.com/channel/UCrgWUk26g5G6R3eqLOlvkyw |
//+------------------------------------------------------------------+
//#include <Szabó Zsolt\PatternFounder.mqh>

double SPI;
double PatternPercent;

//+------------------------------------------------------------------+
//| Expert tick function                                             |
//+------------------------------------------------------------------+

int OnInit()
{
    return(INIT_SUCCEEDED);
}

void OnTick()
{
    int indicator_handle = iCustom(_Symbol, _Period, "PatternFounder");
    double SPIBuffer[];
    double PBuffer[];
    ArraySetAsSeries(SPIBuffer, true);
    ArraySetAsSeries(PBuffer, true);

    CopyBuffer(indicator_handle, 0, 0, 1, SPIBuffer);
    CopyBuffer(indicator_handle, 1, 0, 1, PBuffer);

    SPI = SPIBuffer[0];
    PatternPercent = PBuffer[0];

    Print("SPI: "+SPI);
    Print("PatternPercent: "+PatternPercent);
    Print("PatternPercent: "+DoubleToString(PatternPercent, 2));
    if (PatternPercent > 0){Print("PatternPErcent nagyobb ám, mint 0!");}
}

//+------------------------------------------------------------------+
//| Expert start function                                            |
//+------------------------------------------------------------------+

int start()
{
    return 0;
}
 
void OnTick()
{
    int indicator_handle = iCustom(_Symbol, _Period, "PatternFounder");

Perhaps you should read the manual, especially the examples.
   How To Ask Questions The Smart Way. (2004)
      How To Interpret Answers.
         RTFM and STFW: How To Tell You've Seriously Screwed Up.

They all (including iCustom) return a handle (an int). You get that in OnInit. In OnTick/OnCalculate (after the indicator has updated its buffers), you use the handle, shift and count to get the data.
          Technical Indicators - Reference on algorithmic/automated trading language for MetaTrader 5
          Timeseries and Indicators Access / CopyBuffer - Reference on algorithmic/automated trading language for MetaTrader 5
          How to start with MQL5 - General - MQL5 programming forum - Page 3 #22 (2020)
          How to start with MQL5 - MetaTrader 5 - General - MQL5 programming forum - Page 7 #61 (2020)
          MQL5 for Newbies: Guide to Using Technical Indicators in Expert Advisors - MQL5 Articles (2010)
          How to call indicators in MQL5 - MQL5 Articles (2010)

 
William Roeder #:

Perhaps you should read the manual, especially the examples.
   How To Ask Questions The Smart Way. (2004)
      How To Interpret Answers.
         RTFM and STFW: How To Tell You've Seriously Screwed Up.

They all (including iCustom) return a handle (an int). You get that in OnInit. In OnTick/OnCalculate (after the indicator has updated its buffers), you use the handle, shift and count to get the data.
          Technical Indicators - Reference on algorithmic/automated trading language for MetaTrader 5
          Timeseries and Indicators Access / CopyBuffer - Reference on algorithmic/automated trading language for MetaTrader 5
          How to start with MQL5 - General - MQL5 programming forum - Page 3 #22 (2020)
          How to start with MQL5 - MetaTrader 5 - General - MQL5 programming forum - Page 7 #61 (2020)
          MQL5 for Newbies: Guide to Using Technical Indicators in Expert Advisors - MQL5 Articles (2010)
          How to call indicators in MQL5 - MQL5 Articles (2010)

Thanks for the nothing!

 
You asked:
Zsolt Szabo: What did i do wrong?

I answered that.

Zsolt Szabo #: Thanks for the nothing!

That is not nothing. Live in ignorance. On my Do Not Help List.

 
William Roeder #:
You asked:

I answered that.

That is not nothing. Live in ignorance. On my Do Not Help List.

Thank you! ;)