Array outside the OnTick function

 

hey guys, got a problem here: I want my EA to do a price level calculation exactly once per day and compare it to the prize level from the day before. I also want the time the calculation happens to be a user input, as well as it working on multiple timeframes. The way i am doing this is basically with the iHighest function, with the count being a variable. the variable is calculated by the Bars() function and datetime inputs, which are calculated by TimeCurrent, then just picking the year, month and day and string them together in a datetime string form. anyways, main issue right now is, i have to somehow access the datetime from 24 hours before the current datetime. i figured, this could be done by just storing the datetime in an array, and since the calculation is only done once per day you can just assign array[1]  =  array[0] at the end of the function. however, the array is reset every time the calculations are made, so the array[1] loses its value. taking the array out of the onTick function gives me multiple errors, mainly "array declaration without type", which i dont really understand. no compilation errors if i put it inside the onTick function though. any ideas? 


string timeArray[];

ArraySetAsSeries(timeArray,true);

ArrayResize(timeArray,2,0);



void OnTick(){

   int amountBars;

   MqlDateTime structTime;

   TimeCurrent(structTime);

   

   int intMonth = structTime.mon;

   string stringMonth;

   if(structTime.mon < 10){

      stringMonth = "0" + IntegerToString(intMonth);

   }

   if(structTime.mon >= 10){

      stringMonth = IntegerToString(intMonth);

   }

   

   

   int intDay = structTime.day;

   string stringDay;

   if(structTime.day < 10){

      stringDay = "0" + IntegerToString(intDay);

   }

   if(structTime.day >= 10){

      stringDay = IntegerToString(intDay);

   }

   

   



   

   string currentTimeDate = "D'"+IntegerToString(structTime.year)+"."+stringMonth+"."+stringDay;

   timeArray[0] = currentTimeDate;

   if(timeArray[0] != timeArray[1]){

      Print("NEW DAY");

   }

      Print(timeArray[1]," ",timeArray[0]);



   timeArray[1] = timeArray[0];

   string lookbackTimeDate;

  // amountBars = Bars(_Symbol,PERIOD_CURRENT,timeArray[1],timeArray[0]);

}
 

What you want is already programmed may times : search and study (daily breakout) in documentation, forum and CodeBase: https://www.mql5.com/en/search#!keyword=daily%20breakout

Take one of these and change it according to your ideas. It's a lot faster and much less troublesome.

 
Carl Schreiber #:

What you want is already programmed may times : search and study (daily breakout) in documentation, forum and CodeBase: https://www.mql5.com/en/search#!keyword=daily%20breakout

Take one of these and change it according to your ideas. It's a lot faster and much less troublesome.

so through the link you provided i only found people selling their EAs or links to their websites. I would want to learn how to program it myself, not just for this specific EA but also just to learn how to do things like this in general. It's not even so much about the EA but more about the learning process.
 
Carl Schreiber #:

What you want is already programmed may times : search and study (daily breakout) in documentation, forum and CodeBase: https://www.mql5.com/en/search#!keyword=daily%20breakout

Take one of these and change it according to your ideas. It's a lot faster and much less troublesome.

also, in addition to noone actually showing their code over there, all of these strategies found when searching for "daily breakout" work only with the previous daily candle. it's a lot easier and i already coded it that way, i would like to be able to have other timeframes as well though, so from 4pm-4pm for example, or really any other time window imaginable.
 
EntropyM #: so through the link you provided i only found people selling their EAs or links to their websites. I would want to learn how to program it myself, not just for this specific EA but also just to learn how to do things like this in general. It's not even so much about the EA but more about the learning process.
Then restrict the search to the CodeBase (its the filters on the left) so that you only see those and not any from the market ... https://www.mql5.com/en/search#!keyword=daily%20breakout&module=mql5_module_codebase
Reason: