//+------------------------------------------------------------------+ // 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 InpMonthsToCalculate = 1; // Количество месяцев для расчета
//±-----------------------------------------------------------------+ //| Функция инициализации пользовательского индикатора | //±-----------------------------------------------------------------+ int OnInit() { return (INIT_SUCCEEDED); 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[]) {
for(int month = 0; month < InpMonthsToCalculate; month++) {
double H_L[10]; double openATR[10]; int m = 0; // Расчет значений ATR с использованием данных месячного таймфрейма for(int i = 0; i < InpAtrPeriod && i + month < iBars(_Symbol, PERIOD_MN1); i++) { int shift = i + month; 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); string suffix = IntegerToString(month); datetime time_start = iTime(_Symbol, PERIOD_MN1, month); datetime time_end = time_start + 31 * 24 * 60 * 60; ObjectCreate(0, "priceHigh", OBJ_TREND, 0, time_start, priceHigh, time_end, priceHigh); ObjectCreate(0, "priceLow", OBJ_TREND, 0, time_start, priceLow, time_end, priceLow); ObjectCreate(0, "priceHigh_0.5", OBJ_TREND, 0, time_start, priceHigh_2, time_end, priceHigh_2); ObjectCreate(0, "priceLow_0.5", OBJ_TREND, 0, time_start, priceLow_2, time_end, priceLow_2); ObjectSetInteger(0, "priceHigh", OBJPROP_COLOR, clrCrimson); ObjectSetInteger(0, "priceLow", OBJPROP_COLOR, clrCrimson); ObjectSetInteger(0, "priceHigh_0.5", OBJPROP_COLOR, clrBlue); ObjectSetInteger(0, "priceLow_0.5", OBJPROP_COLOR, clrBlue); ObjectSetInteger(0, "priceHigh", OBJPROP_WIDTH, 2); ObjectSetInteger(0, "priceLow", OBJPROP_WIDTH, 2); ObjectSetInteger(0, "priceHigh_0.5", OBJPROP_WIDTH, 2); ObjectSetInteger(0, "priceLow_0.5", OBJPROP_WIDTH, 2); } } - Assistant
- User
- Assistant
- User
все “ ” замени на " "
- Assistant
Конечно, вот исправленный код Pine Script с замененными кавычками:
//@version=5 indicator("ATR Levels", overlay=true) // входные параметры InpAtrPeriod = input.int(10, title="Период ATR") InpMonthsToCalculate = input.int(1, title="Количество месяцев для расчета") // функция для получения значения ATR atrValue = ta.atr(InpAtrPeriod) // получение месячных данных var float[] openATR = array.new_float(0) var float[] H_L = array.new_float(0) var int m = 0 for month = 0 to (InpMonthsToCalculate - 1) highArray = request.security(syminfo.tickerid, "M", high) lowArray = request.security(syminfo.tickerid, "M", low) openArray = request.security(syminfo.tickerid, "M", open) for i = 0 to (InpAtrPeriod - 1) if (i + month < array.size(highArray)) maxHigh = array.get(highArray, i + month) minLow = array.get(lowArray, i + month) openValue = array.get(openArray, i + month) if not na(maxHigh) and not na(minLow) and not na(openValue) array.push(openATR, openValue) array.push(H_L, maxHigh - minLow) m := m + 1 // вычисление ATR среднего значения float ATR = 0.0 if m > 1 for i = 0 to (m - 2) sum = array.get(H_L, i) + array.get(H_L, i + 1) ATR := ATR + sum / 2 / array.get(openATR, i + 1) * 100 ATR_avg = ATR / (m - 1) // цены для отображения на графике priceHigh = array.get(openATR, 0) * (1 + ATR_avg / 100) priceLow = array.get(openATR, 0) * (1 - ATR_avg / 100) priceHigh_half = array.get(openATR, 0) * (1 + ATR_avg / 200) priceLow_half = array.get(openATR, 0) * (1 - ATR_avg / 200) // создание линий на графике hline(priceHigh, title="priceHigh", color=color.new(color.red, 0), linewidth=2) hline(priceLow, title="priceLow", color=color.new(color.red, 0), linewidth=2) hline(priceHigh_half, title="priceHigh_0.5", color=color.new(color.blue, 0), linewidth=2) hline(priceLow_half, title="priceLow_0.5", color=color.new(color.blue, 0), linewidth=2) - User
Cannot call 'array.size' with argument 'id'='highArray'. An argument of 'series float' type was used but a 'array<fun_arg>' is expected. что делать
- Assistant
Ошибка
Cannot call 'array.size' with argument 'id'='highArray'. An argument of 'series float' type was used but a 'array<fun_arg>' is expected.указывает на то, что переменная является серией значений (), а не массивом (). В этой ошибке нам нужно обращаться к серии значений напрямую, вместо того чтобы взаимодействовать с ними как с массивом. - User
Could not find function or function reference 'min' что делатть
- Assistant