Problems with iCustom

 

Hello

I am having issues with grabbing data from an indicator and saving/using that in a multi currency EA. I made loops and used array's for each currency and the numbers all come in and work but every tick or update on timer a few of the values are duplicates of the preceding currency's value. I am using iRSI and iMA for the mutli-currency and those values don't duplicate or anything so I know that I am using the array's and loops properly. It's just that when the data updates some values from the indicator duplicate, so I can only assume it's an issue with my use of iCustom or that the indicator needs to be adapted somehow to work with all the currencies (which I thought natively happens anyway).

This is the relevant parts of the EA.

void OnTick() {
   for(int i=0;i<ArraySize(TradePair);i++) {
      if(Point==0.0001 || Point==0.01) { PairPip=MarketInfo(TradePair[i],MODE_POINT);pipsfactor=1;} 
         else if(Point==0.00001 || Point==0.001) {PairPip=MarketInfo(TradePair[i],MODE_POINT)*10; pipsfactor=10;}
     bid[i]= MarketInfo(TradePair[i],MODE_BID); ask[i]= MarketInfo(TradePair[i],MODE_ASK);
//-------------------------------------------
Lev_A[i]=iCustom(TradePair[i],0,"ICWR_Chirag",ExtDepth,ExtDeviation,ExtBackstep,WaveHeight,0,0);
Pri_1[i]=ObjectGetDouble(TradePair[i],"ActiveWave",OBJPROP_PRICE1,1);
Pri_2[i]=ObjectGetDouble(TradePair[i],"ActiveWave",OBJPROP_PRICE2,1);

if(Pri_1[i]>Pri_2[i]){DColor[i]=BearColor;
   Pri_100P[i]=Pri_1[i];//100% level
   Pri_75P[i]=Pri_2[i] + (Pri_1[i]-Pri_2[i])*0.75;//75% level
   Pri_61P[i]=Pri_2[i] + (Pri_1[i]-Pri_2[i])*0.618;//61.8% level
   Pri_50P[i]=Pri_2[i] + (Pri_1[i]-Pri_2[i])*0.5;//50% level
   Pri_38P[i]=Pri_2[i] + (Pri_1[i]-Pri_2[i])*0.382;//38.2% level
   Pri_25P[i]=Pri_2[i] + (Pri_1[i]-Pri_2[i])*0.25;//25% level
   Pri_0P[i]=Pri_2[i];//0% level
if(iClose(TradePair[i],0,1)>Pri_61P[i] && iClose(TradePair[i],0,1)<Pri_38P[i]) Channel[i]=Green;}

else{DColor[i]=BullColor;
   Pri_100P[i]=Pri_1[i];//100% level
   Pri_75P[i]=Pri_1[i] + (Pri_2[i]-Pri_1[i])*0.25;//75% level
   Pri_61P[i]=Pri_1[i] + (Pri_2[i]-Pri_1[i])*0.382;//61.8% level
   Pri_50P[i]=Pri_1[i] + (Pri_2[i]-Pri_1[i])*0.5;//50% level
   Pri_38P[i]=Pri_1[i] + (Pri_2[i]-Pri_1[i])*0.618;//38.2% level
   Pri_25P[i]=Pri_1[i] + (Pri_2[i]-Pri_1[i])*0.75;//25% level 
   Pri_0P[i]=Pri_2[i];//0% level
if(iClose(TradePair[i],0,1)<Pri_61P[i] && iClose(TradePair[i],0,1)>Pri_38P[i]) Channel[i]=Green;}
}
}

void OnTimer() {
   for(int i=0;i<ArraySize(TradePair);i++) {
         int Decimal=MarketInfo(TradePair[i],MODE_DIGITS);
         if(Point==0.0001 || Point==0.01) {PairPip=MarketInfo(TradePair[i],MODE_POINT); pipsfactor=1;} 
         else if(Point==0.00001 || Point==0.001) {PairPip=MarketInfo(TradePair[i],MODE_POINT)*10; pipsfactor=10;}

/*       ObjectDelete("0 "+StringSubstr(TradePair[i],0,6));
       ObjectDelete("25 "+StringSubstr(TradePair[i],0,6));
       ObjectDelete("382 "+StringSubstr(TradePair[i],0,6));
       ObjectDelete("618 "+StringSubstr(TradePair[i],0,6));
       ObjectDelete("75 "+StringSubstr(TradePair[i],0,6));
       ObjectDelete("100 "+StringSubstr(TradePair[i],0,6));*/



         SetText("0   ", DoubleToStr(Pri_0P[i],Decimal),  650,(i*16),clrWhite,8);
         SetText("25  ", DoubleToStr(Pri_25P[i],Decimal), 700,(i*16),clrWhite,8);
         SetText("382 ", DoubleToStr(Pri_38P[i],Decimal), 750,(i*16),clrWhite,8);
         SetText("618 ", DoubleToStr(Pri_61P[i],Decimal), 800,(i*16),clrWhite,8);
         SetText("75  ", DoubleToStr(Pri_75P[i],Decimal), 850,(i*16),clrWhite,8);
         SetText("100 ", DoubleToStr(Pri_100P[i],Decimal),900,(i*16),clrWhite,8);
  }
}

Any ideas? I can provide any other information that you may need to help me.

Thanks

 
  1. Lev_A[i]=iCustom(TradePair[i],0,"ICWR_Chirag",ExtDepth,ExtDeviation,ExtBackstep,WaveHeight,0,0);
    Why did you post your MT4 question in the Root / MT5 EA section instead of the MQL4 section, (bottom of the Root page?)
              General rules and best pratices of the Forum. - General - MQL5 programming forum

  2. On MT4: Unless the current chart is the specific pair/TF referenced, you must handle 4066/4073 errors.
              Download history in MQL4 EA - MQL4 and MetaTrader 4 - MQL4 programming forum

  3. if(Point==0.0001 || Point==0.01) { PairPip=MarketInfo(TradePair[i],MODE_POINT);pipsfactor=1;} 
             else if(Point==0.00001 || Point==0.001) {PairPip=MarketInfo(TradePair[i],MODE_POINT)*10; pipsfactor=10;}
    The predefine variable Point is only for the current pair. Rewrite using the actual symbol's PairPip.

  4. Do not assume that a bar index on the current chart is the same on other charts. (Other chart may have started a new bar, but the current chart hasn't yet received a new tick.) Always use iBarShift.

  5. You should encapsulate your iCustom calls to make your code self-documenting.
              Detailed explanation of iCustom - MQL4 and MetaTrader 4 - MQL4 programming forum
 
whroeder1:
  1. Why did you post your MT4 question in the Root / MT5 EA section instead of the MQL4 section, (bottom of the Root page?)
              General rules and best pratices of the Forum. - General - MQL5 programming forum

  2. On MT4: Unless the current chart is the specific pair/TF referenced, you must handle 4066/4073 errors.
              Download history in MQL4 EA - MQL4 and MetaTrader 4 - MQL4 programming forum

  3. The predefine variable Point is only for the current pair. Rewrite using the actual symbol's PairPip.

  4. Do not assume that a bar index on the current chart is the same on other charts. (Other chart may have started a new bar, but the current chart hasn't yet received a new tick.) Always use iBarShift.

  5. You should encapsulate your iCustom calls to make your code self-documenting.
              Detailed explanation of iCustom - MQL4 and MetaTrader 4 - MQL4 programming forum

Hello,

Thanks for your reply.

1. I'm truly sorry, I didn't mean to do that. In my haste and frustration I must have overlooked this small but important detail. Once again I apologize.

2. I have the chart on the correct TF but being that it handles trades for 28 pairs, I do not have all the charts open. I have not been getting any errors in the Journal or Experts tab though.

3. Do you mean by making PairPip an array for example PairPip[i]  or are you saying i shouldnt use Point and should go directly with something like:  

if(MarketInfo(TradePair[i],MODE_POINT)==.0001 || MarketInfo(TradePair[i],MODE_POINT)==.01){
   PairPip[i]=MarketInfo(TradePair[i],MODE_POINT);
   pipsfactor=1;
   } 
else if(MarketInfo(TradePair[i],MODE_POINT)==0.00001 || MarketInfo(TradePair[i],MODE_POINT)==0.001){
   PairPip[i]=MarketInfo(TradePair[i],MODE_POINT)*10; 
   pipsfactor=10;
   }

4. That sounds like great and logical advice, but I am afraid that I don't really know how to implement what you are saying. Could you give me an example, of how to do it. I understand the iBarShift format etc, but I don't really understand how to use it properly.

5. How do I do this? Just by adding { } like.....

Lev_A[i]={iCustom(TradePair[i],0,"ICWR_Chirag",ExtDepth,ExtDeviation,ExtBackstep,WaveHeight,0,0);}
 

I looked at the link under your 2nd point and I can see that I am probably having errors without even knowing it as the charts i need may not be updating. since i use the 5m, 1h, 4h and daily charts for 28 pairs.

I tried to follow through your post but couldn't make it work for me. I put:

void OnTick(){
   while(!download_history(PERIOD_M15) ){ Sleep(1000); RefreshRates(); }
}

into the Ontick() section of my EA.


I then copied this section into the top portion of my EA. It looks like I am supposed to replace THIS_SYMBOL with my TradePair[i] variable, but my variable is calculated much further down in my OnTimer() function.

#define HR2400 PERIOD_D1 * 60    // 86400 = 24 * 3600
int      TimeOfDay(datetime when=0){      if(when == 0)  when = TimeCurrent();
                                          return( when % HR2400 );            }
datetime DateOfDay(datetime when=0){      if(when == 0)  when = TimeCurrent();
                                          return( when - TimeOfDay(when) );   }
#define SYMBOL string
#define THIS_SYMBOL ""
bool  download_history(ENUM_TIMEFRAMES period=PERIOD_CURRENT){
   return download_history(_Symbol, period); 
}
bool  download_history(
      SYMBOL            symbol=THIS_SYMBOL,     ///< The symbol required.
      ENUM_TIMEFRAMES   period=PERIOD_CURRENT   /**< The standard timeframe.*/){
   if(symbol == THIS_SYMBOL)     symbol = _Symbol;
   if(period == PERIOD_CURRENT)  period = _Period;
   datetime today = DateOfDay();
   ResetLastError();
   datetime other = iTime(symbol, period, 0);
   if(_LastError == 0 
   && today == DateOfDay(other)) return true;   
   if(_LastError != ERR_HISTORY_WILL_UPDATED
   && _LastError != ERR_NO_HISTORY_DATA)                   // the ")" after DATA was missing, I thought I had to add it. Please confirm
      Print(StringFormat("iTime(%s,%i) Failed: %i", symbol, period,_LastError));
   return false;
}
Reason: