FORTS Please help - page 30

 
demonsn:
Thank you. Added your option as a parallel check. Now it's just a matter of catching the right moment.

I'm 100% sure it will work!

Because you didn't fill the structure correctly (not just the fields, but the values as well).

Strange that the compiler didn't "swear".

You:

MqlTradeRequest.action = TRADE_ACTION_DEAL;

It needs to:

MtRequest.action = TRADE_ACTION_DEAL;
 

But no! The code in my message is not from the Expert Advisor, it is a corrected fragment of logs where debugging information is written from the Expert Advisor. My bad, my mistake.)

The EA itself fills in the structure as required, but the result of the check is different. It either calculates the margin correctly or gives some nonsense like in the example.

Here is a fragment from the live site

   MqlTradeRequest MtRequest = {0}; 

   switch(OrderType)
   {
      case ORDER_TYPE_BUY:         
         MtRequest.price     = CurrentTick.ask;         
         break;

      case ORDER_TYPE_SELL:         
         MtRequest.price     = CurrentTick.bid;
         break;

      default:
         LogFile.Log(LOG_PRINT,__FUNCTION__," error: Invalid OrderType");
         return(false);
   }

   MtRequest.tp        = 0.0;
   MtRequest.sl        = 0.0;
   MtRequest.action    = TRADE_ACTION_DEAL;
   MtRequest.magic     = 0;
   MtRequest.symbol    = strSymbol;
   MtRequest.volume    = dblLots;
   MtRequest.deviation = Config.Deviation;
   MtRequest.type      = OrderType;
   MtRequest.type_filling = Config.OrdersFillingType;
 

Make it so:

   MqlTradeRequest MtRequest = {0}; 
   MqlTradeRequest MtResult = {0}; 

   switch(OrderType)
   {
      case ORDER_TYPE_BUY:         
         MtRequest.price     = CurrentTick.ask;         
         break;

      case ORDER_TYPE_SELL:         
         MtRequest.price     = CurrentTick.bid;
         break;

      default:
         LogFile.Log(LOG_PRINT,__FUNCTION__," error: Invalid OrderType");
         return(false);
   }

   MtRequest.action    = TRADE_ACTION_DEAL;
   MtRequest.magic     = 77777777777777;
   MtRequest.symbol    = strSymbol;
   MtRequest.volume    = dblLots;
   MtRequest.type      = OrderType;
   MtRequest.type_filling = Config.OrdersFillingType;
   MtRequest.type_time = ORDER_TIME_DAY;
 

Here's another moment in the log:

 MqlTradeRequest structure:
   action: Action Deal
   magic: 0
   order: 0
   symbol: Si-12.15
   volume: 2.00
   price: 63365
   stoplimit: 0
   sl: 0
   tp: 0
   deviation: 50
   type: ORDER_TYPE_SELL
   type_filling: ORDER_FILLING_FOK
   type_time: gtc
   expiration: 1970.01.01 00:00
   comment: (null)

 MqlTradeCheckResult structure:
   retcode: 10019 (There is not enough money to complete the request)
   balance: 133921.71
   equity: 132772.57
   profit: 0.00
   margin: 172148.68
   margin_free: -39376.11
   margin_level: 77.13
   comment: No money

I pass the same structure to OrderSend() and everything opens perfectly!

By the way, build 1194.

Selling Si-12.15, 2 lots. GO for 1 contract is 5090 rubles. A trade should have the QR 5090*2 = 10180 RUB. But the function returns 172148.68 RUB, which equals 172148.68 / 5090 = 33.82 contracts!

What a miracle...

 
demonsn:

Here's another moment in the log:

I pass the same structure to OrderSend() and everything opens fine!

By the way, build 1194.

Selling Si-12.15, 2 lots. GO for 1 contract is 5090 rubles. A trade should have the QR 5090*2 = 10180 RUB. And the function returns 172148.68 rubles, which corresponds to 172148.68 / 5090 = 33.82 contracts!

What wonders...

1. I gave you a sample of how to properly fill out the structure, and you ignore this advice.

Then why are you asking?

2. 1194 build is not compatible with current servers (Renat mentioned this. Use build 1159 for now).

3. I don't use OrderCheck() at all, I check the funds myself.

//+------------------------------------------------------------------+
//| Expert Check money function                                      |
//+------------------------------------------------------------------+ 
bool CheckMoney( const string a_symbol, const long volume )
{
  if ( volume <= 0 )
  {
    Print( "Check Money: Объём лота указан не правильно!" );
    retutn ( false );
  } 
//---
  double a_go = SymbolInfoDouble( a_symbol, SYMBOL_MARGIN_INITIAL ) * double( volume);
  double free_margin = ( AccountInfoDouble( ACCOUNT_FREEMARGIN ) / 100 ) * 90; //90% от свободных средств
//---  
  if ( a_go <= free_margin )
  {
    return( true );
  }
  Print( "Check Money: Не достаточно средств!" );
  return( false );
}
 
Михаил:

1. I have given you a sample of how to fill in the structure correctly, and you ignore this advice.

Why are you asking then?

2) Build 1194 is not compatible with the current servers (Renat mentioned this. Use build 1159 for now).

3. I don't use OrderCheck() at all, I check the means myself.


1. I don't ignore it at all. I'm not ignoring it at all. I've included your sample into the code, now I'm observing it.

2. Oh, man! I didn't know that.

3. I did the same thing. And the function is almost exactly the same, except 90% (good idea, by the way)

I raised this question because my function (similar to yours) checks CS and allows to open position, while standard OrderCheck() sometimes fails.


This probably refers to point 2.

In the terminal log there are a lot of messages like:

2015.10.22 21:28:13.966 Ticks   old tick @RTS (tick: 2015.10.22 18:28:21, last: 2015.10.22 18:28:22) 0/0
2015.10.22 21:28:13.966 Ticks   old tick RTS-12.15 (tick: 2015.10.22 18:28:21, last: 2015.10.22 18:28:22) 0/0
2015.10.22 21:28:13.966 Ticks   old tick @RTS (tick: 2015.10.22 18:28:21, last: 2015.10.22 18:28:22) 0/0
2015.10.22 21:28:13.966 Ticks   old tick RTS-12.15 (tick: 2015.10.22 18:28:21, last: 2015.10.22 18:28:22) 0/0
2015.10.22 21:28:13.966 Ticks   old tick @RTS (tick: 2015.10.22 18:28:21, last: 2015.10.22 18:28:22) 0/0
2015.10.22 21:28:13.966 Ticks   old tick RTS-12.15 (tick: 2015.10.22 18:28:21, last: 2015.10.22 18:28:22) 0/0
2015.10.22 21:27:40.995 Ticks   old tick @LKOH (tick: 2015.10.22 18:27:48, last: 2015.10.22 18:27:49) 0/0
2015.10.22 21:27:40.995 Ticks   old tick LKOH-12.15 (tick: 2015.10.22 18:27:48, last: 2015.10.22 18:27:49) 0/0
2015.10.22 21:26:38.952 Ticks   old tick @Si (tick: 2015.10.22 18:26:46, last: 2015.10.22 18:26:47) 0/0
2015.10.22 21:26:38.952 Ticks   old tick Si-12.15 (tick: 2015.10.22 18:26:46, last: 2015.10.22 18:26:47) 0/0
2015.10.22 21:26:38.952 Ticks   old tick @Si (tick: 2015.10.22 18:26:46, last: 2015.10.22 18:26:47) 0/0
2015.10.22 21:26:38.952 Ticks   old tick Si-12.15 (tick: 2015.10.22 18:26:46, last: 2015.10.22 18:26:47) 0/0
2015.10.22 21:26:38.952 Ticks   old tick @Si (tick: 2015.10.22 18:26:46, last: 2015.10.22 18:26:47) 0/0
2015.10.22 21:26:38.952 Ticks   old tick Si-12.15 (tick: 2015.10.22 18:26:46, last: 2015.10.22 18:26:47) 0/0
2015.10.22 21:26:38.952 Ticks   old tick @Si (tick: 2015.10.22 18:26:46, last: 2015.10.22 18:26:47) 0/0
2015.10.22 21:26:38.952 Ticks   old tick Si-12.15 (tick: 2015.10.22 18:26:46, last: 2015.10.22 18:26:47) 0/0
2015.10.22 21:26:38.952 Ticks   old tick @Si (tick: 2015.10.22 18:26:46, last: 2015.10.22 18:26:47) 0/0
 
demonsn:


1. Why should I ignore it? I'm not ignoring it at all. I've included your sample in the code, now I'm watching.

2. Oh, man! I didn't know that.

3. I did the same thing. And the function is almost exactly the same, except 90% (good idea, by the way)

I precisely brought up this question because my function (similar to yours) checks CS and allows to open position, while standard OrderCheck() sometimes glitches.

So use your own on FORTS - it is much more correct :)
 
Михаил:
So use all your own on FORTS - it's much more correct :)

That's how you end up doing it! Tempted somewhere to use someone else's code or library, in order to save time on writing a "wheel" or test some idea.

But in the end you have to spend a week on catching errors and defects of other developers. In the end everything is rewritten so that there is no trace of other people's code.

 

Hello!

Futures glues appeared in the test window, which in itself is very pleasing, however, when trying to match the glue with the contract, I found that there are no trades on the glue at all - everything is fine on the contracts - there are quite a lot of trades. I checked on four instruments Si,RTS,GAZR,SBRF and the period 01.01.2015 -24.10.2015.

 
Andrey Kotrin:

Hello!

Futures glues appeared in the test window, which in itself is very pleasing, however, when trying to match the glue with the contract, I found that there are no trades on the glue at all - everything is fine on the contracts - there are quite a lot of trades. I checked on four instruments Si,RTS,GAZR,SBRF and the period 01.01.2015 -24.10.2015.

The tester does not work correctly on futures.
Reason: