set different stop loss

Viewing 8 posts - 1 through 8 (of 8 total)
  • Author
    Posts
  • #102821 quote
    stefou102
    Participant
    Veteran

    Hello,

    I’m working with stop orders in order to open  new positions in my automated strategies. I have an issue with my SL however. My idea is to:

    1.  set a first stop once the position is open, just below the previous candle low/high
    2. For the next bars, I would like to use another stop, a bit further, which is then fixed through the trade

    The issue I have is that when used separately the code for point 1 and 2 works fine, but when combined only point 1 is working. So in the code the instruction “set stop loss” seems to prevail over “sell/existshort at stop”.

    Does someone know why?

    If long=1 then
    buy positionSize contracts at buyLevel STOP
    stopbougieL=Lowest[7](low)-2*pipsize
    set stop loss abs((close-low))+2*pipsize
    endif
    if short=1 then
    sellshort positionSize contracts at SellLevel STOP
    stopbougieS=highest[7](high)+2*pipsize
    set stop loss abs((close-high))+2*pipsize
    endif
    
    if longonmarket then
    sell at stopbougieL stop
    graph close
    elsif shortonmarket then
    exitshort at stopbougieS stop
    endif
    
    
    #102831 quote
    Vonasi
    Moderator
    Master

    Whenever LONG = 1 or SHORT = 1 then the STOP LOSS order will be read and placed. The following should work as long as you are not wanting to use accumulating positions:

    If long=1 then
    buy positionSize contracts at buyLevel STOP
    stopbougieL=Lowest[7](low)-2*pipsize
    if not onmarket then
    set stop loss abs((close-low))+2*pipsize
    endif
    endif
    
    if short=1 then
    sellshort positionSize contracts at SellLevel STOP
    stopbougieS=highest[7](high)+2*pipsize
    if not onmarket then
    set stop loss abs((close-high))+2*pipsize
    endif
    endif
     
    if longonmarket then
    sell at stopbougieL stop
    graph close
    elsif shortonmarket then
    exitshort at stopbougieS stop
    endif
    #102835 quote
    stefou102
    Participant
    Veteran

    thx Vonasi, but actually I already used the “not onmarket” function, I just cut it wrongly when I copy paste the code here.

    So no, on my charts, it still doesn’t work

    #102838 quote
    Vonasi
    Moderator
    Master

    Sorry my mistake. A SET STOP LOSS order need only be sent once and is then on the market until it is either cancelled or the value changed. Setting it to zero is supposed to cancel them but it did not use to work (maybe it does now?) An alternative is to use SET STOP %LOSS 100.

    If long=1 then
    buy positionSize contracts at buyLevel STOP
    stopbougieL=Lowest[7](low)-2*pipsize
    if not onmarket then
    set stop loss abs((close-low))+2*pipsize
    endif
    endif
     
    if short=1 then
    sellshort positionSize contracts at SellLevel STOP
    stopbougieS=highest[7](high)+2*pipsize
    if not onmarket then
    set stop loss abs((close-high))+2*pipsize
    endif
    endif
     
    if longonmarket then
    set stop ploss 0
    sell at stopbougieL stop
    graph close
    elsif shortonmarket then
    set stop ploss 0
    exitshort at stopbougieS stop
    endif
    #102840 quote
    Vonasi
    Moderator
    Master

    An alternative is to just use pending stop orders and not use SET STOP orders.

    If long=1 then
    buy positionSize contracts at buyLevel STOP
    stopbougieL=Lowest[7](low)-2*pipsize
    if not onmarket then
    sell at close - abs((close-low))+2*pipsize stop
    endif
    endif
     
    if short=1 then
    sellshort positionSize contracts at SellLevel STOP
    stopbougieS=highest[7](high)+2*pipsize
    if not onmarket then
    exitshort at close + abs((close-high))+2*pipsize stop
    endif
    endif
     
    if longonmarket then
    sell at stopbougieL stop
    graph close
    elsif shortonmarket then
    exitshort at stopbougieS stop
    endif
    #102854 quote
    stefou102
    Participant
    Veteran

    Thx very much Vonasi ,

    your trick with SET STOP %LOSS 100 seems to be working! Testing the code on my strategy, it improves a bit the profit factor, which was the goal, as I noticed that sometimes, the market moves directly against you (meaning in the same bar when you took the trade), and it’s best to cut directly.

    #102856 quote
    Vonasi
    Moderator
    Master

    So I’m guessing that SET STOP pLOSS 0 is still not cancelling any set stop orders then?

    #102867 quote
    stefou102
    Participant
    Veteran

    works also, at least on backtest

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

set different stop loss


ProOrder: Automated Strategies & Backtesting

New Reply
Author
author-avatar
stefou102 @stefou102 Participant
Summary

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

Topic Details
Forum: ProOrder: Automated Strategies & Backtesting
Language: English
Started: 07/18/2019
Status: Active
Attachments: No files
Logo Logo
Loading...