Long bar Mean reverting code help
Forums › ProRealTime English forum › ProOrder support › Long bar Mean reverting code help
- This topic has 5 replies, 2 voices, and was last updated 5 years ago by Stratus6.
-
-
10/10/2018 at 12:19 PM #82452
Hi All,
I would be very grateful for any help with this small sell side code.
The idea is for shorter time frames which I use for day trading but struggling to automate it.
Principles as below. Sell side only in this case.
- Two longer than average bars become the new ‘range’
- The middle of this range is the ‘mean’ for buying back.
- Once the range is set every new bar triggers a sell unless its low crosses below the mean
- At the ‘mean’ all shorts are bought back and the trade ends
Questions are one
- Is this code ok as I cannot backtest it because I dont know how to (2)
- How do I set a MAX position
Long bars marker123456789101112131415161718192021222324252627282930313233DEFPARAM CumulateOrders = True //Once Upper = 1Once Lower = 1c1 = abs(High[1] - Low[1]) > 1.5*averagetruerange[7]c2 = abs(High[0] - Low[0]) > 0.8*abs(High[1] - Low[1])c3 = abs(High[0] - Low[0]) < abs(High[1] - Low[1])c4 = High[1] > High[0]If c1 and c2 and c3 and c4 thenUpper = High[1]Lower = Lowest[2](low)Rangebar=1EndifIf Rangebar=1 and Low > (Upper+Lower)/2 thensellshort 0.1 lots at Upper + averagetruerange[7] limitEndifIf Low crosses under (Upper+Lower)/2 thenRangebar=0Exitshort at (Upper+Lower)/2 limitendifSet stop $loss 500
Many thanks in advance
10/22/2018 at 10:50 PM #8336810/23/2018 at 7:52 AM #83374Your code looks OK.
To back test just press the ‘ProBacktest my system’ button.
If by MAX position you mean that you want to set a limit to the number of positions opened then you can do this with a condition based on COUNTOFPOSITION or by adding 1 to a variable IF ONMARKET and then resetting that variable IF NOT ONMARKET and then use that variable quantity in your conditions as to whether to put a sellshort order on the market.
1 user thanked author for this post.
10/23/2018 at 4:26 PM #83400Hi Vonasi,
Many thanks for your reply.
I have tried the back test but the problem I have is the position becomes to large.
I have 2 questions
- Is there a way to code maximum position size ie. Sell every bar until position reaches 10 lots.
- Also If I want to set a buy level at say the low[1] before the first lots is sold, how would I code this, as currently each new sell creates a new buy back level!
Once again this beginner really appreciates your time!
10/23/2018 at 8:45 PM #83413123If Rangebar=1 and Low > (Upper+Lower)/2 and countofposition < 10 thensellshort 0.1 lots at Upper + averagetruerange[7] limitEndifI’m not sure I fully understand question 2. Maybe this works as it fixes the levels until you have no trades on the market:1234If not onmarket and c1 and c2 and c3 and c4 thenUpper = High[1]Lower = Lowest[2](low)Rangebar=11 user thanked author for this post.
10/28/2018 at 2:18 PM #83645 -
AuthorPosts
Find exclusive trading pro-tools on