Symbol Point Value - page 3

 
Dominik Christian Egert #:
As I said, I >ignore< this specific value.

I still calculate the tick value in account currency myself. I use quotes of currencies to do that.

In your case, for SPX it's Profit-Currency to account currency.

You take the symbol GBPUSD and get the quote. Then you calculate the account value from it.

Same goes for example 1. You get the quote of GBPUSD.

Edit: you need only the current prices. That's all. Tick size comes after you have the tick value.

Hi,

I guess I’m struggling with this bit - “Then you calculate the account value from it”. How?

 
Converting from USD to GBP. How do you do it?

Let's say you have 1 USD how much is this in GBP?

Current quote for GBPUSD is 1.22800. This means 1 GBP is worth 1.22800 USD.

1 USD is 1/1.22800 GBP

This is how it's calculated.

And the other way around is a multiplication.

How many USD are 1 GBP?

1 GBP is 1 * 1.22800 USD.

That's why you need to know if it is a reverse quote, so you can distinguish between the two calculation modes.

That's all. Simple math.

All you need to figure out is to find the symbols. I've given you a function example on how to find symbols.

You should be able to solve it from here on forward.
 
Dominik Christian Egert #:
Converting from USD to GBP. How do you do it?

Let's say you have 1 USD how much is this in GBP?

Current quote for GBPUSD is 1.22800. This means 1 GBP is worth 1.22800 USD.

1 USD is 1/1.22800 GBP

This is how it's calculated.

And the other way around is a multiplication.

How many USD are 1 GBP?

1 GBP is 1 * 1.22800 USD.

That's why you need to know if it is a reverse quote, so you can distinguish between the two calculation modes.

That's all. Simple math.

All you need to figure out is to find the symbols. I've given you a function example on how to find symbols.

You should be able to solve it from here on forward.

Yes understood. 

 So if I want to put a stop loss n ticks or points away from an entry how would you go about calculating the price? Or more specifically if I have an entry at P1 and stop at P2 and wanted to a monetary risk of £100 say how would you calculate the lot size?

 
Long: P1 - P2 = ticks * Point()

Symbol: EurUsd -> quote 1.04500

Hidden Quote: EURGBP 0.85750

Tick value EurUsd in Eur for every USD tick:
eur_tick = 1.0 / 1.04500

EurUsd Tick value in GBP:
Gbp_tick = eur_tick / 0.85750

I've just tipped this from top of my head.

I hope it is correct.


The volume, try to figure out, please.


 
Dominik Christian Egert #:
Long: P1 - P2 = ticks * Point()

Symbol: EurUsd -> quote 1.04500

Hidden Quote: EURGBP 0.85750

Tick value EurUsd in Eur for every USD tick:
eur_tick = 1.0 / 1.04500

EurUsd Tick value in GBP:
Gbp_tick = eur_tick / 0.85750

I've just tipped this from top of my head.

I hope it is correct.


The volume, try to figure out, please.


Aren't you mixing ticks and points in your first line? Fernando nicely pointed out that point and tick size can be different?

 
EdFuk #:

Aren't you mixing ticks and points in your first line? Fernando nicely pointed out that point and tick size can be different?

Yes, no.... 

Well, If you get these values from the symbols specifications, yes, Fernando's statement is reference here. - In this case I was refering to ticks and points as the same value, the smallest change in the least significant digit on the price.

- I use them synonymously here.... :-) 

BTW, I loked up the formula for the volume in my code:

Long:


const double vol = NormalizeVolume(LIB_USER_INPUT(CustomSymbol), 1.0 / ((tick_value / account_currency_risk) / (_open - _sl)));

and Short:

const double vol = NormalizeVolume(LIB_USER_INPUT(CustomSymbol), 1.0 / ((tick_value / account_currency_risk) / (_sl - _open)));



And for reference here the formulas for the price:


Symbol Currency tick value:

            contract_size   = ::SymbolInfoDouble(c_symbol, SYMBOL_TRADE_CONTRACT_SIZE);
            mbp_diff        = (::SymbolInfoString(c_symbol, SYMBOL_CURRENCY_MARGIN)) != (::SymbolInfoString(c_symbol, SYMBOL_CURRENCY_PROFIT));
            digit_f         = ::MathPow(10.0, ::SymbolInfoInteger(c_symbol, SYMBOL_DIGITS));
	    tick_size	    = 1.0 / digit_f;

        MqlTick current_quote = {};
        ::SymbolInfoTick(c_symbol, current_quote);

    // Return
    return((mbp_diff) ? ((contract_size * vol * tick_size) / current_quote.bid) : (contract_size / (digit_f / vol)));


Account currency tick value:

    // Get symbol tick value

        const double tick_value = mqp_SymbolTickValue(symbol, vol);


    // Get hidden quote

        MqlTick hidden_quote = {};
        ::SymbolInfoTick(hidden_symbol, hidden_quote);

    // Return
    return(((is_hidden_symbol) ? ((hidden_rev_quote) ? 1.0 / hidden_quote.bid : hidden_quote.bid) : 1.0) * tick_value);


You could argue using ask, depending on the direction, and how you take spread into account, but for me, I stick to bid price and manage spread later.


These are all only code snippets, but should give enough details on how to go forward with oyur work. - Maybe you can put together a full function and post it here for others to "copy and paste".


EDIT: 

As a sidenote, all calculations are always refering to one standard lot of the symbols contract definition. 

 
Dominik Christian Egert #:

Yes, no.... 

Well, If you get these values from the symbols specifications, yes, Fernando's statement is reference here. - In this case I was refering to ticks and points as the same value, the smallest change in the least significant digit on the price.

- I use them synonymously here.... :-) 

BTW, I loked up the formula for the volume in my code:

Long:


and Short:



And for reference here the formulas for the price:


Symbol Currency tick value:


Account currency tick value:


You could argue using ask, depending on the direction, and how you take spread into account, but for me, I stick to bid price and manage spread later.


These are all only code snippets, but should give enough details on how to go forward with oyur work. - Maybe you can put together a full function and post it here for others to "copy and paste".


EDIT: 

As a sidenote, all calculations are always refering to one standard lot of the symbols contract definition. 

Thanks Dominik,


I will review and get back to you. 


Cheers,


Ed

 
Dominik Christian Egert #:

Yes, no.... 

Well, If you get these values from the symbols specifications, yes, Fernando's statement is reference here. - In this case I was refering to ticks and points as the same value, the smallest change in the least significant digit on the price.

- I use them synonymously here.... :-) 

BTW, I loked up the formula for the volume in my code:

Long:


and Short:



And for reference here the formulas for the price:


Symbol Currency tick value:


Account currency tick value:


You could argue using ask, depending on the direction, and how you take spread into account, but for me, I stick to bid price and manage spread later.


These are all only code snippets, but should give enough details on how to go forward with oyur work. - Maybe you can put together a full function and post it here for others to "copy and paste".


EDIT: 

As a sidenote, all calculations are always refering to one standard lot of the symbols contract definition. 

Hi Dominik,


Thanks once again for posting the detailed post. I see that you are using the contract size and symbol digits in your tick value calculation which you get from the symbol specification. I can't see how your calculation would work for say the following instrument from AMP Global:


I did something similar in my code before and it was working fine with the instruments I was trading because they were FX where point size=tick size and were relatively straight forward but I can't see how your code would handle the above symbol correctly?


Many thanks,


Ed

 
EdFuk #:

Hi Dominik,


Thanks once again for posting the detailed post. I see that you are using the contract size and symbol digits in your tick value calculation which you get from the symbol specification. I can't see how your calculation would work for say the following instrument from AMP Global:


I did something similar in my code before and it was working fine with the instruments I was trading because they were FX where point size=tick size and were relatively straight forward but I can't see how your code would handle the above symbol correctly?


Many thanks,


Ed

That is correct, it does not work, this is because the specifications on this symbol are different. 

As you can see, there is a different calculation mode specified for this symbol. - Originally you asked for CFD specs. But here the formula is different.


Here is my code for giving the correct results, although, I was not able to test all of the implementations. I marked untested in red.


    // Retrieve cacheable values

            c_symbol        = symbol;
            contract_size   = ::SymbolInfoDouble(c_symbol, SYMBOL_TRADE_CONTRACT_SIZE);
            face_value      = ::SymbolInfoDouble(c_symbol, SYMBOL_TRADE_FACE_VALUE);
            interest        = ::SymbolInfoDouble(c_symbol, SYMBOL_TRADE_ACCRUED_INTEREST);
            liquidity_rate  = ::SymbolInfoDouble(c_symbol, SYMBOL_TRADE_LIQUIDITY_RATE);
            c_calc_mode     = (ENUM_SYMBOL_CALC_MODE)::SymbolInfoInteger(c_symbol, SYMBOL_TRADE_CALC_MODE);
            mbp_diff        = (::SymbolInfoString(c_symbol, SYMBOL_CURRENCY_MARGIN)) != (::SymbolInfoString(c_symbol, SYMBOL_CURRENCY_PROFIT));
            digit_f         = ::MathPow(10.0, ::SymbolInfoInteger(c_symbol, SYMBOL_DIGITS));
            tick_size       = ::SymbolInfoDouble(c_symbol, SYMBOL_TRADE_TICK_SIZE);
            tick_value      = ::SymbolInfoDouble(c_symbol, SYMBOL_TRADE_TICK_VALUE);


    // Get quotes

        MqlTick current_quote = {};
        ::SymbolInfoTick(c_symbol, current_quote);


    // Select calculation type
    switch(c_calc_mode)
    {
        case SYMBOL_CALC_MODE_FOREX:                                    
        case SYMBOL_CALC_MODE_FOREX_NO_LEVERAGE:        
        case SYMBOL_CALC_MODE_CFD:                      
        case SYMBOL_CALC_MODE_CFDINDEX:                 
        case SYMBOL_CALC_MODE_CFDLEVERAGE:              
        case SYMBOL_CALC_MODE_EXCH_STOCKS:              
        case SYMBOL_CALC_MODE_EXCH_STOCKS_MOEX:         return((mbp_diff) ? ((contract_size * vol * tick_size) / current_quote.bid) : (contract_size / (digit_f / vol)));
        case SYMBOL_CALC_MODE_FUTURES:                  
        case SYMBOL_CALC_MODE_EXCH_FUTURES:             
        case SYMBOL_CALC_MODE_EXCH_FUTURES_FORTS:       return(((1.0 / digit_f) * vol * tick_value) / tick_size);
        case SYMBOL_CALC_MODE_EXCH_BONDS:               
        case SYMBOL_CALC_MODE_EXCH_BONDS_MOEX:          return((vol * current_quote.bid * face_value * contract_size) + (interest * vol * contract_size));
        case SYMBOL_CALC_MODE_SERV_COLLATERAL:          return(vol * contract_size * current_quote.bid * liquidity_rate);
    }

    // Return
    return(DBL_MAX);



For reference, I have taken the calculation formulas from the documentation:

https://www.mql5.com/en/docs/constants/environment_state/marketinfoconstants#enum_symbol_info_integer


EDIT:

As you will notice, on Futures* you need to rely on the value TICK_VALUE, since it is the only reference given for the unterlying asset, there is no other way inside of MQL to determine the value, except, of course, taking a test-position and calculation the resulting values from the resulting deals. 

I guess aone approach could be to have a script that determines these values by testing them with a position, then entering them into the inputs of the EA, but in fact, I would assume, the values given on Futures* should be consistent with brokers, circumventing the aforementioned problem of unknown currency applied to the given TICK_VALUE.


Basically, it is important to understand the underlying contracts, and futures are different from CFDs or Forex. - IE try to calculate the correct margin with the given specifications by the broker "FXflat", you will see, I really had some difficulties understanding how it works, and to make it work across different brokers. But once you understand, its hard to not understand, and even harder to think of a different way of doing it. 

Documentation on MQL5: Constants, Enumerations and Structures / Environment State / Symbol Properties
Documentation on MQL5: Constants, Enumerations and Structures / Environment State / Symbol Properties
  • www.mql5.com
Symbol Properties - Environment State - Constants, Enumerations and Structures - MQL5 Reference - Reference on algorithmic/automated trading language for MetaTrader 5
 

Thanks Dominik,


Yes that is what I thought. I have to admit I seem to have bypassed the documentation (always a bad idea) and calculated using something that worked for FX. I will now get to work and base the calculations on the documentation. As you say where tick value is used in the calculation, like for exchange futures, hopefully it will be in account currency. I will check using the AMP global example I posted above.


It seems that for the calculation types that don't use tick value the brokers just output the value which could either be in account currency or profit. I'm hoping where it is required it comes out in account currency otherwise there is no standard and it's impossible to use.


Thanks for your help.


Cheers,


Ed

Reason: