Any questions from newcomers on MQL4 and MQL5, help and discussion on algorithms and codes - page 549

 

Is the following abbreviated construction in the code correct: a < b && ( c > d1 || c >d2 || c > d3) ?

This is to avoid writing: (a < b && c > d1) || (a < b && c > d2) etc. many times.

 
HeAic:

Is the following abbreviated construction in the code correct: a < b && ( c > d1 || c >d2 || c > d3) ?

This is to avoid writing: (a < b && c > d1) || (a < b && c > d2) and so on many times.

Of course it will do. The only thing I would do when writing such large constructions is to explicitly specify the priority brackets:

(a < b)  && ( c > d1 || c >d2 || c > d3)

For MT4/5 compilers, we can do it without the specified brackets, because the existing priorities will not allow us to calculate the result of the expression in a different way. But these parentheses have two advantages:

  1. The expression is easier to understand visually without any questions about priorities (don't remember the priorities for each compiler).
  2. If the code is moved to another compiler, which may have different priorities, the code will work the same as in the current compiler.
 
Alexey Viktorov:

Thank you, if

S_sk= SymbolInfoInteger("EURUSD",SYMBOL_SELECT);

returned the falce, there is no symbol in Market Watch, how do I add it there?

 
lil_lil:

Thank you, if

returned the falce, there is no symbol in Market Watch, how do I add it there?

SymbolSelect()

Everything is in the help. Cursor on function name and F1

 
Artyom Trishkin:

SymbolSelect()

It's all in the help. Cursor on the function name and F1

Thank you.

 

What is the reason for this? I wrote a script which sets limit orders in MT5. When I send it to the chart in the terminal the orders are not set, although the result.retcode returns 10009(order executed)

 
iv1986:

What is the reason for this? I wrote a script which sets limit orders in MT5. When I send it to the chart in the terminal the orders are not set, although the result.retcode returns 10009 (order executed)

  1. Code.
  2. Log.
  3. Statedments.
Where is it all?

 
Ihor Herasko:

  1. Code.
  2. Logbook.
  3. Statment.
Where is it all?

{MqlTradeRequest request={0};
MqlTradeResult result={0};
double Bid=SymbolInfoDouble(Symbol(),SYMBOL_BID);
double Ask=SymbolInfoDouble(Symbol(),SYMBOL_ASK);
int digits=SymbolInfoInteger(_Symbol,SYMBOL_DIGITS);
double p=NormalizeDouble(ChartPriceOnDropped(),digits);
if( SymbolInfoDouble(_Symbol,SYMBOL_TRADE_TICK_SIZE)==10)
{p=MathRound(ChartPriceOnDropped()*0.1)/0.1;
}
int V=75;
if (p<Ask)
{
request.action =TRADE_ACTION_PENDING; // type of trade operation
request.symbol =Symbol(); // symbol
request.volume =MathFloor(AccountInfoDouble(ACCOUNT_BALANCE)/V/((Ask-p)/
SymbolInfoDouble(_Symbol,SYMBOL_TRADE_TICK_SIZE)*SymbolInfoDouble(_Symbol,SYMBOL_TRADE_TICK_VALUE));
if (request.volume>AccountInfoDouble(ACCOUNT_BALANCE)/SymbolInfoDouble(_Symbol,SYMBOL_MARGIN_INITIAL))
{ request.volume=MathFloor(AccountInfoDouble(ACCOUNT_BALANCE)/SymbolInfoDouble(_Symbol,SYMBOL_MARGIN_INITIAL));
}
request.type =ORDER_TYPE_BUY_LIMIT; // order type
request.price =NormalizeDouble(Ask-SymbolInfoDouble(_Symbol,SYMBOL_TRADE_TICK_SIZE),digits); // price to open
request.deviation=50; // allowable deviation from price
request.sl =p; // Stop Loss position
request.tp =NormalizeDouble(Ask+(Ask-p)*3,digits); // Take Profit position
request.type_filling=ORDER_FILLING_IOC;
request.type_time=ORDER_TIME_DAY;
request.stoplimit=Ask;
OrderSend(request,result);
}
if (p>Bid)
{
request.action =TRADE_ACTION_PENDING; // type of trade operation
request.symbol =Symbol(); // symbol
request.volume =MathFloor(AccountInfoDouble(ACCOUNT_BALANCE)/V/((p-Bid)/
SymbolInfoDouble(_Symbol,SYMBOL_TRADE_TICK_SIZE)*SymbolInfoDouble(_Symbol,SYMBOL_TRADE_TICK_VALUE));
if (request.volume>AccountInfoDouble(ACCOUNT_BALANCE)/SymbolInfoDouble(_Symbol,SYMBOL_MARGIN_INITIAL))
{ request.volume=MathFloor(AccountInfoDouble(ACCOUNT_BALANCE)/SymbolInfoDouble(_Symbol,SYMBOL_MARGIN_INITIAL));
} // volume
request.type =ORDER_TYPE_SELL_LIMIT; // order type
request.price =NormalizeDouble(Bid+SymbolInfoDouble(_Symbol,SYMBOL_TRADE_TICK_SIZE),digits); // price to open
request.deviation=50; // allowable deviation from price
request.sl =p; // Stop Loss position
request.tp =NormalizeDouble(Bid-(p-Bid)*3,digits); // Take Profit position
request.type_time=ORDER_TIME_DAY;
request.type_filling=ORDER_FILLING_IOC;
request.stoplimit=Bid;
OrderSend(request,result);

}

the log says: 2018.05.14 10:12:38.187 Trades '992940': sell limit 3.00 Si-6.18 at 62066 (62065) sl: 62331 tp: 61267 placed for execution

 
iv1986:

The log says: 2018.05.14 10:12:38.187 Trades '992940': sell limit 3.00 Si-6.18 at 62066 (62065) sl: 62331 tp: 61267 placed for execution

This is written in the general log. And what's in the "Experts" log? And not just one line, but the whole log. There is not much to see through the keyhole.

Besides, there is no check for return codes in the cited code. So it's not clear on what basis the conclusion about the error code is made.

To advise something, you need to have clearly reproducible steps (to see what you see), and there are none here. Cut out the problematic part of the code, run it yourself and then show exactly what is failing.

P. S. To insert the code, please use the "</>" icon or Alt+S.

 

At the end of the code alsoAlert(result.retcode);

in the general log:

2018.05.14 12:08:16.984 Scripts script LIMIT (Si-6.18,M15) loaded successfully

2018.05.14 12:08:17.187 Trades '992940': buy limit 3.00 Si-6.18 at 62091 (62092) sl: 61821 tp: 62905

2018.05.14 12:08:17.484 Trades '992940': accepted buy limit 3.00 Si-6.18 at 62091 (62092) sl: 61821 tp: 62905

2018.05.14 12:08:17.500 Trades '992940': buy limit 3.00 Si-6.18 at 62091 (62092) sl: 61821 tp: 62905 placed for execution

2018.05.14 12:08:17.546 Trades '992940': order #13235300 buy limit 3.00 / 3.00 Si-6.18 at 62091 done in 337.532 ms

2018.05.14 12:08:17.578 Scripts script LIMIT (Si-6.18,M15) removed


In the Experts column: 2018.05.14 12:08:17.578 LIMIT (Si-6.18,M15) Alert: 10009, nothing else




Reason: