Defining exit strategy based on profit target
Forums › ProRealTime English forum › ProOrder support › Defining exit strategy based on profit target
- This topic has 5 replies, 2 voices, and was last updated 5 years ago by
AleksLi.
-
-
01/04/2020 at 10:59 PM #115904
Hi guys,
I’m trying to define the exit parameters of my strategy to be the following:
Exit on the next open if we’ve achieved a close 0.3% higher than the trade bars’ close.
I’m having trouble with this because a simple take profit won’t do. I’m trying to exit on the next bar once we’ve achieved that 0.3% profit target. Here’s my autogenerated code:
12345678910111213141516171819// Definition of code parametersDEFPARAM CumulateOrders = False // Cumulating positions deactivated// Conditions to enter long positionsindicator1 = MoneyFlowIndex[4]c1 = (indicator1 = 0)IF c1 THENBUY 1 SHARES AT MARKETENDIF// Conditions to exit long positionspercent = close / close[-1] - 1c2 = (percent >= 0.3)IF c2 THENSELL AT MARKET TOMORROWOPENENDIFI’ve trying looking in the documentation, but I’ve only been able to define the percent parameter, not the “exit on the next bar once we’ve achieved 0.3% profit” part.
Let me know what you think,
Aleks
01/04/2020 at 11:11 PM #11590501/05/2020 at 9:55 AM #115911AleksLi – Welcome to the forums.
Please always use the ‘Insert PRT Code’ button when posting code to make it more readable for others. I have tidied up your posts 🙂
Glad you fixed your own problem however there is an issue in your code.
You cannot use [-1 ] after CLOSE as it must be a positive integer value. CLOSE[1] is the previous bars close. If you want to compare current price to the price your trade opened at then you need to use TRADEPRICE or POSITIONPRICE. I usually use the latter to avoid any confusion as TRADEPRICE can also be the last price you sold at.
Also it is simpler just to do the exit price calculation as part of the condition.
1234567// Conditions to exit long positionsc2 = close >= positionprice * 1.003IF c2 THENSELL AT MARKET TOMORROWOPENENDIF1 user thanked author for this post.
01/05/2020 at 12:52 PM #115921Thank you very much for your reply Vonasi!
One issue I have though- for some reason after inserting the positionprice variable, the backtest doesn’t generate any positions? I’ve tried removing selling rules altogether and it generated a buy signal.
For reference, here’s my latest code:
1234567891011121314151617181920212223242526272829// Definition of code parametersDEFPARAM CumulateOrders = false // Cumulating positions deactivated// Prevents the system from creating new orders to enter the market or increase position size before the specified timenoEntryBeforeTime = 143000timeEnterBefore = time >= noEntryBeforeTime// Prevents the system from placing new orders to enter the market or increase position size after the specified timenoEntryAfterTime = 210000timeEnterAfter = time < noEntryAfterTime// Prevents the system from placing new orders on specified days of the weekdaysForbiddenEntry = OpenDayOfWeek = 6 OR OpenDayOfWeek = 0// Conditions to enter long positionsindicator1 = MoneyFlowIndex[4]c1 = (indicator1 = 0)IF c1 THENBUY 1 SHARES AT MARKETENDIF// Conditions to exit long positionsc2 = close >= positionprice * 1.003IF c2 THENSELL AT MARKET TOMORROWOPENENDIFI’ve tried fiddling around with brackets, and that hasn’t helped. I’ve also used other rules to exit positions (like my first attempt) and that generated backtest results.
01/05/2020 at 2:01 PM #115922Sorry – I was coding without thinking too hard about it!
The problem is that your c2 condition is true when you are not on the market because POSITIONPRICE = 0 and so this cancels out any buy orders. The addition of an ONMARKET condition should solve the problem.
Try this (not tested):
12345678910111213141516171819202122232425262728defparam cumulateorders = false// Prevents the system from creating new orders to enter the market or increase position size before the specified timenoEntryBeforeTime = 143000timeEnterBefore = time >= noEntryBeforeTime// Prevents the system from placing new orders to enter the market or increase position size after the specified timenoEntryAfterTime = 210000timeEnterAfter = time < noEntryAfterTime// Prevents the system from placing new orders on specified days of the weekdaysForbiddenEntry = OpenDayOfWeek = 6 OR OpenDayOfWeek = 0// Conditions to enter long positionsindicator1 = MoneyFlowIndex[4]c1 = (indicator1 = 0)IF c1 THENBUY 1 SHARES AT MARKETENDIF// Conditions to exit long positionsc2 = close >= positionprice * 1.003IF onmarket and c2 THENSELL AT MARKET TOMORROWOPENENDIF01/05/2020 at 2:55 PM #115929 -
AuthorPosts
Find exclusive trading pro-tools on