Features of the mql5 language, subtleties and tricks - page 133

 
Alexey Viktorov:
Why?
tried it already
 
Nikolai Semko:
tried it already

But here

Forum on trading, automated trading systems and trading strategies testing

Peculiarities of mql5, tips and tricks

Nikolai Semko, 2019.04.03 22:33

Yes, thank you Alexey. I had forgotten about this feature. Saw it before, but never used it.

Tried it. Something is going wrong. It deletes it, but after deleting it, everything stops.

I simply added one line of code to the DrawSetup() function before calculation of the indicator with the following parameters.

IndicatorRelease(handle);
handle=iMA(_Symbol,_Period,per1,0,MaMethod,PriceBase);
for(int i=0;i<N;i++) handle=iMA(_Symbol,_Period,per2,0,MaMethod,handle);

The indicator simply stops working and I am still unable to understand the reason.

I absolutely agree with you. It is just a useless toy.


Not like that at all.
 
Alexey Viktorov:

But here


it's not like that at all.
I tried it before. I deleted the code from myself as unsuccessful.
 
You could also try releasing all the handels in a chain, starting with the most deeply buried.
 
Andrey Khatimlianskii:
You can also try releasing all handles in a chain, starting from the most deeply buried one.

Well, it's not working. Or if it does work, then some brakes are applied.

void BuildMaFromMa()
  {
   static int h[];
   for(int i=0;i<ArraySize(h);i++) IndicatorRelease(h[i]);
   handle=iMA(_Symbol,_Period,per1,0,MaMethod,PriceBase);
   ArrayResize(h,N);
   if (N>0) h[0]=handle; 
   for(int i=0;i<N;i++)
     {
      handle=iMA(_Symbol,_Period,per2,0,MaMethod,handle);
      h[i]=handle;
     }
  }

If you document the line withIndicatorRelease, then everything works fine, but otherwise some brakes are on and I don't understand what's happening.

Files:
 

Forum on trading, automated trading systems and testing trading strategies

Indicators: MaFromMa

Nikolai Semko, 2019.04.04 01:00

I wanted to compare the performance of recursion and iteration.

It turns out that recursion is more than twice as fast...

Probably because the stack works faster...

It's an amazing thing. I expected the opposite effect. ))

#define  size 1000000
uint sum1=0,sum2=0;
int i;
int X[];
//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
void OnStart()
  {
   ArrayResize(X,size);
   for(i=0;i<size;i++) X[i]=rand();

   ulong t=GetMicrosecondCount();
   i=0;
   while(i<size) { sum1+=X[i]; i++;}
//Recursion();
   ulong t1=GetMicrosecondCount()-t;

   t=GetMicrosecondCount();
   i=0;
//while(i<size) { sum1+=X[i]; i++;}
   Recursion();
   ulong t2=GetMicrosecondCount()-t;
   Print("время выполнения цикла    = "+string(t1)+" , контрольная сумма = "+string(sum1));
   Print("время выполнения рекурсии = "+string(t2)+" , контрольная сумма = "+string(sum2));
  }
//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
void Recursion()
  {
   sum2+=X[i];
   i++;
   if(i<size) Recursion();
  }
//+------------------------------------------------------------------+
2019.04.03 19:06:40.776 TestLoopVsRecursion (EURUSD,M1) время выполнения цикла    = 1667 , контрольная сумма = 3510404212
2019.04.03 19:06:40.776 TestLoopVsRecursion (EURUSD,M1) время выполнения рекурсии = 697 , контрольная сумма = 3510404212
2019.04.03 19:06:41.697 TestLoopVsRecursion (EURUSD,M1) время выполнения цикла    = 1653 , контрольная сумма = 3492310620
2019.04.03 19:06:41.697 TestLoopVsRecursion (EURUSD,M1) время выполнения рекурсии = 699 , контрольная сумма = 3492310620
2019.04.03 19:06:42.549 TestLoopVsRecursion (EURUSD,M1) время выполнения цикла    = 1529 , контрольная сумма = 3510953577
2019.04.03 19:06:42.549 TestLoopVsRecursion (EURUSD,M1) время выполнения рекурсии = 696 , контрольная сумма = 3510953577
2019.04.03 19:06:43.332 TestLoopVsRecursion (EURUSD,M1) время выполнения цикла    = 1559 , контрольная сумма = 3512212419
2019.04.03 19:06:43.332 TestLoopVsRecursion (EURUSD,M1) время выполнения рекурсии = 698 , контрольная сумма = 3512212419
2019.04.03 19:06:44.098 TestLoopVsRecursion (EURUSD,M1) время выполнения цикла    = 1707 , контрольная сумма = 3497178596
2019.04.03 19:06:44.098 TestLoopVsRecursion (EURUSD,M1) время выполнения рекурсии = 472 , контрольная сумма = 3497178596
2019.04.03 19:06:44.839 TestLoopVsRecursion (EURUSD,M1) время выполнения цикла    = 2088 , контрольная сумма = 3485051380
2019.04.03 19:06:44.839 TestLoopVsRecursion (EURUSD,M1) время выполнения рекурсии = 482 , контрольная сумма = 3485051380
2019.04.03 19:06:45.538 TestLoopVsRecursion (EURUSD,M1) время выполнения цикла    = 1612 , контрольная сумма = 3487817581
2019.04.03 19:06:45.538 TestLoopVsRecursion (EURUSD,M1) время выполнения рекурсии = 448 , контрольная сумма = 3487817581
2019.04.03 19:06:46.397 TestLoopVsRecursion (EURUSD,M1) время выполнения цикла    = 1742 , контрольная сумма = 3475121003
2019.04.03 19:06:46.397 TestLoopVsRecursion (EURUSD,M1) время выполнения рекурсии = 497 , контрольная сумма = 3475121003
2019.04.03 19:06:47.262 TestLoopVsRecursion (EURUSD,M1) время выполнения цикла    = 1701 , контрольная сумма = 3485556615
2019.04.03 19:06:47.262 TestLoopVsRecursion (EURUSD,M1) время выполнения рекурсии = 701 , контрольная сумма = 3485556615

 

Guys, do you have a tried and tested and reliable function to calculate the lot by percentage of deposit for MT5, without a stop loss?

Share...

 
During Optimization, you may encounter the following message in the Tester Log
Tester  OnTesterInit failed. Optimization cannot be started.


It is almost impossible to understand the cause from this message, as there is no reference to the Terminal log at all. That is where you need to look for the cause.


Here is an example of such an EA

input int Range = 0; // 1..9

int Tmp = 1 / Range;

void OnTesterDeinit() {}

double OnTester()
{
  return(Tmp);
}


The Expert Advisor optimizes in a range where Range does not reach zero. But at the same time, the optimization fails.

The reason is that the Frame mode of Expert Advisors is always launched with the input parameters rigidly prescribed in EX5. In this case, the Frame mode results in adivision by zero.

If OnTesterDeinit is removed from the source code, the Optimization will run without any problems.


It would be nice if the TesterJournal in such situations has a reference to the TerminalJournal. Otherwise it's not always possible to understand (debug is not available during Optimization), what's going on.

 

You may encounter a situation where EAs do not start on a chart.

On the left is the usual cursor when dragging an EA to a chart. On the right is our case.


There will be no entries in the log. In general, the barring cursor is the only visual identifier of such charts.


If you save the tpl template, these charts will be distinguished by a single line

tester=1

This is probably the only programmatic option to identify the type of chart. It's a frame chart.


So if you want to protect yourself from automated trading, you can work only with these charts.

 

Forum on trading, automated trading systems and trading strategy testing

Bugs, bugs, questions

Nikolai Semko:

Synthetic tool formula gives error "Unknown parsing error" if symbol name starts with (or contains) a dot.

Slava, 2019.04.19 06:08

If a character name contains a full stop, a dash or something else you don't understand (how about "RTS-12.19"?), then the name must be surrounded by apostrophes

Reason: