2 Profit Targets
Forums › ProRealTime English forum › ProOrder support › 2 Profit Targets
- This topic has 8 replies, 2 voices, and was last updated 2 years ago by robertogozzi.
-
-
08/10/2021 at 9:58 AM #174994
Hi all,
Hi, I would like to ask if it is possible to have your algo with 2 TP target. Apologies if this questions have been raised. I tried to look up past topics but the topic was a while ago and the answer was the brokers cannot support partial TP at that time. If there is a relevant topic on this already appreciate if you can provide the link to me. If not, I hope you will find this qns interesting:
Simple algo is to buy 2 shares when the price cross over the lower bollinger band, and to sell 1 share when the price higher than the middle of the bollinger, and to sell another 1 share when the price is higher than the top of the bollinger.
Basically:
// Conditions to enter long positions
BBDown= BollingerDown[55](close)
c1 = (close CROSSES OVER BBDown)IF c1 THEN
BUY 2 SHARES AT MARKET
ENDIF// Conditions to exit long positions
TP1 = Average[55](close)
c2 = (close >= TP1)
TP2 = BollingerUp[55](close)
c3 = (close >= TP2)IF c2 THEN
SELL 1 AT MARKET
ENDIFIF c3 THEN
SELL 1 AT MARKET
ENDIFThe code SELL 1 AT MARKET gives an error. Can anyone advise how I should code this?
Thank you and have a great day ahead.
08/10/2021 at 10:37 AM #174999You’ve been returned an error because your syntax is missing the keyword CONTRACT, after 1 for the first TP.
For the second TP, I suggest that just remove 1 (instead of adding CONTRACT), as the second TP has to close ALL positions (even if only 1 is left).
1 user thanked author for this post.
08/10/2021 at 1:22 PM #175016Thank you Roberto, as always. In the code below, the long triggered to by 2 when the price cross over the lower bollinger band (BB) of 2 standard deviation (STD), and sell 1 to TP when the price is above the BB up of 1 STD, and sell another 1 when the price is above BB up of 2 STD. In the picture, the BB 1 std is white dotted lines and BB 2 std is magenta dotted lines. I modified the codes based on your suggestion. The result now able to sell 1 at TP1 and the remaining at TP2. However the TP2 level seems to be wrong. Can you pls help? Tks. I have attached the screenshot. Its EURUSD 10 mins chart. Tks
12345678910111213141516171819202122232425// Definition of code parametersDEFPARAM CumulateOrders = False // Cumulating positions deactivated// Conditions to enter long positionsindicator1 = BollingerDown[55](close)c1 = (close CROSSES OVER indicator1)IF c1 THENBUY 2 SHARES AT MARKETENDIF// Conditions to exit long positionsBB1STD = Average[55](close)+std[55](close)c2 = (close >= BB1STD)BB2STD = BollingerUp[55](close)c3 = (close >= BB2STD)IF c2 THENSELL 1 CONTRACT AT MARKETENDIFIF c3 THENSELL AT MARKETENDIF08/10/2021 at 1:44 PM #175018The error is in line 13.
STD is not needed for the middle line, it’s just an average:
1BB1STD = Average[55](close)08/10/2021 at 2:32 PM #175019Hi Roberto,
Thanks for the fast response. I change the code already. But the TP2 still not executed correctly. The TP2 shud be executed at the top of the BBBand (magenta dotted line). See the attached screen shot. Appreciate if you can help. Sorry to trouble you again.
12345678910111213141516171819202122232425// Definition of code parametersDEFPARAM CumulateOrders = False // Cumulating positions deactivated// Conditions to enter long positionsindicator1 = BollingerDown[55](close)c1 = (close CROSSES OVER indicator1)IF c1 THENBUY 2 SHARES AT MARKETENDIF// Conditions to exit long positionsBB1STD = Average[55](close)c2 = (close >= BB1STD)BB2STD = BollingerUp[55](close)c3 = (close >= BB2STD)IF c2 THENSELL 1 CONTRACT AT MARKETENDIFIF c3 THENSELL AT MARKETENDIF08/10/2021 at 7:54 PM #175046Hi Roberto et al, I think I know what the problem is. So i long 2 shares. As you can see, I have defined 2 TP conditions. So say the less aggressive TP1 target is reached first, and we sell 1 contract at TP1 and have a remaining 1 share left. Then in the next consecutive candles the program will always read the condition for TP1, and thus TP2 will not be reached as the remaining 1 share will always get hit on the TP1 condition. How do i change my code so that for my 2 shares that I buy, 1 will get executed on TP1, and the other on TP2?
Tks
08/10/2021 at 9:55 PM #175068At line 3 add
123If Not OnMarket thenFlag = 0EndifAdd this line between lines 9 and 10
1Flag = 1Lines 19-21 should be replaced by
1234IF c2 and Flag THENSELL 1 CONTRACT AT MARKETFlag = 0ENDIF1 user thanked author for this post.
08/11/2021 at 7:14 PM #175120Hi Roberto, thanks lots your suggestion works wonder. But just as I thought things are as simple as they look, they are not. Apparently there is also LongOnMarket and ShortOnMarket! So if I have both BUY and SELLSHORT in the same strategy, I have to use both LongOnMarket and ShortOnMarket as shown in the code below. Is my understanding correct? Tks in advance.
1234567If Not LongOnMarket thenFlagLong = 0EndifIf Not ShortOnMarket thenFlagShort = 0Endif08/11/2021 at 8:17 PM #175124 -
AuthorPosts
Find exclusive trading pro-tools on