Any variable can be initialised when defined. If the variable is not explicitly initialized, the value stored in the variable can be whatever you want. Implicit initialization is not performed.
I have two builds of 687 (on different brokers), tried to compile both with the same result (but sometimes I get 30 correctly), I can not understand whether I'm dumb or the ski is not moving!
I'm trying to use MQL5.I have disassembled exp_tema.mq5 and modified the code. Now I should print in log MA of each candle (last 20). But I don't understand why some entries are missing in the log. I noticed that if ma[3] is missing in log, then there is no ma[13]. Why is this happening? Where is the error there?
inputstring Symb0 = "EURUSD";
inputbool Trade0 = true;
int MA_Shift0=1;
inputint MA_Per0 = 100;
//+-----------------------------------+inputstring Symb1 = "USDCHF";
inputbool Trade1 = true;
int MA_Shift1=1;
inputint MA_Per1 = 100;
bool MA (int Number,
string Symbol_, // имя символаbool Trade,
int MA_Per, // период для расчета средней линииint MA_Shift // смещение индикатора по горизонтали
)
{
//---- проверка запрета на торговлюif(!Trade)return(true);
//---- объявление переменной для хранения итогового размера массивов переменныхstaticint Size_=0;
//---- объявление массива для хранения хэндлов индикаторов как статической переменнойstaticint Handle[];
staticint Recount[],MinBars[];
double ma[20];
if(Number+1>Size_) // вход в блок инициализации только на первом старте
{
Size_=Number+1; // для этого номера вход в блок закрыт//---- изменение размеров массивов переменныхArrayResize(Handle,Size_);
ArrayResize(Recount,Size_);
ArrayResize(MinBars,Size_);
//---- определение минимально количества баров, достаточного для расчета
MinBars[Number]=3*MA_Per;
//---- предварительное обнуление ячеек массивов//---- используем массив как таймсериюArraySetAsSeries(ma,true);
//---- получение хендла индикатора
Handle[Number]=iMA(Symbol_,0,MA_Per,MA_Shift,MODE_SMA,PRICE_CLOSE);
Print("+++++++++Handle[Number]= ",Handle[Number]);
}
//---- проверка количества баров на достаточность для расчета if(Bars(Symbol_,0)<MinBars[Number])return(true);
//---- Получение торговых сигналов if(IsNewBar(Number,Symbol_,0) || Recount[Number]) // вход в блок на смене бара или при неудачном копировании данных
{
//---- используя хэндлы индикатора, копируем значения индикаторного буфера//---- в специально подготовленный для этого статический массивif(CopyBuffer(Handle[Number],0,0,20,ma)<0)
{
Recount[Number]=true; // так как данные не получены, то следует вернуться // в этот блок получения торговых сигналов на следующем тике!return(false); // выходим из функции TradeSignalCounter() без получения торговых сигналов
}
//---- все операции копирования из индикаторного буфера завершены успешно
Recount[Number]=false; // можно не возвращаться в этот блок до очередной смены бараPrint("+++++++++ma[0]= ",ma[0]);
Print("+++++++++ma[1]= ",ma[1]);
Print("+++++++++ma[2]= ",ma[2]);
Print("+++++++++ma[3]= ",ma[3]);
Print("+++++++++ma[4]= ",ma[4]);
Print("+++++++++ma[5]= ",ma[5]);
Print("+++++++++ma[6]= ",ma[6]);
Print("+++++++++ma[7]= ",ma[7]);
Print("+++++++++ma[8]= ",ma[8]);
Print("+++++++++ma[9]= ",ma[9]);
Print("+++++++++ma[10]= ",ma[10]);
Print("+++++++++ma[11]= ",ma[11]);
Print("+++++++++ma[12]= ",ma[12]);
Print("+++++++++ma[13]= ",ma[13]);
Print("+++++++++ma[14]= ",ma[14]);
Print("+++++++++ma[15]= ",ma[15]);
Print("+++++++++ma[16]= ",ma[16]);
Print("+++++++++ma[17]= ",ma[17]);
Print("+++++++++ma[18]= ",ma[18]);
Print("+++++++++ma[19]= ",ma[19]);
}
return(true);
}
//+------------------------------------------------------------------+//| Expert initialization function |//+------------------------------------------------------------------+intOnInit()
{
//---//---return(0);
}
//+------------------------------------------------------------------+//| Expert deinitialization function |//+------------------------------------------------------------------+voidOnDeinit(constint reason)
{
//---
}
//+------------------------------------------------------------------+//| Expert tick function |//+------------------------------------------------------------------+voidOnTick()
{
//---
MA(0,Symb0,Trade0,MA_Per0,MA_Shift0);
MA(1,Symb1,Trade1,MA_Per1,MA_Shift1);
}
//+------------------------------------------------------------------+//+------------------------------------------------------------------+//| IsNewBar() function |//+------------------------------------------------------------------+bool IsNewBar(int Number,string symbol,ENUM_TIMEFRAMES timeframe)
{
//----staticdatetime Told[];
datetime Tnew[1];
//---- объвление переменной для хранения размеров массивов переменныхstaticint Size_=0;
//---- изменение размеров массивов переменныхif(Number+1>Size_)
{
uint size=Number+1;
//----if(ArrayResize(Told,size)==-1)
{
string word="";
StringConcatenate(word,"IsNewBar( ",Number,
" ): Ошибка!!! Не удалось изменить размеры массивов переменных!!!");
Print(word);
//---- int error=GetLastError();
ResetLastError();
if(error>4000)
{
StringConcatenate(word,"IsNewBar( ",Number," ): Код ошибки ",error);
Print(word);
}
//----
Size_=-2;
return(false);
}
}
CopyTime(symbol,timeframe,0,1,Tnew);
if(Tnew[0]!=Told[Number])
{
Told[Number]=Tnew[0];
return(true);
}
//----return(false);
}
I have a suggestion to the developers - make default values for all built-in types. C++ is not a model in this sense.
You will really save a lot of time and nerves for yourself and those answering the questions as above.
while((a/b)<1 && !IsStopped())//---------
what equals a?
By default (in the example above) a=2.652664430987377e-314 , but in this case the while loop works its way to a+b=30.
Of course, you can immediately assign double a=1;
But the situation doesn't change.
The output is always a+b=30
And return returns 0 , the debugger shows it all.
What are these glitches or am I missing something?
Initialisation of variables:
Any variable can be initialised when defined. If the variable is not explicitly initialized, the value stored in the variable can be whatever you want. Implicit initialization is not performed.
Fia:
The output is always a+b=30
And return returns 0 , the debugger shows it all.
I can hardly believe it.
What's stopping you from checking it out?
Especially for this purpose I gave a simple code.
I have two builds of 687 (on different brokers), tried to compile both with the same result (but sometimes I get 30 correctly), I can not understand whether I'm dumb or the ski is not moving!
Check I do not know what to think.
So far, it hasn't been possible to reproduce. So let's start at the beginning.
What bit rate, OS?
No luck with reproduction yet.
What bit rate, OS?
Win7 64 bit
Don't even know, just unloaded just now loaded MT5 compiled, same thing.
I can take off video (will think I'm making fun of it).
P.S. Now i just tapped it, once again it worked 30, i compiled it and now it works null a few more times (magic)
Good afternoon.
I'm trying to use MQL5.I have disassembled exp_tema.mq5 and modified the code. Now I should print in log MA of each candle (last 20). But I don't understand why some entries are missing in the log. I noticed that if ma[3] is missing in log, then there is no ma[13]. Why is this happening? Where is the error there?
Win7 64 bit
I don't know, just unloaded MT5 now, ran a copy, same thing.
I can take off a video or something (i think i'm just messing with you).
You do not need a screenshot.
Make a detailed Print in the code so that we can see in the log what the intermediate variables are equal to.