//±-----------------------------------------------------------------+ // ATR.mq5 //…
- User
//±-----------------------------------------------------------------+ //| ATR.mq5 | //| Copyright 2024, MetaQuotes Ltd. | //| https://www.mql5.com | //±-----------------------------------------------------------------+ #property copyright "Copyright 2024, MetaQuotes Ltd." #property link "https://www.mql5.com" #property version"1.00" #property indicator_chart_window #property indicator_buffers 0 #property indicator_plots 0
//— input parameters input int InpAtrPeriod = 10; // ATR period
int PeriodEXT(ENUM_TIMEFRAMES tf) { switch(tf) { case PERIOD_M1 : return 10; case PERIOD_M5 : return 10; case PERIOD_M15 : return 10; case PERIOD_M30 : return 10; case PERIOD_H1 : return 10; case PERIOD_H4 : return 10; case PERIOD_D1 : return 5; case PERIOD_W1 : return 14; case PERIOD_MN1 : return 31; default : return 14; // Default period } } int ExtendPeriodDays = 0; // Number of days to extend the lines
//±-----------------------------------------------------------------+ //| Custom indicator initialization function | //±-----------------------------------------------------------------+ int OnInit() { return (INIT_SUCCEEDED); }
//±-----------------------------------------------------------------+ //| Custom indicator iteration function | //±-----------------------------------------------------------------+ 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[]) { ExtendPeriodDays = PeriodEXT(Period()); double H_L[10]; int m = 0; double openATR[10];
// Calculate moving average and MADiff using monthly timeframe data for (int i = 0; i < InpAtrPeriod; i++) { int shift = i + 1; 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 < 9; i++) { double sum = H_L[i] + H_L[i + 1]; ATR += sum / 2 / openATR[i + 1] * 100; }
double ATRavg = NormalizeDouble(ATR / 9, 2);
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);
datetime time_end = iTime(_Symbol, PERIOD_M1, 0); // Extend the time_end by specified number of days time_end += ExtendPeriodDays * 24 * 60 * 60; // Compute time for 10 candles back from the current time datetime time_start = iTime(_Symbol, PERIOD_MN1, 1);
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);
- Assistant
- User
',' - open parenthesis expected TESTTEST.mq5 77 39 implicit conversion from 'number' to 'string' TESTTEST.mq5 77 33 ',' - open parenthesis expected TESTTEST.mq5 78 37 implicit conversion from 'number' to 'string' TESTTEST.mq5 78 31 ',' - open parenthesis expected TESTTEST.mq5 79 35 implicit conversion from 'number' to 'string' TESTTEST.mq5 79 29 ')' - open parenthesis expected TESTTEST.mq5 80 59 ',' - open parenthesis expected TESTTEST.mq5 99 39 implicit conversion from 'number' to 'string' TESTTEST.mq5 99 33 ',' - open parenthesis expected TESTTEST.mq5 103 41 implicit conversion from 'number' to 'string' TESTTEST.mq5 103 35
- Assistant
- User
нужно что бы он рисовал их до конца предыдущего месяца
- Assistant