programming moving average & multiple entries
Forums › ProRealTime English forum › ProOrder support › programming moving average & multiple entries
- This topic has 4 replies, 2 voices, and was last updated 5 years ago by Vonasi.
-
-
08/13/2018 at 2:43 PM #78082
Hi, I am a first time user and trying to automate and back test a strategy:
- On the simple creation I have set up on the hour chart a buy and sell strategy. However, I only want to buy when the price is above 20 moving average on the weekly chart and sell when the price is below the 20 moving average on the weekly chart. Is this possible over different time frames, if not how is it done on the same time frame.
- After my initial entry, I would also like to enter the market every 50 points until it reaches my exit point; and then exit all positions. e.g. – If two moving averages haven’t crossed to give me my exit I want to keep adding to my position until they cross.
Can I have some help coding this please?
Thanks, Rob
08/13/2018 at 4:15 PM #78087Number 1 is easy but bear in mind that MTF is currently only under test in demo mode so you can’t trade something like this live just yet:
123456789101112timeframe(weekly, default)c1 = close > average[20](close)c2 = close < average[20](close)timeframe (default)if c1 thenbuy 1 contract at marketendifif c2 thensell at marketendifRun it on an hourly chart and this should just buy at the close of every hourly candle if it is above the weekly[20] average and sell if it is below. This weekly average is updated every hour. If you want to use the start of the week average at a fixed level then change the DEFAULT in line 1 to UPDATEONCLOSE.
You will need to clarify number two a little more. Do you want to buy every time price moves 50 pips in your favour or 50 pips against you?
08/13/2018 at 4:23 PM #780901234567891011121314151617timeframe(weekly, default)c1 = close > average[20](close)c2 = close < average[20](close)timeframe (default)if not onmarket and c1 thenbuy 1 contract at marketbuy 1 contract at close + 50 stopendifif onmarket thenbuy 1 contract at tradeprice + 50 stopendifif c2 or (your other exit conditions) thensell at marketendifThis might be the sort of thing you are looking for in number 2?
08/14/2018 at 12:42 PM #78142Hi Vonasi,
Thanks for your help – the MTF coding isn’t doing what I was looking for.
I already have 4 commands; c1 buy, c2 sell, c3 sellshort, c4 exitshort on the hourly chart. Picture two moving averages e.g. a 10 & 50, each time the 10 crosses over the 50, my strategy buys. Then when the 10 crosses under the 50 it closes the long and opens a short and so on. I want the buy to happen only when the price is trading above a weekly 20 moving average – this limits my exposure in the market and therefore having less entries.
I want it to only execute c1-c2 when the weekly moving average is above 20, and only execute c3-c4 when the weekly moving average is below 20? Can this be done…?
With my number 2 question – I want to buy every time it moves 50 pips against me (haven’t tried this code yet as I need to get weekly moving average working first).
Many thanks,
Rob
08/14/2018 at 2:05 PM #78149123456789101112131415161718192021222324252627timeframe(weekly, default)c1 = close > average[20](close)c2 = close < average[20](close)timeframe (default)c3 = average[10](close) crosses over average[50](close)c4 = average[10](close) crosses under average[50](close)if c1 and c3 thenexitshort at marketbuy 1 contract at marketbuy 1 contract at close - 50 limitendifif longonmarket thenbuy 1 contract at tradeprice - 50 limitendifif c2 and c4 thensell at marketsellshort 1 contract at marketsellshort 1 contract at close + 50 limitendifif shortonmarket thensellshort 1 contract at tradeprice + 50 limitendifNot tested and not sure it is what you want as your strategy description is a little difficult to interpret.
-
AuthorPosts
Find exclusive trading pro-tools on