RE: [amibroker] Re: Backtest multiple systems across multiple timeframes
Thanks Tomasz, It s gonna take me some time to understand your idea. I'm not very satisfied with the overall way AB is handling this kind of topic.. anyways thanks for the assistance. could you explain a little more on how you put the #include statements? How many systems did you plug together? How many different timeframes? Did optimization for capital allocation work? (optimize percentrisked) Greets, Matthias From: amibroker@yahoogroups.com [mailto:amibro...@yahoogroups.com] On Behalf Of tf28373 Sent: Donnerstag, 9. September 2010 11:01 To: amibroker@yahoogroups.com Subject: [amibroker] Re: Backtest multiple systems across multiple timeframes Hi Matthias Some time ago I was working on the same problem. The solution I have come across is as following: 1) use #include command in the main code 2) inside the #include function do like this (of course all is just an example which will need adjustment to your needs): a) function(parameter1, parameter2,...,timeframe,...,parameterN) { switch (timeframe) { case 60: TimeFrameSet(inHourly); break; case 15: TimeFrameSet(in15Minute); break; case 5: TimeFrameSet(in5Minute); break; default: break; } //here comes the calculations of channels, threshold, averages, oscillator, etc, everything you need to obtain signals' conditions TimeFrameRestore();//AGAIN - it is just an example, by the way - sorry for illegable layout switch (timeframe) { case 60: channel1=TimeFrameExpand(chan1,inHourly,expandLast); channel2=TimeFrameExpand(chan2,inHourly,expandLast); oscillator1=TimeFrameExpand(osc1,inHourly,expandLast); break; case 15: //the logic of code the same as above... break; case 5: //as above break; default: channel1=chan; channel2=chan2; oscillator1=osc2; break; } //here comes the buy/sell/cover/short/stop conditions and position sizing, etc } Although using #include results in slower code exection, it is a kind of idea to handle different timeframes system backtest, so I hope that even if it does not help directly, it will at least inspire you to find your own solution. Regards Tomasz --- In amibroker@yahoogroups.com mailto:amibroker%40yahoogroups.com , Matthias meridian...@... wrote: Hi, thanks to the contribution of Ed Pottasch, supported by Bruce, I was able to dig a little deeper into Amibroker coding. Everybody who is interested in applying multiple systems on the same underlying simultaneously should look here, great piece of work: http://finance.groups.yahoo.com/group/AmiBroker-at/message/5349 Thanks Ed, thanks Bruce. Unfortunately, I stumbled across a couple of questions when backtesting multiple systems across different timeframes, hope someone can help, sorry for the post being a bit lenghty. Both systems are traded on the same underlying, in order to make things easier for AB (Which is a bit strange) I used the same set of data, just renamed it. both systems operate on the same timeframe, say 15mins. Question 1: I use the same variable percentrisked for both systems. Wanted to optimize for percent risked (only!, this is NOT shown in the example below), so to say capital allocated to each system for the smoothest equity curve, AB keeps crashing... Can I use the same variable name in each sub-section or are there limits? should I dedicated percentrisked1 to system1 and percentrisked2 to system2 only? I am not a programmer, but for my understanding, both variables are local, so AB should not be crashing...? Is using Setoption in this context appropriate or would it result in wrong values? if(Name()==DAX_CFD_day1) { percentrisked=2.0; factor=Optimize(ATR-Factor,8.5,3,12,0.5); number=(percentrisked)/(ATR(14)*factor)*20; SetPositionSize(number, spsPercentOfEquity); SetOption(commissionmode,3); SetOption(Commissionamount,1.2); SetOption(AllowSameBarExit,True); SetOption(ActivateStopsImmediately,True); .systemlogic here } if(Name()==DAX_CFD_day) { percentrisked=Optimize(Bolli,0.6,0.5,1,0.1); sl=2;//Optimize(sl,2,2,2.5,0.5);//good:6 number=(percentrisked/(Ref(ATR(14),-1)*sl))*20; SetPositionSize(number, spsPercentOfEquity); SetOption(commissionmode,3); SetOption(Commissionamount,1.2); SetOption(AllowSameBarExit,True); SetOption(ActivateStopsImmediately,True); SetOption(FuturesMode,True); SetTradeDelays(1,1,1,1); Equity(1); ... systemlogic here } Question 2: Both systems above use 15min timeframe. Another system is using 1hr timeframe and is trading FX. I was not able to re-write the logic so that I could backtest the 3 systems with AA settings 15min timeframe. Any ideas? I do have about 8 systems, lowest timeframe is 5min, highest timeframe 4hrs. That would require a lot of re-writing... Am I alone with my I have too many-systems Problem or am I missing somehting? original logic in 1hr timeframe: percentrisked=0.007; sl=4.5; tp=2.5; number=((percentrisked)/(Ref(ATR(14),-0)*sl)); SetPositionSize(number,spsPercentOfEquity);
RE: [amibroker] Backtest multiple systems across multiple timeframes
Hi Ed, Good to hear from you again. Basetime interval of the databse is 5min (I don't use ticks, it s downloaded data from my broker, not IB), but both systems are 15min timeframe, should be easy to handle. Win XP, SP3, 4GB RAM..32bit OS, I could create another database, true, but I wanted to backtest the systems using One/Single - Equitypool logic, all taking their money from ONE ACCOUNT as done in my RT Trading. Purpose of this is to find out how much money every sub-system can trade to result in the smoothest equity curve, so no extensive search or optimization is necessary as the systems are already profitable. Having 8 systems, it would require 8-optimization variables, that's true. But because the systems operate on multiple timeframes, I'm not sure how to re-write the logic. values/results always differ by more than 10%. or AB crashes when optimizing 'percentrisked'. From: amibroker@yahoogroups.com [mailto:amibro...@yahoogroups.com] On Behalf Of Edward Pottasch Sent: Mittwoch, 8. September 2010 22:03 To: amibroker@yahoogroups.com Subject: Re: [amibroker] Backtest multiple systems across multiple timeframes Matthias, will have a look at your questions in more detail tomorrow. But that crashing may be caused due to memory problems of your computer rather than an error in your code. So if your systems are to be used in the 5-min timeframe try using a database that has its base time interval set to 5 minutes rather than ticks or 1-minute. So, if you have a data provider then simply create a new database using for the base time interval 5 minutes that solved a lot of my crash problems, regards, Ed From: Matthias mailto:meridian...@gmx.de Sent: Wednesday, September 08, 2010 8:55 PM To: amibroker@yahoogroups.com Subject: [amibroker] Backtest multiple systems across multiple timeframes Hi, thanks to the contribution of Ed Pottasch, supported by Bruce, I was able to dig a little deeper into Amibroker coding. Everybody who is interested in applying multiple systems on the same underlying simultaneously should look here, great piece of work: http://finance.groups.yahoo.com/group/AmiBroker-at/message/5349 Thanks Ed, thanks Bruce. Unfortunately, I stumbled across a couple of questions when backtesting multiple systems across different timeframes, hope someone can help, sorry for the post being a bit lenghty. Both systems are traded on the same underlying, in order to make things easier for AB (Which is a bit strange) I used the same set of data, just renamed it. both systems operate on the same timeframe, say 15mins. Question 1: I use the same variable percentrisked for both systems. Wanted to optimize for percent risked (only!, this is NOT shown in the example below), so to say capital allocated to each system for the smoothest equity curve, AB keeps crashing... Can I use the same variable name in each sub-section or are there limits? should I dedicated percentrisked1 to system1 and percentrisked2 to system2 only? I am not a programmer, but for my understanding, both variables are local, so AB should not be crashing...? Is using Setoption in this context appropriate or would it result in wrong values? if(Name()==DAX_CFD_day1) { percentrisked=2.0; factor=Optimize(ATR-Factor,8.5,3,12,0.5); number=(percentrisked)/(ATR(14)*factor)*20; SetPositionSize(number, spsPercentOfEquity); SetOption(commissionmode,3); SetOption(Commissionamount,1.2); SetOption(AllowSameBarExit,True); SetOption(ActivateStopsImmediately,True); .systemlogic here } if(Name()==DAX_CFD_day) { percentrisked=Optimize(Bolli,0.6,0.5,1,0.1); sl=2;//Optimize(sl,2,2,2.5,0.5);//good:6 number=(percentrisked/(Ref(ATR(14),-1)*sl))*20; SetPositionSize(number, spsPercentOfEquity); SetOption(commissionmode,3); SetOption(Commissionamount,1.2); SetOption(AllowSameBarExit,True); SetOption(ActivateStopsImmediately,True); SetOption(FuturesMode,True); SetTradeDelays(1,1,1,1); Equity(1); ... systemlogic here } Question 2: Both systems above use 15min timeframe. Another system is using 1hr timeframe and is trading FX. I was not able to re-write the logic so that I could backtest the 3 systems with AA settings 15min timeframe. Any ideas? I do have about 8 systems, lowest timeframe is 5min, highest timeframe 4hrs. That would require a lot of re-writing... Am I alone with my I have too many-systems Problem or am I missing somehting? original logic in 1hr timeframe: percentrisked=0.007; sl=4.5; tp=2.5; number=((percentrisked)/(Ref(ATR(14),-0)*sl)); SetPositionSize(number,spsPercentOfEquity); SetOption(maxopenpositions,1); CCIperiod=Optimize(CCI,36,34,40,1); CCIthreshold=optimize(CCIthres,89,88,96,1); MAperiod=Optimize(maperiod,7,6,8,1); MA1= MA(C,MAperiod); MA2= MA(Ref(C,-2),MAperiod); CCIshort=CCI(CCIperiod)=ccithreshold; CCIbuy= CCI(CCIperiod)=-CCIthreshold; Buyok=Ref(CCIbuy,-1) AND Cross(MA1,MA2); Sellok=CCIshort; Shortok=Ref(CCIshort,-1) AND Cross(MA2,MA1); Coverok=CCIbuy;
RE: [amibroker] Re: Optimizer target with genetic optimization
Hi, Mike is right, just change the target in the settings/walk-forward-tab. Anyways, you can design your custom metric, too, this is a very valuable feature, just google amibroker add custom metric. For me, I played along with the max. k-ratio and min. ulcer-index. My daytrading systems on futures and FX became much more stable in out-of-sample tests when optimizing for k-ratio or Ulcer-Index instead of CAR/MDD, especially when keeping the in-sample-period very small, say 3-6months, the out of sample to about 3-6months, too. If you're playing with this feature, I d appreciate it if you could write a little bit about your experience, like what kind of system you trade, what underlying and of course, your optimization target. Thanks, Matthias From: amibroker@yahoogroups.com [mailto:amibro...@yahoogroups.com] On Behalf Of radmobile_radmobile Sent: Montag, 23. August 2010 21:48 To: amibroker@yahoogroups.com Subject: [amibroker] Re: Optimizer target with genetic optimization This can be achieved through the custom backtester interface. See: http://www.amibroker.com/kb/2008/05/19/historical-portfolio-backtest-metrics / -RM --- In amibroker@yahoogroups.com mailto:amibroker%40yahoogroups.com , DougOriard d...@... wrote: When running one of the genetic optimizers, like cmae or trib, is it possible to change the optimization target from CAR/MDD to just % profit, or other target value? CAR/MDD is too heavily biased on minimizing MDD. It would be better to optimize for CAR*(100 - MDD), where MDD is taken as absolute value. Is there a way to do this?
RE: [amibroker] Re: How to configure CAME to look for a Optimization target MINIMUM
Hi, Worked for me! Thanks a lot. Taking my example, I typed Ulcer-Index-II and it did the run. I didn't understand why it would not show up in the drop-down menu. Thanks, Matthias From: amibroker@yahoogroups.com [mailto:amibro...@yahoogroups.com] On Behalf Of Mike Sent: Montag, 9. August 2010 08:16 To: amibroker@yahoogroups.com Subject: [amibroker] Re: How to configure CAME to look for a Optimization target MINIMUM The drop list from which to choose the metric for optimization is an editable field. Just type in the name (case sensitive) of your metric instead of choosing from the default list of metrics. Mike --- In amibroker@yahoogroups.com mailto:amibroker%40yahoogroups.com , Matthias meridian...@... wrote: Hi, I tried this one out, but when performing Walk-Forward Analysis, I cannot choose my custom metric as objective function. Effectively, I'd like to MINIMIZE Ulcer-Index when performing WFA. Portfolio: enable CBT is ticked, path is specified. Metric appears in the report, and the column is added, but cannot be chosen from Walk-Forward Optimization Target. SetCustomBacktestProc(); if( Status(action) == actionPortfolio ) { bo = GetBacktesterObject(); bo.Backtest(); // run default backtest procedure st = bo.GetPerformanceStats(0); // get stats for all trades Ulcer = -1*st.GetValue(UlcerIndex); bo.AddCustomMetric( Ulcer-Index-II,Ulcer ); } Also checked the links where it states: The Optimization target field defines the optimization raport COLUMN NAME that will be used for sorting results and finding the BEST one. Any built-in column can be used (as appears in the optimization output), or you can use any custom metric that you define in custom backtester. The default is CAR/MDD, you can however select any other built-in metric from the combo. You can also TYPE-IN any custom metric that you have added via custom backtester interface. Any suggestions? Matthias --- In amibroker@yahoogroups.com mailto:amibroker%40yahoogroups.com , Mike sfclimbers@ wrote: Add your own custom metric to be used as the optimization target. Simply calculate your metric as the negative of your intended metric. The result will be that originally large values become smaller (i.e. more negative) and originally small values become larger (i.e. less negative). Refer to custom metrics for more detail: http://www.amibroker.com/guide/a_custommetrics.html Set custom target on WFA settings (applies to regular optimization too, not just walk forward): http://www.amibroker.com/kb/2008/02/12/getting-started-with-automatic-walk-f orward-optimization/ Mike --- In amibroker@yahoogroups.com mailto:amibroker%40yahoogroups.com , elizabeth19852002 elizabeth.kennedy@ wrote: Hello all, I would appreciate if someone can please tell me how to configure optimizations like CAME so that it looks for a MINIMUM (as opposed to a Maximum) of an optimization target (such as user defined objective function). Just by adding OptimizerSetEngine(cmae); in AFL and setting the Optimization target in the Walkforward tab does not tell it to look for a MINIMUM or MAXIMUM of the optimization target during optimization ??? Thanking you Liz
RE: [amibroker] Trading Systems, Position Sizing and Monte Carlo Analysis
Hi Lionel, With “this book”, I suppose you mean this one: http://www.amazon.com/Trading-Systems-Optimisation-Portfolio-Construction/dp/1905641796/ref=sr_1_1?ie=UTF8 http://www.amazon.com/Trading-Systems-Optimisation-Portfolio-Construction/dp/1905641796/ref=sr_1_1?ie=UTF8s=booksqid=1280174971sr=8-1 s=booksqid=1280174971sr=8-1 I was talking to Mike and he said that Tharp uses MC for position sizing in his book “the definitive guide to position sizing”. That’s why Mr. Tharp “entered the discussion”. I just wanted to add a critical review on his new book “supertrader”. So, I guess I don’t understand your question. The books cannot really be compared. Matthias From: amibroker@yahoogroups.com [mailto:amibro...@yahoogroups.com] On Behalf Of Lionel Issen Sent: Donnerstag, 29. Juli 2010 03:29 To: amibroker@yahoogroups.com Subject: RE: [amibroker] Trading Systems, Position Sizing and Monte Carlo Analysis Thanks. How does this book compare with Van Tharp’s book? http://www.amazon.com/Trading-Systems-Optimisation-Portfolio-Construction/dp/1905641796/ref=sr_1_1?ie=UTF8 http://www.amazon.com/Trading-Systems-Optimisation-Portfolio-Construction/dp/1905641796/ref=sr_1_1?ie=UTF8s=booksqid=1280174971sr=8-1 s=booksqid=1280174971sr=8-1
RE: [amibroker] Trading Systems, Position Sizing and Monte Carlo Analysis
MC = Monte Carlo Cheers, Matthias From: amibroker@yahoogroups.com [mailto:amibro...@yahoogroups.com] On Behalf Of Lionel Issen Sent: Freitag, 30. Juli 2010 02:02 To: amibroker@yahoogroups.com Subject: RE: [amibroker] Trading Systems, Position Sizing and Monte Carlo Analysis Hi Matthias: Thanks for this information. Excuse my ignorance, but what does MC mean? Lionel From: amibroker@yahoogroups.com [mailto:amibro...@yahoogroups.com] On Behalf Of Matthias K. Sent: Thursday, July 29, 2010 10:49 AM To: amibroker@yahoogroups.com Subject: RE: [amibroker] Trading Systems, Position Sizing and Monte Carlo Analysis Hi Lionel, With “this book”, I suppose you mean this one: http://www.amazon.com/Trading-Systems-Optimisation-Portfolio-Construction/dp/1905641796/ref=sr_1_1?ie=UTF8 http://www.amazon.com/Trading-Systems-Optimisation-Portfolio-Construction/dp/1905641796/ref=sr_1_1?ie=UTF8s=booksqid=1280174971sr=8-1 s=booksqid=1280174971sr=8-1 I was talking to Mike and he said that Tharp uses MC for position sizing in his book “the definitive guide to position sizing”. That’s why Mr. Tharp “entered the discussion”. I just wanted to add a critical review on his new book “supertrader”. So, I guess I don’t understand your question. The books cannot really be compared. Matthias From: amibroker@yahoogroups.com [mailto:amibro...@yahoogroups.com] On Behalf Of Lionel Issen Sent: Donnerstag, 29. Juli 2010 03:29 To: amibroker@yahoogroups.com Subject: RE: [amibroker] Trading Systems, Position Sizing and Monte Carlo Analysis Thanks. How does this book compare with Van Tharp’s book? http://www.amazon.com/Trading-Systems-Optimisation-Portfolio-Construction/dp/1905641796/ref=sr_1_1?ie=UTF8 http://www.amazon.com/Trading-Systems-Optimisation-Portfolio-Construction/dp/1905641796/ref=sr_1_1?ie=UTF8s=booksqid=1280174971sr=8-1 s=booksqid=1280174971sr=8-1
RE: [amibroker] Multiple Time Frames
Hi, There's lots of mistakes in this code: 1. You're missing timeframeexpand 2. IIF cannot be use like this, I wonder if it returned you a result at all Ok. I'm not sure about your Stochastic-Thingie, but you should be able to customize my example to your needs. Furthermore check the tutorial. http://www.amibroker.com/guide/h_timeframe.html 5min-Chart, your smallest interval, could be anything, 15min, 1hr, I take 5min for now. I wanna buy if the Close (5min) is greater than EMA(C,200) indaily and only before 12 o'clock in the morning. TimeFrameSet(inDaily); EMA1=EMA(C,200); TimeFrameRestore(); Buy=IIf(CTimeFrameExpand(EMA1,inDaily) AND TimeNum()=12,1,0); Sell=0; Anyways, you don't really need IIF here. Works like this, too TimeFrameSet(inDaily); EMA1=EMA(C,200); TimeFrameRestore(); Buy=CTimeFrameExpand(EMA1,inDaily) AND TimeNum()=12; Sell=0; Matthias From: amibroker@yahoogroups.com [mailto:amibro...@yahoogroups.com] On Behalf Of Jonathan Lee Sent: Dienstag, 27. Juli 2010 19:47 To: amibroker@yahoogroups.com Subject: [amibroker] Multiple Time Frames Hi amibroker experts, I'm a little stuck with multiple time frames - and was hoping someone could assist. It's probably a straight forward solution as I'm pretty much a newbie at this. I've got a basic oscillator (similar to stochastics) in which I have determined that 30 is oversold, 70 is overbought and 50 at mid range. i'm using the higher time frame as a condition, so looking at the hourly chart, I only want a buy signal to be actioned if the daily chart (%K and %D) is less than the mid range (50). I put all my daily parameters between: TimeFrameSet (inDaily) and TimeFrameRestore (); And my buy/sell instruction (in the hourly setting) is as follows: IIf((DailySK=DailyMid AND DailySD=DailyMid),Buy=SK=Lower AND SD=Lower AND Cross(SK,SD),0); IIf((DailySK=DailyMid AND DailySD=DailyMid),Sell=SK=Upper AND SD=Upper AND Cross(SD,SK),0); Short=Cover=0; For some reason I am getting results which ignore the higher time frame? Much appreciated. Jonathan
RE: [amibroker] Optimize Time Parameters
Hi, I'm using this. It's pretty much self-explanatory. Works based on hours. Depending on which data you use, the timestamp might be different. So to say timestart might be 055900 instead of 06. Watch out for Fridays, too, if you don't wanna hold the trader over the weekend. timestart=06;//Optimize(timestart,06,00,23,1); window=08;//Optimize(windowlength,07,04,10,1); Check=timestart+window; timeok=TimeNum()=timestart AND TimeNum()=Check; Greetings, Matthias From: amibroker@yahoogroups.com [mailto:amibro...@yahoogroups.com] On Behalf Of pcmoxon Sent: Mittwoch, 28. Juli 2010 17:11 To: amibroker@yahoogroups.com Subject: [amibroker] Optimize Time Parameters Hi, I am working on an intraday system and want to optimize the trading hours the system should trade. I have a Start Time parameter (using ParamTime) and I would like to optimize the system using this field. Does anyone know how to optimize using Time fields? Any examples you know of would really help. Kind Regards, Pete
RE: [amibroker] Re: Trading Systems, Position Sizing and Monte Carlo Analysis
Hi, Thanks Mike for your explanation and the link. The definite guide to position sizing is the only book I'm missing in my van Tharp collection, looks like just found my next bday present, hehee. Just to make this complete, the new Supertrader book is pretty lame in my opinion, nothing really new, just a little bit of everything from Tharp. I shall look up on Vince, thanks for the info. Following up with the previous posts we need to look outside the samples to get the full pictures I'd like to hear a little more on that, too, if you're willing to share. Thanks, Matthias From: amibroker@yahoogroups.com [mailto:amibro...@yahoogroups.com] On Behalf Of mkecera Sent: Mittwoch, 28. Juli 2010 17:48 To: amibroker@yahoogroups.com Subject: [amibroker] Re: Trading Systems, Position Sizing and Monte Carlo Analysis Yes. That's what I was trying to point out. I would be interested to hear more about we need to look outside the samples to get the full pictures if you would like to share. Best regards, MK --- In amibroker@yahoogroups.com mailto:amibroker%40yahoogroups.com , paultsho paul.t...@... wrote: I think the emphasis of MK's comments is about the use (or misuse) of the phase monte carlo simulation to equate to random rearrangement of trades and its possible ramification. Monte Carlo simulation is based on ARTIFICALLY simulating data points by recreating the a chance process, running it many times, and directly observing the results - http://www3.wabash.edu/econometrics/EconometricsBook/chap9.htm bootstrap is resampling repeatedly and randomly from an original, initial sample - http://www3.wabash.edu/econometrics/EconometricsBook/chap23.htm. While leaving the discussion on assumptions aside (I'll say more when I get a bit more time). One of the problems of equating bootstrapping with monte carlo is that incorrect conclusions are also drawn about the methodology. I do not believe resampling of trades gives us a reliable picture about the behaviour of a trading system. We should all be familiar with rearranging the deck chairs on the Titanic does no good at all. Similarly, I think we need to look outside the samples to get the full pictures.
RE: [amibroker] Re: Trading Systems, Position Sizing and Monte Carlo Analysis
Hi, Mike, you suggested Ralph Vince - The Handbook of Portfolio Mathematics: Formulas for Optimal Allocation Leverage (Wiley Trading 2007) - The Leverage Space Trading Model: Reconciling Portfolio Management Strategies and Economic Theory (Wiley Trading 2009) Did you read them? Could you give me a brief summary, something a little bit more critical than Amazon’s praises to the sky? I like Vince’s work, guess I shall read them, I just don’t like the term economic theory. But before this topic falls asleep: If I got it right: This one is about trading one system on a market-portfolio, than figuring out some statistics etc. What I’d like to read up on is something like a TRADING SYSTEM PORTFOLIO on 1 market, so to say not pick the markets scientifically, but the systems. Additionally, my comments on MC are incomplete because I didn’t dig very deep into the material. I am aware of the methods you described below, but still I don’t really believe it’s useful. What’s the use of knowing average performance, best performance, worst performance, etc.? If you have that info, do you base something on it, say position sizing, emergency system stop? My walkforward oos is something that I do trust more, guess that’s my opinion. From: amibroker@yahoogroups.com [mailto:amibro...@yahoogroups.com] On Behalf Of Mike Sent: Dienstag, 27. Juli 2010 00:02 To: amibroker@yahoogroups.com Subject: [amibroker] Re: Trading Systems, Position Sizing and Monte Carlo Analysis Books that you might be interested in: Ralph Vince - The Handbook of Portfolio Mathematics: Formulas for Optimal Allocation Leverage (Wiley Trading 2007) - The Leverage Space Trading Model: Reconciling Portfolio Management Strategies and Economic Theory (Wiley Trading 2009) Your comments on Monte Carlo are incomplete. Monte Carlo is not just changing the the order of trades. Monte Carlo can also be used to treat existing trades as a pool of trades from which a greater number of trades may be sampled in order to project a longer term equity curve. For example, if you have a collection of trades that you feel adequately represent the range of trades that your system will generate, you can randomly draw some number of trades (with replacement) from the pool to generate thousands of equity curves (e.g. draw 100 trades from a pool of 30). You may then analyze the resulting equity curves to get such information as average performance, best performance, worst performance, etc. Mike --- In amibroker@yahoogroups.com mailto:amibroker%40yahoogroups.com , Matthias K. meridian...@... wrote: Hi, Indeed this is a very interesting topic. Many thanks go to Howard Bandy, it is literally a must read when working with Amibroker. I’m curiously waiting for the new one. Regarding System Design and Position Sizing: Well, I believe that there are a lot of books out there, but different authors really do mix up terminology, so this is how I interpret it: Position sizing Tells you how much, e.g. how many contracts or shares one should buy, Howard just mentioned 2 algos, fixed fraction and fixed ration. Ralph Vince’s book is a must read on this, however, it’s not quite easy going. Furthermore, there’s martingale and antimartingale, whereas martingale pretty much means: the more you lose, the more you bet. I believe it’s a sure-fire way to the poorhouse, that’s why I use ALWAYS anti-martingale. No black swans welcome in my trading. Risk management Obivously, there’s a clear overlap with position sizing, but still I believe it’s meant to be a little different. Say you have a system with a plugged in position sizing algo. You backtest it and you’ll have an estimate of the drawdown. Obviously, you will want to adjust position size so that you can stomach the drawdown. But as a safety measure, you might plug in another strategy. It might be an equity MA-Crossover, it might be something psychological (a divorce, an illness), it might also be a safety stop due to increased market volatility / markets crash. Remember to always measure drawdown in percentage terms, e.g. Tradestation Strategy Report is pretty useless, because it only shows drawdown as an absolute figure so it requires Excel to actually calculate drawdown in percentage terms. Also CAR is calculated correctly in AB, I’ve seen other software, costing 2k€, still calculating CAR wrong (10 times 10% per annum is NOT 100%) Portfolio Management Hahaa, I believe this is where a few gold bucks a buried. Portfolio in terms of which markets to trade has been discussed in the literature, still this is a very specialized topic already. There not many books found on this, that’s why I spend so much time thinking about it: Nothing to be found means a lot to be made and understanding it in great detail might give me/you a larger edge. Especially
RE: [amibroker] Trading Systems, Position Sizing and Monte Carlo Analysis
Hi, Indeed this is a very interesting topic. Many thanks go to Howard Bandy, it is literally a must read when working with Amibroker. I’m curiously waiting for the new one. Regarding System Design and Position Sizing: Well, I believe that there are a lot of books out there, but different authors really do mix up terminology, so this is how I interpret it: Position sizing Tells you how much, e.g. how many contracts or shares one should buy, Howard just mentioned 2 algos, fixed fraction and fixed ration. Ralph Vince’s book is a must read on this, however, it’s not quite easy going. Furthermore, there’s martingale and antimartingale, whereas martingale pretty much means: the more you lose, the more you bet. I believe it’s a sure-fire way to the poorhouse, that’s why I use ALWAYS anti-martingale. No black swans welcome in my trading. Risk management Obivously, there’s a clear overlap with position sizing, but still I believe it’s meant to be a little different. Say you have a system with a plugged in position sizing algo. You backtest it and you’ll have an estimate of the drawdown. Obviously, you will want to adjust position size so that you can stomach the drawdown. But as a safety measure, you might plug in another strategy. It might be an equity MA-Crossover, it might be something psychological (a divorce, an illness), it might also be a safety stop due to increased market volatility / markets crash. Remember to always measure drawdown in percentage terms, e.g. Tradestation Strategy Report is pretty useless, because it only shows drawdown as an absolute figure so it requires Excel to actually calculate drawdown in percentage terms. Also CAR is calculated correctly in AB, I’ve seen other software, costing 2k€, still calculating CAR wrong (10 times 10% per annum is NOT 100%) Portfolio Management Hahaa, I believe this is where a few gold bucks a buried. Portfolio in terms of which markets to trade has been discussed in the literature, still this is a very specialized topic already. There not many books found on this, that’s why I spend so much time thinking about it: Nothing to be found means a lot to be made and understanding it in great detail might give me/you a larger edge. Especially a scientific approach that is not based on gut-feel, is missing. This is what I am currently working on: Portfolio Management in terms of Trading Systems. So to say, have a trading systems farm, probably 3-5 systems on one underlying to have a very smooth equity curve. This includes diversification across a) methodology (Mean Reversion, Trendfollowing, Breakouts,etc.) and b) timeframe (day-trading, swing trading, position trading). Well, I have found 2-3 books on this topic, all of them sort of scratching the surface, mentioning the topic, but that’s it. So how can systems be combined wisely and when should systems be switched off, reoptimized, etc. If anybody knows some books on this, I’d be very happy to read up on it so if someone knows an author, please post! So far, having many systems with different logics is the direction I’m going right now. Something that’s worth having a look inside is this one: http://www.amazon.de/Trading-Systems-Development-Portfolio-Optimisation/dp/1905641796 again, it’s scratching the topic only. The way I develop systems is always the same (If anyone doesn’t agree with this approach, I’d like to know why) 1 contract, share, etc. Commissions excluded 3-5 (5max!) input parameters, such as indicators, ma’s: it’ll result in a raw system with in-built exits and entries but no stops. Optimize the inputs for STABILITY, a profitable set of parameters with a stable surrounding region Plug-In Commissions Add filters Add stops/targets according to Sweeney’s MAE MFE Plug-in the position sizing algo, “the compounder” Test out of sample Works fine for me. After this, I pretty much try to combine systems. Currently this is a bit troublesome in Ami, but I shall let you know when I have done enough research, unfortunately I believe it’s gonna take me some months. What I believe to be very controversial is the topic “adding noise” to data. I don’t think it reflects human emotion anymore. Same as dealing with a random sequence: a coin toss, e.g., can be displayed as a graph too, but it’s still a normal distribution. So: When doing quant-trading and believing in it, you make one big assumption: Markets behave logically, sometimes. I found out that markets contain a large amount of noise, random behavior. But there are occasions when people get hit on the wrong spot and start buying or selling aggressively . That’s the time when my systems jump in and make the kill - then I’m out. This behavior cannot be found in a random, probably noisy set of data. Monte Carlo pretty much changes the trade sequence only, right now I cannot really see why some people think it’s so useful. It might give you a better
RE: [amibroker] Trading Systems, Position Sizing and Monte Carlo Analysis
Well, it’s written in English, otherwise it wouldn’t be very useful to post it ;) Try this one instead. http://www.amazon.com/Trading-Systems-Optimisation-Portfolio-Construction/dp/1905641796/ref=sr_1_1?ie=UTF8 http://www.amazon.com/Trading-Systems-Optimisation-Portfolio-Construction/dp/1905641796/ref=sr_1_1?ie=UTF8s=booksqid=1280174971sr=8-1 s=booksqid=1280174971sr=8-1 If living in the States, I believe you could order it from amazon UK, I’m sure they have it in stock there. Just please be aware that it scratches this topic (multiple systems portfolio, portfolio composition, etc.) only. Half of the book is “beginner’s” talk, like where to start from and so forth. The remaining rest is, very very good food for thought. I don’t quite understand the critics in Amazon. (Ok, ok enough advertisement J ) Maybe this one is worth adding (Stridsman): http://www.amazon.com/Trading-Systems-That-Work-Evaluating/dp/007135980X/ref=sr_1_1?ie=UTF8 http://www.amazon.com/Trading-Systems-That-Work-Evaluating/dp/007135980X/ref=sr_1_1?ie=UTF8s=booksqid=1280175191sr=1-1 s=booksqid=1280175191sr=1-1 This book is outstanding from the very page onwards. But it deals with “long-term” trendfollowing, futures being the only instrument traded (I don’t have the money to actively trade say 20 futures markets long-term. To do so, you need 2.5M€ or about 3m$, that’s what I estimated) The methodologies inside are so much worth the money. From: amibroker@yahoogroups.com [mailto:amibro...@yahoogroups.com] On Behalf Of Lionel Issen Sent: Montag, 26. Juli 2010 22:01 To: amibroker@yahoogroups.com Subject: RE: [amibroker] Trading Systems, Position Sizing and Monte Carlo Analysis Your link for Trading Systems: A New Approach to System Development and Portfolio OptimisationTrading Systems: A New Approach to System Development and Portfolio Optimisation led to Amazon Germany. I couldn’t find any US sellers. Is the book only published in German, is it also available in English? Lionel Issen From: amibroker@yahoogroups.com [mailto:amibro...@yahoogroups.com] On Behalf Of Matthias K. Sent: Monday, July 26, 2010 2:19 PM To: amibroker@yahoogroups.com Subject: RE: [amibroker] Trading Systems, Position Sizing and Monte Carlo Analysis Hi, Indeed this is a very interesting topic. Many thanks go to Howard Bandy, it is literally a must read when working with Amibroker. I’m curiously waiting for the new one. Regarding System Design and Position Sizing: Well, I believe that there are a lot of books out there, but different authors really do mix up terminology, so this is how I interpret it: Position sizing Tells you how much, e.g. how many contracts or shares one should buy, Howard just mentioned 2 algos, fixed fraction and fixed ration. Ralph Vince’s book is a must read on this, however, it’s not quite easy going. Furthermore, there’s martingale and antimartingale, whereas martingale pretty much means: the more you lose, the more you bet. I believe it’s a sure-fire way to the poorhouse, that’s why I use ALWAYS anti-martingale. No black swans welcome in my trading. Risk management Obivously, there’s a clear overlap with position sizing, but still I believe it’s meant to be a little different. Say you have a system with a plugged in position sizing algo. You backtest it and you’ll have an estimate of the drawdown. Obviously, you will want to adjust position size so that you can stomach the drawdown. But as a safety measure, you might plug in another strategy. It might be an equity MA-Crossover, it might be something psychological (a divorce, an illness), it might also be a safety stop due to increased market volatility / markets crash. Remember to always measure drawdown in percentage terms, e.g. Tradestation Strategy Report is pretty useless, because it only shows drawdown as an absolute figure so it requires Excel to actually calculate drawdown in percentage terms. Also CAR is calculated correctly in AB, I’ve seen other software, costing 2k€, still calculating CAR wrong (10 times 10% per annum is NOT 100%) Portfolio Management Hahaa, I believe this is where a few gold bucks a buried. Portfolio in terms of which markets to trade has been discussed in the literature, still this is a very specialized topic already. There not many books found on this, that’s why I spend so much time thinking about it: Nothing to be found means a lot to be made and understanding it in great detail might give me/you a larger edge. Especially a scientific approach that is not based on gut-feel, is missing. This is what I am currently working on: Portfolio Management in terms of Trading Systems. So to say, have a trading systems farm, probably 3-5 systems on one underlying to have a very smooth equity curve. This includes diversification across a) methodology (Mean Reversion, Trendfollowing, Breakouts,etc.) and b) timeframe (day-trading, swing trading
RE: [amibroker] Help with DDE connections using TOS
Hi, Did you try putting a symbol into realtime quote list by type in symbol (use the symbol's name of your DDE provider). Other than that, try to look up in the documentation of TOC, not sure what it stands for/where it comes from. NO backfill available via DDE. Matthias From: amibroker@yahoogroups.com [mailto:amibro...@yahoogroups.com] On Behalf Of bar607 Sent: Donnerstag, 22. Juli 2010 23:11 To: amibroker@yahoogroups.com Subject: [amibroker] Help with DDE connections using TOS Hi, I configured the DDE connection according to this post with people that have successful done it http://finance.groups.yahoo.com/group/amibroker/message/149673 I did exactly as it stated but I still can NOT connect through DDE. Can anyone help me? Thanks, Pin
RE: [amibroker] Re: Help with DDE connections using TOS
Hi, Backfill means filling your chart with historical data for a specific period. All you can do with DDE is to get CURRENT realtime quotes, store them and good. If you switch off your computer on Monday, turn it on on Tuesday, you won't have data for Monday, no way to get it from your DDE source/interface. However, you can import historical quotes MANUALLY if your server has historical data available in ASCII format, e.g., and you can download them. With your provider, this seems to be the case, but it's quite a hassle updating the database manually if trading say, 1min charts. An elegant solution is the COM interface, that several providers, e.g. Esignal offer. AB has a dedicated Plug-In for each provider in the list. Backfilling data with the COM/RT-plugin is not a problem, however, it'll require you to spend a little money on a monthly base. Have a nice weekend, Matthias From: amibroker@yahoogroups.com [mailto:amibro...@yahoogroups.com] On Behalf Of bharat Sent: Freitag, 23. Juli 2010 19:53 To: amibroker@yahoogroups.com Subject: [amibroker] Re: Help with DDE connections using TOS Dear Matthias You have written that no backfill available via DDE.But does it apply to server which has data available?I think server of TBMX has 14 years data stored on it,because I am able to draw chart for 14 yeas data. --- In amibroker@yahoogroups.com mailto:amibroker%40yahoogroups.com , Matthias K. meridian...@... wrote: Hi, Did you try putting a symbol into realtime quote list by type in symbol (use the symbol's name of your DDE provider). Other than that, try to look up in the documentation of TOC, not sure what it stands for/where it comes from. NO backfill available via DDE. Matthias From: amibroker@yahoogroups.com mailto:amibroker%40yahoogroups.com [mailto:amibroker@yahoogroups.com mailto:amibroker%40yahoogroups.com ] On Behalf Of bar607 Sent: Donnerstag, 22. Juli 2010 23:11 To: amibroker@yahoogroups.com mailto:amibroker%40yahoogroups.com Subject: [amibroker] Help with DDE connections using TOS Hi, I configured the DDE connection according to this post with people that have successful done it http://finance.groups.yahoo.com/group/amibroker/message/149673 I did exactly as it stated but I still can NOT connect through DDE. Can anyone help me? Thanks, Pin
RE: [amibroker] Backtest Report Long/Short trades columns?
Hi, It's very hard to understand the system's logic only by numbers. But as a matter of fact you identified the problem already: when you're testing long only, the shorts are skipped, thus it'll result in a very different equity curve as compared to the result when trading long and short together. So far, if everything went right, you just figured out the difference of trading a long-only system and a short-only system. If trading stocks, one might consider the long-side only because the indices and stocks sort of have a long-bias. In order to smoothen your equity curve, you might want to combine a short and a long system. The result is something like you're showing here. It'll pretty much enable you to make money in both bull and bear markets and ideally smoothens out the equity curve and reduces drawdowns and flat periods. Looks good to me if your coding has been right and doesn't look into the future. Always: CAR/MDD ratio: above 1,5 over 10 years time is outstanding, as it's a risk adjusted measure, it'll equal/weigh up profits versus losses|drawdown and will not consider net profit only To sum it up: the more trades you have, the longer your backtesting period is, the higher your CAR/MDD ratio: the better your system. Don't forget to include commissions/ spreads, anyhow. They might deteriorate your big picture. Especially with mid-caps. A good custom backtest metric might be a combination of number of trades and CAR/MDD, so to say, make 50 Trades per year and still give a CAR/MDD ratio above 1. Greetings M From: amibroker@yahoogroups.com [mailto:amibro...@yahoogroups.com] On Behalf Of Ron Sent: Donnerstag, 22. Juli 2010 06:31 To: amibroker@yahoogroups.com Subject: [amibroker] Backtest Report Long/Short trades columns? I have a strategy that over time is either long or short but not both at the same time. I'm having difficulty understanding the Long and Short trades columns in the back test report when I run the back test in Long and Short mode. Long only backtest gives (Net Profit 458.76%) Initial capital 10.00 10.00 10.00 Ending capital 558757.12 558757.12 106586.98 Net Profit 458757.12 458757.12 6586.98 Net Profit % 458.76 % 458.76 % 6.59 % Exposure % 38.28 % 38.28 % 0.00 % Net Risk Adjusted Return % 1198.47 % 1198.47 % N/A Annual Return % 30.78 % 30.78 % 1.00 % Risk Adjusted Return % 80.42 % 80.42 % N/A Short only backtest gives (Net Profit 75.89%) Initial capital 10.00 10.00 10.00 Ending capital 175889.18 106586.98 175889.18 Net Profit 75889.18 6586.98 75889.18 Net Profit % 75.89 % 6.59 % 75.89 % Exposure % 28.44 % 0.00 % 28.44 % Net Risk Adjusted Return % 266.88 % N/A 266.88 % Annual Return % 9.21 % 1.00 % 9.21 % Risk Adjusted Return % 32.38 % N/A 32.38 % The Long Short backtest gives, Initial capital 10.00 10.00 10.00 Ending capital 921758.81 712441.67 315904.12 Net Profit 821758.81 612441.67 215904.12 Net Profit % 821.76 % 612.44 % 215.90 % Exposure % 66.78 % 38.28 % 28.50 % Net Risk Adjusted Return % 1230.56 % 1599.91 % 757.56 % Annual Return % 41.40 % 35.84 % 19.65 % Risk Adjusted Return % 62.00 % 93.62 % 68.96 % Notice the Long Net Profit is 612.44% and Short is 215.90% which is quite a bit different then when I ran them independently. Other columns are different as well but I'll focus on Net Profit % for now. I expect there is some compounding thing happening here but if someone asked me I couldn't explain it. Does anyone out there have a explanation. Thanks in advance, Ron
RE: [amibroker] Still trying to combine systems
Hi, Any news on your approach? Just ran through the afl online lib and found an idea from Paul Ho called something like testing multiple systems without going into CBT. Maybe you wanna give it a try Greets from Germany M From: amibroker@yahoogroups.com [mailto:amibro...@yahoogroups.com] On Behalf Of Gonzaga Sent: Mittwoch, 14. Juli 2010 17:49 To: amibroker@yahoogroups.com Subject: [amibroker] Still trying to combine systems Hi I have been fighting with AFL to write a sample program that let us combine two systems, as I told in a recent thread. I haven´t been able. The idea is easy: two type of buy conditions, one in the crossing of two averages, the other after falling four bars, using EOD bars. Both systems uses the same pool of money, and are PORTFOLIO SYSTEMS, buying as far as ten stocks, 10% of the money every purchase. THE BUY condition is easy to combine. But I have to tell AFL that if the last BUY as been using the First condition, the SELL has to be checked with the crossing of the averages again. And if the last BUY condition as been the second, the SELL condition has to be another one. (2 bars away from buying day). After trying it many times without using Custom backtester interface, I think the only way is using backtester interface. So I write the exact code, so anybody can test it and fill the custom backtest part.. I think it should be easy; the problem is that I don't really understand the logic of the custom backtester, so I don't know what to do Any suggestion will be very very much appreciated.. //BEGGINING OF CODE posQty=Param(Posiciones simultaneas,10,1,20,1); CapMinimo=Param(Cap minimo,2,1,200,5); SetOption(InitialEquity, 10 ); SetOption(AllowPositionShrinking, True ); SetOption(MaxOpenPositions, PosQty ); SetOption (accountmargin,100); PositionSize = -100/(posqty); Buy=Sell=0; SetTradeDelays(1,1,1,1); //FIRST SYSTEM--- Buy1= Cross(MA(C,15),MA(C,70)); BuyPrice1=Open; SellA=Cross(MA(C,70),MA(C,15)); SellPriceA=Open; //SECOND SYSTEM--- Buy2= CO AND Ref(C,-1)Ref(O,-1) AND Ref(C,-2)Ref(O,-2) AND Ref(C,-3)Ref(O,-3); SellB= Ref(Buy,-2); //BUY- Buy=IIf(Buy1,True,IIf(Buy2,True,False)); BuyPrice=Open; nombre1=Name(); typeBuy=IIf(Buy1,1,IIf(Buy2,2,0));//if buy1, array 'typebuy' is 1. If Buy2, is 2. Else is 0 n=BarsSince(Buy); //NEXT TWO SENTENCES DOES NOT WORK //Sell= IIf( Ref(typebuy,-n)==1, Cross(MA(C,15),MA(C,70)),False); //Sell= IIf( NOT Sell AND Ref(Buy2,-n), Ref(Buy,-2),False); //INSTEAD, USE OF CUSTOMBACKTESTER SetCustomBacktestProc(); if (Status(action) == actionPortfolio) { bo = GetBacktesterObject(); // Get backtester object bo.PreProcess(); // Do pre-processing (always required) for (i = 0; i BarCount; i++) // Loop through all bars { for (sig = bo.GetFirstSignal(i); sig; sig = bo.GetNextSignal(i)) { if (sig.isentry() AND Buy1[i]) //m } // End of for loop over signals at this bar bo.ProcessTradeSignals(i); // Process trades at bar (always required) } // End of for loop over bars bo.PostProcess(); // Do post-processing (always required) } PositionScore=Ref(StochK(15,3),-1); Buy=ExRem(Buy,Sell); Sell=ExRem(Sell,Buy); PlotShapes(IIf(Ref(Buy,-1),shapeUpArrow,shapeNone),colorBlue,0,L,-15); PlotShapes(IIf(Ref(Buy,-1),shapeHollowSquare ,shapeNone),colorBlue,0,BuyPrice,0); PlotShapes(IIf(Ref(Sell,-1),shapeDownArrow,shapeNone),colorRed,0,H,-15); PlotShapes(IIf(Ref(Sell,-1),shapeHollowSquare,shapeNone),colorRed,0,SellPric e,0); //---END OF CODE--
RE: [amibroker] Re: pl. code this
Why not spend a minute in YOUR education and try to solve your programming riddle yourself? If theres specific advice on a specific step in your coding, go ask for it: Please do! Present your code! Theres plenty of sophisticated long-term users in here that offer their valuable advice for free if they see your piece of the pie But as long as you dont want to dig a little deeper into Amibroker coding, why bother at all? Im sure you bought that piece of software because itll serve you a precious service for the time youre trading / future purpose. So why not make the effort and understand it in great detail? Believe me, this path is worth pursuing. Btw: this awesome John Carter Idea is not going to be as great as you think - trading it mechanically. Greets from Germany, M From: amibroker@yahoogroups.com [mailto:amibro...@yahoogroups.com] On Behalf Of bharat Sent: Montag, 19. Juli 2010 04:06 To: amibroker@yahoogroups.com Subject: [amibroker] Re: pl. code this AFL which you have mentioned is available here.Check and tweak. --- In amibroker@yahoogroups.com mailto:amibroker%40yahoogroups.com , cas soni soni...@... wrote: Hello ,I had given you BBsqueeze .afl  indicator long time ago...use that..i think it is same as per mt4 indicator..* i dont have that afl have a nice time. . --- On Sun, 18/7/10, bharat bharat_parth2...@... wrote: From: bharat bharat_parth2...@... Subject: [amibroker] Re: pl. code this To: amibroker@yahoogroups.com mailto:amibroker%40yahoogroups.com Date: Sunday, 18 July, 2010, 5:41 PM  Hi Found full MT4 code for this.Pl. Code AFL === // This indicator is based on a strategy mentioned in John Carter's book, Mastering the Trade. The basic idea // behind the strategy is that markets tend to move from periods of low volatility to high volatility and // visa versa. The strategy aims to capture moves from low to high volatility. For gauging this he uses two // common indicators - Bollinger Bands and Keltner Channels (ok, not so common!). He also uses the Momentum // indicator to provide a trade bias as soon as the Bollinger Bands come back outside the Keltner Channels. // // The Squeeze_Break indicator combines this into a signal indicator and has the following components: // 1. A positive green histogram means that the Bollinger Bands are outside the Keltner Channels // and the market is lightly to be trending or volatile. The stronger the histogram the stronger // the directional price move. // 2. A negative red histogram means that the Bollinger Bands are inside the Keltner Channels // and the market is lightly to be consolidating. The stronger the red histogram the tighter // price action is becoming. // 3. Incorporated into the indicator is a Momentum indicator. According to the strategy J. Carter // goes long when the Bollinger Bands break outside the Keltner Bands and the Momentum indicator // is above the zero line. He goes short when the Momentum indicator is below the zero line on the // break. // 4. I've also added other indicator info in the top left hand corner to give a broader idea // of current market conditions. // 5. The indicator provides audio alerts when a potential breakout is occurring. // // This indicator tends to be better with the larger timeframes. Personally I don't trade on an alert // signal alone. It's just a handy tool for warning me of potential breakout trades. // === #property copyright DesORegan #property link mailto: oregan_...@... // // indicator properties // #property indicator_separate_window #property indicator_buffers 3 #property indicator_color1 ForestGreen #property indicator_color2 Red #property indicator_color3 Blue // === // User Inputs // === extern int Boll_Period=20; extern double Boll_Dev=2.0; extern int Keltner_Period=20; extern double Keltner_Mul=1.5; extern int Momentum_Period=12; extern int Back_Bars=1000; extern bool Alert_On=true; extern bool On_Screen_Info=true; // = // Buffer Array Declarations // = double Pos_Diff[]; // Pos Histogram double Neg_Diff[]; // Neg Histogram double Momentum[]; // Momentum Indicator // === // Internal Array Declarations // === double Squeeze[]; // Used to track which i (index value) is above // and below zero line. 0 followed by 1 triggers alert // = //
RE: [amibroker] Hold a trade for a minimum # of bars
Hi, This one is from Mr. Janeczko, he put it online as an example, but I cannot find the link. Replace buy/sell,etc. witch your rules, the rest is pretty much self-explanatory. Buy = MACD() 0 AND RSI() 30; Sell = MACD() 0 OR Cross( 70, RSI() ); SetPositionSize(1,spsShares); // now we would like to ensure that position is NOT // exited during first MinHoldBars MinHoldBars = 17; // say don't want to exit for first 17 bars since entry // first filter out buy signals occuring outside testing range Buy = Buy AND Status(barinrange); BarsInTrade = 0; for( i = 0; i BarCount; i++ ) { // if in-trade, then increase bar counter if( BarsInTrade 0 ) BarsInTrade ++; else if( Buy[ i ] ) BarsInTrade = 1; // on buy signal start counting bars-in-trade // if we are in trade - remove sells occurring too soon if( BarsInTrade MinHoldBars ) Sell[ i ] = 0; else if( Sell[ i ] ) BarsInTrade = 0; // on sell reset barsintrade flag } printf(barsintrade:\n); WriteVal(barsintrade); Greets, Matthias From: amibroker@yahoogroups.com [mailto:amibro...@yahoogroups.com] On Behalf Of JEFF F Sent: Donnerstag, 15. Juli 2010 00:41 To: amibroker@yahoogroups.com Subject: [amibroker] Hold a trade for a minimum # of bars Can anyone tell me how to hold a trade for a minimum # of bars (such as 3) before checking for a sell signal? I have tried settradedelay(0,3,0,0) but when i backtest, the trade still happens the next day. Same with changing the delay within the settings button. Any help is appreciated. Thanks
RE: [amibroker] FOREX brokers and data feed differences
Not sure if it helps, but give it a try: FX is traded 24 hrs, thus the timestamp of your MT broker may be stamped differently as compared to finam (=Russia) data. Be careful with data selection in FX anyways, it's an interbank market that is not watched by authorities, hence is not regulated. Data from one provider may be more volatile, compared to another. Having too little information about your project, it's difficult to give you better advice than this: When backtesting a FX-System, be sure that the data comes from the broker you want to trade with! If you're thinking of buying data, you might stumble across their site: http://disktrading.is99.com/disktrading/ Unfortunately the FX data is very very noisy and I abandoned it for system development in FX (unless you trade on daily charts). Their futures data is ok (as in ok, not outstanding), though. Here's another free data source you may wanna play with. http://www.dukascopy.com/swiss/english/data_feed/csv_data_export/ Last but not least: IMHO always give ECN brokers a preference, they're interested in executing your trades only and don't act as a market maker. IB is an ECN borker, MB Trading (has MT4) is another one. From: amibroker@yahoogroups.com [mailto:amibro...@yahoogroups.com] On Behalf Of BruceD Sent: Dienstag, 6. Juli 2010 06:59 To: amibroker@yahoogroups.com Subject: [amibroker] FOREX brokers and data feed differences This is my first post on this forum so please point me in the right direction if I'm doing something wrong. I'm looking for advice from someone who may have been down this road allready. I've been trading FOREX using MQ4 for a few years, but have allways been frustrated by its inadequate back testing capabilites. I recently found AmiBroker and Howard Bandy's books. This has been a real quantum leap for me and I'm anxious to apply some of the methods I've learned. Here's the problem: Using AmiQuote to download FOREX history, the data feed comes from FinAm. Using the backtesting and optimization tools in AmiBroker I've develped a succesfull trading system, however, I don't have a broker set up to accept live trades from AmiBroker yet. As a test, I wrote the same system in the MQ4 system with my existing broker and ran it live for a while. Its performance was poor. Further research has shown that difference in performance is due to the fact that the data from FinAm and that from my MQ4 based broker (IBFX) is very different! I would like to switch to a FOREX broker that will allow me to do live trading from AmiBroker, hopefully that uses the same data source as FinAm, and of course that has reasonable rates. If I read the info on FinAm's website properly, their small USD 10 fee per trade in addition to a higher than normal spread is a deal breaker for me. Has anyone else experienced this issue with FOREX data? Does anyone have a broker they are doing live FOREX trading with via AmiBroker that they are happy with? I do a lot of intra-day trades. Any suggestions would be appreciated. Again, if I'm posting incorrectly or in the wrong area, please let me know. Thanks!
RE: [amibroker] Re: How to mix systems
Que tal gonzaga? After sending this email, I figured that this might happen: I was answering to Paul's post. Strange Yahoo, sorry for the confusion. I'm afraid I cannot help you on your custom backtest proc, yet. Hi System Mixers, I've been following this thread. I see people want to do different things when they say mix systems. If all you want to do is backtest on daily bars with multiple systems, yet be able to test each system by itself first, one simple way might be to obtain each system's equity curve (preferably walk-forward OOS curve), and then export that curve to a CSV file. Once you have say, 2 or more systems that you want to time / combine, you can then create a new AB database with nothing in it, and then import the equity curves as pseudo/fake symbols using just Date and Close, where the Close is your equity value from that system. Then you could write one code to rank or time the equity curves. Sure, that's quite a bit different than controlling and combining all the individual orders of all the systems, but if you want to keep your system's separate and just time their individual equity curves, then this sort of approach might work. The down side is that you wouldn't be able to see how much risk you are taking on 1 stock. Like, if all systems pile into AAPL Long, that might be pretty bad. Another down side is I could see it being a pain to update going forward. -Paul Answer: As you can see from my questions/answers, I'm always interested in finding new solutions. but quote me if I'm wrong: with your approach you are NOT using ONE equity pool. Say you have 100k$, with your methodology you would do one of the following: Assign 50k$ or 50% to System1 Assign 50k$ or 50% to System2 == Backtest and combine equity curves as you said. Alternativley you might prop up the result in using 100k$ to backtest your 2 Systems. If you operate on a non-percent-risk model, it might work, but a non-percent-risk model ( e.g. fixed number of shares) is not really state-of-art. ...just thinking out loud...