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

 
iv1986:

At the end of the code also Alert(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

Well here's how to help you? First, you write that Sell Limit is not exhibited, you give extracts from the log. And now we are speaking about a Buy Limit order. So, the problem must be floating. In addition, you have never cited the statment. You claim that the order is not visible in reality. And the statment may help to clarify the situation.

 
void OnStart()
 {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;                     // тип торговой операции
             request.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;                        // тип ордера
             request.price    =NormalizeDouble(Ask-SymbolInfoDouble(_Symbol,SYMBOL_TRADE_TICK_SIZE),digits);     // цена для открытия
             request.deviation=50;                                     // допустимое отклонение от цены
             request.sl      =p;                                      // Stop Loss позиции
             request.tp      =NormalizeDouble(Ask+(Ask-p)*3,digits);    // Take Profit позиции
             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;                     // тип торговой операции
             request.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));
             }                                      // объем 
             request.type     =ORDER_TYPE_SELL_LIMIT;                        // тип ордера
             request.price    =NormalizeDouble(Bid+SymbolInfoDouble(_Symbol,SYMBOL_TRADE_TICK_SIZE),digits);      // цена для открытия
             request.deviation=50;                                     // допустимое отклонение от цены
             request.sl      =p;                                      // Stop Loss позиции
             request.tp      =NormalizeDouble(Bid-(p-Bid)*3,digits); // Take Profit позиции
             request.type_time=ORDER_TIME_DAY;
             request.type_filling=ORDER_FILLING_IOC;
             request.stoplimit=Bid;
             OrderSend(request,result);
            }  
       
       Alert(result.retcode);          
     return;
   }
 
Ihor Herasko:

How can I help you? First, you write that Sell Limit is not being placed, and you give excerpts from the log. Now we are talking about a Buy Limit order. So, the problem must be floating. In addition, you have never cited the statment. You claim that the order is not visible in reality. The statment may help you clarify the situation.

Neither Sell Limit nor Buy Limit is set, Alert(result.retcode) returns 10009. Where can I get this "statment", what do I need to do?

 
iv1986:

Run this code on my own. Note that you will get a division error of 0 on the non-binary symbols, as there is no initialising margin there.

In the code where I managed to run it, I had to add a volume check. Otherwise, the volume was equal to zero:

if (request.volume < SymbolInfoDouble(_Symbol, SYMBOL_VOLUME_MIN))
   request.volume = SymbolInfoDouble(_Symbol, SYMBOL_VOLUME_MIN);

After that, the order is set successfully. Also note that it triggers quite quickly - it is close to the price. Therefore, the order itself might not be noticed by you. The order will either become a position or be attached to it if the account type is netting.

 
iv1986:

Neither Sell Limit nor Buy Limit is set, Alert(result.retcode) returns 10009. Where can I get this "retcode", what should I do?

The "History" tab of the "Toolbox" window. In the context menu select "Orders". Then select "Report" from the context menu - "HTML". But you will probably be able to see for yourself why the order is missing: its status will be marked "filled".

 

Found my 2009 script, but it now compiles with a warning:'M' - unrecognized character escape sequence 1.mq4 66 37

PapkaFiles    = TerminalPath()+"\MQL4\Files\\";//Путь к терминалу 

Can you tell me what to tweak in the line to compile correctly?

 
Ihor Herasko:

Run this code on my own. Note that you will get a division error of 0 on the non-binary symbols, as there is no initialising margin there.

In the code where I managed to run it, I had to add a volume check. Otherwise, the volume was equal to zero:

After that, the order is set successfully. Also note that it triggers quite quickly - it is close to the price. Therefore, the order itself might not be noticed by you. It is converted to a position or attached to it if the account type is netting.

Thank you!
 
HeAic:

Found my 2009 script, but it now compiles with a warning:'M' - unrecognized character escape sequence 1.mq4 66 37

Can you tell me what to tweak in the line to compile correctly?

Put a double backslash before MQL4
 
Hello, can you tell me if it's possible to connect a copying signal and a robot to an mt4 account and connect all this to the vps?
 
Artyom Trishkin:
Put a double backslash before MQL4
and before F as well. All slashes should be double slashes