Alexey Belyakov: I changed it and get error: " 'array_atr' - invalid array access"
maybe something will help - you just need to create an indicator, not an expert
- The Expert Advisor works in the same way, but it will be displayed in the tester
//+------------------------------------------------------------------+//| тест.mq5 |//| Copyright 2021, MetaQuotes Ltd. |//| https://www.mql5.com |//+------------------------------------------------------------------+#property copyright"Copyright 2021, MetaQuotes Ltd."#property link"https://www.mql5.com"#property version"1.00"#property indicator_separate_window#property indicator_buffers1#property indicator_plots1//--- plot iATR#property indicator_label1"iATR"#property indicator_type1DRAW_LINE#property indicator_color1clrLightSeaGreen#property indicator_style1STYLE_SOLID#property indicator_width11//--- входные параметрыinputint atr_period=14; // период для вычисленияinputstring symbol=" "; // символinputENUM_TIMEFRAMES period=PERIOD_CURRENT; // таймфрейм//--- индикаторный буферdouble iATRBuffer[];
//--- переменная для хранения хэндла индикатора iACint handle;
//--- переменная для храненияstring name=symbol;
//--- имя индикатора на графикеstring short_name;
//--- будем хранить количество значений в индикаторе Average True Rangeint bars_calculated=0;
//+------------------------------------------------------------------+//| Custom indicator initialization function |//+------------------------------------------------------------------+intOnInit()
{
//--- привязка массива к индикаторному буферуSetIndexBuffer(0,iATRBuffer,INDICATOR_DATA);
//--- определимся с символом, на котором строится индикатор
name=symbol;
//--- удалим пробелы слева и справаStringTrimRight(name);
StringTrimLeft(name);
//--- если после этого длина строки name нулеваяif(StringLen(name)==0)
{
//--- возьмем символ с графика, на котором запущен индикатор
name=_Symbol;
}
//--- создадим хэндл индикатора
handle=iATR(name,period,atr_period);
if(handle==INVALID_HANDLE)
{
//--- сообщим о неудаче и выведем номер ошикбиPrintFormat("Не удалось создать хэндл индикатора iATR для пары %s/%s, код ошибки %d",
name,
EnumToString(period),
GetLastError());
//--- работа индикатора завершается досрочноreturn(INIT_FAILED);
}
//--- покажем на какой паре символ/таймфрейм рассчитан индикатор Average True Range
short_name=StringFormat("iATR(%s/%s, period=%d)",name,EnumToString(period),atr_period);
IndicatorSetString(INDICATOR_SHORTNAME,short_name);
//--- нормальное выполнение инициализации индикатора//---return(INIT_SUCCEEDED);
}
//+------------------------------------------------------------------+//| Custom indicator iteration function |//+------------------------------------------------------------------+intOnCalculate(constint rates_total,
constint prev_calculated,
constdatetime &time[],
constdouble &open[],
constdouble &high[],
constdouble &low[],
constdouble &close[],
constlong &tick_volume[],
constlong &volume[],
constint &spread[])
{
//---- проверка количества баров на достаточность для расчетаif(BarsCalculated(handle)<rates_total
||rates_total<0)
return(0);
//---- объявления локальных переменныхint to_copy,limit;
//---- расчеты необходимого количества копируемых данных и//стартового номера limit для цикла пересчета баровif(prev_calculated>rates_total || prev_calculated<=0)// проверка на первый старт расчета индикатора
{
to_copy=rates_total; // расчетное количество всех баров
limit=rates_total-1; // стартовый номер для расчета всех баров
}
else
{
to_copy=rates_total-prev_calculated+1; // расчетное количество только новых баров
limit=rates_total-prev_calculated; // стартовый номер для расчета новых баров
}
//---- копируем вновь появившиеся данные в массивыif(CopyBuffer(handle,0,0,to_copy,iATRBuffer)<=0)
return(0);
//---- индексация элементов в массивах как в таймсерияхArraySetAsSeries(iATRBuffer,true);
ArraySetAsSeries(open,true);
ArraySetAsSeries(high,true);
ArraySetAsSeries(low,true);
ArraySetAsSeries(close,true);
//--- return value of prev_calculated for next callreturn(rates_total);
}
//+------------------------------------------------------------------+
error : implicit conversion from 'number' to 'string'
is there something wrong with the pluses?
NOT an implicit conversion. It's when you add strings to numbers, the numbers are converted to string variables. And you need an explicit one. and hopefully trendstep has a string type. )))
I changed it and get error: " 'array_atr' - invalid array access "
maybe something will help - you just need to create an indicator, not an expert
- The Expert Advisor works in the same way, but it will be displayed in the tester
Changed and get error: " 'array_atr' - invalid array access "
An array element is referenced with '[]'.
For example, a reference to a null element:
array_atr[0]An array element is referenced with '[]'.
For example, a reference to a null element:
Vladimir Thank you! Done!
Vladimir Thank you! Done!I wanted to find out what you were trying to get and I only got as far as here and didn't get it.
I change MarketInfo to SymbolInfoInteger and I get - so:
and I get errors.
possible loss of data due to type conversion
';' - open parenthesisexpectedPlease help me and tell me how it should work.
Hi!
I change MarketInfo to SymbolInfoInteger and I get - so:
and I get errors.
possible loss of data due to type conversion
';' - open parenthesisexpectedPlease help and write how it should be in fact.
Or better like this
Or better still
Now I can't figure out why it says this:
possible loss of data due to type conversion
What's wrong with it?
Thanks so much for your help !
Now I can't figure out why it says this:
possible loss of data due to type conversion
What's wrong here?
Long or bul Not int.
Long or Bull Not Int.
Now it's not clear - what's wrong - here:
error : implicit conversion from 'number' to 'string'
is there something wrong with the pluses?
Thanks sorted !!!
Now it's not clear - what's wrong - here:
error : implicit conversion from 'number' to 'string'
is there something wrong with the pluses?
NOT an implicit conversion. It's when you add strings to numbers, the numbers are converted to string variables. And you need an explicit one. and hopefully trendstep has a string type. )))