Questions from Beginners MQL5 MT5 MetaTrader 5 - page 405

 
Leanid Aladzyeu:

Here's the code:

if(OrderStopLoss()>Ask+(TrailingStop+TrailingStep)*Point)

You do not consider the possibility that OrderStopLoss() is equal to zero. And zero in any case will be less than the expressionAsk+(TrailingStop+TrailingStep)*Point, and the condition will return false.

 
if((OrderStopLoss()>Ask+(TrailingStop+TrailingStep)*Point)||OrderStopLoss()==0)
Try it and see if it works. I haven't really got into the code.
 

Thank youVitalii Ananev,Vladimir Zubov!

I am writing an EA based on the RSI indicator. The principle of the EA will be to open orders by the indicator but it will also close by the same indicator (I do not know closing price)

if(OrderType()==OP_BUY && irsa <=20 || irsa >=40 )

OrderClose(ticket,Lot,Ask,Slippage,Blue);

return(0);

This condition is not met. Why? (It opens and immediately closes the order, and so on in the loop).

Here is the main question. My Expert Advisor will work with a large number of orders and I need to calculate the average, high and low price for all orders in the market, how do I find the closing prices of all orders to achieve a total profit and other similar operations?

 
Leanid Aladzyeu:

As indicated in the reference gives an error.

Yes!? And what kind of error does it give you? What does the compiler say?

 
Leanid Aladzyeu:

Thank youVitalii Ananev,Vladimir Zubov!

I am writing an EA based on the RSI indicator. The principle of the EA will be to open orders by the indicator but it will also close by the same indicator (I do not know closing price)

if(OrderType()==OP_BUY && irsa <=20 || irsa >=40 )

OrderClose(ticket,Lot,Ask,Slippage,Blue);

return(0);

This condition is not met. Why? (It opens and immediately closes the order, and so on in the loop).

Here is the main question. My Expert Advisor will be working with a large number of orders and I need to calculate the average, high and low price for all orders in the market, how do I find the closing prices of all orders to achieve a total profit and other similar operations?

The closing price of a position will not be known until the position is closed. After that, you can find out the closing price in the history of trades with the function OrderClosePrice().

It opens and immediately closes the position, because the closing condition is met. Check the logic of the close condition. Try to write it in this way to begin with:

if(OrderType()==OP_BUY && (irsa <=20 || irsa >=40))
{
  OrderClose(ticket,Lot,Ask,Slippage,Blue);

 return(0); 
}

Read reference about priority of calculations of logical expressions.

"You need to calculate the average, high and low price for all orders in the market" - I'm sorry, what price are we talking about? The open order price? The current price of a currency pair? The price when the total profit of all open positions will be reached without any losses?

 
Tapochun:

Yes!? And what kind of error does it give out? What does the compiler say?

Sorry, no error, but the sample method doesn't work for me (I get errors with trawling).
 
Vitalii Ananev:

The closing price of the position will not be known until the position is closed. The OrderClosePrice() function can then be found in the transaction history.

It opens and immediately closes the positions, because the close condition is fulfilled. Check the logic of the close condition. Try to write it in this way to begin with:

Read the help on priority of calculations of logical expressions.

Well, how to be in for example with a grid, there need a total TP or (and) the total price.

Maybe there is a buffer(s) where the price should be saved or maybe the indicator itself has a buffer where the open price of the last order is saved (and you can take and save the price from there to our global buffer)

 
Leanid Aladzyeu:

If we set a grid, we will need a total TP or (and) a total price.

Maybe there is a buffer(s) to save the price or in the indicator itself maybe there is a buffer where the opening price of the last order is stored (and from there we can take and save it to our global buffer)

I recommend to start studying the language with textbook Kovalev (you can find it on our site). It is, of course, a bit outdated, but in combination with the documentation it will be ok!
 
Leanid Aladzyeu:

Thank youVitalii Ananev,Vladimir Zubov!

I am writing an EA based on the RSI indicator. The principle of the EA will be to open orders by the indicator but it will also close by the same indicator (I do not know closing price)

if(OrderType()==OP_BUY && irsa <=20 || irsa >=40 )

OrderClose(ticket,Lot,Ask,Slippage,Blue);

return(0);

This condition is not met. Why? (It opens and immediately closes the order, and so on in the loop).

Here is the main question. If your EA will be working with a large number of orders and you need to calculate the average, high and low price for all orders in the market, how do you find the closing price of all orders to achieve a total profit and other similar operations?

You are trying to close a buy order on an asc, if you don't understand elementary things - read the documentation.

Or are you used to the rule of thumb?

 
Leanid Aladzyeu:

If we set a grid, we will need a total TP or (and) a total price.

Maybe there is a buffer(s) to save the price or in the indicator itself maybe there is a buffer where the opening price of the last order is stored (and from there we can take and save it to our global buffer)

You should calculate the average open price for all positions. And based on that calculate the total Take Profit for all positions. The open price of the positions is known (OrderOpenPrice()). Add up everything and divide by the number of open positions.
Reason: