Questions from Beginners MQL5 MT5 MetaTrader 5 - page 1406

 
MrBrooklin #:

Hello Marco!


Sincerely, Vladimir.

Thank you, it's a bit of a misnomer. This code does not open many positions. Without it, it opens a lot more.
 
Marco Nicholas #:
Hello. Can you advise how to correctly implement this condition in the code.

I need to open the first position after the time specified in the settings (hour, minute, example "open first trade after 23-55") and then disregard this condition.

This code works perfectly, but it opens absolutely all deals after "one_time_current.hour" and "one_time_open.min" I only need to execute this condition once (to open 1 position) and not apply it to subsequent ones.

Hello Marco! You asked for help to make it so that one position was opened. Now you are writing that:

Спасибо, немного не то. Такой код не дает открыть много позиции. Без него открывает намного больше.

First you need to decide how many positions you want to open - many or one. Perhaps, machine translation of the words may not have enabled you to correctly formulate your request.

Regards, Vladimir.

 
Marco Nicholas #:
Hello. Can you advise how to correctly implement this condition in the code.

I need to open the first position after the time specified in the settings (hour, minute, example "open first trade after 23-55") and then disregard this condition.

This code works perfectly, but it opens absolutely all deals after "one_time_current.hour" and "one_time_open.min" We only need to execute this condition once (for opening of 1 position) and not apply it to subsequent ones.

So there should be another condition for the next ones, but without ignoring the condition "after 23:55", is that how I understand it?

 
MrBrooklin #:

Hello Marco! You asked for help to make one position open. Now you are writing that:

First, you need to decide how many positions you want to open - many or one. Perhaps, machine translation of the words does not allow you to correctly formulate your request.

Regards, Vladimir.

Yes, that's right, we misunderstood each other. When I wrote:

"This code works fine, but absolutely all trades open after "one_time_current.hour" and "one_time_open.min"but we only need to execute this condition once (to open 1 position) and not apply it to subsequent ones. "

I wanted to clarify this, not to open one position " 1 position" (you must have understood it that way), I meant to apply the condition to open only the first position and not apply it to subsequent ones.

Thank you for responding.

 
Alexey Viktorov #:

So there should be another condition for the next positions, but without ignoring the "after 23:55" condition, is that how I understand it?

It turns out, yes, it does not need to be applied (cancelled) for the next positions. We only need toopen the first position (as for the start of the EA, after a certain hour and minute), and for subsequent positions this condition does not need to be applied.

Is it possible to do it all in one condition?

if(one_time_current.hour>=one_time_open.hour && one_time_current.min>=one_time_open.min)
 
Marco Nicholas #:

It turns out yes, it does not need to be applied (cancelled) to the next positions. It only needs to beapplied to open the first position (as for the start of the EA, after a certain hour and minute), and for subsequent positions this condition does not need to be applied.

Is it possible to do it all in one condition?

  bool first_position_was_opened=false;
  ...
  if(first_position_was_opened || ( one_time_current.hour>=one_time_open.hour && one_time_current.min>=one_time_open.min))

And don't forget to set "first_position_was_opened=true" after opening any position.

The "first_position_was_opened" variable must be global or static.
 
Please help!!!
I need a function that calculates profits for the last week for a specific symbol and magik.
I've found examples without magik, but I can't get magik to work(((.
 
JRandomTrader #:

And don't forget to set "first_position_was_opened=true" after opening any position.

The "first_position_was_opened" variable must be global or static.

Thank you. Interesting working variant.

I also want to note that my first variant originally worked too, under one condition: if you divide the openings for the first and for subsequent positions. It's also possible via else.

if(one_time_current.hour>=one_time_open.hour && one_time_current.min>=one_time_open.min)
if(item_positions==0) для первой


if(item_positions>0) для последующих

Thanks to your answers, learning mql5 is much faster.
 

Or you can use PositionsTotal() instead of the first_position_was_opened variable in the code from @JRandomTrader:

if(PositionsTotal() > 0 || (one_time_current.hour>=one_time_open.hour && one_time_current.min>=one_time_open.min)) {}

In this case, this variable is not needed and you don't need to set this variable to True after opening and to False after closing all positions.

 

Good afternoon. I'm testing an EA and when I debug it using historical data everything goes as expected. Trades are initiated and closed as they should and the EA seems to be working correctly.
However, when I enable this same EA to "trade" on the demo account, it simply doesn't send the orders, remaining totally inert.
In other words, I can carry out backtests based on this EA, including following it on the chart during debugging, but for some reason it doesn't send orders on the market in real time (demo account).

The asset I'm testing is WINM22.


The following messages appear in the MT5 "diary":
- expert loaded successfully
- automated trading is enabled

And nothing else. Not even an error message throughout the trading session.

Can anyone help me understand what's going on?



The commands I'm using to send orders are:
mrequest.action = TRADE_ACTION_DEAL;
mrequest.price = NormalizeDouble(last_price,1);
mrequest.sl = NormalizeDouble(last_price + STP,1);
mrequest.tp = NormalizeDouble(last_price - TKP,1);
mrequest.symbol= _Symbol;
mrequest.volume = Lot;
mrequest.magic = EA_Magic; 
mrequest.type= ORDER_TYPE_SELL;
mrequest.type_filling = ORDER_FILLING_FOK;
mrequest.deviation=NormalizeDouble(slippage,_Digits);
OrderSend( mrequest , mresult );

Thank you.

Reason: