different limit amounts for long and short trades

Viewing 13 posts - 1 through 13 (of 13 total)
  • Author
    Posts
  • #86481 quote
    aland
    Participant
    Average

    Hi there,

    I am testing the following code.

    It seems that the short and long are both using the StopLimitShort param ignoring my StopLimit amount which is diffrent.

    Is there a way to set different target Profits for short and long orders?

    IF ProfitState>=STRATEGYPROFIT AND LongTriggered=0 THEN 
    BUY BuyMultiplier*StakeSize CONTRACTS AT MyBuyprice stop
    SET TARGET PROFIT StopLimit
    ENDIF
    IF ProfitState>=STRATEGYPROFIT AND ShortTriggered=0 THEN 
    SELLSHORT StakeSize CONTRACTS AT MySellprice stop
    SET TARGET PROFIT StopLimitShort
    ENDIF
    
    
    SET STOP LOSS StopLoss
    #86489 quote
    robertogozzi
    Moderator
    Master

    Remove line 4 and, at line 5, replace IF with ELSIF.

    LongTriggered and ShortTriggered are likely to both retain value 0 and, not having other different conditions to filter trades, the code for SHORT trades is always read and executed (despite trades may not be opened due to DEFPARAM CUMULATEORDERS=Fslse) since it is simply written after the code for LONG trades.

    If you switch both code chunks then  STOPLIMIT will override STOPLIMITSHORT.

    aland thanked this post
    #86496 quote
    jebus89
    Participant
    Master

    Also if ur in a trade and want 1 stop for long trades, and 1 stop for short trades i guess u can use:

    If Longonmarket then
    set stop ploss 100
    
    endif
    
    If shortonmarket then
    
    set stop ploss 50
    
    endif
    #86497 quote
    GraHal
    Participant
    Master

    1 stop for long trades, and 1 stop for short trades

    Yes as you show above, but this means the SL is only effective on the next bar when the code can determine if the position is Long or Short.

    Better way is as below and then the SL is effective immediately after buy and does not have to wait until the next bar.

    Hope that makes sense?

    IF ProfitState>=STRATEGYPROFIT AND LongTriggered=0 THEN 
    BUY BuyMultiplier*StakeSize CONTRACTS AT MyBuyprice stop
    SET TARGET PROFIT StopLimit
    set stop ploss 100
    ENDIF
    #86499 quote
    robertogozzi
    Moderator
    Master

    aland‘s problem is the TP, not the SL which is the same for all trades.

    #86511 quote
    aland
    Participant
    Average

    Thanks guys,

    Yes, the problem I have is with target profit (and not stop loss)

    and…I do want both BUY and SELLSTOP orders which is why it is ok that they are both triggered one after the other (not if/else).

    What I am not sure about is why does each order share the limit (and maybe the SL as well)

    The questions are:

    1. whether or not I can set a separate value on each one of the orders as I originally planned
    2. set the limit anew on the next bar like (like jebus89 suggested) – I am not worried about it being on the next bar as it will still work, but not sure if it is possible or if there isn’t an easier method.
    #86525 quote
    Vonasi
    Moderator
    Master
    MyTargetLong = 100
    MyTargetShort = 50
    
    LongExit = MyBuyPrice + MyTargetLong
    ShortExit = MySellPrice - MyTargetShort
    
    IF ProfitState>=STRATEGYPROFIT AND LongTriggered=0 THEN 
    BUY BuyMultiplier*StakeSize CONTRACTS AT MyBuyprice stop
    Sell at MyTargetLong Limit
    ENDIF
    
    IF ProfitState>=STRATEGYPROFIT AND ShortTriggered=0 THEN 
    SELLSHORT StakeSize CONTRACTS AT MySellprice stop
    ExitShort at MyTargetShort Limit
    ENDIF
     
    If longonmarket then
    Sell at MyTargetLong Limit
    endif
    
    If shortonmarket then
    ExitShort at MyTargetShort Limit
    endif
    
    SET STOP LOSS StopLoss

    Not sure if the above would do what you want – not tested at all.

    aland thanked this post
    #86541 quote
    aland
    Participant
    Average

    Thanks Vonasi,

    I’ll test it.

    I am wondering why you need to set the limit twice in your code, once during the order and than again after it started running.

    Is it because each bar needs a new order and there is no “memory” between the bars?

    Also, a somewhat unrelated question. My code orders a buy and a sell at the same time but only one can be called at a time, Since the margins have gone up so much in the EU, have you guys considered opening just one order at a time. for example:

    if last position is closer to buy stop then to sell stop then create buy order else if sell is closer then close the current buy order and open sell order instead.

    or do you have any other way of working around the high margin requests?

     

    Thanks

    #86565 quote
    Vonasi
    Moderator
    Master

    Yes you have to repeat the orders as STOP and LIMIT orders only last one bar and are then cancelled so you have to place a new order at every bar.

    Unfortunately there is no coding solution that I know of to overcome the new higher margins – the only solution I’m afraid to say is a bigger bank balance to start with! 🙂

    I don’t really like strategies that chop and change from long to short opening and closing positions just because now long looks like a good idea and in the next moment closing what could have been a good trade if given some room just to go the opposite way. I much prefer two completely separate strategies – one long and one short. Most markets have very different characteristics when going down compared to up so I see no reason to combine the two. It is simpler to keep them separate even if it means that sometimes you might be long as well as short at the same time.

    #86579 quote
    GraHal
    Participant
    Master

    Yes you have to repeat the orders as STOP and LIMIT orders only last one bar and are then cancelled so you have to place a new order at every bar.

    I’m confused now, it’s not difficult! 🙂

    Isn’t below setting the limit order level at time of a buy and then the Order remains (no need to be renewed) until MyTargetLong is triggered (or any StopLoss is triggered or any SellShort is triggered)?

     

    IF ProfitState>=STRATEGYPROFIT AND LongTriggered=0 THEN 
    BUY BuyMultiplier*StakeSize CONTRACTS AT MyBuyprice stop
    Sell at MyTargetLong Limit
    ENDIF
    
    #86580 quote
    Vonasi
    Moderator
    Master

    I am assuming that LongTriggered can switch back to 1 at any point due to whatever changing conditions are deciding its state. This means that you could place an order and have it filled and then at the next bar LongTriggered switches to 1 and no sell order is placed leaving you with a position on the market with no exit order to close it. Thus the need for separate sell/sellshort orders to be placed at every bar whilst long or short positions are open on the market.

    GraHal thanked this post
    #86583 quote
    GraHal
    Participant
    Master

    I looked at it again (now my grandson not wanting to do jigsaws! 🙂 ) and I was confusing myself!

    I was reading it as …

    BUY BuyMultiplier*StakeSize CONTRACTS AT MyBuyprice stop
    Sell at MyBuyPrice + MyTargetLong Limit
    ENDIF
    #86585 quote
    Vonasi
    Moderator
    Master

    Now you are confusing me but as long as we are both confused then all is well with the world. 🙂

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

different limit amounts for long and short trades


ProOrder: Automated Strategies & Backtesting

New Reply
Author
author-avatar
aland @aland Participant
Summary

This topic contains 12 replies,
has 5 voices, and was last updated by Vonasi
7 years, 2 months ago.

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