//+------------------------------------------------------------------+ //| Copyright (C) 2026, boyvlad | //| https://www.mql5.com/en/users/boyvlad | //+------------------------------------------------------------------+ //--- Do not remove! #property tester_everytick_calculate //--- #property indicator_chart_window #property indicator_buffers 1 #property indicator_plots 1 //--- #property indicator_type1 DRAW_LINE #property indicator_color1 clrOrange #property indicator_style1 STYLE_SOLID #property indicator_width1 2 #property indicator_label1 "Applied price" //--- #property copyright "Copyright (C) 2026, boyvlad" #property link "https://www.mql5.com/en/users/boyvlad" input(name="Price") ENUM_APPLIED_PRICE inpAppliedPrice = PRICE_CLOSE; double buffer[]; int OnInit() { SetIndexBuffer(0, buffer, INDICATOR_DATA); return INIT_SUCCEEDED; } int OnCalculate(const int32_t rates_total, const int32_t 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 int32_t &spread[]) { if(rates_total < 2 || rates_total < prev_calculated) { PrintFormat(__FUNCTION__" Something went wrong. rates_total %i, prev_calculated %i", rates_total, prev_calculated); return 0; } int barIdxToRecalcFrom; switch(rates_total - prev_calculated) { case 0: case 1: barIdxToRecalcFrom = prev_calculated - 1; break; default: barIdxToRecalcFrom = 0; break; } for(int i = barIdxToRecalcFrom; i < rates_total; i++) buffer[i] = calculate(i, inpAppliedPrice, open, high, low, close); return rates_total; } double calculate(int barIdx, ENUM_APPLIED_PRICE a_mode, const double &open[], const double &high[], const double &low[], const double &close[]) { switch(a_mode) { case PRICE_OPEN: return open[barIdx]; case PRICE_HIGH: return high[barIdx]; case PRICE_LOW: return low[barIdx]; case PRICE_MEDIAN: return (high[barIdx] + low[barIdx]) / 2.0; case PRICE_TYPICAL: return (high[barIdx] + low[barIdx] + close[barIdx]) / 3.0; case PRICE_WEIGHTED: return (high[barIdx] + low[barIdx] + close[barIdx] + close[barIdx]) / 4.0; default: return close[barIdx]; } }