//+------------------------------------------------------------------+ //| 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 clrRed #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, SMA26Buffer); SetIndexLabel(0, "open"); SetIndexLabel(1, "close"); SetIndexLabel(2, "co"); SetIndexLabel(3, "sma26"); 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; datetime currentTime = time[bufferIndex]; datetime m15Time = iTime(NULL, PERIOD_M15, iBarShift(NULL, PERIOD_M15, currentTime, true)); int m15bar = iBarShift(NULL, PERIOD_M15, currentTime, true); double m15Open = iOpen(NULL, PERIOD_M15, iBarShift(NULL, PERIOD_M15, m15Time)); double m15Close = iClose(NULL, PERIOD_M15, iBarShift(NULL, PERIOD_M15, m15Time)); OpenBuffer[bufferIndex] = m15Open; CloseBuffer[bufferIndex] = m15Close; COBuffer[bufferIndex] = CloseBuffer[bufferIndex] - OpenBuffer[bufferIndex]; // Calculate the SMA of the last 26 COBuffer values (except the live candle) double sum = 0; int count = 0; for(int j = bufferIndex + 1; j < rates_total && count < 26; j++, count++) { sum += COBuffer[j]; } S1Buffer[bufferIndex] = (count > 0) ? sum / count : 0; } // Return that calculation is successful return(rates_total); }