В данном случае нужно производить поэлементное копирование.
Как я понял , поэлементно - это при помощи функции OrderSelect () Тем не менее меня раздирает любопытство - есть у этого массива имя или нет ? У меня такое ощущение что имя этого массива является государственной тайной.
Есть индикатор написанной на mql5, надо переводить на mql4.
#property version"2.000"#property description"When the 'Main' and 'Signal' lines cross, the indicator signals ..."#property indicator_separate_window#property indicator_buffers2#property indicator_plots2//--- plot MACD_Last_Сrossing#property indicator_label1"MACD"#property indicator_type1DRAW_HISTOGRAM#property indicator_color1clrSilver#property indicator_style1STYLE_SOLID#property indicator_width12#property indicator_label2"Signal"#property indicator_type2DRAW_LINE#property indicator_color2clrRed#property indicator_style2STYLE_DASH#property indicator_width22//--- input parametersinput group "MACD"inputint Inp_MACD_fast_ema_period= 12; // MACD: period for Fast average calculationinputint Inp_MACD_slow_ema_period= 26; // MACD: period for Slow average calculationinputint Inp_MACD_signal_period = 9; // MACD: period for their difference averaginginputENUM_APPLIED_PRICE Inp_MACD_applied_price = PRICE_CLOSE; // MACD: type of priceinput group "Alerts"inputstring InpSoundName = "alert.wav"; // Sound Nameinputuchar InpSoundRepetitions = 3; // Repetitionsinputuchar InpSoundPause = 3; // Pause, in secondsinputbool InpMain_and_Signal = true; // Main AND Signalinputbool InpMain_and_Zero = true; // Main AND '0'inputbool InpSignal_and_Zero = true; // Signal AND '0'//--- indicator buffersdouble MACDBuffer[];
double SignalBuffer[];
//---int handle_iMACD; // variable for storing the handle of the iMACD indicatorint bars_calculated = 0; // we will keep the number of values in the Moving Averages Convergence/Divergence indicatorint start = 0;
datetime m_last_sound = 0; // "0" -> D'1970.01.01 00:00';uchar m_repetitions = 0; //string m_text = ""; //datetime m_prev_bars = 0; // "0" -> D'1970.01.01 00:00';//+------------------------------------------------------------------+//| Custom indicator initialization function |//+------------------------------------------------------------------+intOnInit()
{
//--- indicator buffers mappingSetIndexBuffer(0,MACDBuffer,INDICATOR_DATA);
SetIndexBuffer(1,SignalBuffer,INDICATOR_DATA);
//--- create handle of the indicator iMACD
handle_iMACD=iMACD(Symbol(),Period(),Inp_MACD_fast_ema_period,Inp_MACD_slow_ema_period,
Inp_MACD_signal_period,Inp_MACD_applied_price);
//--- if the handle is not createdif(handle_iMACD==INVALID_HANDLE)
{
//--- tell about the failure and output the error codePrintFormat("Failed to create handle of the iMACD indicator for the symbol %s/%s, error code %d",
Symbol(),
EnumToString(Period()),
GetLastError());
//--- the indicator is stopped earlyreturn(INIT_FAILED);
}
start=Inp_MACD_fast_ema_period+Inp_MACD_slow_ema_period+Inp_MACD_signal_period;
//---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(rates_total<start)
return(0);
//--- number of values copied from the iMACD indicatorint values_to_copy;
//--- determine the number of values calculated in the indicatorint calculated=BarsCalculated(handle_iMACD);
if(calculated<=0)
{
PrintFormat("BarsCalculated() returned %d, error code %d",calculated,GetLastError());
return(0);
}
//--- if it is the first start of calculation of the indicator or if the number of values in the iMACD indicator changed//---or if it is necessary to calculated the indicator for two or more bars (it means something has changed in the price history)if(prev_calculated==0 || calculated!=bars_calculated || rates_total>prev_calculated+1)
{
//--- if the MACDBuffer array is greater than the number of values in the iMACD indicator for symbol/period, then we don't copy everything//--- otherwise, we copy less than the size of indicator buffersif(calculated>rates_total)
values_to_copy=rates_total;
else
values_to_copy=calculated;
}
else
{
//--- it means that it's not the first time of the indicator calculation, and since the last call of OnCalculate()//--- for calculation not more than one bar is added
values_to_copy=(rates_total-prev_calculated)+1;
}
//--- fill the arrays with values of the iMACD indicator//--- if FillArraysFromBuffer returns false, it means the information is nor ready yet, quit operationif(!FillArraysFromBuffers(MACDBuffer,SignalBuffer,handle_iMACD,values_to_copy))
return(0);
//--- memorize the number of values in the Moving Averages indicator Convergence/Divergence
bars_calculated=calculated;
//--- main loop//--- we work only at the time of the birth of new bardatetime time_0=time[rates_total-1];
if(time_0!=m_prev_bars)
{
m_last_sound = 0; // "0" -> D'1970.01.01 00:00';
m_repetitions = 0; //
m_text = "";
m_prev_bars = time_0;
}
//---int i=rates_total-1;
if((MACDBuffer[i-1]<SignalBuffer[i-1] && MACDBuffer[i]>SignalBuffer[i]) || (MACDBuffer[i-1]>SignalBuffer[i-1] && MACDBuffer[i]<SignalBuffer[i]) ||
(MACDBuffer[i-1]<0.0 && MACDBuffer[i]>0.0) || (MACDBuffer[i-1]>0.0 && MACDBuffer[i]<0.0))
{
if(m_repetitions>=InpSoundRepetitions)
return(rates_total);
//---datetime time_current=TimeCurrent();
if(time_current-m_last_sound>InpSoundPause)
{
//--- Main AND Signalif(InpMain_and_Signal)
{
if(MACDBuffer[i-1]<SignalBuffer[i-1] && MACDBuffer[i]>SignalBuffer[i])
{
PlaySound(InpSoundName);
Alert("MACD and Signal Intersection UP, ",TimeToString(time[i]));
m_last_sound=time_current;
m_repetitions++;
return(rates_total);
}
if(MACDBuffer[i-1]>SignalBuffer[i-1] && MACDBuffer[i]<SignalBuffer[i])
{
PlaySound(InpSoundName);
Alert("MACD and Signal Intersection DOWN, ",TimeToString(time[i]));
m_last_sound=time_current;
m_repetitions++;
return(rates_total);
}
}
//--- Main AND '0'if(InpMain_and_Zero)
{
if(MACDBuffer[i-1]<0.0 && MACDBuffer[i]>0.0)
{
PlaySound(InpSoundName);
Alert("MACD and Zero Intersection UP, ",TimeToString(time[i]));
m_last_sound=time_current;
m_repetitions++;
return(rates_total);
}
if(MACDBuffer[i-1]>0.0 && MACDBuffer[i]<0.0)
{
PlaySound(InpSoundName);
Alert("MACD and Zero Intersection DOWN, ",TimeToString(time[i]));
m_last_sound=time_current;
m_repetitions++;
return(rates_total);
}
}
//--- Signal AND '0'if(InpSignal_and_Zero)
{
if(SignalBuffer[i-1]<0.0 && SignalBuffer[i]>0.0)
{
PlaySound(InpSoundName);
Alert("Signal and Zero Intersection UP, ",TimeToString(time[i]));
m_last_sound=time_current;
m_repetitions++;
return(rates_total);
}
if(SignalBuffer[i-1]>0.0 && SignalBuffer[i]<0.0)
{
PlaySound(InpSoundName);
Alert("Signal and Zero Intersection DOWN, ",TimeToString(time[i]));
m_last_sound=time_current;
m_repetitions++;
return(rates_total);
}
}
}
}
//--- return value of prev_calculated for next callreturn(rates_total);
}
//+------------------------------------------------------------------+//| Indicator deinitialization function |//+------------------------------------------------------------------+voidOnDeinit(constint reason)
{
//---
}
//+------------------------------------------------------------------+//| Filling indicator buffers from the iMACD indicator |//+------------------------------------------------------------------+bool FillArraysFromBuffers(double &macd_buffer[], // indicator buffer of MACD valuesdouble &signal_buffer[], // indicator buffer of the signal line of MACDint ind_handle, // handle of the iMACD indicatorint amount // number of copied values
)
{
//--- reset error codeResetLastError();
//--- fill a part of the iMACDBuffer array with values from the indicator buffer that has 0 indexif(CopyBuffer(ind_handle,0,0,amount,macd_buffer)<0)
{
//--- if the copying fails, tell the error codePrintFormat("Failed to copy data from the iMACD indicator, error code %d",GetLastError());
//--- quit with zero result - it means that the indicator is considered as not calculatedreturn(false);
}
//--- fill a part of the SignalBuffer array with values from the indicator buffer that has index 1if(CopyBuffer(ind_handle,1,0,amount,signal_buffer)<0)
{
//--- if the copying fails, tell the error codePrintFormat("Failed to copy data from the iMACD indicator, error code %d",GetLastError());
//--- quit with zero result - it means that the indicator is considered as not calculatedreturn(false);
}
//--- everything is finereturn(true);
}
//
Для авторизации и пользования сайтом MQL5.com необходимо разрешить использование файлов Сookie.
Пожалуйста, включите в вашем браузере данную настройку, иначе вы не сможете авторизоваться.
Вы вошли в аккаунт. Двухфакторная аутентификация отключена. Настройте её заново и отсканируйте новый QR-код или продолжите с отключённой двухфакторной аутентификацией.
Задача такая, перебирая все акции из списка, смотреть значения скользящей. Как проще всего сделать?
Вот, вроде бы, простая логика. Но не открывает ордера советник. Есть мысли, как заставить? Спасибо.
Вот, вроде бы, простая логика. Но не открывает ордера советник. Есть мысли, как заставить? Спасибо.
OnTick(() внутри бесконечного цикла внутри OnInit() ?
И как OnTick() должен исполниться по Вашему?
OnTick(() внутри бесконечного цикла внутри OnInit() ?
И как OnTick() должен исполниться по Вашему?
Сперва даже не понял, что это. Жестоко)))
Является ли данный список(желтый) НЕ пользовательским массивом?
Является ли данный список(желтый) НЕ пользовательским массивом?
да
да
А как он называется? Какое его имя нужно указывать, если из него нужно копировать что то , или передавать в другие функции в качестве аргумента ?
А как он называется? Какое его имя нужно указывать, если из него нужно копировать что то , или передавать в другие функции в качестве аргумента ?
В данном случае нужно производить поэлементное копирование.
В данном случае нужно производить поэлементное копирование.
Как я понял , поэлементно - это при помощи функции OrderSelect () Тем не менее меня раздирает любопытство - есть у этого массива имя или нет ?
У меня такое ощущение что имя этого массива является государственной тайной.
Спасибо
Есть индикатор написанной на mql5, надо переводить на mql4.