Change Stop Loss in Strategy

Forums ProRealTime English forum ProOrder support Change Stop Loss in Strategy

Currently, there are 0 users and 1 guest visiting this topic.
View all attachments
Viewing 15 posts - 1 through 15 (of 16 total)
  • #179834 Report

    Hi I am using a strategy to open up to 2 positions and would like to change the stop loss after the price moved 10 point from the entry. In backtesting it seems that it is working however, it doesnt work in real execution. I ran this strategy today and it didnt change the stop loss. Luckily I was in profit and hit the target.

    Does it have anything to do with IG limitation? Is there any work around?

    sl=21
    tp=29

    if countoflongshares<80 and countofshortshares<80 then
    if dhigh(0) – lowest[1]>30 and close[0]>open[1] and dopen(0) – lowest[1]>1 then
    buy 50 contracts at market
    SET STOP LOSS sl
    set target profit tp
    endif
    if highest[1] – dlow(0)>30 and close[0]<open[1] and highest[1] – dopen(0) >1 then
    sellshort 50 contracts at market
    SET STOP LOSS sl
    set target profit tp
    endif
    endif
    if longonmarket and close = tradeprice + 10 then
    set stop loss 0
    elsif longonmarket and close = tradeprice -20 then
    set target profit 0
    endif
    if shortonmarket and close= tradeprice -10 then
    set stop loss 0
    elsif shortonmarket and close= tradeprice +20 then
    set target profit 0
    endif

    #179836 Report

    set stop loss 0 disables the Stop Loss and set target profit 0 disables the Take Profit.

    Why are you using them?

    Moreover, when accumulating positions TradePrice should be replaced by PositionPrice.

     

    #179843 Report

    thanks for your reply, I am trying to change the stop loss to 0 (that means the entry price ) when I am 10 points away from my entry .

    #179860 Report

    No, to set the stop loss to breakeven you can’t do that, as this will leave your strategy WITHOUT a stop loss.

    You will have to exit using a pending STOP order.

     

    #179896 Report

    Thanks, I changed it to the below but it seems that it is still not working:

    f longonmarket and close = positionprice -15 then
    sell countoflongshares contracts at positionprice limit
    endif
    if longonmarket and close = positionprice +12 then
    sell countoflongshares contracts at positionprice stop
    endif
    if shortonmarket and close= positionprice +15 then
    buy countofshortshares contracts at positionprice limit
    endif
    if shortonmarket and close= positionprice -12 then
    buy countofshortshares contracts at positionprice stop
    endif

    #179902 Report

    this trail works with cumulating positions, but it’s triggered at a % level rather than points – typically 0.2 – 0.3 %.

    a1 and a2 are how fast you want it to trail.

    Sensitivity is a choice of what triggers it – close, high, low or typicalprice (close+high+low)/3

     

    1 user thanked author for this post.
    #179904 Report

    Sorry, I’m still half asleep – you asked about stop loss, not trailing stop … maybe it’s useful to you anyway.

    #179935 Report

    Link to above TS code added as Log 308 here …

    Snippet Link Library

     

    #179978 Report

    Try this one:

    #180046 Report

    thanks it is working now, however, if I hit the stop or target the order stays open . Is there any command to check at each bar :

    if not onmarket cancel all open orders?

    #180053 Report

    I think it’s due to close = positionprice, because it’s impossible that a price is equal to another one.

    Try using >= or <=.

    #180061 Report

    yeah make sense, how about canceling the order after the position is closed? I dont want for the order to stay after  I am not in the market.

    #180078 Report

    I just read in the other discussion that the Pending orders are cancelled at the end of each bar. Let me explain again what I am looking for:

     

    If long on the market and price moves in my favor by 15 points I want to change the stop loss to the entry to breakeven if the price moved back. If I use the pending order when the first bar closes above the entry + 15 it will create a pending order however , this pending order will be cancelled as soon as price closes between entry and 15 points. So it cannot be used as a stop loss

    Is there any other workaround?

    #180084 Report

    Thanks for your help .I figured it out.

    Just couples of question , why are you using this: (LongOnMarket AND ShortOnMarket[1]) OR (LongOnMarket[1] AND ShortOnMarket)

     

    and is there any reason that you are using “-1” for flag2?

    #180094 Report

    (LongOnMarket AND ShortOnMarket[1]) OR (LongOnMarket[1] AND ShortOnMarket) is used to reset some variables when there’s a Stop & Reverse, because Not OnMarket is false in that case,

    “-1” and “1” are used to tell flag2 from flag1.

     

     

Viewing 15 posts - 1 through 15 (of 16 total)

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