Saturday, September 04, 2010

Fixed Equity per Trade [FAE]

Descripton
Summary:
This position sizing script is used to allocate a fixed amount of equity on each trade.


Variables
TypeIdentifierDescription
Number_fixedEquityPerTradeUse for the fixed amount of equity to invest in a single trade, denominated in the account currency.
Boolean_enableExitSizingUse to indicate whether to enable the Fixed Equity per Trade to determine the size of exit orders.

OnInitialize
Use for the fixed amount of equity to invest in a single trade.
Function Parameters
TypeIdentifierDescription
NumberfixedEquityPerTradeUse for the fixed amount of equity to invest in a single trade, denominated in the account currency. [Default 5000]
BooleanenableExitSizingUse to indicate whether to enable the Fixed Equity per Trade to determine the size of exit orders. [Default True]
Implementation
	 ' Assign the parameter to a script variable.
	_fixedEquityPerTrade = fixedEquityPerTrade
	_enableExitSizing = enableExitSizing

OnPositionSize
Function Parameters
TypeIdentifierDescription
IntegerorderIndex
Implementation
	 ' Get the order type.
	Define typeOrder As Integer = OrderType(orderIndex)
	 ' Get the order symbol index.
	Define symbolIndex As Integer = OrderSymbolIndex(orderIndex)
	 ' If the order type is an entry order then calculate the position size.
	If (typeOrder = C_BUY Or _
		typeOrder = C_SELL_SHORT) Then
		Define close As Number = BarClose(symbolIndex)
		If (close <> 0) Then
			Return MathFloor(_fixedEquityPerTrade / close)
		Else
			Return 0
		End If
	Else If (_enableExitSizing)
		 ' If the order type is an exit order then calculate the position size.
		Define openPositions() As Integer = PositionIndexList(C_OPEN)
		For i As Integer = 0 To openPositions.Length - 1
			If (PositionSymbolIndex(openPositions(i)) = symbolIndex) Then
				Return PositionQuantity(openPositions(i))
			End If
		Next
	End If
	Return 0

Copyright © 2010 IQBroker, LLC. All rights reserved.