Stop loss and take profit

Viewing 15 posts - 1 through 15 (of 15 total)
  • Author
    Posts
  • #66646 quote
    voigtbs
    Participant
    Average

    I need some help please. In my strategy I would like the stop to be 2 pips lower than the low of the previous candle. It is a fixed stop and should not move. The profit should then be my stop loss in pips * 1.5. I just cannot get it right.

    Thank you

    #66651 quote
    Nicolas
    Keymaster
    Master

    Topic moved to automatic trading forum.

    Below is an example of how to set a stoploss on the Low of the previous candlestick, minus 2 points below it. With an adjusted takeprofit size calculated with the stoploss distance.

    if not lononmarket and buycondition then
     buy 1 contract at market 
     stoploss = close-(Low[1]-2*pointsize)
     set stop loss stoploss
     set target profit stoploss*1.5
    endif
    #66655 quote
    voigtbs
    Participant
    Average

    Thank you – I appreciate your help

    #75542 quote
    Valentin
    Participant
    Junior

    Hello Nicolas,

    I hope you are doing well, I tried to implement your code* into my program but it doesn’t work. *I removed the 2 first lines, and instead of putting the SL 2 pips below the low of the previous day, I decided to put it at the lowest price of the 2 last candlesticks.

    The issue I have is that my code closes my trades straight after opening them.

    You can find below your code l implemented after my buying conditions.

    IF c1 AND c2 THEN
    BUY 1 CONTRACT AT MARKET
    ENDIF
    
    // Conditions pour fermer une position acheteuse
    c7 = close-(Lowest[2](low))
    set stop loss c7
    set target profit c7*2
    
    IF c7 THEN
    SELL AT MARKET
    ENDIF
    

    I hope you can help me to fix that!

    Many thanks in advance,

    #75544 quote
    Vonasi
    Moderator
    Master

    Remove this part of your code:

    IF c7 THEN
    SELL AT MARKET
    ENDIF

    c7 will always return a positive value so it will always sell. You do not need it as the SET instructions will set the stoploss at the lowest low of the two candles at the open of each bar.

    #75545 quote
    robertogozzi
    Moderator
    Master

    Lines 6-7-8 will change each bar making your SL and TP mobile, I am not sure it’s what you meant to have.

    #75549 quote
    Vonasi
    Moderator
    Master

    Lines 6-7-8 will change each bar making your SL and TP mobile, I am not sure it’s what you meant to have.

    I thought I would answer the first question before waiting for the second question! 🙂

    #75567 quote
    Valentin
    Participant
    Junior

    Good morning,

    Thank you both of you for your help !

    And no, I dont want any trailing stop or take profit moving at each bar. I want them settled up once at the opening at the trade and that’s it.

    How can I make this happen please?

    Thank you in advance,

    #75569 quote
    Nicolas
    Keymaster
    Master

    In order to settle tp and sl one time only, lines 6 to 8 should be placed just after your buy order and in your conditional block.

    #75982 quote
    Valentin
    Participant
    Junior

    Bonjour Nicolas, et merci pour l’aide !

    #76008 quote
    GraHal
    Participant
    Master

    Below is an example of how to set a stoploss on the Low of the previous candlestick, minus 2 points below it. With an adjusted takeprofit size calculated with the stoploss distance

    Congratulations you have won a prize for being No 50 in GraHal’s Link Library

    The Prize is a BIG THANK YOU to you and all the other contributors to the Link Library
    Snippet Link Library

    #76011 quote
    Vonasi
    Moderator
    Master

    The Prize is a BIG THANK YOU to you and all the other contributors to the Link Library

    Being statistically motivated I just worked out that 31% of the snippets are mine and the next highest contributors are Nicolas and Robertogozzi on 18% each. So 31% of the prize is technically mine. From my analysis of these results I have concluded that I need to switch off the laptop and go and do something else a bit more often. I will start with switching it off and opening a beer. 🙂

    GraHal thanked this post
    #76012 quote
    robertogozzi
    Moderator
    Master

    Vonasi, you deserve 31% of the prize for snippets, but 62% of empty cans!

    GraHal thanked this post
    #76017 quote
    GraHal
    Participant
    Master

    From my analysis of these results I have concluded that I need to switch off the laptop and go and do something else a bit more often. I will start with switching it off and opening a beer.

    From seeing the performance of  your Demo account in the last few months when you get it Live we will all give you a big thank you (again) but this time for the beers and party aboard your big new Yacht (pass your old boat to Nicolas and Roberto! ) 🙂

    #76020 quote
    Vonasi
    Moderator
    Master

    …and now I would say that statistically we are 100% off topic. 🙂

Viewing 15 posts - 1 through 15 (of 15 total)
  • You must be logged in to reply to this topic.

Stop loss and take profit


ProOrder: Automated Strategies & Backtesting

New Reply
Author
author-avatar
voigtbs @voigtbs Participant
Summary

This topic contains 14 replies,
has 6 voices, and was last updated by Vonasi
7 years, 7 months ago.

Topic Details
Forum: ProOrder: Automated Strategies & Backtesting
Language: English
Started: 03/29/2018
Status: Active
Attachments: No files
Logo Logo
Loading...