How to check number of shares sold?

Questions about MultiCharts and user contributed studies.
treksis
Posts: 13
Joined: 18 Jul 2014
Has thanked: 4 times

How to check number of shares sold?

Postby treksis » 03 Aug 2014

Hi, I'm trying a new strategy and I need to be able to stop the script if the number of shares sold at once, exceeds x amount.

Code: Select all

variable:amount;
amount=50: // 50 shares
if number_of_shares_sold_at_once > amount then
#return.
Is there a way to get the number of shares sold at once?

User avatar
Smoky
Posts: 507
Joined: 03 Dec 2010
Location: Thailand
Has thanked: 97 times
Been thanked: 115 times

Re: How to check number of shares sold?

Postby Smoky » 03 Aug 2014

From wiki :

MarketPosition_at_Broker_for_The_Strategy

Will will return '17' if the current position at the broker for the strategy is 17 contracts long.
Will return '-132' if the current position at the broker for the strategy is 132 contracts short.
Will return '0' if the current position at the broker for the strategy is flat.
Will return '0' if the Automated Trading Mode is not turned on.

treksis
Posts: 13
Joined: 18 Jul 2014
Has thanked: 4 times

Re: How to check number of shares sold?

Postby treksis » 03 Aug 2014

From wiki :

MarketPosition_at_Broker_for_The_Strategy

Will will return '17' if the current position at the broker for the strategy is 17 contracts long.
Will return '-132' if the current position at the broker for the strategy is 132 contracts short.
Will return '0' if the current position at the broker for the strategy is flat.
Will return '0' if the Automated Trading Mode is not turned on.
does this only work if I have a broker account attached to multichart?
It keeps returning 0.

User avatar
Smoky
Posts: 507
Joined: 03 Dec 2010
Location: Thailand
Has thanked: 97 times
Been thanked: 115 times

Re: How to check number of shares sold?

Postby Smoky » 03 Aug 2014

From wiki :

MarketPosition_at_Broker_for_The_Strategy

Will will return '17' if the current position at the broker for the strategy is 17 contracts long.
Will return '-132' if the current position at the broker for the strategy is 132 contracts short.
Will return '0' if the current position at the broker for the strategy is flat.
Will return '0' if the Automated Trading Mode is not turned on.
does this only work if I have a broker account attached to multichart?
It keeps returning 0.
With no broker, try
MarketPosition + CurrentContracts
http://www.multicharts.com/trading-soft ... etPosition
http://www.multicharts.com/trading-soft ... tContracts

MarketPosition(0) * CurrentContracts

Will return a value of "-9" if the strategy is short 9 contracts, and will return a value of "4" if the strategy is long four contracts.

MarketPosition : to know if long or short
Returns a numerical value, indicating the type of the specified position.
A value of 1 indicates a long position, -1 indicates a short position, and 0 is returned only if the current position is specified and indicates that the current position is flat.

CurrentContracts :
CurrentContracts returns an absolute value for both long and short positions.

This function can only be used in signals.
To use the CurrentContracts or CurrentShares in an indicator, see i_CurrentContracts and i_CurrentShares respectively.


Return to “MultiCharts”