Questions from Beginners MQL5 MT5 MetaTrader 5 - page 940

 
Artyom Trishkin:

It won't work here - he doesn't use smartphones and other new gadgets - there's a phone from Smolny...

There's at least one like-minded person here. I, too, ignore all these gadgets and social media. Except there's no phone from the Kremlin...

 

I'm sick of the requotes.

//+------------------------------------------------------------------+
void OpenSell()
  {

   m_symbol.Name("EURUSD");
   RefreshRates();
   if(m_trade.Sell(InpLots,"EURUSD",m_symbol.Bid(),0.0,0.0))
     {
      if(m_trade.ResultDeal()==0)
        {
         Print("#1 Sell -> false. Result Retcode: ",m_trade.ResultRetcode(),
               ", description of result: ",m_trade.ResultRetcodeDescription());
         PrintResultTrade(m_trade,m_symbol);
        }
      else
        {
         Print("#2 Sell -> true. Result Retcode: ",m_trade.ResultRetcode(),
               ", description of result: ",m_trade.ResultRetcodeDescription());
         PrintResultTrade(m_trade,m_symbol);
        }

     }

//---
  }
//+------------------------------------------------------------------+

What is wrong with this code? I don't even get the result of an order execution check.

I just get a table with a requote, that's all.


 
ilvic:

I'm sick of the requotes.

What is wrong with this code? I don't even get the result of an order execution check.

I just get a table with a requote and that's all.


You should paste thePrintResultTrade resultas a code. Not in the form of a picture but in the form of a code.

 

This is the expert writing. Please note he does not write the result of the test

2018.11.02 15:20:36.769 Above (EURUSD,M1)       CTrade::OrderSend: instant sell 1.00 EURUSD at 1.14299 [requote (1.14307/1.14317)]

And this is what the log says.

2018.11.02 11:18:49.826 Network '13107230': scanning network for access points
2018.11.02 11:19:17.821 Network '13107230': scanning network finished
2018.11.02 15:20:35.846 Trades  '13107230': instant sell 1.00 EURUSD at 1.14299 (deviation: 100)
2018.11.02 15:20:36.769 Trades  '13107230': requote 1.14307 / 1.14317 (instant sell 1.00 EURUSD at 1.14299 (deviation: 100))

Server methaquotes demo

 
ilvic:

This is written by an expert. Please note he does not write the result of the test

And this is what the log says.

Server methaqvotes demo

Insert thePrintResultTraderesultas a code. Not as a picture, but as a code.


Or youdon't get toPrintResultTrade at alland get thrown out first?

 

Is it ? If not then tell me what you mean.

//+------------------------------------------------------------------+
//| Print CTrade result                                              |
//+------------------------------------------------------------------+
void PrintResultTrade(CTrade &trade,CSymbolInfo &symbol)
  {
   Print("File: ",__FILE__,", symbol: ",m_symbol.Name());
   Print("Code of request result: "+IntegerToString(trade.ResultRetcode()));
   Print("code of request result as a string: "+trade.ResultRetcodeDescription());
   Print("Deal ticket: "+IntegerToString(trade.ResultDeal()));
   Print("Order ticket: "+IntegerToString(trade.ResultOrder()));
   Print("Volume of deal or order: "+DoubleToString(trade.ResultVolume(),2));
   Print("Price, confirmed by broker: "+DoubleToString(trade.ResultPrice(),symbol.Digits()));
   Print("Current bid price: "+DoubleToString(symbol.Bid(),symbol.Digits())+" (the requote): "+DoubleToString(trade.ResultBid(),symbol.Digits()));
   Print("Current ask price: "+DoubleToString(symbol.Ask(),symbol.Digits())+" (the requote): "+DoubleToString(trade.ResultAsk(),symbol.Digits()));
   Print("Broker comment: "+trade.ResultComment());
  }
//+------------------------------------------------------------------+
 
ilvic:

This is the expert writing. Please note he does not write the result of the test

And this is what the log says.

Server methaquotes demo.

Why did you have to cut the code? Example of opening function inParabolic SAR EA code

//+------------------------------------------------------------------+
//| Open Sell position                                               |
//+------------------------------------------------------------------+
void OpenSell(double sl,double tp)
  {
   sl=m_symbol.NormalizePrice(sl);
   tp=m_symbol.NormalizePrice(tp);

   double short_lot=InpLots;
//--- check volume before OrderSend to avoid "not enough money" error (CTrade)
   double free_margin_check= m_account.FreeMarginCheck(m_symbol.Name(),ORDER_TYPE_SELL,short_lot,m_symbol.Bid());
   double margin_check     = m_account.MarginCheck(m_symbol.Name(),ORDER_TYPE_SELL,short_lot,m_symbol.Bid());
   if(free_margin_check>margin_check)
     {
      if(m_trade.Sell(short_lot,m_symbol.Name(),m_symbol.Bid(),sl,tp))
        {
         if(m_trade.ResultDeal()==0)
           {
            Print("#1 Sell -> false. Result Retcode: ",m_trade.ResultRetcode(),
                  ", description of result: ",m_trade.ResultRetcodeDescription());
            PrintResultTrade(m_trade,m_symbol);
           }
         else
           {
            Print("#2 Sell -> true. Result Retcode: ",m_trade.ResultRetcode(),
                  ", description of result: ",m_trade.ResultRetcodeDescription());
            PrintResultTrade(m_trade,m_symbol);
           }
        }
      else
        {
         Print("#3 Sell -> false. Result Retcode: ",m_trade.ResultRetcode(),
               ", description of result: ",m_trade.ResultRetcodeDescription());
         PrintResultTrade(m_trade,m_symbol);
        }
     }
   else
     {
      Print(__FUNCTION__,", ERROR: method CAccountInfo::FreeMarginCheck returned the value ",DoubleToString(free_margin_check,2));
      return;
     }
//---
  }
 
ilvic:

Is it ? If not then tell me what you mean.

You threw out check step #3 from the code.

 
Vladimir Karputov:

Insert the result ofPrintResultTrade as code. Not as a picture, but as a code.


Or youdon't get toPrintResultTrade and get thrown out earlier?

Exactly, if the order is executed, your print will look like this

2018.11.02 10:09:12.648 Above (EURUSD,M1)       #2  Buy -> true. Result Retcode: 10009, description of result: done at 1.14387

If there is a requote, the Expert Advisor remains silent.

And I am left with an unfilled order

 
ilvic:

Exactly, if the order is executed, the print will look like this

If a requote, the Expert Advisor will be silent like a fish.

And I am left with an unfilled order.

In my post, I gave an example of a function. I did not cut it. There is an example inParabolic SAR EA

Reason: