Questions from Beginners MQL5 MT5 MetaTrader 5 - page 635

 

Help, please. What's wrong here?

 double buy_OrderProfit = 0;
 double sell_OrderProfit = 0;
 double buy_Order_price  = 0;
 double sell_Order_price = 0;
 
  double Drop_proc1 =AccountEquity();
  double Drop_proc2 =AccountBalance();
  double Drop_proc3 =(Drop_proc1*100)/Drop_proc2;
  
  if (Drop_procK <= Drop_proc3)
  {
  for(int i=OrdersTotal()-1; i>=0; i--)
       if ((OrderSelect(i,SELECT_BY_POS,MODE_TRADES))&& (OrderSymbol()==Symbol() && OrderMagicNumber()==Magic))
            if((OrderType()==OP_SELL) sell_OrderProfit + OrderProfit())
                 if((OrderType()==OP_BUY)  buy_OrderProfit + OrderProfit()) 

  for (int i=OrdersTotal()-1; i>=0; i--)
        if ((OrderSelect(i,SELECT_BY_POS,MODE_TRADES))&& (OrderSymbol()==Symbol() && OrderMagicNumber()==Magic))
             if ((OrderType()==OP_BUY ) && ( buy_OrderProfit < sell_OrderProfit ) )     
                  OrderClose (OrderTicket(),OrderLots(),MarketInfo(OrderSymbol(),MODE_BID),slippage);
                    if ((OrderType()==OP_SELL) && sell_OrderProfit < buy_OrderProfit )
                         OrderClose (OrderTicket(),OrderLots(),MarketInfo(OrderSymbol(),MODE_ASK),slippage);  
        } 
   else 1=1;

error 'if' - expressions are not allowed on a global scope v.4.1.5(2).mq4 793 3



 
new-rena:

Gentlemen!

How can I know if the market is closed or not during initialization of an MQL4 Expert Advisor? (what command?)

There is no such command. You can try to place a long-range pending order and then delete it if it does.
 
Kisolen:

Help, please. What's wrong here?

The if condition can only be inside a function.
 
Sergei Vladimirov:
The if condition can only be inside a function.
Thank you for responding. This code is inside the void OnTick() function, inside the curly brackets. It is far at the top, I apologize for not copying it. Is that how I understand it? This is a function, right? And there is still an error.
 
Kisolen:
Thank you for responding. This code is inside void OnTick() function, inside the curly brackets. It's far at the top, sorry I didn't copy it. Is that how I understand it? This is a function, right? And there is still an error.
The compiler writes that if is in the global scope. Maybe it's just an imbalance of parentheses, check it out (not surprising, by the way, with this style of code).
 
Vitaly Muzichenko:

Try this one, it seemed to work once, but I haven't used it:

Your code does not work, because the current time is determined by TimeCurrent(), and it returns the time of last quote, and your function will always return true. You can do the same with TimeLocal(), taking into account the time zone difference between computer and server, but this does not guarantee the correct result: the clock on the computer may be wrong, and it may not fill the time of session on the server, and on holidays (New Year), nobody knows what will be returned... And there is no simple and reliable function like MarketIsClosed() in µl.
 
Sergei Vladimirov:
There is no such command. You could try to place a long-range pending order and then delete it if it does.

Yes, a good option. The team will return a "Market is closed" error.

It's resolved.

Thank you!

 

Good afternoon, everyone.

Please advise which way to dig, or if you can a piece of code for an example :)

I need the following:

I have an Expert Advisor and an indicator on a chart. How to change indicator parameters with Expert Advisor?

Thanks in advance for the answers.

 
GrRusel:

Good afternoon, everyone.

Please advise which way to dig, or if you can a piece of code for an example :)

I need the following:

I have an Expert Advisor and an indicator on a chart. How to change indicator parameters with Expert Advisor?

Thanks in advance for the answers.

You will not change the indicator settings visually, but when reading data into the Expert Advisor through iCustom from the indicator, you can set parameters that are received by the Expert Advisor from this indicator. Or you can use global variables, if you teach the indicator to use them.
 
Vladimir Zubov:
You will not change the indicator settings visually, but when reading data into the Expert Advisor through iCustom from the indicator, you can set parameters that are received by the Expert Advisor from this indicator. Or you can use global variables, if you teach the indicator to use them.
I do it all through icustom. But when I change settings for the indicator, I want the indicator to change its visualization settings - for example, I have changed OBOS zones. I have decided to change OBOS zones. Maybe I should remove it from the chart and then add it with new settings but it has to be done through Expert Advisor. Hasn't anyone encountered such a problem and every time they change everything by hand - it can't be...
Reason: