[WARNING CLOSED!] Any newbie question, so as not to clutter up the forum. Professionals, don't go by. Can't go anywhere without you. - page 656

 
artmedia70:
What may cause stack overflow? When you open a position with big take (take is calculated from volatility and multiplied by 100, the size is 41*100), then a stack overflow is written into the log and... ... just take it. No more positions are opened until this one closes, and this one, of course, will not close because of the huge TP... And the EA does not work correctly at all, because it should close all positions when the predefined total profit of the open positions is reached... But it doesn't happen, even though this one position has been in huge profits for a long time, about two thousand points... How do I fight it? One cannot be secured against the situation when all open positions will overflow the stack, and everything will go upside down...


the stack cannot overflow just with a number that is outside the type range - there will be another error

data passed into a function or a recursive call to a function without quitting can overflow the stack.

start() is also a function - maybe you have a lot of variables there.

the stack is a memory region where intermediate values (local variables) of a function are stored; you might be breaking the stack yourself if you're using dynamic arrays and haven't correctly checked the array scope, i.e., you're writing data not in an array, but in a memory region that comes right after the array

try to move some of the arrays to global variables - put them at the top of the board

ZS: at least it's the same in all programming languages - I think it's the same in mql

 
IgorM:


the stack cannot overflow just with a number that is outside the type range - there will be another error

data passed into a function or a recursive call to a function without quitting can overflow the stack.

start() is also a function - maybe you have a lot of variables there.

the stack is a memory region where intermediate values (local variables) of a function are stored; you might be breaking the stack yourself if you're using dynamic arrays and haven't correctly checked the array scope, i.e., you're writing data not in an array, but in a memory region that comes right after the array

try to move some of the arrays to global variables - put them at the top of the board

ZS: at least it's the same in all programming languages - I think it's the same in mql

Igor, you know that I have avoided using arrays so far... I only have a couple of arrays in my code - an array of orders before the tick and an array of orders after the tick. I have them defined in the global variable area. The funny thing is that I moved the code to open these positions elsewhere in the EA and the error disappeared. It looks like there was a recursive call to open orders, although I didn't really bother with it. I simply decided that it would not be appropriate to place the opening immediately after closing all the positions in the code to check if the total profit was reached and all the positions were closed... I made a mess of it... :)
 
artmedia70:
Igor, you know that I have avoided using arrays so far... I only have a couple of arrays in my code - an array of orders before the tick and an array of orders after the tick. I have them defined in the global variable area. The funny thing is that I moved the code to open these positions elsewhere in the EA and the error disappeared. It looks like there was a recursive call to open orders, although I didn't really bother with it. I simply decided that it would not be appropriate to place the opening immediately after closing all the positions in the code to check if the total profit was reached and all the positions were closed... I made a mess of it... :)

I made a template for creating an EA - when an order is placed, the flag of such an order is immediately set and afterwards, before opening a new order of this type, I always check the flag - whether the order exists, but I am writing EAs with only one order
 
IgorM:

I have long ago made a template for creating an EA - when I place an order, I immediately set a sign (flag) that such an order exists, and then before opening a new order of this type I always check the flag - whether such an order exists, but I write EAs with only one order
Well, I, and I think that everyone else, has their own developments, templates and other goodies. This is not the point. I am still struggling with drawdowns and trying different methods, functions and the like. If I work strictly with the trend, I cannot understand how to catch trend exhaustion if on one, the older TF the trend has already turned into a flat, while on the younger one it is still there, but it is coming to an end. When opening a position in a low-order one the probability is high that it may cause a drawdown and not be closed in time. I am now trying to work with 4-hour charts starting from the 4-hour chart, where we define the direction and work only in this direction at all of the lows. The moment of transition from trend to flat I kind of identified more or less, we will look at the results.
 
Craft:


Yes, I got "0", but what should I do? I can't do it both ways (I even tried equal periods), I tried both Print("NormalizeDouble(c1b_1..."), but I got zeros (only c1b[i] shows the value, all others including c1s[i] are zeros), may help me to bring one of them to a working condition or share a hint, if you notice any defects?

New:

Old:

Whole:


Yuri, in the future, if code is repeated at least twice, it should be allocated to a method, and you won't need heaps of arrays cluttering up the code.
Here's a method for you:

//+------------------------------------------------------------------+
double iCCIAverage(string cci_symbol, int cci_timeframe, int cci_period, int cci_applied_price, int ma_period, int ma_method, int ma_shift){
   double array[];
   int loop_array;
   ArrayResize(array,ma_period + ma_shift);
   for(int loop = ma_period + ma_shift - 1; loop >= 0; loop--, loop_array++)array[loop_array] = iCCI(cci_symbol, cci_timeframe, cci_period, cci_applied_price, loop);
   return(iMAOnArray(array, 0, ma_period, 0, ma_method, ma_shift));
}
//+------------------------------------------------------------------+

I think everything is clear with parameters, enter data and by varying ma_shift parameter get the shift you need. Note that this method can be used as a template, just change access methods for indicators i...(...) or iCustom(...). Now your block of trading decisions looks as it should be:

//--------------------------------------------------------------- 5 --
   // Торговые критерии
if (NormalizeDouble(iCCIAverage(Symbol(), 0, PeriodB, PRICE_TYPICAL, AvgB, MODE_SMA, 1),4)<NormalizeDouble(iCCIAverage(Symbol(), 0, PeriodB, PRICE_TYPICAL, AvgB, MODE_SMA, 2),4) &&
   NormalizeDouble(iCCIAverage(Symbol(), 0, PeriodB, PRICE_TYPICAL, AvgB, MODE_SMA, 2),4)>NormalizeDouble(iCCIAverage(Symbol(), 0, PeriodB, PRICE_TYPICAL, AvgB, MODE_SMA, 3),4))
     {                                          // 
      Opn_B=true;                               // Критерий откр. Buy
      Cls_S=true;                               // Критерий закр. Sell
     }
if (NormalizeDouble(iCCIAverage(Symbol(), 0, PeriodS, PRICE_TYPICAL, AvgS, MODE_SMA, 1),4)>NormalizeDouble(iCCIAverage(Symbol(), 0, PeriodS, PRICE_TYPICAL, AvgS, MODE_SMA, 2),4) &&
   NormalizeDouble(iCCIAverage(Symbol(), 0, PeriodS, PRICE_TYPICAL, AvgS, MODE_SMA, 2),4)<NormalizeDouble(iCCIAverage(Symbol(), 0, PeriodS, PRICE_TYPICAL, AvgS, MODE_SMA, 3),4))
     {                                          // 
      Opn_S=true;                               // Критерий откр. Sell
      Cls_B=true;                               // Критерий закр. Buy
     }
//--------------------------------------------------------------- 6 --

Accordingly there is no need now for "old" and "new" variants, trades are opened according to the given criteria (as far as I understood you have a three-bar pattern of tops/troughs smoothed iCC). There is a corrected variant in the file.

Files:
21_2.mq4  14 kb
 

Hello.

Can you please give me the code to write the prices since the order was opened into the array.

How to make each new price to be added to the array.

 
zelek:

Hello.

Can you please give me the code to write the prices since the order was opened into the array.

How to make each new price to be added to the array.


Please be more specific in your question

If you are interested in the current price at the time of placing the order, you can add a call to the code that will be responsible for storing the current price in the global array with changing the array index counter, which you can view later from any point in the code.

 

how to check the performance of an EA - I would just like to display the code execution time in milliseconds

how much better is the performance of MT5 vs MT4

 
IgorM:

how to check the performance of an EA - I would just like to display the code execution time in milliseconds

how much better is the performance of MT5 vs MT4


GetTickCount would help https://docs.mql4.com/ru/common/GetTickCount
 
DDFedor:

GetTickCount will help https://docs.mql4.com/ru/common/GetTickCount


thanks yes it's what i was looking for, has anyone measured the speed of the same type of code for mt4 and mt5 ?

Reason: