2 Profit Targets

Viewing 9 posts - 1 through 9 (of 9 total)
  • #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
    ENDIF

    IF c3 THEN
    SELL 1 AT MARKET
    ENDIF

     

    The code SELL 1 AT MARKET gives an error.  Can anyone advise how I should code this?

    Thank you and have a great day ahead.

    #174999

    You’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.
    #175016

    Thank 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

     

     

     

     

    #175018

    The error is in line 13.

    STD is not needed for the middle line,  it’s just an average:

    #175019

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

     

     

    #175046

    Hi 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

     

     

    #175068

    At line 3 add

    Add this line between lines 9 and 10

    Lines 19-21 should be replaced by

    1 user thanked author for this post.
    #175120

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

     

    #175124

    Yes, that’s correct.

     

    1 user thanked author for this post.
Viewing 9 posts - 1 through 9 (of 9 total)

Create your free account now and post your request to benefit from the help of the community
Register or Login