[ARCHIVE] Any rookie question, so as not to clutter up the forum. Professionals, don't pass by. Nowhere without you - 3. - page 235

 
Zhunko:
If the source code is there, but it has been changed, this is possible. I.e. changing the contents of the source. If the source is lost or renamed, it will not be found.

Thank you Vadim. I see.
 
ikatsko:

How to calculate margin (necessary funds to open an order with lot N) at different values of AccountFreeMarginMode


The margin for an order of 1 lot is equal:

   double OneLotMarg =MarketInfo(Symbol(),MODE_MARGINREQUIRED);

You will figure it out later.

And you also need to check whether you have enough free funds:

   double Free = AccountFreeMargin();
   
   if(Lts*OneLotMarg>Free) return(0);
 
DhP:


And you should also check whether there are enough funds available:

   double Free = AccountFreeMargin();
   
   if(Lts*OneLotMarg>Free) return(0);

This condition is necessary, but not sufficient... As I understood it, you also have to consider the value of spread, i.e. you have to take into account the loss that will be incurred immediately when you open the corresponding order! :))) Or have I forgotten something else?
 

I liked the script of this indicator, its simplicity. please help me to create a script that will place stops on these lines, by going through the orders.

https://www.mql5.com/ru/code/9588

 
MaxZ:
This condition is necessary, but not sufficient... As I understand it, you also have to consider the value of the spread, i.e. you have to consider the loss that will be incurred immediately when you open the corresponding order! :))) Or have I forgotten something else?
I think you are right, but it hardly matters in practice.
 
DhP:
I think you are right, but it hardly matters in practice.

For example, I practise in various competitions. And there have been similar situations. The error 134 would come up. But I still haven't perfected the lot calculation function. I was too lazy... A little later the request is repeated and the order is opened. And a bit later we merge the demo deposit! :)))

Also, this condition will not work when counter orders are opened, when there is not enough money, but the opened lot can be compensated by a counter order.

A few nuances and no more.

 
DhP:
MaxZ:
This condition is necessary, but not sufficient... As I understood it, you also have to consider the value of spread, i.e. you have to consider the loss that will be incurred immediately when you open the corresponding order! :))) Or maybe I forgot something else?
I think you are right, but it hardly matters in practice.

It turns out that the fact that an order opens with a loss equal to the spread has no effect. If we set Risk = 100%, an order is opened with the maximum possible volume, and AccountFreeMargin() shows either "+" or "- " (inthe"Strategy Tester") immediately after it is opened...

But, when opening several orders, the 134 error occurs from time to time. I still do not understand what the error is related to... I take into account the funds needed to open opposite orders by the same condition. This means the opposite order will be opened only when we are in the plus and the corresponding condition triggers.

The code is used to calculate the lot:

double Free    = AccountFreeMargin();
double One_Lot = MarketInfo(Symbol(), MODE_MARGINREQUIRED);      
double Step    = MarketInfo(Symbol(), MODE_LOTSTEP);
newLots = MathFloor(Free*Risk/100/One_Lot/Step)*Step;

p.s.: I don't like to leave bloopers of my own...

 

Greetings Gentlemen!

Please help me to insert into my EA the function to close orders.

The idea is this:

1) if the price of an open SELL order becomes less than the price of the exposed TP of this order, then this order is closed.

2) if the price of an open BUY order is higher than the price of TP set for this order, it will be closed.

If you are able to help please write to oniava@gmail.com, I look forward to hearing from you.

Many thanks in advance.

Sincerely Oleg.


P.S. You can make a separate EA assistant with a magic number.

 
belck:

I liked the script of this indicator, its simplicity. please help me to create a script that will place stops on these lines, by going through the orders.

https://www.mql5.com/ru/code/9588

Start doing it and we will help. This makes it look like "do it for me". There's pretty much everything you need in there. All that's left to do is to cycle in and out of your orders.
 

Hi all. Can you tell me how to prescribe in the EA,

When a certain profit is reached, the EA does not open a position anymore,

It only opens when the EA is next started or restarted.

Reason: