Multi Array über Indikatoren

 

Hallo,


ich hab ja schon ein wenig getestet, aber da ich multidimensionale Arrays ja nicht mit verschiedenen Werten befüllen darf, hat wer eine bessere Idee

ich bau mir gerade einen Symbol Scanner, und versuche da einen Indikator einzubinden, das ganze in einem EA und nicht in einem Indikator


natürlich habe ich schon bei der Array Deklaration einen Fehler, da ich die ja nicht mischen darf.

Aber hat wer eine bessere Idee?

Das ganze rufe ich in einem include auf, ist nur wegen der Übersichtlichkeit im Code vom EA

int MA200h5[];
double MA2005[][3];

//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
void SignalInit()
  {
   
   ArrayResize(MA200h5,SymbolsTotal(true)-1,0);
   ArrayResize(MA2005,SymbolsTotal(true)-1,0);
   
   for(int idx=0; idx<SymbolsTotal(true); idx++)
     {
      string sym = SymbolName(idx,true);
      SymbolSelect((string)sym[idx],true);

      MA200h5[sym[idx]]  = iMA((string)sym[idx],PERIOD_CURRENT,200,0,MODE_EMA,PRICE_CLOSE);
      ArraySetAsSeries(MA2005[sym[idx]],true);
     }
  }

//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
void SignalOnTick()
  {

   for(int idx=0; idx<SymbolsTotal(true); idx++)
     {
      string sym = SymbolName(idx,true);
      SymbolSelect((string)sym[idx],true);
      CopyBuffer(MA200h5[sym[idx]],0,0,5,MA2005[sym[idx]]);
     }


   if(isNewBar(PERIOD_M5))
     {
      for(int idx=0; idx<SymbolsTotal(true); idx++)
        {
         string sym = SymbolName(idx,true);
         SymbolSelect((string)sym[idx],true);

         MqlRates rates[];
         int copied=CopyRates(NULL,0,0,100,rates);


         if(rates[0].close > MA2005[sym[idx]][0])
            MessageBox("M5: Signal Long " + sym);

        }
     }

  }


//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
bool isNewBar(ENUM_TIMEFRAMES timeFrame)
  {
//----
   static datetime old_Times[4];// an array for old time values
   bool res=false;               // variable for the result
   int  i=0;                     // index of old_Times[] array
   datetime new_Time[1];         // time of a new bar

   switch(timeFrame)
     {
      case PERIOD_M1:
         i= 0;
         break;
      case PERIOD_M2:
         i= 1;
         break;
      case PERIOD_M3:
         i= 2;
         break;
      case PERIOD_M4:
         i= 3;
         break;
      case PERIOD_M5:
         i= 4;
         break;
     
     }
// copying the last bar time to the element new_Time[0]
   int copied=CopyTime(_Symbol,timeFrame,0,1,new_Time);

   if(copied>0) // ok, the data has been copied successfully
     {
      if(old_Times[i]!=new_Time[0])       // if old time isn't equal to new bar time
        {
         if(old_Times[i]!=0)
            res=true;    // if it isn't a first call, the new bar has appeared
         old_Times[i]=new_Time[0];        // saving bar time
        }
     }

   return(res);
  }
 

Was ist mit einem Array einer Struktur?
(ungetestet)

struct sowas {
        double prc,sl,tp;
        int handleA, handleB;
        ...

};
...
sowas arr[];
...
if(CopyBuffer(arr[4].handleA, ...)<=0) return;

Du kannst aber auch Klassen definieren und Array von Klassen.

 
bin eh im Homeoffice, da hab ich morgen was zum schauen ;-)
 
Dann schau Dir auch das an wegen NewBar: https://www.mql5.com/de/code/768
 
Carl Schreiber:
Dann schau Dir auch das an wegen NewBar: https://www.mql5.com/de/code/768

also codeseitig weit schöner, aber in der Handhabung unpraktischer.

vor allem, ich muss für jede Periode eine Variable definieren, hier mit NB1, NB2. Die muss ich mir dann ja auch noch merken, welche ich für welche Periode verwende ;-)

ausser ich mach da was falsch, was ich mir ja fast nicht vorstellen kann

static CIsNewBar NB1,NB2;

   if(NB1.IsNewBar(_Symbol,PERIOD_M1)) Print(" M1 new Bar");
   if(NB2.IsNewBar(_Symbol,PERIOD_M5)) Print(" M5 new Bar");
 

so, das funktioniert wirklich gut

danke calli für den Tip ;-)


struct IndicatorLoad {
        double MA5[];
        int handleA;
        string symbol;

};

IndicatorLoad Indi[];

//if(CopyBuffer(arr[4].handleA, ...)<=0) return;


//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
void SignalInit()
  {

   ArrayResize(Indi,SymbolsTotal(true),0);
  
   for(int idx=0; idx<SymbolsTotal(true); idx++)
     {
      string sym = SymbolName(idx,true);
      SymbolSelect((string)sym[idx],true);

      Indi[idx].handleA  = iMA(sym,PERIOD_M5,200,0,MODE_EMA,PRICE_CLOSE);
      ArraySetAsSeries(Indi[idx].MA5,true);
       
     }


  }

//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
void SignalOnTick()
  {

   
   
   for(int idx=0; idx<SymbolsTotal(true); idx++)
     {
      string sym = SymbolName(idx,true);
      SymbolSelect((string)sym[idx],true);
      
      CopyBuffer(Indi[idx].handleA,0,0,5,Indi[idx].MA5);
     }

    

   for(int idx=0; idx<SymbolsTotal(true); idx++)
        {
         string sym = SymbolName(idx,true);
         SymbolSelect((string)sym[idx],true);

         MqlRates rates[];
         int copied=CopyRates(NULL,0,0,100,rates);


         Print(sym, " ",Indi[idx].MA5[1] );

        }

}
Grund der Beschwerde: