Any rookie question, so as not to clutter up the forum. Professionals, don't pass by. Nowhere without you - 6. - page 190

 

Please, advise how to improve the function of closing orders if equity exceeds the balance by a certain percentage.

For example, if at the moment equity is equal to 115%, I have to close some lots (there may be several orders with different lots) to make the equity equal to 110% of balance.

 
Skydiver:

Please, advise how to improve the function of closing orders if equity exceeds the balance by a certain percentage.

For example, if at the moment equity is equal to 115%, I have to close some lots (there may be several orders with different lots) to make the equity equal to 110% of balance.


Make several functions with different algorithm implementations. Compare the running times. From those that will work correctly, you choose the one that will work for the shortest time - this is "better". So, nothing complicated. ;)))))))
 

It is possible to set levels in the indicator and customize styles by using SetLevelValue and SetLevelStyle functions , but I don't know how to get to their description. Maybe someone has encountered and knows?

 
Desead:

It is possible to set levels in the indicator and customize styles by using SetLevelValue and SetLevelStyle functions , but I don't know how to get to their description. Maybe someone has encountered and knows?


If we are talking about documentation, highlight the word in MetEditor and press F1. Or go online, e.g:
https://docs.mql4.com/ru/customind/SetLevelStyle
 

Good afternoon. could you please advise whether or not an order is already in the right place?

If no, then put

 

Good afternoon!

Can you tell me something? When a market order is open, its open price can be changed using a function:

bool OrderModify( int ticket, double price, double stoploss, double takeprofit, datetime expiration, color arrow_color=CLR_NONE) 

Question - why do we need it? So that the OrderProfit() function would give different results later compared to the initial open price? Or this possibility is intended for something else?

(By the way, does OrderProfit() calculate exactly from the opening price or the information is requested from the server where it is calculated otherwise? The documentation does not say anything about it).

 
sannin:

Good afternoon. could you please advise whether or not an order is already in the right place?

If no, then put

In the right place - in what place?
 
yan720:

Good afternoon!

Can you tell me something? When a market order is open, its open price can be changed using a function:

Question - why do we need it? So that the OrderProfit() function would give different results later compared to the initial open price? Or this possibility is intended for something else?

(By the way, does OrderProfit() calculate exactly from the opening price or the information is requested from the server where it is calculated otherwise? The documentation does not say anything about it).

We can only modify the price of a pending order. The open price of the market position cannot be changed. It would be strange to buy bread at 20, come home and change the purchase price to 5 rubles, and then in the wallet to see the arrival of the 15 rubles difference... Fantastic... ;)

You can modify stop price of a market position: Stop Loss and Take Profit.

OrderProfit() returns position profit/loss in deposit currency. Of course, it is calculated from opening price.

 
artmedia70:

Only the price of the pending order can be modified. The opening price of a market position can no longer be modified. It would be strange to buy bread at 20, come home and change the purchase price to 5 roubles, and then see in your wallet the arrival of 15 roubles of difference... Fantastic... ;)

You can modify the stop price of a market position: Stop Loss and Take Profit.


Thanks for the reply. I was surprised myself that such a question has arisen at all. Although, maybe I misunderstood what I saw and what caused the question.

I'm looking at other people's code now to see what ways (different from mine and perhaps more efficient) certain algorithms are implemented. Right now I'm looking at the notorious Ilan 1.6 Expert Advisor (attached). I can see that it was assembled from various parts and then rebuilt. But the line 337 contains a user-defined trailing stop function (although the flag of its use is forcibly cleared at the beginning). This function is called on line 52.

My question arises because the trailing stop mentioned above modifies open orders (and there can be several of them) by a stop loss maintaining their initial TakeProfit but setting the same value (AveragePrice, which is calculated in lines 173 and 178) to those orders as an open price (second parameter of OrderModify function).

Or, is this parameter (open price) simply ignored by the server when modifying an open order and the price can be set to any value?

Files:
ilan1.6.mq4  20 kb
 
yan720:

Thank you for your answer. I was surprised myself that such a question had arisen at all. Although, maybe I misunderstood what I saw and what caused the question.

I'm now looking at other people's code to see what methods (different from mine and perhaps more efficient) are used to implement certain algorithms. Right now I'm looking at the notorious Ilan 1.6 Expert Advisor (attached). I can see that it was assembled from various parts and then rebuilt. But the line 337 contains a user-defined trailing stop function (although the flag of its use is forcibly cleared at the beginning). This function is called on line 52.

My question arises because the trailing stop mentioned above modifies open orders (and there can be several of them) by a stop loss maintaining their initial TakeProfit but setting the same value (AveragePrice, which is calculated in lines 173 and 178) to those orders as an open price (second parameter of OrderModify function).

Or, is that parameter (open price) simply ignored by the server when modifying an open order and the server can set any price?

When modifying a market position, the price should be set and equal to the opening price : OrderOpenPrise()

PS If I were you, I wouldn't look for "efficient algorithms" in this code - it looks like the person wrote code without really knowing what he's doing there...