Вы упускаете торговые возможности:
- Бесплатные приложения для трейдинга
- 8 000+ сигналов для копирования
- Экономические новости для анализа финансовых рынков
Регистрация
Вход
Вы принимаете политику сайта и условия использования
Если у вас нет учетной записи, зарегистрируйтесь
Спасибо. Это, что надо!)
Скажите, я правильно понимаю, что если не вызывать индикатор в коде советника, а написать логику индикатора в самом советнике, а потом оперировать показаниями на определенном баре, то можно ускорить оптимизацию?
Код:
//| Test_iBands.mq5 |
//| Copyright © 2016, Vladimir Karputov |
//| http://wmua.ru/slesar/ |
//+------------------------------------------------------------------+
#property copyright "Copyright © 2016, Vladimir Karputov"
#property link "http://wmua.ru/slesar/"
#property version "1.00"
//---
int handle_iBands; // variable for storing the handle of the iBands indicator
//+------------------------------------------------------------------+
//| Expert initialization function |
//+------------------------------------------------------------------+
int OnInit()
{
//--- create handle of the indicator iBands
handle_iBands=iBands(Symbol(),Period(),20,0,2.0,PRICE_CLOSE);
//--- if the handle is not created
if(handle_iBands==INVALID_HANDLE)
{
//--- tell about the failure and output the error code
PrintFormat("Failed to create handle of the iBands indicator for the symbol %s/%s, error code %d",
Symbol(),
EnumToString(Period()),
GetLastError());
//--- the indicator is stopped early
return(INIT_FAILED);
}
//---
return(INIT_SUCCEEDED);
}
//+------------------------------------------------------------------+
//| Expert deinitialization function |
//+------------------------------------------------------------------+
void OnDeinit(const int reason)
{
//---
}
//+------------------------------------------------------------------+
//| Expert tick function |
//+------------------------------------------------------------------+
void OnTick()
{
//---
double upper =iBandsGet(UPPER_BAND,0);
double lower =iBandsGet(LOWER_BAND,0);
double middle=iBandsGet(BASE_LINE,0);
//---
Comment("Upper ",DoubleToString(upper,Digits()+1),"\n",
"Lower ",DoubleToString(lower,Digits()+1),"\n",
"Middle ",DoubleToString(middle,Digits()+1));
}
//+------------------------------------------------------------------+
//| Get value of buffers for the iBands |
//| the buffer numbers are the following: |
//| 0 - BASE_LINE, 1 - UPPER_BAND, 2 - LOWER_BAND |
//+------------------------------------------------------------------+
double iBandsGet(const int buffer,const int index)
{
double Bands[];
ArraySetAsSeries(Bands,true);
//--- reset error code
ResetLastError();
//--- fill a part of the iStochasticBuffer array with values from the indicator buffer that has 0 index
if(CopyBuffer(handle_iBands,buffer,0,index+1,Bands)<0)
{
//--- if the copying fails, tell the error code
PrintFormat("Failed to copy data from the iBands indicator, error code %d",GetLastError());
//--- quit with zero result - it means that the indicator is considered as not calculated
return(0.0);
}
return(Bands[index]);
}
//+------------------------------------------------------------------+
и результат работы:
CopyBuffer(handle_iBands,buffer,0,index+1,Bands)
Параметры "0" и "index+1" не надо поменять местами? Ведь, тогда получается, что последним элементом массива Bands будет ноль. И почему "index+1", а не "index"?
Спасибо за замечание - я неэкономно копировал - от элемента "0", до элемента "index". Экономный вариант будет такой:
//| Get value of buffers for the iBands |
//| the buffer numbers are the following: |
//| 0 - BASE_LINE, 1 - UPPER_BAND, 2 - LOWER_BAND |
//+------------------------------------------------------------------+
double iBandsGet(const int buffer,const int index)
{
double Bands[1];
//--- reset error code
ResetLastError();
//--- fill a part of the iStochasticBuffer array with values from the indicator buffer that has 0 index
if(CopyBuffer(handle_iBands,buffer,index,1,Bands)<0)
{
//--- if the copying fails, tell the error code
PrintFormat("Failed to copy data from the iBands indicator, error code %d",GetLastError());
//--- quit with zero result - it means that the indicator is considered as not calculated
return(0.0);
}
return(Bands[0]);
}
Объявляем сразу статический массив:
потом копируем один элемент:
с позиции index.
Спасибо за замечание - я неэкономно копировал - от элемента "0", до элемента "index". Экономный вариант будет такой:
//| Get value of buffers for the iBands |
//| the buffer numbers are the following: |
//| 0 - BASE_LINE, 1 - UPPER_BAND, 2 - LOWER_BAND |
//+------------------------------------------------------------------+
double iBandsGet(const int buffer,const int index)
{
double Bands[1];
//--- reset error code
ResetLastError();
//--- fill a part of the iStochasticBuffer array with values from the indicator buffer that has 0 index
if(CopyBuffer(handle_iBands,buffer,index,1,Bands)<0)
{
//--- if the copying fails, tell the error code
PrintFormat("Failed to copy data from the iBands indicator, error code %d",GetLastError());
//--- quit with zero result - it means that the indicator is considered as not calculated
return(0.0);
}
return(Bands[0]);
}
Объявляем сразу статический массив:
потом копируем один элемент:
с позиции index.
Я уж боялся, что задаю глупые вопросы и еще, что совсем ничего не понимаю))
Тогда, вот еще один момент:
{
if(symbol==NULL)
symbol=Symbol();
if(timeframe==0)
timeframe=Period();
double Low[];
double low=0;
ArraySetAsSeries(Low,true);
int copied=CopyLow(symbol,timeframe,index,1,Low);
if(copied>0) low=Low[0];
return(low);
}
Это часть кода из файла 123.mq5, который Вы корректировали. Я правильно понимаю, что здесь тоже лучше будет создать статический массив на один элемент?
Я уж боялся, что задаю глупые вопросы и еще, что совсем ничего не понимаю))
Тогда, вот еще один момент:
{
if(symbol==NULL)
symbol=Symbol();
if(timeframe==0)
timeframe=Period();
double Low[];
double low=0;
ArraySetAsSeries(Low,true);
int copied=CopyLow(symbol,timeframe,index,1,Low);
if(copied>0) low=Low[0];
return(low);
}
Это часть кода из файла 123.mq5, который Вы корректировали. Я правильно понимаю, что здесь тоже лучше будет создать статический массив на один элемент?