//+------------------------------------------------------------------+ // ProjectName //…
- User
//+------------------------------------------------------------------+ //| ProjectName | //| Copyright 2020, CompanyName | //| http://www.companyname.net | //+------------------------------------------------------------------+ #property indicator_chart_window #property indicator_buffers 0 #property indicator_plots 0
//— входные параметры input int InpAtrPeriod = 10; // Период ATR
//±-----------------------------------------------------------------+ //| Функция инициализации пользовательского индикатора | //±-----------------------------------------------------------------+ int OnInit() { return (INIT_SUCCEEDED); }
//+------------------------------------------------------------------+ //| | //+------------------------------------------------------------------+ void OnDeinit(const int reason) { ObjectDelete(0,"priceHigh"); ObjectDelete(0,"priceLow"); ObjectDelete(0,"priceHigh_0.5"); ObjectDelete(0,"priceLow_0.5"); }
//±-----------------------------------------------------------------+ //| Функция итерации пользовательского индикатора | //±-----------------------------------------------------------------+ 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[]) { double H_L[10]; double openATR[10]; int m = 0;
// Расчет значений ATR с использованием данных месячного таймфрейма for(int i = 0; i < InpAtrPeriod && i < iBars(_Symbol, PERIOD_MN1); i++) { int shift = i; double maxHigh = iHigh(_Symbol, PERIOD_MN1, shift); double minLow = iLow(_Symbol, PERIOD_MN1, shift); openATR[m] = iOpen(_Symbol, PERIOD_MN1, shift); H_L[m] = NormalizeDouble(maxHigh - minLow, _Digits); m++; }
double ATR = 0; for(int i = 0; i < m - 1; i++) { double sum = H_L[i] + H_L[i + 1]; ATR += sum / 2 / openATR[i + 1] * 100; }
double ATRavg = NormalizeDouble(ATR / (m - 1), 2);
if(m > 0) { double priceHigh = openATR[0] + (openATR[0] * ATRavg / 100); double priceLow = openATR[0] - (openATR[0] * ATRavg / 100); double priceHigh_2 = openATR[0] + (openATR[0] * ATRavg / 200); double priceLow_2 = openATR[0] - (openATR[0] * ATRavg / 200);
code - Assistant
To convert the given MQL5 script for calculating and plotting ATR-based price levels into Pine Script (used for TradingView), we need to follow a more script-oriented design as Pine Script has a different structure and set of functionalities. Below is a Pine Script version that performs similar tasks: it calculates ATR-based levels and plots them on the chart.
pinescript - User
неправильно считается atr
- Assistant
Let's correct the ATR calculation. In Pine Script, the ATR is typically calculated using the built-in
ta.atrfunction, but if you need to compute it manually, we need to ensure that it's done correctly. Here is how you can adjust the script to properly calculate ATR-based price levels, utilizingta.atr.pinescript