Discussion of article "The checks a trading robot must pass before publication in the Market" - page 5

 
Oleksii Chepurnyi:
But then there's a chance of missing a deal.....
It's about the market. So there should be no errors. Or there should be their adequate processing.
 
Artyom Trishkin:
It's about the market. So there should be no errors. Or there should be their adequate processing.

If it wasn't for the market, I wouldn't have bothered much :)

I understand that the margin is for slippage?

 
Oleksii Chepurnyi:

If it wasn't for the market, I wouldn't have bothered much :)

I understand that the margin is for slippage?

Yes, in fact, to reduce the probability of making a mistake in case of sharp price movements a little bit more.

 
Oleksii Chepurnyi:

If it wasn't for the market, I wouldn't have bothered much :)

I understand that the margin is for slippage?

Slippage - at execution, and here - correctness of the trade request at the moment of the market environment state.

Calculated - checked correctness, corrected if necessary and sent the request. Then we checked the result of the request. This is on the EA side.

And execution is on the server side, and the slippage value is already required by the server part to accept or reject the request when the price changes.

 

Afternoon.

From the documentation:

SYMBOL_VOLUME_LIMIT.

The maximum allowed for this symbol is the total volume of an open position and pending orders in one direction (Buy or Sell). For example, if the limit is 5 lots, you can have an open Buy position with the volume of 5 lots and place a Sell Limit pending order with the volume of 5 lots. But you cannot place a Buy Limit pending order (because the total volume in one direction will exceed the limit) or place a Sell Limit order of more than 5 lots.


As far as I understand, the calculation should take into account the volume of all positions and orders only in the direction in which we are going to open a deal or place an order.

But here the Limitation on the number of lots for one symbol the direction is not taken into account at all....

Or have I misunderstood something?

 
Vladislav Andruschenko:

Perhaps the lot should be normalised in this function so that there is no Disabled.

and then the function writes that there is no money, but it does not send a request to the server to open positions, which satisfies the rules of the market.

I have recently started to use such an instruction about 2 years ago:

Actually everything works.

When opening a trade, the Expert Advisor simply returns the Print("Not Enought Money Margin Required "+( string)margin) string;

The Expert Advisor is tested in the market, everyone is happy with it

Thanks Vladislav!

Your variant is still working, unlike mine, which previously worked fine and this one, to which the validator directs us:

bool CheckMoneyForTrade(string symb, double lots,int type)
  {
   double free_margin=AccountFreeMarginCheck(symb,lots,type);
   //-- if there's not enough money
   if(free_margin<0)
     {
      string oper=(type==OP_BUY)? "Buy":"Sell";
      Print("Not enough money for ", oper," ",lots, " ", symb, " Error code=",GetLastError());
      return(false);
     }
   //-- the test was successful
   return(true);
  }
 
Ramiz Mavludov:
Thanks Vladislav!

Your variant is still working unlike mine, which worked fine before and this one, which the validator directs us to:

Where is this code shown?

PS I found it in the Portuguese and Japanese versions of the article and corrected it. There is also gd
 
Oleksii Chepurnyi:

Afternoon.

From the documentation:

SYMBOL_VOLUME_LIMIT.

The maximum allowed for this symbol is the total volume of an open position and pending orders in one direction (Buy or Sell). For example, if the limit is 5 lots, you can have an open Buy position with the volume of 5 lots and place a Sell Limit pending order with the volume of 5 lots. However, you cannot place a Buy Limit pending order (because the total volume in one direction will exceed the limit) or place a Sell Limit order of more than 5 lots.


As far as I understand, the calculation should take into account the volume of all positions and orders only in the direction in which we are going to open a deal or place an order.

But here the Limitation on the number of lots for one symbol the direction is not taken into account at all....

Or have I misunderstood something?

You are right, in this example the direction is not taken into account. You can try to do it by taking into account the sign: Buy orders are taken positively, Sell - negatively. The value and sign on the output will give us the volume and direction.

We need to correct

 
Rashid Umarov:

Where is this code shown?

PS Found it in the Portuguese and Japanese versions of the article and corrected it. There is also gd

I can't show it now, when I sent it for validation, in the report clicking on the 148 error I got to the

bool CheckMoneyForTrade(string symb, double lots,int type)
  {
   double free_margin=AccountFreeMarginCheck(symb,lots,type);
   //-- if there's not enough money
   if(free_margin<0)
     {
      string oper=(type==OP_BUY)? "Buy":"Sell";
      Print("Not enough money for ", oper," ",lots, " ", symb, " Error code=",GetLastError());
      return(false);
     }
   //-- the test was successful
   return(true);
  }
The version of the site was still in Russian.
 
Rashid Umarov:

You are right, in this example the direction is not taken into account. We can try to do it by taking into account the sign: Buy orders are taken positively, Sell - negatively. The value and sign at the output will give us the volume and direction.

Need to be corrected

I don't understand about the sign...

I wrote this

//--- maximum volume for all items
   double max_volume = SymbolInfoDouble(CheckSymb,SYMBOL_VOLUME_LIMIT);
   if(ED(max_volume,0)) return(true);
//---
   double sum_volume = 0;
   int    oper = 0;
   if(CheckOperation==ORDER_TYPE_BUY  || CheckOperation==ORDER_TYPE_BUY_LIMIT  || CheckOperation==ORDER_TYPE_BUY_STOP  || CheckOperation==ORDER_TYPE_BUY_STOP_LIMIT)  oper = 1;
   if(CheckOperation==ORDER_TYPE_SELL || CheckOperation==ORDER_TYPE_SELL_LIMIT || CheckOperation==ORDER_TYPE_SELL_STOP || CheckOperation==ORDER_TYPE_SELL_STOP_LIMIT) oper = 2;
   for(int i=PositionsTotal()-1; i>=0; i--)
     {
      if(!pst.SelectByIndex(i)) ShowError;
      if(pst.Symbol()==CheckSymb)
        {
         if(oper==1 && pst.PositionType()==POSITION_TYPE_BUY)  sum_volume += pst.Volume();
         if(oper==2 && pst.PositionType()==POSITION_TYPE_SELL) sum_volume += pst.Volume();
        }
     }
   for(int i=OrdersTotal()-1; i>=0; i--)
     {
      if(!ord.SelectByIndex(i)) ShowError;
      if(ord.Symbol()==CheckSymb)
        {
         if(oper==1 && (ord.OrderType()==ORDER_TYPE_BUY  || ord.OrderType()==ORDER_TYPE_BUY_LIMIT  || ord.OrderType()==ORDER_TYPE_BUY_STOP  || ord.OrderType()==ORDER_TYPE_BUY_STOP_LIMIT))  sum_volume += ord.VolumeCurrent();
         if(oper==2 && (ord.OrderType()==ORDER_TYPE_SELL || ord.OrderType()==ORDER_TYPE_SELL_LIMIT || ord.OrderType()==ORDER_TYPE_SELL_STOP || ord.OrderType()==ORDER_TYPE_SELL_STOP_LIMIT)) sum_volume += ord.VolumeCurrent();
        }
     }
   if(sum_volume+CheckVolume > max_volume)
     {
      Alert(OrdersText(0010),DoubleToString(max_volume,VolumeDigits(CheckSymb)));
      return(false);
     }
//---
   return(true);