Current price and position's entry price
Author: BCWEALTH
Creation Date: 5/20/2009 3:14 AM
profile picture

BCWEALTH

#1
How do I get current price ? I need to calculate position's entry price minus current price.



Example: I would like to have more than one order, New order will be generated when current price is 1% down from last position's entry price.

I need last orders's entry price MINUS current real-time price.


Thanks
profile picture

Eugene

#2
QUOTE:
How do I get current price ?

Please see the WealthScript Programming Guide, The Bars Object > OHLC/V Series > How to: Access a OHLC/V value.
QUOTE:
I need to calculate position's entry price minus current price.

Hit F11, in the QuickRef window find the Position object, EntryPrice Property.
QUOTE:
I need last orders's entry price MINUS current real-time price.

Current real-time price (the ghost bar) is inaccessible.
QUOTE:
I would like to have more than one order, New order will be generated when current price is 1% down from last position's entry price.

CODE:
Please log in to see this code.
profile picture

BCWEALTH

#3
Thanks Eugene,

Can I specify number of shares on the BuyAtMarket function ?

I would like to buy 100 shares on 1st order, 2nd order would be 500 shares.


Thanks

profile picture

Eugene

#4
Unfortunately no, until a newer version comes out that will support scripting the position size (so called PosSizers aka $imuscripts in Version 4).
profile picture

BCWEALTH

#5
Eugene,

Do you have a routine that calculates total profit of all positions ?

If not, Do I calculate each position's entry price - current price) * shares and add it ?



Thanks
Bruce
profile picture

Eugene

#6
Hi Bruce,

If you wanted to do a manual calculation inside your Strategy code, then the Shares property will always be 1 while the Strategy is executing.
profile picture

BCWEALTH

#7
Hi Eugene,

Here's my code, Can you please fix it ?

CODE:
Please log in to see this code.


High[bar] - p.EntryPrice does not work because High could be the same bar as entry bar and myProfit calculations is invalid. If it is possible, I need to calculate real time total profit.



Thanks
Bruce


profile picture

Eugene

#8
Bruce,

Please re-read my reply from 5/20/2009 11:34 AM.

Note that the Position object already has the necesary properties like .NetProfitAsOfBar/.NetProfitAsOfBarPercent etc. - you'll find them along with some code examples illustrating their usage in the QuickRef.
profile picture

BCWEALTH

#9
Thanks Eugene. NetProfitAsOfBar works.

I can't wait for the newer version that will support scripting the position size,

Will it be this year ?



profile picture

Eugene

#10
Please see Robert's reply on PosSizers here:
5/17/2009 5:53 PM
This website uses cookies to improve your experience. We'll assume you're ok with that, but you can opt-out if you wish (Read more).