Help to work my indicator only on WEDNESDAY

 

Dear coder, please help to modify my code that will restrict the indcator to work only on WEDNESDAY and when I load them on my chart it should be showing arrows only on wednesdays.

Thanking you

  int  DayOfWeek();
   
   
   for(int i = limit-1; i >= 0; i--)
     {
      if(iHigh(NULL,PERIOD_M30,i) > iHigh(NULL,PERIOD_M30,1+i)
      && iHigh(NULL,PERIOD_M30,1+i) < iHigh(NULL,PERIOD_M30,1+i+1) //Candlestick High crosses above Candlestick High
      
            
      && iClose(NULL,PERIOD_M30,i) == Close[i] 
      )
        {if(DayOfWeek()!=4 ) return(0);
         Buffer1[i] = Low[i] - 3 * myPoint; 
         if(i == 1 && Time[1] != time_alert) myAlert("indicator", "Buy"); 
         time_alert = Time[1];
        }
      else
        {
         Buffer1[i] = 0;
        }
      
      if(iLow(NULL,PERIOD_M30,i) < iLow(NULL,PERIOD_M30,1+i)
      && iLow(NULL,PERIOD_M30,1+i) > iLow(NULL,PERIOD_M30,1+i+1) //Candlestick Low crosses below Candlestick Low
      
      
      && iClose(NULL,PERIOD_M30,i) == Close[i] 
      )
        {if(DayOfWeek()!=4 ) return(0);
         Buffer2[i] = High[i] + 3 * myPoint; 
         if(i == 1 && Time[1] != time_alert) myAlert("indicator", "Sell"); 
         time_alert = Time[1];
        }
      else
        {
         Buffer2[i] = 0;
        }
     }
   return(rates_total);
  }
//+------------------------------------------------------------------+

in Advance.

 
change return(0) to return (rates_total)
 

... and :
DayOfWeek() returns zero-based day of the week (0-Sunday,1,2,3,4,5,6)

Thus Wednesday is 3 (not 4)

 
  1. Ralf Graf: DayOfWeek() returns zero-based day of the week (0-Sunday,1,2,3,4,5,6) Thus Wednesday is 3 (not 4)
    It returns an int for backwards compatibility. Use the enumeration and make your code self documenting, with no wrong numbers:
    ENUM_DAY_OF_WEEK dow = (ENUM_DAY_OF_WEEK)DayOfWeek();
    if(dow == WEDNESDAY) ...
               Symbol Properties - Environment State - Standard Constants, Enumerations and Structures - MQL4 Reference

  2. SIRAJ Multani: modify my code that will restrict the indcator to work only on WEDNESDAY and when I load them on my chart it should be showing arrows only on wednesdays.
    Ambiguous. Ralf's suggestion will allow the indicator to work only on Wednesday. But if it does work it will paint all bars. If you want to only paint Wednesday's bars you'll need:
    if( (ENUM_DAY_OF_WEEK)TimeDayOfWeek(Time[i])== Wednesday)
             Buffer1[i] = Low[i] - 3 * myPoint; 
  3.       if(iLow(NULL,PERIOD_M30,i) < iLow(NULL,PERIOD_M30,1+i)
          && iLow(NULL,PERIOD_M30,1+i) > iLow(NULL,PERIOD_M30,1+i+1) //Candlestick Low crosses below Candlestick Low
    
    You have restricted the indicator to the M30 chart. Why? If the chart is not M30 then you are mixing apples and oranges and you must handle 4066/4073 errors.
              Download history in MQL4 EA - MQL4 and MetaTrader 4 - MQL4 programming forum

  4. Your lookback is two.
              How to do your lookbacks correctly.

 
whroeder1:
  1. It returns an int for backwards compatibility. Use the enumeration and make your code self documenting, with no wrong numbers:           Symbol Properties - Environment State - Standard Constants, Enumerations and Structures - MQL4 Reference

  2. Ambiguous. Ralf's suggestion will allow the indicator to work only on Wednesday. But if it does work it will paint all bars. If you want to only paint Wednesday's bars you'll need:
  3. You have restricted the indicator to the M30 chart. Why? If the chart is not M30 then you are mixing apples and oranges and you must handle 4066/4073 errors.
              Download history in MQL4 EA - MQL4 and MetaTrader 4 - MQL4 programming forum

  4. Your lookback is two.
              How to do your lookbacks correctly.

I tried this it works, but with the PERIOD_M30 I get the solution by using iBarShift and that worked too.

Seriously guys, you are just awsome....you deserve lot of respect. Thank you so much for helping me.

 
SIRAJ Multani:

I tried this it works, but with the PERIOD_M30 I get the solution by using iBarShift and that worked too.

Seriously guys, you are just awsome....you deserve lot of respect. Thank you so much for helping me.

extern ENUM_DAY_OF_WEEK DAY = WEDNESDAY;
   
   
  
     Comment( DAY );
   return(0);
  }
//+------------------------------------------------------------------+

When I try this on Comment it returns 3 and not WEDNESDAY on the chart . On My chart I was expecting my Comment will display WEDNESDAY

I dont know where is the Mistake, please Help

 
string            as_string(ENUM_DAY_OF_WEEK dow, COUNT len=0){
   string DOW_xxx = EnumToString(dow);                         // DOW_XXX
   return StringSubstr(DOW_xxx, 4, len);                       // XXX
}
Comment( as_string(DAY) );
 
whroeder1:
Comment( as_string(DAY) );
   return(0);
}
//+------------------------------------------------------------------+

  



   string as_string(ENUM_DAY_OF_WEEK dow, COUNT len=0)
   {
   string DOW_xxx = EnumToString(dow);                         // DOW_XXX
   return StringSubstr(DOW_xxx, 4, len);                       // XXX
   }
   
   Comment( as_string(DAY) );
   


//+------------------------------------------------------------------+
void OnDeinit(const int reason)
  {
  Comment("");
   
  }

this gives me 4 errors

'COUNT' - declaration without type

'len' - comma expected   

'Comment' - declaration without type   
'len' - undeclared identifier  
 

 
SIRAJ Multani: this gives me 4 errors 'COUNT' - declaration without type
You couln't figure out that COUNT is a uint?
 
whroeder1:
You couln't figure out that COUNT is a uint?
sorry I could not find the solution how to add this code in which position of the indicator and how to interpret
 
whroeder1:
You couln't figure out that COUNT is a uint?
Please help me to complete this