//+------------------------------------------------------------------+ //| CandleLines.mq4| //| Copyright 2024, YourNameHere | //| http://www.yourwebsite.com | //+------------------------------------------------------------------+ #property strict #property indicator_chart_window #property indicator_buffers 4 #property indicator_color1 clrBlack #property indicator_style1 STYLE_SOLID #property indicator_width1 2 #property indicator_color2 clrGreen #property indicator_style2 STYLE_SOLID #property indicator_width2 2 #property indicator_color3 clrBlue #property indicator_style3 STYLE_SOLID #property indicator_color4 clrOrange #property indicator_style4 STYLE_SOLID double OpenBuffer[]; double CloseBuffer[]; double COBuffer[]; double S1Buffer[]; int OnInit() { // Set the indicator buffers SetIndexBuffer(0, OpenBuffer); SetIndexBuffer(1, CloseBuffer); SetIndexBuffer(2, COBuffer); SetIndexBuffer(3, S1Buffer); SetIndexLabel(0, "open"); SetIndexLabel(1, "close"); SetIndexLabel(2, "co"); SetIndexLabel(3, "s1"); return(INIT_SUCCEEDED); } int OnCalculate(const int rates_total, const int prev_calculated, const datetime &time[], const double &open[], const double &high[], const double &low[], const double &close[], const long &tick_volume[], const long &volume[], const int &spread[]) { int barsToProcess = rates_total - prev_calculated; // Loop through the bars for(int i = 0; i < barsToProcess; i++) { int bufferIndex = rates_total - i - 1; // Get the time of the current bar datetime currentTime = time[bufferIndex]; // Find the corresponding M15 bar time datetime m15Time = iTime(NULL, PERIOD_M15, iBarShift(NULL, PERIOD_M15, currentTime, true)); int m15bar = iBarShift(NULL, PERIOD_M15, currentTime, true); // Get the open and close prices from the M15 timeframe double m15Open = iOpen(NULL, PERIOD_M15, iBarShift(NULL, PERIOD_M15, m15Time)); double m15Close = iClose(NULL, PERIOD_M15, iBarShift(NULL, PERIOD_M15, m15Time)); // Assign the M15 open and close prices to the buffers OpenBuffer[bufferIndex] = m15Open; CloseBuffer[bufferIndex] = m15Close; COBuffer[bufferIndex] = CloseBuffer[bufferIndex] - OpenBuffer[bufferIndex]; S1Buffer[bufferIndex] = iMAOnArray(COBuffer, 0, 26, 0, MODE_SMA, m15bar+1); } // Return that calculation is successful return(rates_total); }