Hi,
Is it possibile to get a system to optimize a variable itself, for example, each month, and then use the new variable?
Thanks!
Hello, yes it is possible (never done it before, but got ideas on this..). But it also mainly depends of the strategy itself and how many variables to optimize and the criteria you’d like to be optimize? gain, drawdown%, sharpe ratio, etc.. ?
Beware that it would involve a lot of work though!
Wow, that would be amazing! 🙂
I have two systems in mind, one I wrote and one i found here:
https://sites.google.com/site/prorealtimecodes/my-backtests/ma-cross-optimised
Acctually a simple MA Cross, works good in backtests on OMX 5 min, probably on DAX as well. (I added stops and target.)
I would like to use the 3 last past month to optimize “x” and “y”, “pl” and “pp”, and use the variable on the upcoming 4 month. The variable with highest gain.
So I would like to use januari, februari and march data, to use on upcoming april.
This optimizing would then happen each month, using 3 last past months.
//-------------------------------------------------------------------------
// Main code : MA Cross Optimized
//-------------------------------------------------------------------------
// ma_cross_optimised
//works really well on 5 min ftse
//variable y, slow ma
//variable x, fast ma
REM Buy
indicator1 = Average[x](close)
indicator2 = Average[y](close)
c1 = (indicator1 crosses over indicator2)
IF c1 THEN
BUY 1 shares AT MARKET nextbaropen
ENDIF
REM Sell
indicator3 = Average[x](close)
indicator4 = Average[y](close)
c2 = (indicator3 CROSSES UNDER indicator4)
IF c2 THEN
SELL AT MARKET nextbaropen
ENDIF
REM Short
indicator5 = Average[x](close)
indicator6 = Average[y](close)
c3 = (indicator5 CROSSES UNDER indicator6)
IF c3 THEN
SELLSHORT 1 shares AT MARKET nextbaropen
ENDIF
REM Exit short
indicator7 = Average[x](close)
indicator8 = Average[y](close)
c4 = (indicator7 CROSSES OVER indicator8)
IF c4 THEN
EXITSHORT AT MARKET nextbaropen
ENDIF
// Stops and targets
SET STOP pLOSS pl
SET TARGET pPROFIT pp
I use about min value: 1 max value: 300 and step: 5, when I optimize X and Y.
The author says: “Shows results of best historical ma crossing for time frame. No guarantee of future success though!”
I think possibile future success could benefit from optimization each month 🙂
Hi, is this post still work in progress?
I currently trade similar 5 minute systems and manually optimise the variables each weekend for the upcoming week, looking back over a 4 week period to keep up with current market conditions. Getting the system to optimise itself would be a great help, especially when you need to optimise more than 1 market/system.
From what Nicolas said, it may be a lot of work, but it would be a really useful timesaver in the long run. You will also be able to play with the period of time looked back for the optimisation and see which period gives the best results over time.
Many thanks for all your help, this is a great website.
Thank you Robin for your compliment.
Optimization of what already happened is like rewrite the whole history. It not guarantee at all, that past behaviour of something would be the same in future. “Simple” optimization of parameters alone is not effective, it needs a lot of others confirmation to reduce the possibilities that optimized result are not curve-fitted. Human always needs everything to be the more perfect and that introduce a bias in our manner to build things, like trading strategies, and that’s where we fail.
Making an auto-optimization module would be quiet interesting for development and coding purpose, but be sure that it would not make anyone a millionaire 🙂
Thank you for your reply and advice Nicolas 🙂
Hi Nicolas,
From what you have said, my current weekly optimisation based on the previous 4 weeks performance, isn’t a good method in the long run. To try not to overfit, if I keep the moving averages the same, I can get consistent results, I just need to adapt the stop loss and the take profit to achieve higher profits each week. I tried using a percentage of ATR for both the stop and take profit, but on a 5 minute chart there is too much noise for this to be effective, and I can’t use multi timeframes (% of daily ATR) to cut through the noise. Is there anything you suggest to keep up with the changing volatility in the market so I optimise the stop and take profit (also the moving averages?)?
Trading, for example GBPUSD, using the basic unoptimised test settings below for the averages and a 1:2+ stop and take profit, this system is profitable each month. Recently I thought I should automate it as it’s a very simple, mechanical system. I do add some other indicators when I day trade manually, but want to simplify it so it’s not over fitted to past performance, as you have suggested.
DEFPARAM CumulateOrders = false
x = time > 080000 and time < 160000
indicator1 = close
indicator2 = TriangularAverage[18](close)
indicator3 = TriangularAverage[45](close)
c1 = (indicator1 crosses over indicator2)
c2 = (indicator2 > indicator3)
IF NOT SHORTONMARKET and x and c1 and c2 THEN
BUY 1 PERPOINT AT MARKET
ENDIF
c3 = (indicator1 crosses under indicator2)
c4 = (indicator2 < indicator3)
IF NOT LONGONMARKET and x and c3 AND c4 THEN
SELLSHORT 1 PERPOINT AT MARKET
ENDIF
SET STOP pLOSS 30
SET TARGET pPROFIT 60
Do you have any suggestions as to how I can improve this system? In backtesting and live forward auto-trading, I have found optimising to be more successful, but I could have just been lucky. If you can help me find flexible and optimised stop and take profit solutions, I’ll be eternally grateful 🙂
Thanks for all your help,
Robin.
Hi Robin, Do you mean for example, an stop loss or target profit changing position when price reach a determinated level?
If you want breakeven profit every time the markets gives you the chance, should be something like this:
IF LongOnMarket AND Close>PositionPrice+Spread THEN
BreakEven = PositionPrice+myProfit
ENDIF
SELL AT BreakEven STOP
If you want this stop based only on ATR indicator, can’t help you more ATM.
Adolfo.
Hi Adolfo,
Thanks for your post. I’m looking for stop and target systems that evolve with market volatility until entry, and are then fixed for the duration of the trade. I was thinking of something based on ATR, but I’m sure there are other measures of volatility that could be used. Using ATR would be fine, but there is too much noise on a lower timeframe to get something consistently working.
Cheers,
Robin.
@Robin
If you can keep the same moving average values and keep consistent good results, then keep your strategy the same and don’t even try to make it much better with optimization. I’m not a guru, this is what I think, so make your own decision about it 🙂
What your are pointing about the ATR takeprofit and stoploss is much clever, it is commonly accepted that ATR tp and sl computed on the fly are much efficient because they are adapted to the current market behaviour.
A % of the daily ATR is possible to calculate on the smaller timeframe. In ProBuilder, it is possible to get the daily OHLC with the instructions : DOPEN, DHIGH, DLOW and DCLOSE.
Hi Nicolas,
Thanks for your help. I’ll try using a % of the daily ATR for stop and TP. Just gotta figure out how to write it 🙂
Robin.
Directly from Wikipedia :
First, you’ll have the calculate the true range with :
The true range is the largest of the:
- Most recent period’s high minus the most recent period’s low
- Absolute value of the most recent period’s high minus the previous close
- Absolute value of the most recent period’s low minus the previous close
Then make an exponential average of the result over n period.
Many thanks. I’m new to coding so i’m trying to work out how to represent it in PRT code, lol 🙂
I’m trying to write the Daily True Range as an indicator. I wrote the code below but although it accepts the code without error, nothing appears in the indicator screen. I’m new to coding so not sure where i’m going wrong:
a=DHigh(close)
b=DClose(1)
c=DLow(close)
x=max(a,b)
y=min(b,c)
DailyTrueRange = (x-y)
RETURN DailyTrueRange COLOURED(0,255,0) AS "DailyTrueRange"
I then need to write the code to create the Daily Average True Range indicator so I can call it to my system and use a % of it. Would the code for DATR be as below? I’m not sure how I’d combine the DTR and the Wilder average (or exponential average) to create the DATR.
DATR=WilderAverage[n](DTR[n](close))
Many thanks for your help,
Robin.