Welcome to NexusFi: the best trading community on the planet, with over 150,000 members Sign Up Now for Free
Genuine reviews from real traders, not fake reviews from stealth vendors
Quality education from leading professional traders
We are a friendly, helpful, and positive community
We do not tolerate rude behavior, trolling, or vendors advertising in posts
We are here to help, just let us know what you need
You'll need to register in order to view the content of the threads and start contributing to our community. It's free for basic access, or support us by becoming an Elite Member -- see if you qualify for a discount below.
-- Big Mike, Site Administrator
(If you already have an account, login at the top of the page)
GetPositionAveragePrice and GetPositionQuantity can't return 0
I want to use GetPositionAveragePrice and GetPositionQuantity to set the profit target to be earning 20% of the entry price as follows. But in the price chart, the profit target is the same as the entry price, that means the target = 0. Why GetPositionAveragePrice and GetPositionQuantity cannot function and return 0?
Buy ( "Buy1" ) 100 shares this bar on close;
target = (GetPositionAveragePrice("AMD",GetAccountID())*GetPositionQuantity("AMD",GetAccountID())* 0.2);
SetProfitTarget(target);
Thanks for your help!
Raymond
Can you help answer these questions from other members on NexusFi?
the values might simply not have updated, yet. Besides that you are using broker related functionalities that will only work in real time. I would suggest using the print reserved word to check the internal values within your code.
Thanks ABCTG! Are there any function I can use to get the average price and total position of all entries in non-real time? Because I only use it to do backtesting analysis.
you are welcome. PosTradeEntryPrice or EntryPrice will both work, but you will face the problem that the entry price is only available after your fill and this might result in the target not being placed on the bar after your entry.
For the code snippet you posted it might by far be easier to simply set the target when you are not in a position using the Close of the current bar and also to use the SetStopContract reserved word to ensure the value is applied to each share.
Regards,
ABCTG
P.S.: By the way you can show your appreciation for posts on futures.io by clicking the "Thanks" button next to the respective post.