How to calculate % of Equity

How to create strategies and indicators
Message
Author
Radek
Posts: 11
Joined: Tue Jul 14, 2009 11:53 am

How to calculate % of Equity

#1 Postby Radek » Sat Aug 01, 2009 10:26 pm

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

philBell
Posts: 24
Joined: Thu Jul 23, 2009 7:20 am
Location: Brighton, UK

#2 Postby philBell » Sat Aug 08, 2009 9:42 am

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

ghamm
Posts: 39
Joined: Wed Feb 11, 2009 3:02 pm

#3 Postby ghamm » Sat Aug 08, 2009 10:55 am

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..

Radek
Posts: 11
Joined: Tue Jul 14, 2009 11:53 am

#4 Postby Radek » Sun Aug 09, 2009 8:51 am

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

tanmay80
Posts: 10
Joined: Wed Jan 19, 2011 5:38 pm
Location: 92808
Contact:

Dynamic lot size calculation based on pip value

#5 Postby tanmay80 » Fri May 06, 2011 6:05 pm

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?

FT Support
Posts: 905
Joined: Sat Jul 11, 2009 10:54 am

#6 Postby FT Support » Tue May 10, 2011 1:41 pm

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: Select all

// 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 product here:
http://www.forexcopier.com

Wessel
Posts: 63
Joined: Tue Oct 12, 2010 6:45 pm

#7 Postby Wessel » Tue May 24, 2011 8:56 am

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: Select all

// 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;



Return to “FT API”

Who is online

Users browsing this forum: No registered users and 28 guests