NexusFi: Find Your Edge


Home Menu

 





GetPositionAveragePrice and GetPositionQuantity can't return 0


Discussion in MultiCharts

Updated
    1. trending_up 1,655 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?
April Jobs Beat Flips Fed Hike Odds Past 52% for First T …
Traders Hideout
CME Raises Energy Futures Margins After Iran-War Volatil …
Commodities
ATFX Suspends Prop Trading Unit ATFunded -- Full Review …
Funded Trading Evaluation Firms
After $87M Settles NO: Irans Nuclear Redline Sets Up the …
Prediction Markets & Event Contracts
US Prop Firms Race Inside the CFTC Perimeter -- Tradeify …
Funded Trading Evaluation Firms
 
Best Threads (Most Thanked)
in the last 7 days on NexusFi
NexusFi site changelog and issues/problem reporting
16 thanks
Darmok and Jalad at Tanagra
3 thanks
Big Mike in Ecuador
1 thanks
30 Sessions
1 thanks
CME Expands 24/7 Trading to WTI Crude Oil and Gold -- We …
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