Two different stop loss exit strategy
Forums › ProRealTime English forum › ProOrder support › Two different stop loss exit strategy
- This topic has 8 replies, 3 voices, and was last updated 5 years ago by jamesgodfrey80.
Tagged: stoploss
-
-
01/07/2019 at 8:18 AM #88079
Hi all,
I want to add another stop loss to my code below but I’m not sure how to do it. I already have a a fixed stop loss based on price (as you can see below). I was hoping you fine people could help to add another stop loss which would only be allowed to work at the END of an interval (e.g 1hour) for a different stop loss price.
So I would end up with :
- stop loss which can exit at anytime throughout the trade for a fixed price e.g 120 points.
- stop loss which can only exit the trade at the end of a time interval if the price hits e.g 70.
Many thank,
James
The code below is just used as an example !
12345678910111213141516171819202122ValidTime = (TIME > 070000) AND (TIME <120000)once TradeTime = 1IF ValidTime THENTradeTime = 1ELSETradeTime = 0ENDIF// Conditions to enter long positionsindicator1 = Average[55](close)c1 = (close[1] CROSSES OVER indicator1[1])IF c1 and tradetime and close [0] > close [1] THENBUY 1 PERPOINT AT MARKETENDIF// Conditions to enter short positionsindicator2 = Average[45](close)c2 = (close[1] CROSSES UNDER indicator2[1])IF c2 and tradetime and close [0] < close [1] THENSELLSHORT 1 PERPOINT AT MARKETENDIF// Stops and targetsSET STOP pLOSS 100SET TARGET pPROFIT 10001/07/2019 at 2:36 PM #88110If you want to exit an order exactly on the first candlestick Close of the hour, you can test it like this:
1234if hour<>hour[1] thensell at marketexitshort at marketendifYou can of course add any other condition with AND
(.. AND if Close>=70)
01/07/2019 at 6:31 PM #88122Thanks Nicolas for the reply. Sorry I didn’t explain myself better originally.
I only want the trade to exit if the price has gone higher or lower than e.g 40 points, at the end of ANY interval be it the 1st or the 12 or 24th. It would only close when an interval has finished and the price is higher than what I stated.
I hope that makes better sense as currently it will exit after the first interval close.
Hopefully you can help my frustrations in this matter.
Many thanks,
James
01/08/2019 at 8:50 AM #88143Since the code is only read one time at Close, any instruction that close an order is already doing it “at the end of any interval”.
If you want to close an order that is higher than 40 points than your order open price, you can do it as follow:
close a short position in loss of 40 points or more123if close-tradeprice(1)>40*pointsize thenexitshort at marketendifOf course this code will run at the end of each candlestick on the timeframe the strategy is currently running on.
01/08/2019 at 9:57 AM #8814901/08/2019 at 10:43 AM #88154So is tradeprice(1) the price of the currently open trade?
I should have said …
So is tradeprice(1) the price at execution of the currently open trade?
01/08/2019 at 11:01 AM #8815601/09/2019 at 12:35 PM #88241A massive thanks again. Much appreciated ! Only.
I’m having differing back test results. As you can see. The chart on the left has only a basic stop loss based on price. The chart on the right has the basic price stop loss and the added code for exiting the position at the end of an interval. As you can see in the results the chart with the added code has a lot of 0 bar trades when back tested with the added stop loss. I’m unsure why. Any help would be greatly appreciated. The code I’m playing around with is on a 1 hour time frame on the Dow.
Thanks again
01/11/2019 at 11:03 AM #88376Hi all,
please can you let me know if the coding is correct in the highlighted area in the attachment to bring short and long trades out. Please don’t take any notice of the coding as this is just an example.
I seem to be having some anomalies from the results above and am wondering if this part of the code is wrong.
thanks,
james
-
AuthorPosts
Find exclusive trading pro-tools on