ICE Data Services -

Strategy.getPositionSize() Back Testing Functions

getPositionSize() is a method of the Strategy Object that retrieves the current size of a position for back testing analysis through the Strategy Analyzer (Tools-->Back Testing).  The Strategy Object is for back testing purposes only and is not intended for real time trading.



Strategy .getPositionSize( )



Return Value(s)




getPositionSize() returns a positive number of the current size of a long position, a negative number if short and 0 if the strategy is flat or not currently in a position.  This method is typically used where the exit strategy closes portions of a position.


Code Examples

// Retrieve the current size of a position. var nLot = Strategy.getPositionSize();
// Assign the number of shares/contracts of an existing position to a variable that 
// will be used to close half of the position.  When specifying a lot size
// in the doSell() or doCover() methods, ensure that the number for the lot 
// size specified is a whole number by rounding the result like 
below.var nHalf = Math.round(Strategy.getPositionSize() / 2); var nStop = hl2(); Strategy.doSell("Exit Long Signal", Strategy.STOP, Strategy.THISBAR, nHalf, nStop);

See Also

Back Testing Functions
EFS Library:  Back Testing
Strategy Analyzer
eSignal Bulletin Board Search Engine
Help Guides and Tutorials