Questions from Beginners MQL5 MT5 MetaTrader 5 - page 1401

 
freemovpalm #:

Hi all, can you please help me to add martingale to EA, I need after triggering stoploss (getting loss) and on new signal (owl works by indicator) to enter with increased lot (multiplied by coeff). Did I get it right, first I need to write the event - stoploop event (I don't know where and how), and do the maths with lots there (I need additional variables)?

For example, add a variable - counter of losing trades in a row. At each losing trade - increased by 1, at each profitable - reset to 0.

And from this counter set lot (for example - multiplying the minimum lot by 2 in proportion to this counter).

But martingale will not make a losing strategy profitable.

 
JRandomTrader #:

For example, add a variable - counter of losing trades in a row. At each losing trade - it is increased by 1, at each profitable - it is reset to 0.

And from this counter set the lot (for example, multiply the minimum lot by 2 to the extent of this counter).

But martingale will not make a losing strategy profitable.

Thanks, the strategy has an average of 2 and a maximum of 4 losses in a row, that's why I wanted a martin. By the way does anyone have an example of such a counter or owl working on the same principle as I described? I could just copy the necessary lines from there.

 
string Button_TP = "Panel.String1.Button3";

Print(ObjectGetInteger(0, "Panel.String1.Button3", OBJPROP_STATE));
Print(ObjectGetInteger(0, Button_TP, OBJPROP_STATE));

Can you tell me why the first option works and the second doesn't? Can't the name of the button be set to a variable?

 

How can the tester automate the passing of several pairs?
For example, I need to go through 20 pairs. Now I restart the tester for each pair.
I can't figure out how to make a variable.

Are there any solutions?

 
Evgeny Dyuka #:

How can the tester automate the passing of several pairs?
For example, I need to go through 20 pairs. Now I restart the tester for each pair.
I can't figure out how to make a variable.

Do you have any solution?

Forum on trading, automated trading systems & strategy testing

How to receive selected pairs for market review in Strategy Tester?

Alexey Viktorov, 2022.04.14 17:11

You cannot use the MarketWatch terminal in the Strategy Tester. The tester generates its ownMarketWatch from the symbols whose properties have been requested from the program. Therefore, to form aMarketWatch, you need to request any property of the required symbol.

sinput  string  Symb  = "GBPUSD,GBPAUD,GBPCAD,GBPJPY,EURUSD,EURGBP,EURAUD,EURCAD,EURJPY,AUDUSD,AUDNZD,AUDCAD,AUDJPY,NZDUSD,NZDCAD,USDCAD,USDJPY"
string s_arr[];
int OnInit()
{
  int i = 0, symbPos = 0;
  if(StringSplit(Symb, ',', s_arr) <= 0)
   {
    Print(__FUNCTION__ + " Error converting !");
    return(INIT_FAILED);
   }
  while(symbPos >= 0  && !IsStopped())
   {
    if(!SymbolInfoInteger(s_arr[i], SYMBOL_SELECT) || !SymbolInfoInteger(s_arr[i], SYMBOL_VISIBLE))
      SymbolSelect(s_arr[i], true);
    double price = SymbolInfoDouble(s_arr[i], SYMBOL_ASK);
    i++;
   }
 return(INIT_SUCCEEDED);
}/*******************************************************************/

I hope I didn't make mistakes when pulling code from my program...


 
Evgeny Dyuka #:

How can the tester automate the passing of several pairs?
For example, I need to go through 20 pairs. Now I restart the tester for each pair.
I can't figure out how to make a variable.

Are there any solutions?

If we define a pair by an EA parameter which may change during optimization, then we simply run optimization by this parameter to start a pass through several pairs.
This parameter cannot be of 'string' type, but it can be of 'int' or 'enum' type.
Using this parameter, when initializing the EA, we assign to another string variable the name of the desired symbol that corresponds to the value of the parameter.
In the EA code, you will have to replace Symbol() or _Symbol with your own variable with the name of the pair.

Do you understand the principle or do you need a code example?

 
Evgeny Dyuka #:

How can the tester automate the passing of several pairs?
For example, I need to go through 20 pairs. Now I restart the tester for each pair.
I can't figure out how to make a variable.

Are there any solutions?

Sabermultitester is a solution, you can set up passes there by tools and settings.

Библиотеки: MultiTester
Библиотеки: MultiTester
  • 2019.07.19
  • www.mql5.com
Статьи и техническая библиотека по автоматическому трейдингу: Библиотеки: MultiTester
 
Yuriy Bykov #:

If a pair is defined by an EA parameter that can be changed during optimization, then in order to run a multi-pair pass, we simply run the optimization by this parameter.
This parameter cannot be of 'string' type, but it can be of 'int' or 'enum' type.
Using this parameter, when initializing the EA, we assign to another string variable the name of the desired symbol that corresponds to the value of the parameter.
In the EA code, wherever Symbol() or _Symbol is used, we will have to replace it with our own variable with the name of the pair.

Do you understand the principle or do you need a code example?

Great! It didn't occur to me to go through the optimizer.

 
Yuriy Bykov #:

If a pair is defined by an EA parameter that can be changed during optimization, then in order to run a multi-pair pass, we simply run the optimization by this parameter.
This parameter cannot be of 'string' type, but it can be of 'int' or 'enum' type.
Using this parameter, when initializing the EA, we assign to another string variable the name of the desired symbol that corresponds to the value of the parameter.
In the EA code, wherever Symbol() or _Symbol is used, we will have to replace it with our own variable with the name of the pair.

Is the principle clear, or do you need an example code?

What about OnTick() ?
I can substitute my own symbol everywhere, butOnTick() will always be taken fromthe symbol on which the tester is running.
From help: "
The OnTick() event is generated . when a new tick is received for a symbol, to the chart of which the Expert Advisor is attached".

There can be no conflict here? For example, forex is stopped out over the weekend but crypto is not.

 
Yes, that's a problem. I haven't worked with crypto, so I haven't thought about the difference in allowed trading periods. But it's possible to put some cryptocurrency as a working symbol in tester, and add (or not) check that trading is allowed in EA. After that, the main problem is the inconsistency of tick arrival times for different instruments. Here we can try to choose the instrument with more ticks to reduce the error of testing results. In multicurrency Expert Advisors that work attached to one chart, the situation will be the same - OnTick() is triggered only for the main symbol. To correctly track the event of a new bar coming for different symbols in this case I use my library New Bar Event.
New Bar Event
New Bar Event
  • www.mql5.com
Позволяет определить наступление события нового бара в мультивалютном советнике. В вызове OnTick() можно многократно проверять, наступило ли на этом тике событие для нужного инструмента (symbol) и периода графика (timeframe).