Any questions from newcomers on MQL4 and MQL5, help and discussion on algorithms and codes - page 247

 
(NormalizeDouble(AccountFreeMargin()/SymbolInfoDouble(Symbol(),SYMBOL_TRADE_CONTRACT_SIZE),2)-Lots*(CountTrades()+1));

Made up a formula to calculate the lot, can you tell me where the error might be? The order does not open because of some incorrectness.

The formula is still valid for a deposit of 100$ and above, with a leverage of 1-100 and above. And if the deposit without leverage 1 000$ it turns out that the formula does not work because we have FreeMargin/Contract = 0.01 and we cannot deduct from this value because we will not meet the trading conditions.


On the other hand, why should we deduct it if FR&Margin already takes into account open positions? Then it would look like this

lot=NormalizeDouble(AccountFreeMargin()/SymbolInfoDouble(Symbol(),SYMBOL_TRADE_CONTRACT_SIZE),2)

I will go and test it.

Совершение сделок - Торговые операции - Справка по MetaTrader 5
Совершение сделок - Торговые операции - Справка по MetaTrader 5
  • www.metatrader5.com
Торговая деятельность в платформе связана с формированием и отсылкой рыночных и отложенных ордеров для исполнения брокером, а также с управлением...
 
geratdc: I made up a formula to calculate the lot, can you tell me where there might be a mistake? The order does not open because of some incorrectness.
      Лот=NormalizeDouble(0.65*AccountBalance()*AccountLeverage()/          // Использую такую формулу
                             MarketInfo(_Symbol, MODE_LOTSIZE),2);
 
STARIJ:

Greetings)) What is 0.65? Where did it come from?

I was thinking about leverage, but I came to the conclusion that the balance is in theory already set with the leverage. Or am I wrong?


Is 0.65 a reserve for 35% slippage or what? By the way, it is a good idea, because if you set the lot in such a way, you will lose a position and that will be the end of the line!

I like it! The formula worked after I removed losing, it's cool)) in short, the lot was 0.02, then when three positions went into drawdown, the emergency lot was calculated as 0.1, that is, 5 times! However, my function is sensitive to further losses when an emergency order is opened so there should not be any problems.

Colleague, thanks for the valuable thoughts! I will go and test it!


I have also decided to check trading conditions. How do you like this code?


// Проверка Баланса
   if(cn==0 && TradeCheck==true && AccountBalance()/SymbolInfoDouble(Symbol(),SYMBOL_TRADE_CONTRACT_SIZE)<SymbolInfoDouble(Symbol(),SYMBOL_VOLUME_MIN))
     {
      Print("Баланс счёта не обеспечивает торговые требования");
      SendMail("EA BJH","Баланс счёта не обеспечивает торговые требования");
      ExpertRemove();  // Снять советник с графика
     }
// Проверка Lots
   else if(cn==0 && TradeCheck==true && AccountBalance()/Lots<SymbolInfoDouble(Symbol(),SYMBOL_TRADE_CONTRACT_SIZE))
     {
      Print("Lots не обеспечивает торговые требования");
      SendMail("EA BJH","Lots не обеспечивает торговые требования");
      ExpertRemove();  // Снять советник с графика
     }
Files:
1.gif  10 kb
 
geratdc: Colleague, thanks for the valuable thoughts! I'll go and test it!

If you flip it over - BUY instead of SELL and SELL instead of BUY - it will be better

Try it, Colleague!!!

The robot, instead of stating a fact, has to issue a recommendation: Boss, add money. I've already wasted those...

 
STARIJ:

If we reverse it - BUY instead of SELL and SELL instead of BUY - it will be better

Try it, Colleague!!!

The robot, instead of stating a fact, should give recommendations: Boss, add money. You've already wasted them...


It's ok, there were specially left settings to trigger an emergency order - I had to see what lot would pick up.

lot=NormalizeDouble(AccountFreeMargin()/SymbolInfoDouble(Symbol(),SYMBOL_TRADE_CONTRACT_SIZE),2);

I've left this one for now. I've tried it with balance, I believe it will be more accurate in terms of margin, but the result is the same. Let's analyze the test results later.

 
geratdc: It's okay.

Internet's back on! Can I write to an email?

 
STARIJ:

Is this how it should be? Levels -0.75 and +0.75.

It is easier to use one variable. First 0. Then +1 -1 +1 -1


Yes, like this. How should I write it in the Expert Advisor in such a way, that when it is launched, if we are in a gap between levels, it takes the value of the last one from which we have bounced?

 
AlGuru: But how do I write it in the EA so that when it starts, if we are in the gap between levels, it takes the value of the last one from which we rebounded?

How do you mean "fought off"? Did it attack us? Fought back when - before the launch? How could we fight back if we'd just launched? Read before you send it - does it all make sense?

 
STARIJ:

What do you mean by fighting back? Did it attack us? Were we beaten back before the launch? How could we fight back if we just launched? Read it before you send it - does it make sense?


OK, not rebounded, but produced a bounce from the line. Provided that the EA is placed on another machine/terminal or in case of computer shutdown, restarting the terminal, it (the EA) started working immediately by calculating at what level the price was last and setting the right variable value, rather than waiting for the price to reach the desired level. I hope I've described it clearly.

 
AlGuru OK, not rebounded, but produced a bounce from the line. Provided that the EA is placed on another machine/terminal or in case of computer shutdown, restarting the terminal, it (the EA) started working immediately by calculating at what level the price was last and setting the right variable value, rather than waiting for the price to reach the desired level. I hope I've described it clearly.

What does it have to do with another machine or terminal? Or shutdown - restart. Do you mean to switch the computer on or to restart the Expert Advisor? Why does it have to be a bounce, but if it leaves the level line and crosses back? And if it waits - it's just skipping one opportunity when switching on. You can discard that at first, and come back to it when you're done. And then where do the lines come from, when do they appear, who puts them in, or how does the EA calculate them. If they are placed on another computer or before the computer is switched off, the price can go far away. If the levels are calculated by the Expert Advisor itself, that's another matter. Look now: the price has bounced from the upper level and wandered between the levels for an hour. And then we have switched on the computer and activated the Expert Advisor. Obviously, we have to attribute the time of action to this bounce. An hour has passed and the rebound is forgotten. You see, there are a lot of questions! And you are clear. It is clear to you, you know the essence of the matter. But from the outside it is darkness. The art of programming is the ability to ask a lot of questions and find answers. Take a look at the script - maybe there's a rational point here

//+-------------------------------------------------------+
//| Проверка                                     PROBA.mq4|
//+-------------------------------------------------------+
#property strict

void OnStart()
{
  bool ДостигнутПервыйУровень=false,
       ДостигнутВторойУровень=false;
  int Переменная1=0, Переменная2=0;
  double Уровень;
  int x;

  Alert("----- Снизу вверх --------");
  for(x=13; x<27; x++)
  {
    Уровень=round(sin(x)*10)/10;

    if(Уровень>0.75)
    {
      Переменная1=1;
      Переменная2=0;
    }

    if(Уровень<-0.75)
    {
      Переменная1=0;
      Переменная2=1;
    }

    Alert("  ", x, "       ", Уровень, "        ", Переменная1, "        ", Переменная2);
  }
  Alert("Номер  Уров  Пер1  Пер2");
}
Reason: