different limit amounts for long and short trades
Forums › ProRealTime English forum › ProOrder support › different limit amounts for long and short trades
- This topic has 12 replies, 5 voices, and was last updated 5 years ago by Vonasi.
-
-
12/07/2018 at 1:53 AM #86481
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?
StopLimit seems to be overriden by StopLimitShort1234567891011IF ProfitState>=STRATEGYPROFIT AND LongTriggered=0 THENBUY BuyMultiplier*StakeSize CONTRACTS AT MyBuyprice stopSET TARGET PROFIT StopLimitENDIFIF ProfitState>=STRATEGYPROFIT AND ShortTriggered=0 THENSELLSHORT StakeSize CONTRACTS AT MySellprice stopSET TARGET PROFIT StopLimitShortENDIFSET STOP LOSS StopLoss12/07/2018 at 8:57 AM #86489Remove 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.
1 user thanked author for this post.
12/07/2018 at 10:17 AM #8649612/07/2018 at 10:43 AM #864971 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?
12345IF ProfitState>=STRATEGYPROFIT AND LongTriggered=0 THENBUY BuyMultiplier*StakeSize CONTRACTS AT MyBuyprice stopSET TARGET PROFIT StopLimitset stop ploss 100ENDIF12/07/2018 at 11:08 AM #86499aland‘s problem is the TP, not the SL which is the same for all trades.
12/07/2018 at 12:40 PM #86511Thanks 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:
- whether or not I can set a separate value on each one of the orders as I originally planned
- 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.
12/07/2018 at 2:10 PM #8652512345678910111213141516171819202122232425MyTargetLong = 100MyTargetShort = 50LongExit = MyBuyPrice + MyTargetLongShortExit = MySellPrice - MyTargetShortIF ProfitState>=STRATEGYPROFIT AND LongTriggered=0 THENBUY BuyMultiplier*StakeSize CONTRACTS AT MyBuyprice stopSell at MyTargetLong LimitENDIFIF ProfitState>=STRATEGYPROFIT AND ShortTriggered=0 THENSELLSHORT StakeSize CONTRACTS AT MySellprice stopExitShort at MyTargetShort LimitENDIFIf longonmarket thenSell at MyTargetLong LimitendifIf shortonmarket thenExitShort at MyTargetShort LimitendifSET STOP LOSS StopLossNot sure if the above would do what you want – not tested at all.
1 user thanked author for this post.
12/07/2018 at 11:04 PM #86541Thanks 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
12/08/2018 at 2:32 PM #86565Yes 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.
12/08/2018 at 4:25 PM #86579Yes 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)?
1234IF ProfitState>=STRATEGYPROFIT AND LongTriggered=0 THENBUY BuyMultiplier*StakeSize CONTRACTS AT MyBuyprice stopSell at MyTargetLong LimitENDIF12/08/2018 at 4:58 PM #86580I 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.
1 user thanked author for this post.
12/08/2018 at 5:47 PM #8658312/08/2018 at 6:08 PM #86585 -
AuthorPosts
Find exclusive trading pro-tools on