• Home
  • Forums
  • Trades
  • News
  • Calendar
  • Market
  • Brokers
  • Login
  • Join
  • User/Email: Password:
  • 10:41am
Menu
  • Forums
  • Trades
  • News
  • Calendar
  • Market
  • Brokers
  • Login
  • Join
  • 10:41am
Sister Sites
  • Metals Mine
  • Energy EXCH
  • Crypto Craft

Options

Bookmark Thread

First Page First Unread Last Page Last Post

Print Thread

Similar Threads

Scripts for Limit entry, Stop entry, Market entry 46 replies

Exit is more important than the entry 59 replies

Newbie need help on trade entry and exit 4 replies

Exit is more important than the entry 16 replies

  • Platform Tech
  • /
  • Reply to Thread
  • Subscribe
  • 5
Attachments: Calculation of Money from entry and exit of a trade..and more
Exit Attachments
Tags: Calculation of Money from entry and exit of a trade..and more
Cancel

Calculation of Money from entry and exit of a trade..and more

  • Post #1
  • Quote
  • First Post: Jan 8, 2020 6:58pm Jan 8, 2020 6:58pm
  •  reteid2222
  • Joined Aug 2015 | Status: Member | 2,520 Posts
Just want to calculate at a distinct bar(the bar is one between open time or close time) the value of points/money of this trade!

Searching for this formula:
ProfitInMoney= (Open-close+.......)*.....
Is there a same formula for points for every different leverages and lotsizes?
When I have a trade with 1 lots or 0.01 with 1:500 or 1:100 i have the same point difference...but which value to write in a trade manager?
Vucking good EA coder...
  • Post #2
  • Quote
  • Jan 8, 2020 11:03pm Jan 8, 2020 11:03pm
  •  hanover
  • Joined Sep 2006 | Status: ... | 8,092 Posts
Inserted Code
double entry_price     = Open[0];      // or whatever you want it to be
double exit_price      = Close[0];     // or whatever you want it to be
double volume_in_lots  = 0.01;         // microlot (or whatever lot size you want)
string symbol          = Symbol();     // or whatever symbol you want
double profit_in_money = (exit_price - entry_price) / MarketInfo(symbol,MODE_POINT) * MarketInfo(symbol,MODE_TICKVALUE) * volume_in_lots;

entry_price and exit_price can be any two price levels that you want to calculate the monetary value between.

The above calculation should work universally. Leverage is irrelevant; it merely determines how much margin (which equates to money in your account) that you need to open a position.

Probably should check for divide by zero error but I'll leave it to you to do that.
 
1
  • Post #3
  • Quote
  • Jan 9, 2020 8:22am Jan 9, 2020 8:22am
  •  emmzett
  • Joined Apr 2008 | Status: Member | 596 Posts
Quoting hanover
Disliked
double entry_price = Open[0]; // or whatever you want it to be double exit_price = Close[0]; // or whatever you want it to be double volume_in_lots = 0.01; // microlot (or whatever lot size you want) string symbol = Symbol(); // or whatever symbol you want double profit_in_money = (exit_price - entry_price) / MarketInfo(symbol,MODE_POINT) * MarketInfo(symbol,MODE_TICKVALUE) * volume_in_lots; entry_price and exit_price can be any two price levels that you want to calculate the monetary value between. The above calculation should work universally....
Ignored
Hanover, you have a small bug in your logic.

@all: Before multiplying with MODE_TICKVALUE you have to divide by MODE_TICKSIZE. MODE_TICKSIZE is always a multiple of MODE_POINT. Usually the relation is 1:1 but that's not always the case, especially for CFDs.
Inserted Code
PL = priceDiff / MODE_POINT / MODE_TICKSIZE * MODE_TICKVALUE * volume

What does that mean? It means there are some rare instruments where MODE_POINT is not equal to MODE_TICKSIZE, e.g. an instrument is priced in 0.05 increments. Many years ago it was the typical way to quote stocks etc.
 
1
  • Post #4
  • Quote
  • Jan 9, 2020 8:35am Jan 9, 2020 8:35am
  •  reteid2222
  • Joined Aug 2015 | Status: Member | 2,520 Posts
Quoting hanover
Disliked
double entry_price = Open[0]; // or whatever you want it to be double exit_price = Close[0]; // or whatever you want it to be double volume_in_lots = 0.01; // microlot (or whatever lot size you want) string symbol = Symbol(); // or whatever symbol you want double profit_in_money = (exit_price - entry_price) / MarketInfo(symbol,MODE_POINT) * MarketInfo(symbol,MODE_TICKVALUE) * volume_in_lots; entry_price and exit_price can be any two price levels that you want to calculate the monetary value between. The above calculation should work universally....
Ignored
Thank you...very well explained!
Attached Image
Vucking good EA coder...
 
 
  • Post #5
  • Quote
  • Jan 9, 2020 9:29am Jan 9, 2020 9:29am
  •  hanover
  • Joined Sep 2006 | Status: ... | 8,092 Posts
Quoting emmzett
Disliked
PL = priceDiff / MODE_POINT / MODE_TICKSIZE * MODE_TICKVALUE * volume
Ignored
Thanks for the heads-up, but in that case I think your calculation should read:
Inserted Code
PL = priceDiff / MODE_TICKSIZE * MODE_TICKVALUE * volume
Can you please confirm? Dividing by both POINT and TICKSIZE doesn't seem right to me. Although the inflated profit is appealing.
 
1
  • Post #6
  • Quote
  • Edited 11:01am Jan 9, 2020 10:31am | Edited 11:01am
  •  hayseed
  • Joined Nov 2006 | Status: Member | 3,637 Posts
Quoting hanover
Disliked
{quote} Thanks for the heads-up, but in that case I think your calculation should read: PL = priceDiff / MODE_TICKSIZE * MODE_TICKVALUE * volume Can you please confirm? Dividing by both POINT and TICKSIZE doesn't seem right to me. Although the inflated profit is appealing.
Ignored
//-----

hey hanover..... this might be off topic...... started to mention something similar last night but decided against it......

the need for ticksize is to adjust tickvalue to it's standard constant..... tickvalue changes due to the price change between 2 ticks..... you can verify that in seconds with 1 line of print code....

if the price jumps 10 pips in a single tick, the tickvalue would be 10 times greater.... the ticksize division of 10 returns tickvalue to it's constant.... the same logic holds true if price moves 1/10 of a pip in a single tick.....

all in all, for some reason i have never been able to get the individual components to always equal the order profit.... maybe 10% of the time its a couple pennies off..... quite possibly it's just a digit rounding issue.....

below is the easy to read script..... maybe yall can see my error.... see if the 'o' and 'p' columns match......h
//----

Inserted Code
p = (OrderClosePrice()-OrderOpenPrice())*((MarketInfo(OrderSymbol(),MODE_TICKVALUE)/MarketInfo(OrderSymbol(),MODE_TICKSIZE)))*OrderLots();

//---- edit added screen shot of common differences in column o and p
Attached Image (click to enlarge)
Click to Enlarge

Name: profit.png
Size: 68 KB
Attached File(s)
File Type: mq4 history to excel.mq4   3 KB | 149 downloads
File Type: ex4 history to excel.ex4   9 KB | 113 downloads
to trade and code, keep both simple... no call to impress....h
 
 
  • Post #7
  • Quote
  • Jan 9, 2020 11:52am Jan 9, 2020 11:52am
  •  emmzett
  • Joined Apr 2008 | Status: Member | 596 Posts
Quoting hanover
Disliked
{quote} Thanks for the heads-up, but in that case I think your calculation should read: PL = priceDiff / MODE_TICKSIZE * MODE_TICKVALUE * volume Can you please confirm? Dividing by both POINT and TICKSIZE doesn't seem right to me. Although the inflated profit is appealing.
Ignored
Of course you are right. MODE_TICKSIZE is already an absolute double, not a simple multiplier (an int). Comes from me not testing what I write. Thanks :-)
 
1
  • Post #8
  • Quote
  • Edited 2:26pm Jan 9, 2020 2:09pm | Edited 2:26pm
  •  hanover
  • Joined Sep 2006 | Status: ... | 8,092 Posts
Quoting hayseed
Disliked
for some reason i have never been able to get the individual components to always equal the order profit.... maybe 10% of the time its a couple pennies off..... quite possibly it's just a digit rounding issue..... below is the easy to read script..... maybe yall can see my error.... see if the 'o' and 'p' columns match
Ignored
Hayseed,

TICKSIZE is always constant, as far as I know, and is generally the same as POINT (except in rare instances, as emmzett points out. I hadn't previously encountered this, as I tend to work only with the majors). I believe the reason for the small discrepancy between your columns O and P is that, whenever you are trading a pair XXXYYY, and YYY is a currency different to your account deposit currency (say ZZZ), then TICKVALUE changes as price moves, because it's used to convert YYY back to ZZZ, and the YYYZZZ exchange rate will have almost certainly changed between the opening and the closing of the position.

To explain using MQL4, what you're effectively doing is:
open_value = open_price / TICKSIZE * tickvalue_at_time_of_close * volume;
close_value = close_price / TICKSIZE * tickvalue_at_time_of_close * volume;
profit = close_value - open_value;

Whereas I expect if you were to save the value of TICKVALUE at the time the position is opened, and do the following:
open_value = open_price / TICKSIZE * tickvalue_at_time_of_open * volume;
close_value = close_price / TICKSIZE * tickvalue_at_time_of_close * volume;
profit = close_value - open_value;
then any discrepancy should be solely due to rounding.

If YYY and ZZZ are the same (for example, if you trade EURUSD and your deposit currency is USD) then there shouldn't be any discrepancy.

There may be additional reasons that I'm unaware of, but I'm pretty sure that's it.

David
_________________________

[EDIT]
For example, performing a dump of EURAUD, its tickvalue is the same as the current AUDUSD exchange rate (0.68514), as the deposit currency is USD:
Attached Image (click to enlarge)
Click to Enlarge

Name: PPI 600.png
Size: 19 KB
 
1
  • Post #9
  • Quote
  • Jan 9, 2020 4:27pm Jan 9, 2020 4:27pm
  •  hayseed
  • Joined Nov 2006 | Status: Member | 3,637 Posts
Quoting hanover
Disliked
I believe the reason for the small discrepancy between your columns O and P is that, whenever you are trading a pair XXXYYY, and YYY is a currency different to your account deposit currency (say ZZZ), then TICKVALUE changes as price moves, because it's used to convert YYY back to ZZZ, and the YYYZZZ exchange rate will have almost certainly changed between the opening and the closing of the position.
Ignored
//----

hey hanover..... ..... i never thought of the reverse back to usd conversion factor..... you almost have to be correct....

the reason i did not post anything last night was because my work on it was from long ago and half forgotten.... not to mention never figured out down to the penny.....

just as you said, as far as i remember every xxxusd trade would be correct.... anything else had a high chance of being a few cents off.....

hope your trading is going good..... and your fire extinguishers are fully charged.....h
to trade and code, keep both simple... no call to impress....h
 
 
  • Post #10
  • Quote
  • Last Post: Jan 9, 2020 6:15pm Jan 9, 2020 6:15pm
  •  hanover
  • Joined Sep 2006 | Status: ... | 8,092 Posts
Quoting hayseed
Disliked
i never thought of the reverse back to usd conversion factor
Ignored
hey Hay,

It makes sense when I think about it. Suppose I want to buy EURAUD, which means that I'm 'selling' AUD to buy EURos at the EURAUD rate; but if my deposit currency is USD, then I need to somehow convert enough USD in my account to (electronic) AUDs beforehand, to provide some AUDs for me to 'sell'. Hence the AUDUSD rate conversion that's built into TICKVALUE.

Then the reverse sequence applies when I close the 'position'.

Of course in reality I'm not buying or selling anything tangible, it's all just a big electronic video game. Until I (hopefully) withdraw my profits.

Anyway, I hope you had a great holiday, all the best for 2020.

DL
 
 
  • Platform Tech
  • /
  • Calculation of Money from entry and exit of a trade..and more
  • Reply to Thread
0 traders viewing now
Top of Page
  • Facebook
  • Twitter
About FF
  • Mission
  • Products
  • User Guide
  • Media Kit
  • Blog
  • Contact
FF Products
  • Forums
  • Trades
  • Calendar
  • News
  • Market
  • Brokers
  • Trade Explorer
FF Website
  • Homepage
  • Search
  • Members
  • Report a Bug
Follow FF
  • Facebook
  • Twitter

FF Sister Sites:

  • Metals Mine
  • Energy EXCH
  • Crypto Craft

Forex Factory® is a brand of Fair Economy, Inc.

Terms of Service / ©2023