Forex Tester Forum (Professional Training Software for Traders) Forum Index Forex Tester Forum (Professional Training Software for Traders)

Back to main site   Risk disclosure
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

How to calculate % of Equity

 
Post new topic   Reply to topic    Forex Tester Forum (Professional Training Software for Traders) Forum Index -> FT API
View previous topic :: View next topic  
Author Message
Radek



Joined: 14 Jul 2009
Posts: 11

PostPosted: Sun Aug 02, 2009 3:26 am    Post subject: How to calculate % of Equity Reply with quote

Hi,
I am working on strategy which is determining size of order by % of Equity. Let's say Equity is $100000 and I want to place order with risk $1000, which is 1%. I know price and stop loss, how do I calculate # of lots in EURUSD or GBPJPY?
I am using this, but its not working properly.
((Equity * (risk*0.01)) / distanceSL*0.1)

Radek
Back to top
View user's profile Send private message
philBell



Joined: 23 Jul 2009
Posts: 25
Location: Brighton, UK

PostPosted: Sat Aug 08, 2009 2:42 pm    Post subject: Reply with quote

Forgive me if I don't understand the question, but I'm puzzled by the use of variables risk and distanceSL in the equation, and by the 0.1 at the end, and in the absence of a greater piece of your program I'm unclear of your intentions; I'm in the UK, and use spreadbetting rather than purchasing contracts. In spreadbetting, the maximum loss (ie risk) on a trade is betSize*distance between entry and stop loss. To make this 1% of your capital, for a Buy

poundsPerPoint := 0.01 * Equity / (entry - stopLoss);

or for a Sell

poundsPerPoint := 0.01 * Equity / (stopLoss - entry);

If your equation is "correct" for what you are trying to do, but giving the wrong answer, your use of brackets looks very odd to me. The language will apply a string of consecutive mulitiply and divide operations left-to-right, except that it will work out the contents of brackets first. Your post looks as if you are trying to divide something by distanceSL*0.1, but it is actually multiplying by 0.1/distanceSL in effect. You've put in lots of brackets, in ways that my students used to do when they didn't feel confident about the order in which the computer is going to perform their calculations, and I wonder if you didn't need

size := Equity * risk * 0.01 / ( distanceSL * 0.1 );

ie "multiply Equity by risk and by 0.01, then divide that result by the result of multiplying distanceSL by 0.1". What your version is doing is "multiply Equity by risk and 0.01 and 0.1, then divide the result by distanceSL" - and if that's what you intended, why not combine 0.01 multiplied by 0.1 into a single number 0.001?

Phil Bell
Back to top
View user's profile Send private message
ghamm



Joined: 11 Feb 2009
Posts: 37

PostPosted: Sat Aug 08, 2009 3:55 pm    Post subject: Reply with quote

This is how I do it in my strategies..

RiskPercent:=3; // only 3% risk for trade..
StopLoss:=50; // 50 pips SL..



Lots := Roundto((AccountEquity() * (RiskPercent * 0.01)) / (StopLoss * 10), -1);

this function assumes that a pip is worth 10 bucks.. You could make it more accurate if you put the actual pip value in the function.. but works ok for me..
Back to top
View user's profile Send private message
Radek



Joined: 14 Jul 2009
Posts: 11

PostPosted: Sun Aug 09, 2009 1:51 pm    Post subject: Reply with quote

philBell wrote:
You've put in lots of brackets, in ways that my students used to do when they didn't feel confident about the order in which the computer is going to perform their calculations, and I wonder if you didn't need
Phil Bell


Sorry about brackets, they are confusing, they are leftover after I was playing with different variations of formula. I also use then to keep some items together visually. Anyway I think that in this formula you don't need them anyway. Brackets are important only if '-' or '+' is involved.
0.1 is only to convert it to mini lots.

I did look into it and what you need to get actual value from 'USDJPY' and then use it with 'GBPJPY', something like this:

if symbol ='USDJPY' then ex_JPY:= (1/Point) * Open(0);

exchange:= 10000;
if (Symbol = 'GBPJPY') then exchange:= ex_JPY;

amount:= ((GetAccountEquity * (risk*0.01)) / distanceSL*0.1 * (exchange/10000));


Radek
Back to top
View user's profile Send private message
tanmay80



Joined: 19 Jan 2011
Posts: 10
Location: 92808

PostPosted: Fri May 06, 2011 11:05 pm    Post subject: Dynamic lot size calculation based on pip value Reply with quote

I need to calculate the lotsize dynamically based on the pip value.

Is there a way using FT2 to calculate pip value for pairs.

for e.g. calculating pip value for USD pairs is trivial but how about pairs not having USD in the symbol e.g. EURJPY

I am assuming you would need the price of USDJPY to go with it.

What if we open 2 charts, 1 for EURJPY and 2nd for USDJPY. Would it be possible to calculate the pipvalue for EURJPY?

Is there another easier method?
Back to top
View user's profile Send private message AIM Address
FT Support



Joined: 11 Jul 2009
Posts: 902

PostPosted: Tue May 10, 2011 6:41 pm    Post subject: Reply with quote

If you wish to calculate pip value for non-USD pairs then you'll need to have ticks generated for crossing USD pairs.

below you can find a code which should calculate pip value, i did not tested this code so please let me know if you find any errors there:

Code:
// cost of 1 secondary currency unit in USD
function GetSecCurCostInUSD(symbolName: ANSIString): double;
var baseCur: ANSIString;
    secondCur: ANSIString;
    info: PCurrencyInfo;
begin
  baseCur := LeftStr(symbolName, 3);
  secondCur := RightSTR(symbolName, 3);

  if GetCurrencyInfo(secondCur+'USD', info) then
  begin
   Result := iClose(secondCur+'USD',1,0);
   exit;
  end else
    if GetCurrencyInfo('USD'+secondCur, info) then
    begin
      Result := 1/(iClose('USD'+secondCur,1,0));
      exit;
    end else
    if GetCurrencyInfo(baseCur+'USD', info) then
    begin
      result := iClose(baseCur+'USD', 1, 0) / iClose(symbolName, 1, 0);
      exit;
    end else
      if GetCurrencyInfo('USD'+baseCur, info) then
      begin
        result := (1/iClose('USD'+baseCur, 1, 0))/iClose(symbolName, 1, 0);
        exit;
      end;

   result := 0;
   Print('GetCostInUSD: not enough information');
end;

//calculates point cost for 1 lot order
function GetPointCostUSD: double;
var
  info: PCurrencyInfo;
  symbolType: TSymbolType;
begin
  symbolType := GetSymbolType(Currency);
  if GetCurrencyInfo(Currency, info) then
  begin
    case symbolType of
      st_Normal: result := info.lot * info.Point;
      st_InvertedUSD: result := info.lot * info.Point/iClose(Currency, 1, 0);
      st_Other: result := GetSecCurCostInUSD(Currency)*info.lot*info.Point;
    end;
  end;
end;

{-----Process single tick---------------------------------------------------}
procedure GetSingleTick; stdcall;
begin
Print('point cost = ' + floattostr(GetPointCostUSD));
end;


_________________
Check our other products here:
www.fx-metropolis.com
www.forexcopier.com
Back to top
View user's profile Send private message Visit poster's website
Wessel



Joined: 12 Oct 2010
Posts: 57

PostPosted: Tue May 24, 2011 1:56 pm    Post subject: Reply with quote

Where can I find this call ?

GetSymbolType(Currency);
And the TSymbolType's
I'm I looking in the wrong place?


W

FT Support wrote:
If you wish to calculate pip value for non-USD pairs then you'll need to have ticks generated for crossing USD pairs.

below you can find a code which should calculate pip value, i did not tested this code so please let me know if you find any errors there:

Code:
// cost of 1 secondary currency unit in USD
function GetSecCurCostInUSD(symbolName: ANSIString): double;
var baseCur: ANSIString;
    secondCur: ANSIString;
    info: PCurrencyInfo;
begin
  baseCur := LeftStr(symbolName, 3);
  secondCur := RightSTR(symbolName, 3);

  if GetCurrencyInfo(secondCur+'USD', info) then
  begin
   Result := iClose(secondCur+'USD',1,0);
   exit;
  end else
    if GetCurrencyInfo('USD'+secondCur, info) then
    begin
      Result := 1/(iClose('USD'+secondCur,1,0));
      exit;
    end else
    if GetCurrencyInfo(baseCur+'USD', info) then
    begin
      result := iClose(baseCur+'USD', 1, 0) / iClose(symbolName, 1, 0);
      exit;
    end else
      if GetCurrencyInfo('USD'+baseCur, info) then
      begin
        result := (1/iClose('USD'+baseCur, 1, 0))/iClose(symbolName, 1, 0);
        exit;
      end;

   result := 0;
   Print('GetCostInUSD: not enough information');
end;

//calculates point cost for 1 lot order
function GetPointCostUSD: double;
var
  info: PCurrencyInfo;
  symbolType: TSymbolType;
begin
  symbolType := GetSymbolType(Currency);
  if GetCurrencyInfo(Currency, info) then
  begin
    case symbolType of
      st_Normal: result := info.lot * info.Point;
      st_InvertedUSD: result := info.lot * info.Point/iClose(Currency, 1, 0);
      st_Other: result := GetSecCurCostInUSD(Currency)*info.lot*info.Point;
    end;
  end;
end;

{-----Process single tick---------------------------------------------------}
procedure GetSingleTick; stdcall;
begin
Print('point cost = ' + floattostr(GetPointCostUSD));
end;

Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    Forex Tester Forum (Professional Training Software for Traders) Forum Index -> FT API All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You can attach files in this forum
You can download files in this forum


Powered by phpBB © 2001, 2005 phpBB Group