简体   繁体   中英

How to calculate indicator buffer only once per day mql4

I have an indicator which gives one signal [Down Buffer]... I wish to only give signal once per day... Like after the first signal it will not paint any signal for the rest of the day! I have tested with below code it's now not painting at all?

//--- indicator buffers
double Buffer1[];
int day = 0;

int OnInit()
{   
  ........................
}

int OnCalculate(......)
 {

 //--- main loop
 for(int i = limit-1; i >= 0; i--)
 { 
  
  //Indicator Buffer 1
  if( here goes my condition )
    {
     if( day != Day() )
     {
        Buffer1[i] = High[i] + iATR(NULL, PERIOD_CURRENT, 14, i); //Set indicator value at Candlestick High + Average True Range
        day = Day();
     }
    }
  else
    {
     Buffer1[i] = EMPTY_VALUE;
    }
 }
 
 return(rates_total);
}

What is wrong with my code? It's now not showing any signal at all...

Note : I have removed some of the code to make it simple...

Use the following function to check whether it is a new day. It returns true if it is a new day, else returns false.

bool IsNewDay(){
   static datetime prevDay = -1;
   if( iTime(_Symbol, PERIOD_D1, 0) == prevDay ) return false;
   prevDay = iTime(_Symbol, PERIOD_D1, 0);
   return true;
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM