Orders Partial Take Profit

Questions about MultiCharts and user contributed studies.
user_01
Posts: 7
Joined: 13 Mar 2024

Orders Partial Take Profit

Postby user_01 » 08 Apr 2024

TLDR: Im trying to implement 3 Partial Take Profit Levels for multiple open orders.
 
I understand the use cases for the different exit functions. However i believe neither one performs the way i want my algo to work.
Method1 : SetStopContract, SetProfitTarget(10)
I know this would set different profit target levels for different trades. E.g. Trade A (entry 90) -> Exit@100, Trade B(entry 95) -> Exit@105. This is good since it isolates each trade individually. However, I am unable to set multiple profit target levels because this function would close out the entire position. So when price reaches 100, the entirety of Trade A will be closed while Trade B is still running. I am trying to set multiple profit target levels. E.g. Trade A(entry 90) -> Exit1(50% of position)@ 100, Exit2(50% of position)@110. So setstopcontract doesnt work.
Method2 : Sell Stop and Sell Limit
I know to set different profit target levels i would have to use Sell Stop. Here is a code snippet.

Code: Select all

if condition1 ... condition2 ....       ...       ...       pt1 = close + 2 * Multiplier * atr;     pt2 = close + 5 * Multiplier * atr; pt3 = close + 7 * Multiplier * atr;       Buy ("Buy") contract_size contracts next bar on market; if marketposition <> 0 and close >= pt1 then begin       Sell("PT1") 0.5 * currentcontracts contracts next bar on market;//close;       end; if marketposition <> 0 and close >= pt2 then begin       Sell("PT2") 0.5 * currentcontracts contracts next bar on market;//close;       end; if marketposition <> 0 and close >= pt3 then begin       Sell("PT3") next bar on market;//close;       end;


However, this also becomes a problem since pt1, pt2, pt3 are updated whenever there is a new buy order. So the first open trade is following the latest open trade's profit target levels. Which is not right. So i thought i could solve this by storing the SL level of each trade in an array. Then i would loop through each open order to get its entrycontracts and entryprice and calculate each trades' PT levels then close them. However another issue occurs because it says i am unable to send orders in a loop.


      
      

Code: Select all

if condition1 ... condition2 ....             ...             ...             arr[OpenEntriesCount] = sl;             Buy ("Buy") contract_size contracts next bar on market;       if marketposition <> 0 then begin             for i = 0 to OpenEntriesCount - 1 begin                   entry_price = OpenEntryPrice(i);                   entry_contracts = OpenEntryContracts(i);                   sl_level = array_getfloatvalue(arr, i);                   pt1 = entry_price + 1 * (entry_price - sl_level);                   pt2 = entry_price + 5 * (entry_price - sl_level);                   pt3 = entry_price + 10 * (entry_price - sl_level);                   if close >= pt1 then                         Sell("PT1") 0.5 * entry_contracts contracts next bar on market;                   if close >= pt2 then                         Sell("PT2") 0.25 * entry_contracts contracts next bar on market;                   if close >= pt3 then                         Sell("PT3") 0.125 * entry_contracts contracts next bar on market;             end;       end;

Please could someone help me out, ive been trying to implement this for quite some time. Is there no functionality to set multiple profit target levels for each individual trade? Thank you in advance to any help.
Last edited by user_01 on 09 Apr 2024, edited 1 time in total.

User avatar
TJ
Posts: 7743
Joined: 29 Aug 2006
Location: Global Citizen
Has thanked: 1033 times
Been thanked: 2222 times

Re: Orders Partial Take Profit

Postby TJ » 09 Apr 2024

See Posts #1 & #2
viewtopic.php?t=11713

user_01
Posts: 7
Joined: 13 Mar 2024

Re: Orders Partial Take Profit

Postby user_01 » 09 Apr 2024

Thank you @TJ. I rectified the original post.

MoeMiami
Posts: 6
Joined: 09 Apr 2024
Been thanked: 1 time

Re: Orders Partial Take Profit

Postby MoeMiami » 14 Apr 2024

1. You would want to use an entrylabel see here https://www.multicharts.com/trading-sof ... itle=Entry Sell from entry ("Entry1") at PT1.
2. pt1 = close + 2 * Multiplier * atr; will update on every bar so you would need to specify the close of the entry bar.

you can use something like this
MP = Marketposition;
Value1 = OpenEntryContracts (0);
if MP = 1 and MP[1] <> 1 then PT1 = Close[1] + ATR
if Value1 = 2 and Value1[1] <> 2 then PT2 = Close[1] + ATR
if Value1 = 3 and Value1[1] <> 3 then PT3 = Close[1] + ATR


There's also a way to identify the specific entries in the position you can check here https://www.multicharts.com/trading-sof ... ion_Trades.

user_01
Posts: 7
Joined: 13 Mar 2024

Re: Orders Partial Take Profit

Postby user_01 » 14 Apr 2024

Thank you MoeMiami, i will look into the functionalities u propose.


Return to “MultiCharts”