I am attempting to map out the Daily Highs of the last 7 days using the code below:
`
#include <TradeTrade.mqh> // Get code from other places
//#include <scriptsfunctions.mqh>
CTrade Trade;
MqlRates DailyOHLC[]; // Declare the arrays at the global scope
int OnInit()
{
EventSetTimer(172799); //every 2 days - 1 second
ArraySetAsSeries(DailyOHLC, true);
return (INIT_SUCCEEDED);
}
//+------------------------------------------------------------------+
//| Expert deinitialization function |
//+------------------------------------------------------------------+
void OnDeinit(const int reason)
{
//---
EventKillTimer();
}
//+------------------------------------------------------------------+
//| Expert tick function |
//+------------------------------------------------------------------+
void OnTick()
{
}
void OnTimer() {
// Copy the latest daily OHLC data into the array
int DailyPrices = CopyRates(_Symbol, PERIOD_D1, 0, 14, DailyOHLC);
// Check if data was successfully copied
if (DailyPrices > 0) {
Print("Successfully copied daily prices. Number of items in DailyOHLC: ", DailyPrices);
// Print the high values of the last 7 daily candles
Print("Daily OHLC Highs: ", DailyOHLC[0].high, " ", DailyOHLC[1].high, " ", DailyOHLC[2].high, " ",
DailyOHLC[3].high, " ", DailyOHLC[4].high, " ", DailyOHLC[5].high, " ", DailyOHLC[6].high);
} else {
Print("Failed to copy daily prices. Return value: ", DailyPrices);
}
}
the problem I am facing is that when I print the daily prices every 2 days or so, I do not find the array to have always changed. what am I doing wrong? is this a data problem? is there a better way?
Journal
I initially set this up to update daily but realised that the “high” of the current candle when set at midnight would just be the opening price, so to combat this I changed the Ontimer function to run every 2 days minus 1 second ( should receive the high of current candle unless current candle high is at close).
C R is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.