NexusFi: Find Your Edge


Home Menu

 





Position Sizing when trading Forex FX


Discussion in NinjaTrader

Updated
      Top Posters
    1. looks_one sburtt with 7 posts (0 thanks)
    2. looks_two Pippi with 5 posts (1 thanks)
    3. looks_3 sagetrade with 2 posts (1 thanks)
    4. looks_4 baruchs with 2 posts (8 thanks)
      Best Posters
    1. looks_one baruchs with 4 thanks per post
    2. looks_two solotrader with 1 thanks per post
    3. looks_3 sagetrade with 0.5 thanks per post
    4. looks_4 Pippi with 0.2 thanks per post
    1. trending_up 5,370 views
    2. thumb_up 11 thanks given
    3. group 3 followers
    1. forum 17 posts
    2. attach_file 0 attachments




 
Search this Thread

Position Sizing when trading Forex FX

  #1 (permalink)
 sburtt 
London, UK
 
Experience: Advanced
Platform: NinjaTrader
Trading: EUR/USD
Posts: 58 since Jul 2012
Thanks Given: 3
Thanks Received: 4

Hi there,
has anybody developed an algorithm in NT to determine position size when trading FX?

This might sound stupid or obvious but the traditional position sizing tools that you find browsing around in the forum or in the NT forum work fine for futures but not for FX. What is needed is an algorithm that adopts different code when trading direct rates (e.i. EURUSD,AUDUSD,NZDUSD) comprared to indirect rates (e.i. USDCAD,USDJPY). This is without taking into consideration cross rates (e.i trading EURJPY with a USD account) that would imply even more complex code.

I am trying to develop this myself, as I believe that embedding Money Management in a strategy can dramatically improve the equity curve of any given strategy. I was wondering if anybody out there would be happy to work with me on this, or even better has this already developed. Thanks, John

Started this thread Reply With Quote

Can you help answer these questions
from other members on NexusFi?
Futures True Range Report
The Elite Circle
Build trailing stop for micro index(s)
Psychology and Money Management
Are there any eval firms that allow you to sink to your …
Traders Hideout
Better Renko Gaps
The Elite Circle
Online prop firm The Funded Trader (TFT) going under?
Traders Hideout
 
  #3 (permalink)
 sburtt 
London, UK
 
Experience: Advanced
Platform: NinjaTrader
Trading: EUR/USD
Posts: 58 since Jul 2012
Thanks Given: 3
Thanks Received: 4


everybody on holiday?

Started this thread Reply With Quote
  #4 (permalink)
sagetrade
Frankfurt / Germany
 
Posts: 47 since Jul 2013
Thanks Given: 28
Thanks Received: 11

would also appreciate qualified comments to this thread

Reply With Quote
  #5 (permalink)
Pippi
Vienna Austria
 
Posts: 8 since Jul 2013
Thanks Given: 2
Thanks Received: 6

This has less to do with position sizing, the problem is that ninja (and most of the other retail software) cannot calculate PnL for FX. It was made under the assumption that (like with stocks or futures) the tick-value of an instrument is constant, while in FX it will fluctuate in $-terms for pairs that are not quoted in US Dollars (like usd/jpy).

For realtime, you could calculate it yourself, but for backtesting its more difficult. Bottom-line is Ninja needs to support multi-currrency portfolios on a realtime and historical basis. Not sure if this is part of 8.0. Probably not, i am always surprised that so few people complain about such a glaring defect.

Reply With Quote
  #6 (permalink)
sagetrade
Frankfurt / Germany
 
Posts: 47 since Jul 2013
Thanks Given: 28
Thanks Received: 11


sburtt View Post
Hi there,
...but the traditional position sizing tools that you find browsing around in the forum or in the NT forum work fine for futures but not for FX.

Which tools are your referring to?

Reply With Quote
Thanked by:
  #7 (permalink)
 solotrader 
Cyprus
 
Posts: 68 since Jul 2013


Pippi View Post
This has less to do with position sizing, the problem is that ninja (and most of the other retail software) cannot calculate PnL for FX. It was made under the assumption that (like with stocks or futures) the tick-value of an instrument is constant, while in FX it will fluctuate in $-terms for pairs that are not quoted in US Dollars (like usd/jpy).

I thought for standard lots the pip value is constant. At least I have not seen any change in for EUR/USD

Reply With Quote
  #8 (permalink)
 baruchs 
Israel
 
Experience: Intermediate
Platform: NinjaTrader
Broker: pfg
Trading: eminis
Posts: 323 since Jun 2009

Actually I've done it a long time ago.
I don't remember all the nuances.
Its a lot of code in different places.
 
Code
In Initialize()
//Series 1 
			if (BarsPeriod.Id == PeriodType.Minute && BarsPeriod.Value >= 5) Add(PeriodType.Minute, 1);
			else Add(PeriodType.Tick, 10);
//Series 2 For Currencies
			if (InstrType == "Currency")
			{
				CalculateSize = true;
				if (UseASK && BackTest) 
				{
					LEntrShExitOnBar = 2;
					Add(Instrument.FullName, PeriodType.Minute, 1, MarketDataType.Ask);
				}

				CurInstrument = TInst.ToString();
				USDQuote = GetUSD ();
				if (USDQuote == "") 
				{
					if (CurInstrument.Substring(0,3) == "USD") ConvertMethod = 2;
					else ConvertMethod = 1;
				}
				else if (USDQuote.Substring(0,4) == "$USD") ConvertMethod = 4;
				else ConvertMethod = 3;
				if (ConvertMethod > 2) 
				{
	//Series 3 Not Always
					Add(USDQuote, PeriodType.Minute, 30);
					if (UseASK && BackTest) USDSerie = 3;
					else USDSerie = 2;
				}
			}

In OnBarUpdate()
				if (Position.MarketPosition == MarketPosition.Flat)
				{
					if (Direction == 1)
					{
						EntryPrice = CalcLongEntry();
						SLPrice = CalcLongSL();
						PTPrice = CalcLongPT();
						GoodRR = true;
						if (PTPrice > 0 && (PTPrice - EntryPrice) / (EntryPrice - SLPrice) < (double)RRRatio / 100) GoodRR = false;
						if (GoodRR && Close[0] < EntryPrice)
						{
							if (CalculateSize) EntrySize = GetLotSize4(AccountSize, rType.ToString(), Risk, EntryPrice, SLPrice, ConvertMethod, USDSerie);
							if (EntrySize > 0) entryOrder = EnterLongStop(LEntrShExitOnBar, true, EntrySize, EntryPrice, EntryName);
						}
					}
					else if (Direction == -1)
					{
						EntryPrice = CalcShortEntry();
						SLPrice = CalcShortSL();
						PTPrice = CalcShortPT();
						GoodRR = true;
						if (PTPrice > 0 && (EntryPrice - PTPrice)  / (SLPrice - EntryPrice) < (double)RRRatio / 100) GoodRR = false;
						if (GoodRR && Close[0] > EntryPrice)
						{
							if (CalculateSize) EntrySize = GetLotSize4(AccountSize, rType.ToString(), Risk, EntryPrice, SLPrice, ConvertMethod, USDSerie);
							if (EntrySize > 0) entryOrder = EnterShortStop(1, true, EntrySize, EntryPrice, EntryName);
						}
					}
					else if (entryOrder != null) CancelOrder(entryOrder);
				}

#region GetLotSize4
		public int GetLotSize4(double AccountSize, string rType, double Risk, double EntryPrice, double SLPrice, int ConvertMethod, int USDSerie)
		{
			double PipValue100K = 0;
			if (!Historical)
			{
				if (ConvertMethod == 1) PipValue100K = 100000 * TickSize; //$XXXUSD
				else if (ConvertMethod == 2) PipValue100K = 100000 * TickSize / Close[0]; //$USDXXX
				else if (ConvertMethod == 3) PipValue100K = 100000 * TickSize * Closes[USDSerie][0] / Close[0]; // USDSerie: $XXXUSD
				else if (ConvertMethod == 4) PipValue100K = 100000 * TickSize / Closes[USDSerie][0]; //USDSerie: $USDXXX
			}
			else PipValue100K = 10; // for backtesting
			int RiskSum = 0;
			if (rType == "Percent") RiskSum = (int)(AccountSize * Risk);
			else RiskSum = (int)Risk;
			double RiskPerTick = RiskSum / (Math.Abs(EntryPrice - SLPrice) / TickSize); 
			int Lots2Trade = (int)Math.Floor(RiskPerTick / (PipValue100K / 100)) * 1000;
//			if (Lots2Trade < 25000) Lots2Trade = 0;
			return Lots2Trade;
		}
#endregion
#region GetUSD
		public string GetUSD ()
		{
			string CurInstr = Instrument.FullName;
			if (CurInstr.Substring(4,3) == "CAD") return "$USDCAD";
			else if (CurInstr.Substring(4,3) == "CHF") return "$USDCHF";
			else if (CurInstr.Substring(4,3) == "JPY") 	return "$USDJPY";
			else if (CurInstr.Substring(4,3) == "NZD") return "$NZDUSD";
			else if (CurInstr.Substring(4,3) == "AUD") return "$AUDUSD";
			else if (CurInstr.Substring(1,3) == "EUR") return "$EURUSD";
			else return "";
		}
#endregion
Its not for newbies.

Baruch

Reply With Quote
  #9 (permalink)
Pippi
Vienna Austria
 
Posts: 8 since Jul 2013
Thanks Given: 2
Thanks Received: 6


solotrader View Post
I thought for standard lots the pip value is constant. At least I have not seen any change in for EUR/USD

Its fixed $10 per pip per 100K lot for all XXX/USD pairs. But not for the others.

Looks like Baruchs' code is good for accurate position sizing. But as far as i can see, there is no way to make Ninja calculate PnL for a backtest this way and use it for performance calculations (which makes optimization results questionable in some cases). Same problem when you trade a portfolio of futures, for example ES and FDAX.

Reply With Quote
Thanked by:
  #10 (permalink)
 baruchs 
Israel
 
Experience: Intermediate
Platform: NinjaTrader
Broker: pfg
Trading: eminis
Posts: 323 since Jun 2009


My calculations should work in BT too.
I don't use it because I don't see an advantage in it.

Reply With Quote




Last Updated on August 2, 2013


© 2024 NexusFi™, s.a., All Rights Reserved.
Av Ricardo J. Alfaro, Century Tower, Panama City, Panama, Ph: +507 833-9432 (Panama and Intl), +1 888-312-3001 (USA and Canada)
All information is for educational use only and is not investment advice. There is a substantial risk of loss in trading commodity futures, stocks, options and foreign exchange products. Past performance is not indicative of future results.
About Us - Contact Us - Site Rules, Acceptable Use, and Terms and Conditions - Privacy Policy - Downloads - Top
no new posts