NexusFi: Find Your Edge


Home Menu

 





SetProfitTarget() doesn't work!


Discussion in MultiCharts

Updated
    1. trending_up 2,090 views
    2. thumb_up 1 thanks given
    3. group 3 followers
    1. forum 2 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 have written a signal to set profit target at 12% of the entire open position. The following is part of the codes to calculate the average price and total no of shares of all opened position. I have printed the output, and have checked the average price and total no of shares are calculated correctly.

However the problem is (1) even if the OpenPositionProfit is smaller than the target, it also sell all the shares.
(2) I have tried to change the profit target to 20%, ie. target = APrice*TTSize*0.12;, it never
sell the shares.

if Date[1] = BuyDate then begin
TTPrice = 0;
TTSize = 0;
posAgo = 0;
numOfTrades = PosTradeCount(posAgo); // get the number of trades for that position
for value1 = 0 to (numOfTrades - 1) begin
TTPrice = TTPrice + PosTradeEntryPrice(posAgo, value1);
TTSize = TTSize + PosTradeSize(posAgo, value1);
end;
APrice = TTPrice / PosTradeCount(posAgo);
target = APrice*TTSize*0.12;
setstopposition;
SetProfitTarget(target);
end;


Thanks for your help,
Raymond


Reply With Quote

Can you help answer these questions
from other members on NexusFi?
The 50/50 Paradox: Peace and Invasion Each at 20% -- Ira …
Prediction Markets & Event Contracts
May 26 Deadline Dies at 7.5% as US Strikes Iran During C …
Prediction Markets & Event Contracts
Iran Peace Expired NO: Ceasefire on Life Support, OPEC a …
Prediction Markets & Event Contracts
CFTC Opens First COT Report Review in 20 Years -- Asks W …
Traders Hideout
Ceasefire Collapse: Iran Fires 24 Missiles, Israel Hits …
Traders Hideout
 
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
CME Expands 24/7 Trading to WTI Crude Oil and Gold -- We …
1 thanks
Big Mike in Ecuador
1 thanks
30 Sessions
1 thanks
  #2 (permalink)
 ABCTG   is a Vendor
 
Posts: 2,448 since Apr 2013
Thanks Given: 494
Thanks Received: 1,643

Hi Raymond,

this is most likely caused by the code. You will have to check what value you are exactly computing as target and compare this to where the target is executed.
Besides that you are placing the SetProfitTarget within a date condition i.e. it would not be issued outside this condition anymore.

Regards,

ABCTG


Follow me on X Reply With Quote
Thanked by:
  #3 (permalink)
 
vmodus's Avatar
 vmodus 
Somewhere, Delaware, USA
Legendary Systematic Algo Trader
 
Experience: Intermediate
Platform: MultiCharts
Broker: Barchart.com
Trading: Everything, it all tastes like chicken
Posts: 1,270 since Feb 2017
Thanks Given: 2,960
Thanks Received: 2,856


Hello Raymond,

As ABCTG mentioned, put you target outside the 'if' statement. My partner ran into the same problem as you a while back. Here is what your code should look like (using your sample):

 
Code
if Date[1] = BuyDate then begin
TTPrice = 0;
TTSize = 0;
posAgo = 0;
numOfTrades = PosTradeCount(posAgo); // get the number of trades for that position
for value1 = 0 to (numOfTrades - 1) begin
TTPrice = TTPrice + PosTradeEntryPrice(posAgo, value1);
TTSize = TTSize + PosTradeSize(posAgo, value1);
end;
APrice = TTPrice / PosTradeCount(posAgo);
target = APrice*TTSize*0.12;
end;

// Stop position outside your 'if' statement
   setstopposition;
   SetProfitTarget(target);
-vmodus


Follow me on X Visit my NexusFi Trade Journal Reply With Quote




Last Updated on March 6, 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