NexusFi: Find Your Edge


Home Menu

 





GetPositionAveragePrice and GetPositionQuantity can't return 0


Discussion in MultiCharts

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




 
Search this Thread

GetPositionAveragePrice and GetPositionQuantity can't return 0

  #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?
Trade idea based off three indicators.
Traders Hideout
Better Renko Gaps
The Elite Circle
NT7 Indicator Script Troubleshooting - Camarilla Pivots
NinjaTrader
Exit Strategy
NinjaTrader
How to apply profiles
Traders Hideout
 
Best Threads (Most Thanked)
in the last 7 days on NexusFi
Spoo-nalysis ES e-mini futures S&P 500
48 thanks
Just another trading journal: PA, Wyckoff & Trends
35 thanks
Tao te Trade: way of the WLD
25 thanks
Bigger Wins or Fewer Losses?
24 thanks
GFIs1 1 DAX trade per day journal
22 thanks
  #2 (permalink)
 ABCTG   is a Vendor
 
Posts: 2,435 since Apr 2013
Thanks Given: 482
Thanks Received: 1,628

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 Twitter 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,435 since Apr 2013
Thanks Given: 482
Thanks Received: 1,628

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 futures.io by clicking the "Thanks" button next to the respective post.

Follow me on Twitter Reply With Quote
Thanked by:




Last Updated on February 25, 2019


© 2024 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 - Privacy Policy - Downloads - Top
no new posts