Summary: This position sizing script is used to allocate a fixed amount of equity on each trade.
' Assign the parameter to a script variable. _fixedEquityPerTrade = fixedEquityPerTrade _enableExitSizing = enableExitSizing
' 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