Im trying to build code to add fixed % position sizing for any pair, and im really finding this difficult. I was wondering if someone could look over this and help get this working!
I guess the hard part is the fact that the calculatin changes if it is a ***/USD , ***/JPY or other pair. And the calculation is relying on a value of another pair.
So here is the code im working on - and next post I'll put it in a system form:
Code: Select all
var
lotsize: double;
JPYCUR: double;
JPYSTP: double;
USDCUR: double;
USDSTP: double;
ALLCUR: double;
ALLSTP: double;
CADCUR: double;
CADSTP: double;
CHFCUR: double;
CHFSTP: double;
JPYCLOSE: DOUBLE;
CHFCLOSE: DOUBLE;
CADCLOSE: DOUBLE;
PATR: integer;
{-----Init strategy-----------------------------------------}
procedure InitStrategy; stdcall;
begin
RegOption('Percentage to risk', ot_Integer, PATR);
PATR := 2;
{-----Process single tick----------------------------------}
procedure GetSingleTick; stdcall;
begin
baseCur := LeftStr(CURRENCY, 3);
secondCur := RightStr(Currency, 3);
JPYCLOSE := iClose('USDJPY', timeframe, 0);
JPYCUR := (100/JPYCLOSE)*10;
JPYSTP := STOPLOSS*JPYCUR;
USDCUR := 10;
USDSTP := STOPLOSS*USDCUR;
CADCLOSE := iClose('USDCAD', timeframe, 0);
CADCUR := (10/CADCLOSE)*10;
CADSTP := STOPLOSS*CADCUR;
CHFCLOSE := iClose('USDCHF', timeframe, 0);
CHFCUR := (10/CHFCLOSE)*10;
CHFSTP := STOPLOSS*CHFCUR;
// position sizing
if GetCurrencyInfo(secondCur+'JPY', info) then
begin
Lotsize := (AccountEquity*(PATR*0.01))/JPYSTP;
end;
if GetCurrencyInfo(secondCur+'USD', info) then
begin
Lotsize := (AccountEquity*(PATR*0.01))/USDSTP;
end ;
if GetCurrencyInfo(secondCur+'CAD', info) then
begin
Lotsize := (AccountEquity*(PATR*0.01))/CADSTP;
end ;
if GetCurrencyInfo(secondCur+'CHF', info) then
begin
Lotsize := (AccountEquity*(PATR*0.01))/CHFSTP;
end ;
So where am I going wrong?
Ohh and... HAPPY NEW YEARS!