Help to pass a variable (int) from an indicator to an Expert Advisor

 

Hi everyone. I have been trying to set a variable in an indicator and then pass it to an Expert Advisor. I was wondering if anyone can help me with what am I doing wrong and how I should get the values that I need.

Brief explanation: I have been trying to get the 'double' value for expertVar[0] and use it ('int') in my expert advisor (in order to know the corrisponding pattern and open the right position (Buy, Sell)).

The question: How can I get the value from the indicator in my expert advisor?

Code for the Pattern Indicator:

#property indicator_chart_window
#property indicator_buffers 3
#property indicator_plots 1 //maybe 2
#property indicator_label1  "Zig Zag"
#property indicator_type1   DRAW_ZIGZAG
#property indicator_color1  clrNONE
#property indicator_style1  STYLE_SOLID
#property indicator_width1  1

//--- Constants and macros
#define SIZE_PATTERN_BUFFER 10
#define NUM_PATTERNS 66
#define NON_EXISTENT_DATETIME D'19.07.1980 12:30:27'

//--- Indicator buffer arrays
double peaks[],troughs[],expertVar[];

//...

int OnInit()
  {
//--- indicator buffers mapping
   SetIndexBuffer(0,peaks,INDICATOR_DATA);
   SetIndexBuffer(1,troughs,INDICATOR_DATA);
   SetIndexBuffer(2,expertVar);
   IndicatorSetInteger(INDICATOR_DIGITS,Digits());
   PlotIndexSetDouble(0,PLOT_EMPTY_VALUE,0.0);
   PlotIndexSetDouble(1,PLOT_EMPTY_VALUE,0.0);
//...
  }

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[])
  {
      if (_patternNames[k]=="Bat")
      expertVar[0]=1;
      if (_patternNames[k]=="Cypher")
      expertVar[0]=3;
      if (_patternNames[k]=="Gartley")
      expertVar[0]=5;
      if (_patternNames[k]=="Butterfly")
      expertVar[0]=7;
//...
}
//...

My Expert Advisor code to get the value from the indicator:

#include <Trade\Trade.mqh>
CTrade trade;
#resource "\\Indicators\\HarmonicPatternFinderV2.ex5"

int Handle=0;
int MyRSIDefinition=0;

int OnInit()
{
   Handle=iCustom(NULL,0,"::Indicators\\HarmonicPatternFinderV2.ex5");
   if(Handle==INVALID_HANDLE)
     {
      printf("Error obtaining handle");
      return(INIT_FAILED);
     }
   MyRSIDefinition=iRSI(_Symbol,_Period,7,PRICE_CLOSE);
   return INIT_SUCCEEDED;
}

void OnTick()
  {
     double Ask=NormalizeDouble(SymbolInfoDouble(_Symbol,SYMBOL_ASK),_Digits);
     double Balance=AccountInfoDouble(ACCOUNT_BALANCE);
     double Equity=AccountInfoDouble(ACCOUNT_EQUITY);
     double MyRSIArray[];
     double MyHandleArray[];
     int MyHandleValue=0;
     ArraySetAsSeries(MyRSIArray,true);
     ArraySetAsSeries(MyHandleArray,true);
     CopyBuffer (MyRSIDefinition,0,0,3,MyRSIArray);
     double MyRSIValue=NormalizeDouble(MyRSIArray[0],2);
     CopyBuffer (Handle,2,0,1,MyHandleArray);
     /*if (CopyBuffer (Handle,2,0,10,MyHandleArray)<0)
      {
         Print("CopyBufferHandle error = ",GetLastError());
      }*/
     double MyHandleValueD=NormalizeDouble (MyHandleArray[0],0);
     MyHandleValue=NormalizeDouble(MyHandleValueD,0);
     switch (MyHandleValue)
     {
         case 1:
            //if(Equity>=Balance && MyRSIValue<40)
            {
               trade.Buy (0.03,NULL,Ask,0,0,NULL);
            }
            break;
         case 2:
            //if(Equity>=Balance && MyRSIValue>60)
            {
               trade.Sell (0.03,NULL,Ask,0,0,NULL);
            }
            break;
         case 3:
            //if(Equity>=Balance && MyRSIValue<40)
            {
               trade.Buy (0.03,NULL,Ask,0,0,NULL);
            }
            break;
         case 4:
            //if(Equity>=Balance && MyRSIValue>60)
            {
               trade.Sell (0.03,NULL,Ask,0,0,NULL);
            }
            break;
         case 5:
            //if(Equity>=Balance && MyRSIValue<40)
            {
               trade.Buy (0.02,NULL,Ask,0,0,NULL);
            }
            break;
         case 6:
            //if(Equity>=Balance && MyRSIValue>60)
            {
               trade.Sell (0.02,NULL,Ask,0,0,NULL);
            }
            break;
         case 7:
            //if(Equity>=Balance && MyRSIValue<30)
            {
               trade.Buy (0.02,NULL,Ask,0,0,NULL);
            }
            break;
         case 8:
            //if(Equity>=Balance && MyRSIValue>70)
            {
               trade.Sell (0.02,NULL,Ask,0,0,NULL);
            }
            break;
         default:
            break;       
     }
  }
// 1= bullish bat, 2=bearsish bat, 3=bullish cypher, 4=bearish cypher,
// 5=bullish gartley, 6=bearish gartley, 7=bullish butterfly, 8=bearish butterfly

I apologize if it's a noob question. I have been trying to look up several topics, but didn't find anything that helped me. Thank you.

Reason: