wrong value for SYMBOL_TRADE_TICK_VALUE - page 5

 
Hi Fernando ,

this is the test I made with the OrderCalcProfit( ...) 


   double dbRiskMax = (500000.0 * 0.01);  
   double dbPriceOpen = 1928.960;
   double dbPriceStopLoss = 1928.655;
   double dbProfit = 0;
   double dbOrderLots = 0; 
   double dbLotsMin = SymbolInfoDouble(szSymbol,SYMBOL_VOLUME_MIN);
   double dbLotsMax = SymbolInfoDouble(szSymbol,SYMBOL_VOLUME_MAX);
   double dbLotsStep = SymbolInfoDouble(szSymbol,SYMBOL_VOLUME_STEP);
   double dbticksize = SymbolInfoDouble(szSymbol, SYMBOL_TRADE_TICK_SIZE);
  
        if( OrderCalcProfit( ORDER_TYPE_BUY, szSymbol, dbLotsMax ,dbPriceOpen, dbPriceStopLoss, dbProfit ) )
        {
           dbOrderLots = round( dbRiskMax * dbLotsMax / ( -dbProfit * dbLotsStep ) ) * dbLotsStep;  // = 1791.900000000000090949
           dbOrderLots = fmin( fmax( dbOrderLots, dbLotsMin ), dbLotsMax );     // then force to 100.0 = dbLotsMax 
        };  

while the resulting dbOrderLots =  1791.90 the force to 100.0 = dbLotsMax 
so the correct value is  1791.90  and is more or less equ to the value of my previous post.  

Ok , I can use this formula or my previous formula.  it's pretty the same.
but I was thinking  about the case of opening a BUY order with riskMax = 5000 with the mentioned prices...

If I well undestand  with a the broker limit of LotSize = SymbolInfoDouble("XAUUSD", SYMBOL_TRADE_CONTRACT_SIZE);  = 10 and the lotsize of 1791.9  limited to 100.0

signifies that I have to put 17 x 100.0 = dbLotsMax  orders ?? or better 

16 x 100.0 = dbLotsMax  orders  +

1  x 91.9 order ??

could you clarify me this 

thanks 


 

 
jossnet #: signifies that I have to put 17 x 100.0 = dbLotsMax  orders ?? or better 

No, you have another volume limit in the contract specifications that you have to abide by, namely SYMBOL_VOLUME_LIMIT, which will not allow you to overstep things so easily.

SYMBOL_VOLUME_LIMIT

Maximum allowed aggregate volume of an open position and pending orders in one direction (buy or sell) for the symbol. For example, with the limitation of 5 lots, you can have an open buy position with the volume of 5 lots and place a pending order Sell Limit with the volume of 5 lots. But in this case you cannot place a Buy Limit pending order (since the total volume in one direction will exceed the limitation) or place Sell Limit with the volume more than 5 lots.

double

 

It is advisable to use OrderCalcProfit() instead of tick_size to calculate the required position size:

    *    (1) avoid wrong tick_values for non-forex symbols (e.g., gold) by some brokers.
    *    (2) apply the correct profit calculation method depending on SYMBOL_TRADE_CALC_MODE,
    *    (3) adjust the tick_value to future rate (SL) if the base currency == account currency.


//+------------------------------------------------------------------+
//| Calculate the appropriate volume for the trade operation planned.|
//|                                                                  |
//| ordertype      : ORDER_TYPE_BUY or ORDER_TYPE_SELL only.         |
//| symbol         : Symbol name                                     |
//| risk_money     : Loss money when SL is hit, in account currency. |
//| price_open     : Open price                                      |
//| price_sl       : Close price                                     |
//| commission_lot : Comm. per lot per side, in account currency.    |
//+------------------------------------------------------------------+
double OrderCalcVolume(ENUM_ORDER_TYPE ordertype, string symbol, double risk_money, double price_open, double price_sl, double commission_lot = 0.0)
  {
   double volume=0;
   double profit=0;
   double maxvol=SymbolInfoDouble(symbol,SYMBOL_VOLUME_MAX);
//---
   if(OrderCalcProfit(ordertype,symbol,maxvol,price_open,price_sl,profit) && profit < 0)
     {
      volume=risk_money/(MathAbs(profit/maxvol)+2*commission_lot);

      // round volume to stepsize and clamp to min and max.
      //volume=CorrectVolume(symbol,volume,price_open,ordertype);
     }
//---
   return volume;
  }

please check the full code at https://www.mql5.com/en/code/viewcode/28029/267359/functions.mqh


Edit:

if your broker provides correct tick values, and you want to use them to calculate the position size, then please note that:

SYMBOL_TRADE_TICK_VALUE_PROFIT  is used to calculate position size of SELL (short) orders.

SYMBOL_TRADE_TICK_VALUE_LOSS  is used to calculate position size of BUY (long) orders.

 

Hi guys :
@Fernando Carreiro  : thanks , so I can suspect that all that limitations is because i have a demo account, Ok  i'll take it in to account.
 
@amrali  thank you for your suggestions. I have just tested this function with the code at the init of the page. Now I apply this line that seem more clear

your line : volume=risk_money/(MathAbs(profit/maxvol)+2*commission_lot); 

last question outside of these considerations.

If I want to use the EA in MAC  notebook  what is better todo :

1. can I use the compiled code in window also for MAC

2. do I have  to recompile the code using metaeditor for MAC
3. is better use the compiled code in window  and use it with Wine for MAC or use Parallel 

what you suggest about ?

Thank a lot to all guys 

 
Trinh Dat #:

Some broker have wrong tick value but profit is true.

try use the function, I also get it from forum 

I just want to thank you.

I got an incorrect tick value in XAUUSD when trying to get lot size per risk, i got 10 instead of 1, with that function I was able to get correct values, works like a charm.

Here is my final code case anyone want:

//+------------------------------------------------------------------+
double CalcLotSize(double riskPorcent, bool isBalance,  double stopLossDistance, string sym = NULL)
  {
   if(sym == NULL)
      sym = _Symbol;
   double lotSize = 0; //Return appropiate lot size
   double balance = isBalance ? AccountInfoDouble(ACCOUNT_BALANCE) : AccountInfoDouble(ACCOUNT_EQUITY); //Get acc balance ou equity
   double riskAmount = balance * (riskPorcent / 100); // porcent value
   double tValue = GetTickValue(sym);
   double tSize = SymbolInfoDouble(sym, SYMBOL_TRADE_TICK_SIZE);
   double point = SymbolInfoDouble(sym, SYMBOL_POINT);;
   double PipValue = (tValue * point) / tSize;
   double lots = riskAmount / (PipValue * stopLossDistance);
   return lots;
  }
//+------------------------------------------------------------------+
double GetTickValue(string symbol = NULL)
  {
   if(symbol == NULL)
      symbol = _Symbol;
   double Price = SymbolInfoDouble(symbol, SYMBOL_ASK);
   double TickSize = SymbolInfoDouble(symbol, SYMBOL_TRADE_TICK_SIZE);
   double Profit = 0;
   if(OrderCalcProfit(ORDER_TYPE_BUY, symbol, 1, Price, Price + TickSize, Profit) && Profit > 0)
      return Profit;
   return (SymbolInfoDouble(symbol, SYMBOL_TRADE_TICK_VALUE)/SymbolInfoDouble(symbol, SYMBOL_TRADE_TICK_SIZE));
  }
 

Wouldn't OrderCheck() return you the values you need in the struct MqlTradeCheckResult:

Field

Description

retcode

Return code

balance

Balance value that will be after the execution of the trade operation

equity

Equity value that will be after the execution of the trade operation

profit

Value of the floating profit that will be after the execution of the trade operation

margin

Margin required for the trade operation

margin_free

Free margin that will be left after the execution of the trade operation

margin_level

Margin level that will be set after the execution of the trade operation

comment

Comment to the reply code, error description

Documentation on MQL5: Constants, Enumerations and Structures / Data Structures / Request Check Result Structure
Documentation on MQL5: Constants, Enumerations and Structures / Data Structures / Request Check Result Structure
  • www.mql5.com
Request Check Result Structure - Data Structures - Constants, Enumerations and Structures - MQL5 Reference - Reference on algorithmic/automated trading language for MetaTrader 5
Reason: