NexusFi: Find Your Edge


Home Menu

 





SetProfitTarget() doesn't work!


Discussion in MultiCharts

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




 
Search this Thread

SetProfitTarget() doesn't work!

  #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?
Trade idea based off three indicators.
Traders Hideout
MC PL editor upgrade
MultiCharts
REcommedations for programming help
Sierra Chart
Exit Strategy
NinjaTrader
ZombieSqueeze
Platforms and Indicators
 
Best Threads (Most Thanked)
in the last 7 days on NexusFi
Spoo-nalysis ES e-mini futures S&P 500
33 thanks
Just another trading journal: PA, Wyckoff & Trends
28 thanks
Tao te Trade: way of the WLD
23 thanks
Bigger Wins or Fewer Losses?
23 thanks
GFIs1 1 DAX trade per day journal
21 thanks
  #2 (permalink)
 ABCTG   is a Vendor
 
Posts: 2,435 since Apr 2013
Thanks Given: 482
Thanks Received: 1,628

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 Twitter Reply With Quote
Thanked by:
  #3 (permalink)
 
vmodus's Avatar
 vmodus 
Somewhere, Delaware, USA
 
Experience: Intermediate
Platform: MultiCharts
Broker: Barchart.com
Trading: Everything, it all tastes like chicken
Posts: 1,271 since Feb 2017
Thanks Given: 2,958
Thanks Received: 2,853


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 Twitter Visit my NexusFi Trade Journal Reply With Quote




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