Just to give an idea, you can use iTime to get the time for the previous day and avoid overcomplication of your loop
double prevDayClose(){
datetime prevDay = iTime(_Symbol, PERIOD_D1, 1); // Get the time of the previous dayint prevBar = iBarShift(_Symbol, PERIOD_D1, prevDay); // Get the bar index of the previous daydouble closePrice = iClose(_Symbol, PERIOD_D1, prevBar); // Get the close price of the previous dayreturn closePrice;
}
make separate functions for iHigh and iLow as it suits
Hello thank's but I do not understand how your suggestion should be useful for this problem
It will display the previous day high in a blue line buffer, and the previous day low in a red line buffer:
//+------------------------------------------------------------------+//| PreviousDayHighLow.mq5 |//| |//| |//+------------------------------------------------------------------+#property indicator_chart_window#property indicator_buffers2#property indicator_plots2#property indicator_label1"Previous Day High"#property indicator_label2"Previous Day Low"#property indicator_color1clrBlue#property indicator_color2clrRed#property indicator_type1DRAW_LINE#property indicator_type2DRAW_LINE#property indicator_style1STYLE_SOLID#property indicator_style2STYLE_SOLID#property indicator_width12#property indicator_width22// Define buffersdouble HighBuffer[];
double LowBuffer[];
// global varsdatetime timeToUse;
bool valuesCalculated = false;
ENUM_TIMEFRAMES prevTimeFrame = PERIOD_CURRENT;
//+------------------------------------------------------------------+//| Expert initialization function |//+------------------------------------------------------------------+intOnInit()
{
// Set the indicator labelIndicatorSetString(INDICATOR_SHORTNAME, "PrevDayHighLow");
// Create buffersSetIndexBuffer(0, HighBuffer);
SetIndexBuffer(1, LowBuffer);
ResetBuffers();
// Return initialization resultreturn(INIT_SUCCEEDED);
}
intOnCalculate(constint rates_total,
constint prev_calculated,
constdatetime &time[],
constdouble &open[],
constdouble &high[],
constdouble &low[],
constdouble &close[],
constlong &tick_volume[],
constlong &volume[],
constint &spread[]){
// Check if the timeframe has changedif (ChartPeriod() != prevTimeFrame){
prevTimeFrame = ChartPeriod();
ResetBuffers(); // Reset indicator buffers when the timeframe changes
valuesCalculated = false; // Reset the flag
}
timeToUse = iTime(_Symbol, PERIOD_D1, 1); // Get the time of the previous day// Calculate and store the previous day's high and low in the buffersif (!valuesCalculated){
for (int i = 0; i < rates_total; i++){
HighBuffer[i] = prevDayHigh(timeToUse);
LowBuffer[i] = prevDayLow(timeToUse);
}
valuesCalculated = true; // Set the flag to true
}
return rates_total;
}
void ResetBuffers(){
ArrayInitialize(HighBuffer, 0); // Reset the HighBuffer to 0ArrayInitialize(LowBuffer, 0); // Reset the LowBuffer to 0
}
double prevDayHigh(constdatetime prevDay){
int prevBar = iBarShift(_Symbol, PERIOD_D1, prevDay); // Get the bar index of the previous daydouble highPrice = iHigh(_Symbol, PERIOD_D1, prevBar); // Get the high price of the previous dayreturn highPrice;
}
double prevDayLow(constdatetime prevDay){
int prevBar = iBarShift(_Symbol, PERIOD_D1, prevDay); // Get the bar index of the previous daydouble lowPrice = iLow(_Symbol, PERIOD_D1, prevBar); // Get the low price of the previous dayreturn lowPrice;
}
It isn't keeping a trend of historic highs and lows of previous days, but I thought your only use case was to focus on the previous day highs and lows (before today)
It will display the previous day high in a blue line buffer, and the previous day low in a red line buffer:
It isn't keeping a trend of historic highs and lows of previous days, but I thought your only use case was to focus on the previous day highs and lows (before today)
Thank you vert much!!!
One question: why on MT4 this does not happen? I mean, i never had to create such a function to reinitialise the indicator.
It will automatically plot a colored horizontal line on the previous highs and lows of the selected period, and it will make the lines consistent on this price when switching timeframes.
Allow the use of cookies to log in to the MQL5.com website.
Please enable the necessary setting in your browser, otherwise you will not be able to log in.
You are signed in. Two-factor authentication has been disabled. Set it up again and scan a new QR code, or continue with two-factor authentication disabled.
I see, it certainly will.
Thank's for trying and giving your feedback.
Maybe someone else can jump in and offer any solution? Thank's
Just to give an idea, you can use iTime to get the time for the previous day and avoid overcomplication of your loop
make separate functions for iHigh and iLow as it suitsJust to give an idea, you can use iTime to get the time for the previous day and avoid overcomplication of your loop
make separate functions for iHigh and iLow as it suitsHello thank's but I do not understand how your suggestion should be useful for this problem
Hello thank's but I do not understand how your suggestion should be useful for this problem
It will display the previous day high in a blue line buffer, and the previous day low in a red line buffer:
It isn't keeping a trend of historic highs and lows of previous days, but I thought your only use case was to focus on the previous day highs and lows (before today)
It will display the previous day high in a blue line buffer, and the previous day low in a red line buffer:
It isn't keeping a trend of historic highs and lows of previous days, but I thought your only use case was to focus on the previous day highs and lows (before today)
Thank you vert much!!!
One question: why on MT4 this does not happen? I mean, i never had to create such a function to reinitialise the indicator.
Thank's
Thank you vert much!!!
One question: why on MT4 this does not happen? I mean, i never had to create such a function to reinitialise the indicator.
to be honest I'm not sure
Here is a new version of what I did which has more functionality with inputs:
https://www.mql5.com/en/code/46324
but I think I can develop it more so that it can also plot the previous candle open and close
to be honest I'm not sure
Here is a new version of what I did which has more functionality with inputs:
https://www.mql5.com/en/code/46324
but I think I can develop it more so that it can also plot the previous candle open and close
Good! Thank you :)