Multi Currency Multi TimeFrame

 

So I'm trying to create a Multi Currency Multi TimeFrame EA.

I've come so far that it loops thru currencies and Periods of my chose.
I send those to a Signal  function that test the signal of my chosen indicator.
So far so good.


My problem is that if my SL takes out my order on the first bar it reopens the order and the then SL takes it out again and again and again.

when I just created a normal EA i could use the static datetime       lastTradeBar; methed but I don't really know how to implement that in a Multi Currency Multi TimeFrame situation.
How do you guys solve this?


void LoopThruSym(string listOfSym)
  {

   if(Mode == All)
     {
      int i;
      int numSymbolmarketWatch=SymbolsTotal(false);
      numSymbols=numSymbolmarketWatch;
      ArrayResize(symbolListFinal,numSymbolmarketWatch);
      for(i=0; i<numSymbolmarketWatch; i++)
        {
         symbolListFinal[i]=SymbolName(i,false);
        }
     }
   else
      if(Mode == Selected)
        {
         string sep=",";
         ushort u_sep;
         int i;
         u_sep=StringGetCharacter(sep,0);
         StringSplit(listOfSym,u_sep,symbolList);
         numSymbols=ArraySize(symbolList);
         ArrayResize(symbolListFinal,numSymbols);
         for(i=0; i<numSymbols; i++)
           {
            symbolListFinal[i]=symbolPrefix+symbolList[i]+symbolSuffix;
            LoopThruPeriod(symbolListFinal[i],periods);
           }
        }
      else
         if(Mode == Current)
           {
            LoopThruPeriod(Symbol(),periods);
           }

   return;

  }

//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
void LoopThruPeriod(string sym, string listOfPeriods)
  {
   if(ModePeriod == All_Period)
     {
      string periodsALL      = "1,5,15,30,60,240,1440,10080,43200";
      string sep=",";
      ushort u_sep;
      int i;
      u_sep=StringGetCharacter(sep,0);
      StringSplit(periodsALL,u_sep,periodList);
      numPeriods=ArraySize(periodList);
      ArrayResize(periodListFinal,numPeriods);
      for(i=0; i<numPeriods; i++)
        {
         periodListFinal[i]=symbolPrefix+periodList[i]+symbolSuffix;
         Trade(sym,StrToInteger(periodListFinal[i]));
        }

     }
   else
      if(ModePeriod == Selected_Period)
        {
         string sep=",";
         ushort u_sep;
         int i;
         u_sep=StringGetCharacter(sep,0);
         StringSplit(listOfPeriods,u_sep,periodList);
         numPeriods=ArraySize(periodList);
         ArrayResize(periodListFinal,numPeriods);
         for(i=0; i<numPeriods; i++)
           {
            periodListFinal[i]=symbolPrefix+periodList[i]+symbolSuffix;
            Trade(sym,StrToInteger(periodListFinal[i]));
           }
        }
   if(ModePeriod == Current_Period)
     {
      Trade(sym,Period());
     }


  }
//+------------------------------------------------------------------+




//+------------------------------------------------------------------+
void Trade(string sym, int period)
  {
   //Print("Symbole = " + sym + " : " + period);
   if(OrderMethod == BuyandSell)
     {
      if(Signal(sym,period) == 1 && CheckMoneyForTrade(sym,Lots,OP_BUY) && CheckVolumeValue(sym,Lots))
         LimitBuy(sym,period);
      else
         if(Signal(sym,period) == -1 && CheckMoneyForTrade(sym,Lots,OP_SELL) && CheckVolumeValue(sym,Lots))
            LimitSell(sym,period);
     }
  else
   if(OrderMethod == BuyOnly)
     {
      if(Signal(sym,period) == 1 && CheckMoneyForTrade(sym,Lots,OP_BUY) && CheckVolumeValue(sym,Lots))
         LimitBuy(sym,period);
     }
   else
      if(OrderMethod == SellOnly)
        {
         if(Signal(sym,period) == -1 && CheckMoneyForTrade(sym,Lots,OP_SELL) && CheckVolumeValue(sym,Lots))
            LimitSell(sym,period);
        }
  //Trail(sym);

   return;
  }
//+------------------------------------------------------------------+





int Signal(string sym, int period)
  {
  if(lastTradeBar!=Time[0])
    { 
    if(PFTP_BuySignal > 0 && PFTP_BuySignal_Prev == 0 && PFTP_Rate > PFTP_Rate_Value)
      {
        myTP = PFTP_TP1;
        mySL = PFTP_BuySL;
        return (1);
      }
    if(PFTP_SellSignal > 0 && PFTP_SellSignal_Prev == 0 && PFTP_Rate > PFTP_Rate_Value)
      {
        myTP = PFTP_TP1;
        mySL = PFTP_SellSL;
        return (-1);
      }
    else
        return (0);
        lastTradeBar=Time[0];
      };
    return (0);
    }
 

I think i may need to do a multidimensional array or a array with multiple variables.

The array need to contain symbol , period and state of lastTradeBar on that symboles period.



This is what i use now.

if(lastTradeBar!=Time[0])

But should it be something like this

if(lastTradeBarArray[sym,period,lastTradeBar]!= Time[0];

or

if(lastTradeBarArray[sym][period][lastTradeBar]!= Time[0];



But i'm not shure how to store those values in there or which one is correct.

 
Mathias Halen: I think i may need to do a multidimensional array or a array with multiple variables.

The array need to contain symbol , period and state of lastTradeBar on that symboles period.

You do not.  When thinking about multidimensional arrays, the first n-1 dimensions are about finding a value. The last dimension is the value(s). You can't do that because the first index (a string) is not compatible with the value (state).

Not compiled, not tested, just typed.

struct MyData{
   string         symbol;
   ENUM_TIMEFRAME period;
   yourENUM       state;
   void set(string aSymbol, ENUM_TIMEFRAME aPeriod, yourENUM aState){
      symbol=aSymbol; period=aPeriod; state=aState;
   }
}
MyData data[];
void addData(string aSymbol, ENUM_TIMEFRAME aPeriod, yourENUM aState){
   int iData = ArrayLength(data);
   ArrayResize(data, iData+1);
   data[iData].set(aSymbol, aPeriod, aState);
}
int lookupData(string aSymbol, ENUM_TIMEFRAME aPeriod){
   int iData = ArrayLength(data)-1;
   for(; iData >= 0; --iData) if(data[iData].symbol == aSymbol && data[iData].period == aPeriod) break;
   return iData;
}

Not compiled, not tested, just typed.