Thursday, September 09, 2010

Commission By Instrument [CBI]

Descripton
Summary:
This commission script calculates the commission paid for an executed stock, futures or forex order, determined by a constant amount in addition to a variable amount based on the order quantity.


Variables
TypeIdentifierDescription
Number_commissionPerStockOrderUse for the commission amount paid for each executed stock order.
Number_commissionPerStockShareUse for the commission amount paid for each share of the executed order.
Number_commissionPerFuturesOrderUse for the commission amount paid for each executed futures order.
Number_commissionPerFuturesContractUse for the commission amount paid for each futures contract of the executed order.
Number_commissionPerForexOrderUse for the commission amount paid for each executed forex order.
Number_commissionPerForexUnitUse for the commission amount paid for each forex unit of the executed order.

OnInitialize
Function Parameters
TypeIdentifierDescription
NumbercommissionPerStockOrderUse for the commission amount paid for each executed stock order. [Default 10]
NumbercommissionPerStockShareUse for the commission amount paid for each share of the executed order. [Default 0.01]
NumbercommissionPerFuturesOrderUse for the commission amount paid for each executed futures order. [Default 0.25]
NumbercommissionPerFuturesContractUse for the commission amount paid for each futures contract of the executed order. [Default 1.5]
NumbercommissionPerForexOrderUse for the commission amount paid for each executed forex order. [Default 1.0]
NumbercommissionPerForexUnitUse for the commission amount paid for each forex unit of the executed order. [Default 0.00002]
Implementation
	 ' Assign the parameters to script variables.
	_commissionPerStockOrder = commissionPerStockOrder
	_commissionPerStockShare = commissionPerStockShare
	_commissionPerFuturesOrder = commissionPerFuturesOrder
	_commissionPerFuturesContract = commissionPerFuturesContract
	_commissionPerForexOrder = commissionPerForexOrder
	_commissionPerForexUnit = commissionPerForexUnit

OnCommission
Function Parameters
TypeIdentifierDescription
IntegerorderIndex
IntegerorderFillIndex
Numberquantity
Numberprice
Implementation
	If (orderFillIndex = 0) Then
		 ' Return the commission being paid for the executed order.
		If (SymbolInstrument(OrderSymbolIndex(orderIndex)) = C_STOCK) Then
			Return _commissionPerStockOrder + (_commissionPerStockShare * quantity)
		End If
		If (SymbolInstrument(OrderSymbolIndex(orderIndex)) = C_FUTURES) Then
			Return _commissionPerFuturesOrder + (_commissionPerFuturesContract * quantity)
		End If
		If (SymbolInstrument(OrderSymbolIndex(orderIndex)) = C_FOREX) Then
			Return _commissionPerForexOrder + (_commissionPerForexUnit * quantity)
		End If
	Else
		 ' Return the commission being paid for the executed order.
		If (SymbolInstrument(OrderSymbolIndex(orderIndex)) = C_STOCK) Then
			Return _commissionPerStockShare * quantity
		End If
		If (SymbolInstrument(OrderSymbolIndex(orderIndex)) = C_FUTURES) Then
			Return _commissionPerFuturesContract * quantity
		End If
		If (SymbolInstrument(OrderSymbolIndex(orderIndex)) = C_FOREX) Then
			Return _commissionPerForexUnit * quantity
		End If
	End If
	Return 0

Copyright © 2010 IQBroker, LLC. All rights reserved.