NexusFi: Find Your Edge


Home Menu

 





SetProfitTarget() doesn't work!


Discussion in MultiCharts

Updated
    1. trending_up 1,991 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?
Hormuz Surges From 14% to 26.5% Intraday as Irans Answer …
Prediction Markets & Event Contracts
US Navy Blockade of Hormuz Starts Today -- Oil Surges 8p …
Prediction Markets & Event Contracts
Irans Answer Due Today: Peace Surges to 33.5%, Invasion …
Prediction Markets & Event Contracts
$24.5 Billion Record Month: Prediction Markets Shatter A …
Prediction Markets & Event Contracts
CFTC Approves First US Bitcoin Perpetual Futures -- Kals …
Traders Hideout
 
Best Threads (Most Thanked)
in the last 7 days on NexusFi
The Pivot Point 113.6³ — Navigating the Prediction of …
26 thanks
Sober Journey With S&P
17 thanks
The Confluence Meter: A Multi-Layered Signal Framework B …
11 thanks
NT8 color choices
10 thanks
Volume Indicators
7 thanks
  #2 (permalink)
 ABCTG   is a Vendor
 
Posts: 2,447 since Apr 2013
Thanks Given: 493
Thanks Received: 1,639

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
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