NexusFi: Find Your Edge


Home Menu

 





GetPositionAveragePrice and GetPositionQuantity can't return 0


Discussion in MultiCharts

Updated
    1. trending_up 1,756 views
    2. thumb_up 2 thanks given
    3. group 2 followers
    1. forum 3 posts
    2. attach_file 0 attachments




 
Search this Thread
  #1 (permalink)
hgchcw
Hong Kong + Hong Kong
 
Posts: 18 since Feb 2019
Thanks Given: 9
Thanks Received: 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


Reply With Quote

Can you help answer these questions
from other members on NexusFi?
requesting .nrd replay files from 2026 spy and qqq
The Elite Circle
Trump Media to sell instant access to market-moving soci …
Traders Hideout
My Rant with AMP Futures
Trading Reviews and Vendors
No book, only a stair: journaling fills where price move …
Cryptocurrency
EA
Platforms and Indicators
 
Best Threads (Most Thanked)
in the last 7 days on NexusFi
BERN ALGOS algo trading journal
3 thanks
NexusFi site changelog and issues/problem reporting
2 thanks
TopStep Trader disappointment
2 thanks
Want your NinjaTrader indicator created, free?
1 thanks
Running trading strategies on a VPS
1 thanks
  #2 (permalink)
 ABCTG   is a Vendor
 
Posts: 2,448 since Apr 2013
Thanks Given: 494
Thanks Received: 1,643

Hi Raymond,

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.

Regards,

ABCTG


hgchcw View Post
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


Follow me on X Reply With Quote
Thanked by:
  #3 (permalink)
hgchcw
Hong Kong + Hong Kong
 
Posts: 18 since Feb 2019
Thanks Given: 9
Thanks Received: 0


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.

Regards,
Raymond


Reply With Quote
  #4 (permalink)
 ABCTG   is a Vendor
 
Posts: 2,448 since Apr 2013
Thanks Given: 494
Thanks Received: 1,643

Hi Raymond,

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.

https://www.multicharts.com/trading-software/index.php/PosTradeEntryPrice

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.

 
Code
if MarketPosition = 0 then //when you are flat, set the target value 
 target = Close * .2 ;
Regards,

ABCTG

P.S.: By the way you can show your appreciation for posts on NexusFi by clicking the "Thanks" button next to the respective post.


Follow me on X Reply With Quote
Thanked by:




Last Updated on February 25, 2019


© 2026 NexusFi®, s.a., All Rights Reserved.
Av Ricardo J. Alfaro, Century Tower, Panama City, Panama, Ph: +507 833-9432 (Panama and Intl), +1 888-312-3001 (USA and Canada)
All information is for educational use only and is not investment advice. There is a substantial risk of loss in trading commodity futures, stocks, options and foreign exchange products. Past performance is not indicative of future results.
About Us - Contact Us - Site Rules, Acceptable Use, and Terms and Conditions - Downloads - Top
no new posts