SYMBOL_TRADE_TICK_VALUE_LOSS vs SYMBOL_TRADE_TICK_VALUE_PROFIT - page 6

 
Jeepack #: My main complaint about tick value is that it only allows you to get the exact loss value of a stop loss if the traded pair's quote currency is the same as your account's currency. If you are trading a pair that has your account's currency as the base currency, then tick value will not give you the correct loss value for your stop loss. You already know why but for those who don't it's because the loss on your trade will be converted with the close price of the trade which will not be the same as the open price while the tick value uses the open price to convert to your account's currency. So for example, if my account is in USD and I trade USDJPY, the tick value multiplied by the size of the price change and lot size will not give me the correct value for the loss on that trade.*edit: I think I have an idea to work out a way to get the correct loss size with tick value with a shortcut that skips all the complicated conversions, will post it later tonight

That is not the intended use of "Tick Value". Tick value is for getting the current value, not future value, not past value.

I have watched these two threads unfold and seen how the three main actors have turned a mole-hill into a mountain by over-analysing and over-complicating things.

I have said nothing because I did not wish to enter into any heated debate.

I have seen nothing thus far that makes me sway from my original remarks in first posts on this and other thread.

And so I will repeat my main remark—the calculations for the risk or reward, are only approximations.

There is no need for any more precise methods because there are other factors that will inevitably affect the final loss or profit at closing time which simply cannot be accounted for 100%.

So simply accept that this approximation is "good enough" and move on to the real and most important part of it all—to actually trade with it and hopefully make some money.

This will be my last post on this matter. I hope you will understand this post's intent.

 
Fernando Carreiro #:

That is not the intended use of "Tick Value". Tick value is for getting the current value, not future value, not past value.

I have watched these two threads unfold and seen how the three main actors have turned a mole-hill into a mountain by over-analysing and over-complicating things.

I have said nothing because I did not wish to enter into any heated debate.

I have seen nothing thus far that makes me sway from my original remarks in first posts on this and other thread.

And so I will repeat my main remark—the calculations for the risk or reward, are only approximations.

There is no need for any more precise methods because there are other factors that will inevitably affect the final loss or profit at closing time which simply cannot be accounted for 100%.

So simply accept that this approximation is "good enough" and move on to the real and most important part of it all—to actually trade with it and hopefully make some money.

This will be my last post on this matter. I hope you will understand this post's intent.

Of course if the discussion is about calculating the risk/reward you are right, it's approximation in all cases. There is not even a useful usage for SYMBOL_TRADE_TICK_VALUE_LOSS/SYMBOL_TRADE_TICK_VALUE_PROFIT or whatever the name you want to give them, they are almost useless because as you said, there are "other factors that will inevitably affect the final loss or profit ".

However, the discussion has come further to how the profit is calculated at closure of a trade (so I am not even talking about tick value here, but just profit/loss calculation using rates). At least it's how (and why) I started to discuss. I knew Metaquotes CEO once said the profit/loss is a parameter for the conversion to account currency, that combined to some experience seeing some trades which do not match the simple logic "Direct: BUY:Ask SELL:Bid - Indirect: BUY:1/Bid SELL:1/Ask", I was sure the profit/loss dependence was real. It appeared I was wrong, I am glad I learnt something from the discussion and also something about how to discuss better, keeping an open mind.

From Metaquotes CEO (back in 2012) : "More precisely, the TickValue when converted to the target currency depends on whether it is unprofitable or not. That is, if we received a loss of 1 pip, then we need to buy it back at the Ask price, and if the profit is 1 pip, then sell it at the Bid price."

Now, the interest of the discussion is also knowledge, as you wrote very nicely : "There is one weapon to beat them all — knowledge! " The above "simple" logic is not correct either, it doesn't match in all cases, it even doesn't match in most cases. I will post with the details of my findings soon and if I am wrong again, I will learn new things.
As we all know there were and there are a lot of recurring discussions about the topic, so hopefully we will be able to draw some conclusions to close the debate.

 
Jeepack #:

My main complaint about tick value is that it only allows you to get the exact loss value of a stop loss if the traded pair's quote currency is the same as your account's currency. If you are trading a pair that has your account's currency as the base currency, then tick value will not give you the correct loss value for your stop loss. You already know why but for those who don't it's because the loss on your trade will be converted with the close price of the trade which will not be the same as the open price while the tick value uses the open price to convert to your account's currency. So for example, if my account is in USD and I trade USDJPY, the tick value multiplied by the size of the price change and lot size will not give me the correct value for the loss on that trade.

*edit: I think I have an idea to work out a way to get the correct loss size with tick value with a shortcut that skips all the complicated conversions, will post it later tonight

If your account is in USD, you can calculate the "future" tick values for USDCAD or USDJPY like this:

double TICK_VALUE_LONG  = SYMBOL_TRADE_TICK_VALUE_LOSS;
double TICK_VALUE_SHORT = SYMBOL_TRADE_TICK_VALUE_PROFIT;

// If account currency == base currency, adjust TickValue to future rate (close). Works only for Forex pairs.
if((AccountCurrency == BaseCurrency) && (AccountCurrency != ProfitCurrency))
  {
   TICK_VALUE_LONG  *= SYMBOL_BID / price_close;     // i.e., (1/Bid) * Bid / future_bid   = 1 / future_bid
   TICK_VALUE_SHORT *= SYMBOL_ASK / price_close;     // i.e., (1/Ask) * Ask / future_ask   = 1 / future_ask
  }

Then, you plug the future tick values in the equation as before to calculate future loss or lot size:

if(ordertype == ORDER_TYPE_BUY)  
    profit = lots * (price_close - price_open) / SYMBOL_TRADE_TICK_SIZE * TICK_VALUE_LONG;
    
if(ordertype == ORDER_TYPE_SELL) 
    profit = lots * (price_open - price_close) / SYMBOL_TRADE_TICK_SIZE * TICK_VALUE_SHORT;


Or better use OrderCalcProfit() which already implements the above feature

Forum on trading, automated trading systems and testing trading strategies

SYMBOL_TRADE_TICK_VALUE_LOSS vs SYMBOL_TRADE_TICK_VALUE_PROFIT

amrali, 2023.02.20 11:29

So, I use OrderCalcProfit() to calculate the expected loss at the (future) exit price. This only applies for Forex symbols where the base currency == account currency, which calculates a correct loss. It applies the necessary adjustment for the tick value, and profit/loss.

Foe other symbols you calculate an approximation using OrderCalcProfit or tick values.

 
Jeepack #:

My main complaint about tick value is that it only allows you to get the exact loss value of a stop loss if the traded pair's quote currency is the same as your account's currency. 

Tick value is in the account currency.

There may be times that it is incorrect, but this is down to the broker, I believe.

 

I haven't had time to read any of the replies on page 6 yet, but I'll check them out tomorow.

I just finished writing a script that you can test on a demo account. You'll see I'm using tick value to calculate risk value for a specified risk size, but I'm also applying a correction to the results by using the position entry price and future close price in the scenario where the traded pair's base currency is the same as the account's currency. Without this adjustment, you get an incorrect value in this scenario if you use tick value to calculate you risk for a specified risk size. My adjustment corrects for this error. You can verify this for yourself and you should see the risk value printed in the journal will always match the exact risk value you get for your position if you hover over the stop loss on your chart, no matter what currency you are trading.

#property copyright "Jeepack"
#property link      "https://www.mql5.com"

enum trade_direction_options { buy, sell };

input trade_direction_options trade_direction = buy; 
input double lots = 1.00;
input double position_open_price = 0.00000;
input int max_risk_in_points = 1000;
input int print_profit_digits = 2;
input int print_timer_seconds = 2;

bool indirect_conversion;
double pos_max_risk,points_to_price_multiplier,risk_in_points,max_risk_quote,tick_value;
string print_string,direction_string,lots_string,points_string;

int OnInit() {
        EventSetTimer(print_timer_seconds);
	if (AccountInfoString(ACCOUNT_CURRENCY) != SymbolInfoString(NULL,SYMBOL_CURRENCY_PROFIT)
		&& AccountInfoString(ACCOUNT_CURRENCY) == SymbolInfoString(NULL,SYMBOL_CURRENCY_BASE)) {
		indirect_conversion = true;
	} else { 
		indirect_conversion = false;
	}
        points_to_price_multiplier = 1 / MathPow(10,_Digits);
        if (lots != 1) lots_string = "lots";
        else lots_string = "lot";
        if (max_risk_in_points != 1) points_string = "points";
        else points_string = "point";
        risk_in_points = -1 * lots * max_risk_in_points;
        max_risk_quote = max_risk_in_points * points_to_price_multiplier;
        return(INIT_SUCCEEDED);
}

void OnDeinit(const int reason) {
        if (IsStopped()) { 
                EventKillTimer();
        }
} 
 
void OnTimer() {
        if (trade_direction == buy) {
                direction_string = "buying";
                tick_value = SymbolInfoDouble(NULL,SYMBOL_TRADE_TICK_VALUE_LOSS);
                if (indirect_conversion) {
                        tick_value *= SymbolInfoDouble(NULL,SYMBOL_BID) / (position_open_price - max_risk_quote);
                }
        } else {
                direction_string = "selling";
                tick_value = SymbolInfoDouble(NULL,SYMBOL_TRADE_TICK_VALUE_PROFIT);
                if (indirect_conversion) {
                        tick_value *= SymbolInfoDouble(NULL,SYMBOL_ASK) / (position_open_price + max_risk_quote);
                }
        }
        pos_max_risk = tick_value * risk_in_points;
        print_string = DoubleToString(max_risk_in_points,0) + " " + points_string + " risk if ";
        print_string += direction_string + " " + DoubleToString(lots,2) + " " + lots_string;
        print_string += " and position open price is " + DoubleToString(position_open_price,_Digits);
        print_string += ": " + DoubleToString(pos_max_risk,print_profit_digits);
        Print(print_string);
}
 
amrali #:

hehe, I just spent the entire evening figuring that out and testing it before I saw your reply. I'm glad to see we came up with the same idea! My script is just a bit different but that's because I wanted to be able to prove that it works by using trades that are already open. I looked at your math and logic and we seem to be doing the exact same thing. I think we can finally take a break from this now! :)

Fernando Carreiro #:

And so I will repeat my main remark—the calculations for the risk or reward, are only approximations.

I never disagreed with any of your claims, except that in some scenarios when it's possible, I don't want to settle for an approximation if the available data allows me to calculate the exact values with a few extra lines of code. I hope you can try my script to see what I mean if you are not already using this trick.

 
Keith Watford #:

Tick value is in the account currency.

There may be times that it is incorrect, but this is down to the broker, I believe.

Exactly, when you code for yourself that's not a big problem you can easily see your broker data (tickvalues) are correct are not.

When you code without having control on the trading environment, for customers (freelance or market) you have to build reliable code and you can't just rely on tickvalue, you need to use conversion rates, and the right formula (logic).

 
Alain Verleyen #:

Exactly, when you code for yourself that's not a big problem you can easily see your broker data (tickvalues) are correct are not.

When you code without having control on the trading environment, for customers (freelance or market) you have to build reliable code and you can't just rely on tickvalue, you need to use conversion rates, and the right formula (logic).

Yes, that's true. You could still add features to the script to calibrate it to different environments though but that depends on how much customization you offer your clients and what they are willing to pay, of course... everything has a price, my price would be too high though so I prefer making the code open source and anyone is free to use it for their own research if they want. The people on this forum help me so much when I'm trying to improve my skills and knowledge that I'm happy to share the end results for free :)

 

In case you want to test the logic from the EA code posted in my above reply, you can do it by simply opening a position and setting a stop loss, making sure you can view the trade levels on your chart. To see the benefits of correcting for future rates, do this with a currency pair that has your account currency as the base currency. Then apply the EA to your chart and enter the settings that match your position's open price, direction, lot size and stop loss distance in points (get this value from the order modify window).

First step

Then look at your terminal's journal and hover over your stop loss level on the chart to see if the calculations printed in your journal match the risk value you see on the stop loss pop-up.

2nd step

If they match, this shows you that applying a correction to the tick value before calculating the risk value (on pairs where your account currency is the base currency) enables you to know the true risk for a position when without this correction, the values wouldn't match. If this is something you want to use in your code, you can apply the corrections using the same logic as the script I posted.

 

Important update:

I think I remember someone saying that OrderCalcProfit() might not work with all instruments. If so you might want to use the script I recently posted instead because I found that there was something missing in the logic proposed by myself and Amrali in order to account for CFD pairs like stock indices or crypto because it's not enough to only check if the account currency is the base currency for these pairs, you also need to make sure the profit currency isn't your account currency. For example NAS100 for my USD account shows USD as both the base currency and the profit currency so the previous code examples would have applied an unnecessary correction to their tick values.

I already changed the code in this comment: https://www.mql5.com/en/forum/441959/page6#comment_45209672 to take this into account so the code should now work for CFD pairs.

The previous code was using:

if (AccountInfoString(ACCOUNT_CURRENCY) == SymbolInfoString(NULL,SYMBOL_CURRENCY_BASE)) {
        indirect_conversion = true;
} else { 
        indirect_conversion = false;
}

But now the updated code that works with CFD pairs uses:

if (AccountInfoString(ACCOUNT_CURRENCY) != SymbolInfoString(NULL,SYMBOL_CURRENCY_PROFIT)
        && AccountInfoString(ACCOUNT_CURRENCY) == SymbolInfoString(NULL,SYMBOL_CURRENCY_BASE)) {
        indirect_conversion = true;
} else { 
        indirect_conversion = false;
}

This update ensures the tick value conversion only takes place with FX pairs that require it.

SYMBOL_TRADE_TICK_VALUE_LOSS vs SYMBOL_TRADE_TICK_VALUE_PROFIT
SYMBOL_TRADE_TICK_VALUE_LOSS vs SYMBOL_TRADE_TICK_VALUE_PROFIT
  • 2023.02.24
  • www.mql5.com
*edit: when I posted the thread, I was confused about the correct way to calculate position size based on entry price and stop loss price, so don't...
Reason: