Welcome to NexusFi: the best trading community on the planet, with over 150,000 members Sign Up Now for Free
Genuine reviews from real traders, not fake reviews from stealth vendors
Quality education from leading professional traders
We are a friendly, helpful, and positive community
We do not tolerate rude behavior, trolling, or vendors advertising in posts
We are here to help, just let us know what you need
You'll need to register in order to view the content of the threads and start contributing to our community. It's free for basic access, or support us by becoming an Elite Member -- see if you qualify for a discount below.
-- Big Mike, Site Administrator
(If you already have an account, login at the top of the page)
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
Can you help answer these questions from other members on NexusFi?
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.
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):