[amibroker] Re: Req Can we have afl showing gravity bars with color? please help

2010-09-06 Thread Mike
Your friend is mistaken.

1. Any indicator can be programmed in AFL. You just have to know the rules 
before you can code them.

2. If the "Trade2Win" forum can be believed, the color gravity chart is nothing 
more than a Heiken Ashi indicator combined with a moving average: 
http://www.trade2win.com/boards/first-steps/51318-colour-charts.html

3. Tomasz published the Heiken Ashi in AFL here: 
http://finance.groups.yahoo.com/group/amibroker/message/112930

The article referenced in that thread can also be found here: 
http://www.earnforex.com/forex-e-books/trading-strategy/Using_The_Heikin_Ashi_Technique_D_Valcu.pdf

I have not used this indicator, so do your own research. But, yes, it certainly 
can be done.

Mike

--- In amibroker@yahoogroups.com, "ford7k"  wrote:
>
> 
> Hi afl experts with exposure along multiple platforms,
> A friend of mine uses tradestation,multicharts etc which I have no idea of.
> After I asked him,what are these colored bars on your chart,he 
> said,buddy-these are not very advanced and not for Amibroker users.
> I had a heated arguement with him when he said said.
> He said these are gravity bars-ever heard of these?
> I admitted-ok i never heard of these.
> he said 
> you too can use  Gravity Colour Charts,but you need to forget amibroker.
> 
> I had no answer.
> I googled and found this thing and some charts etc.
> 
> Can someone here please tell me what this gravity or antigravity stuff is all 
> about?
> 
> Gravity ,I understand is price falling down or going south due to heavy 
> supply in market.
> 
> The link for general info is 
> http://www.ukshareinvestor.com/
> ==
> some info
> 
> My students often asked me if I could devise an easily recognised signal 
> showing just where to enter and exit trades. So I got to work with my 
> programmer telling him exactly what I wanted and how it was to look and he 
> came up with the Gravity Colour Charts. You may have seen me on the BBC Money 
> Programme recently when they featured me training using the Gravity Colour 
> Charts.
> 
> 
> 
> I have used the Gravity Colour Charts trading the US Markets and my student 
> just love the way they provide a very visual buy and sell signal (I will show 
> you exactly how to use them of course). My programmer has now made them 
> available for the UK stock market and they work together with eSignal or 
> ShareScope PLus charts.
> ===
> THe chart uses two indicators called
> GravityLinePBv3u  and GravityLinev3u
> 
> Is there anything close to gravity colorbars in amibroker?
> If a senior like Howard or Mike or Herman etc says -yes this is beyond 
> Amibroker-then I accept my friends remarks.
> However,I would like to know about these gravity bars.
> 
> thanks 
> best regards.
> ford
>




[amibroker] Re: AllowSameBarExit

2010-09-03 Thread Mike
Try using ApplyStop with stopTypeNBar. Otherwise, you will need to strip out 
redundant signals when working with Ref.

Basically, your problem is:

- Your Short logic will result in many redundant signals (e.g. consider 3 up 
bars in a row, you will have 3 Short signals in a row).

- Since your Cover is entirely dependent upon Short, you will also have many 
redundant Cover signals (e.g. 2nd and 3rd bars in example above will also have 
Cover signals since prior bar had a Short signal).

- When you have both a Short and a Cover on the same bar the AllowSameBarExit 
will have a real impact on whether your system is allowed to exit or not.

Mike

--- In amibroker@yahoogroups.com, "palward"  wrote:
>
> I am quite puzzled by the following; hope someone can help.
> I am designing a stock system that exits on the close one bar after an 
> established open position. Below is a non profitable mock up of what I am 
> trying to do.
> 
> The problem is when "AllowSameBarExit" is asssigned true or false. The 
> results in the backtester are significantly different using the same code but 
> changing "AllowSameBarExit" from false to true . My expectation is that the 
> backtest results should be identical since the exit is never on the same bar 
> of entry.
> 
> Why am I getting different results and how can it be corrected?
> 
> Thank you,
> Phil
> 
> Here is the code:
> //
> SetTradeDelays(0,0,0,0); 
> PosQty=20;
> PositionSize = -100/PosQty;
> 
> SetOption( "MaxOpenPositions",PosQty); 
> SetOption("AllowSamebarExit",False);
> 
> Short=High>Ref(High,-1);
> ShortPrice=Max(Open,Ref(High,-1));
> 
> Cover=IIf(Ref(Short,-1),1,0);
> CoverPrice=Close; 
> ///
>




[amibroker] Re: Performance

2010-08-31 Thread Mike
Ok,
I think I understand what you are referring to now. If you are referring
to the "Charts" page of the backtest report (i.e. from Statistics |
Charts | Trades | Formula | Settings | Symbols), then yes, most of those
charts are measuring changes of equity. The same trade taken over and
over will have a lesser and lesser impact on equity as equity grows.
However, the last chart, "Profit Distribution" is based on individual
trade results, not changes in equity. If you want to compare the
characteristics of trades between backtests, refer to this chart.
Here's a sample code you can backtest (using "current symbol") over an
extended period (e.g. 1/1/06 - 12/31/09):
SetOption("InitialEquity", 10);  // Start with $100,000
SetPositionSize(1, spsValue); // Bet $10,000 on every trade
SetOption("PriceBoundChecking", false);   // Disable valid price check.

SetTradeDelays(0, 0, 0, 0);

Buy = Month() != Ref(Month(), -1);
BuyPrice = Open;

Sell = Month() != Ref(Month(), 1);
SellPrice = ValueWhen(Buy, BuyPrice) * 1.50;   // Force every trade as
50% winner
The "Profit Table" chart will show a decreasing return each year since
the fixed performance is less and less relative to the growing equity.
However, the "Profit Distribution" chart will show all trades as as 50%
or 55%. They should actually all be 50%, but I assume that there are
rounding errors causing some to get bumped up into the next category.
If you want to include your own charts in the report, you can add any
AFL file to the directory \Formulas\Report Charts
For example; You could write your own table chart that displayed the
average trade result for each month rather than the change in equity. 
In the example above, every monthly cell in the table would show 50%.
Mike



[amibroker] Re: Definitive Guide to AFL

2010-08-30 Thread Mike
Herman made a typo in his response, it should have read Howard Bandy, not 
Howard Bundy.

You can review the content of his books here:

http://www.blueowlpress.com/#books

Mike




[amibroker] Re: Performance

2010-08-29 Thread Mike
A loss of -2/10 is still a loss of -2/10 regardless of how much you have in the 
bank. Look at the *trade* metrics. If you are trading using a fixed dollar 
value (e.g. always $10 as in your example), then the trade metrics will be 
identical regardless of initial equity. 

Specifcally;
All trades profit/loss %
Winners profit/loss %
Losers profit/loss %
etc.

The only time the values would be different would be if too low an initial 
equity prevented you from entering a trade compared to a higher initial equity.

Mike

--- In amibroker@yahoogroups.com, tstudent  wrote:
>
> Think together.
> 
> I have 50.000 usd, i decide to invest 10.000 usd fixed for every 
> trade. I start my trading system and unfortunatly at the first trade 
> i lose 2.000 usd. Amibroker report a loss of 2.000/50.000 = -4%
> After two years my system has done a very good job. Now i have 100.000 usd
> Next trade i lose the same 2.000 usd. Amibroker report a loss of 
> 2.000/100.000 = -2%
> Do you see what i'm trying to say?
> It seems that my system is more risky/volatile in the first part.
> In summary: It's not possible to compare the various statistics 
> (average, standard deviation, sharpe and so on) in different period, 
> because the unit measure continually change over the time.
> 
> Understand me, i'm not saying that actual Amibroker metric is wrong. 
> Of course it's not.
> What i'm trying to say is that i'd like to have also a neutral metric 
> for validate my trading system.
> A metric indipendent from dollar.
> And it could be useful also for compare different trading systems.
> 
> Is possible to have a backtest report not dollar dependent?
> 
> Of course i can export in excel all the trades and do all the 
> calculations i want.
> But what i'm asking for is if there is the possibility to automatize 
> the process and have an easy and fast way built in  Amibroker.
> 
> Thank you
> 
> 
> At 22.37 28/08/2010, you wrote:
> >
> >
> >Hello,
> >
> >You need to think again.
> >
> >No, there won't be ANY influence if your initial equity is large 
> >enough so no trade is dropped
> >because of insufficient funds.
> >
> >Equity curve is not sum of percent profits, but actual VALUE of 
> >portfolio (in dollar terms).
> >If all trades have equal position size (at entry), then the value of 
> >equity will represent
> >total NET DOLLAR gain/loss of all trades, without any influence.
> >
> >
> >Best regards,
> >Tomasz Janeczko
> >amibroker.com
>




[amibroker] Re: Misunderstanding of Arrays

2010-08-26 Thread Mike
The important thing to realize is that Ref returns an *array*. The "if" 
statement is expecting a *single* boolean value, not an array of booleans.

See common coding mistakes in the user guide:

http://www.amibroker.com/guide/a_mistakes.html

Mike

--- In amibroker@yahoogroups.com, "trfy1120"  wrote:
>
> I have an array called lowest_roc_num.
> 
> If I use the test:
> 
>  JOHN = Ref(Lowest_ROC_NUM,0)==9;
> 
> JOHN gets the value of zero or 1 appropriately.
> 
> If I use the syntax:
> 
> if (Ref(Lowest_ROC_NUM,0) == 9)
>   MARY=10;
> 
> I get an error message saying that the condition in an IF, WHILE or FOR 
> statement must be numeric or boolean, you cannot use an array here.  It then 
> says to use [] to refer to an element of the array.
> 
> I have two problems.  First, I thought REF was referring to an element of the 
> array rather than the whole array and, second, I don't know how to refer to 
> the current bar using [].
> 
> Thanks for any help.
> 
> TRFY
>




[amibroker] Re: Writing the openpos.Handle value

2010-08-26 Thread Mike
I just ran a test to see if you could use StrFormat instead:
_trace( StrFormat( "%1.0g", openpos.Handle ) );
However, it seems that it too suffers from a similar problem; It does
not accept double as an argument type.
Just passing the raw double to _trace doesn't work either:
_trace( "" + openpos.Handle );
One way to work around the limitation would be to introduce JScript to
your code as follows:
EnableScript( "jscript" );

<%
function DoubleToStr( arg )
{
 return "" + arg;
}
%>

SetCustomBacktestProc( "" );

if ( Status( "action" ) == actionPortfolio )
{
 bo = GetBacktesterObject();
 so = GetScriptObject();

 ...
 for ( openpos = bo.GetFirstOpenPos(); openpos ; openpos =
bo.GetNextOpenPos() )
 {
 _trace( so.DoubleToStr( openpos.Handle ) );
 }...
}
The above will be equivalent to what you could have expected from
passing the raw double to _trace.
JScript does not have a native sprintf like C/C++ (from which StrFormat
borrows its formatting behavior), so if you wanted formatting you would
have to write it yourself. Fortunately, you can get a free
implementation from here:
http://www.diveintojavascript.com/projects/javascript-sprintf
<http://www.diveintojavascript.com/projects/javascript-sprintf>
Simply embed the source as-is within the script delimeters (i.e. <% and
%>) in the above example, and it will allow you full blown formatting
along the lines of C/C++ described here:
http://www.cplusplus.com/reference/clibrary/cstdio/printf/
<http://www.cplusplus.com/reference/clibrary/cstdio/printf/>
Specifically, you could call it like below to get exactly what you were
originally asking for:
_trace( so.sprintf( "%1.0f", openpos.Handle ) );
If you have an open ticket, it would be worth adding StrFormat and
_TRACE to the fix request so that they all work for doubles.
Mike
--- In amibroker@yahoogroups.com, "whitneybroach" 
wrote:
>
> Just as a follow-up, I heard from Tomasz off-line.
>
> At the moment, it can't be done with NumToStr.  He is considering
whether to modify NumToStr.  One issue:  because the underlying values
are doubles, the numbers are large, 32- or 64 bits-worth, depending on
your platform.
>
> --- In amibroker@yahoogroups.com, "whitneybroach" WhitneyBroach@
wrote:
> >
> > How do I write an openpos.Handle value to trace?  Does the double
format not convert in NumToStr?
> >
> > Code like this produces only zeros from inside the openpos loop:
> >
> > //
> >
> > for( openpos = bo.GetFirstOpenPos(); openpos ; openpos =
bo.GetNextOpenPos() )
> > {
> > _trace( NumToStr( openpos.Handle, 1.0, False ) );
> >
> > // substituting 1.5 for 1.0 produces more zeros
> >
> > }// for openpos
> >
> > //
> >
> > (The code is checking to see if a dividend has already been paid on
an open position.  Must be able to use multiple positions per symbol.)
> >
>



[amibroker] Re: Help understanding difference between Old Backtester vs Individual Backtest

2010-08-24 Thread Mike
According to the release notes for 4.50.0, Individual backtest is supposed to 
use the (new) portfolio backtester on each individual symbol. So, it is not the 
same as running the old backtester.

"CHANGES FOR VERSION 4.50.0 (as compared to 4.49.0)

new "individual backtest" mode: allows to run new backtester separately on each 
symbol in the selected "apply to" group. (Replaces old backtester functionality 
in testing multiple stocks and provides new reports)"

http://www.amibroker.com/devlog/wp-content/uploads/2007/02/releasenotes.html

One difference that might be affecting your trades is that the old backtester 
does not recognize scale-in/out, as discussed in the pyramiding section of the 
guide:

http://www.amibroker.com/guide/h_pyramid.html

Here are some reporting differences:

http://www.amibroker.com/guide/w_report.html

Mike

--- In amibroker@yahoogroups.com, "radmobile_radmobile"  wrote:
>
> Hello,
> 
> Could someone be kind enough to please breakdown for me the differences 
> between running in Old Backtester mode vs. running as Individual Backtest. I 
> understand certain features are not available to the Old Backtester, but when 
> I am currently trying to see how a simple system preforms on each individual 
> stock applied to a watchlist of 200, I am getting some different results 
> between Old and Individual in terms of the # of trades entered etc. I could 
> not find an official explanation searching through the help file.
> 
> Thanks,
> -RM
>




[amibroker] Re: Date of a Past Price Bar

2010-08-24 Thread Mike
Try this:

printf (tname + " saw a highest Close of " + WriteVal(HighestV, 1.2) + ", " + 
WriteVal(HighestS, 1.0) + "-bars ago on " + NumToStr(ValueWhen(Close == 
HighestV, DateTime()), formatDateTime));

Mike

--- In amibroker@yahoogroups.com, Mubashar Virk  wrote:
>
>   Hi All,
> I need a little help with the following.
> 
> These Lines:
> /
> _N( tname = Name() );
> HighestV = Highest( Close );
> HighestS = HighestBars ( Close );
> printf (tname + " saw a highest Close of " + WriteVal(HighestV, 1.2) + 
> ",   " + WriteVal(HighestS, 1.0) + "-bars ago.");
> ///
> 
> Gives me:
> XYZ saw a highest Close of 1234.56,  50-bars ago.
> 
> QUESTION: What do I need to add at the end of the code to get the 
> following line:
> XYZ saw a highest Close of 1234.56,  50-bars ago on 12/12/2009.
> 
> Thanks,
>




[amibroker] Re: Optimizer target with genetic optimization

2010-08-24 Thread Mike
Bert,

I have not run any tests to confirm. But, based on your description, my guess 
would be that AmiBroker falls back to the default target when the specified 
target could not be found.

If all of the above is true, then a runtime error would probably have been more 
helpful since, as you've pointed out, the results would be very misleading.

Mike

--- In amibroker@yahoogroups.com, "bistrader"  wrote:
>
> Mike,
> 
> I now understand via Tomasz and your replies.  Yet, I tried without custom 
> backtester code and by that I means that I typed CAR*(100 - abs(MDD)) under 
> Setting/Optimization Target.  AmiBroker's walkforward ran just fine with no 
> error, yet I am now, after the fact, guessing that the results are 
> meaningless.  I will do a little test to make sure.
> 
> Thanks
> 
> Bert
> 
> --- In amibroker@yahoogroups.com, "Mike"  wrote:
> >
> > Bert,
> > 
> > I believe that your understanding is correct in that you must create a 
> > custom metric to use anything other than the "out of the box" metrics 
> > provided by AmiBroker.
> > 
> > However, you must provide the name of the custom metric (case sensitive) as 
> > the optimization target, not the mathematical formula.
> > 
> > In your example you would need to enter CARTimes100LessMdd as the 
> > optimization target in the settings (i.e. the same value passed as the 
> > Title argument to bo.addcustommetric).
> > 
> > Mike
> > 
> > --- In amibroker@yahoogroups.com, "bistrader"  wrote:
> > >
> > > Mike and others,
> > > 
> > > Using this example, I would type the following as the "Optimization 
> > > target".
> > > 
> > > CAR*(100 - abs(MDD))
> > > 
> > > Yet, if I want to see these values in the walk forward stats, don't I 
> > > have to add something like the following to the end of the afl?  Or, is 
> > > there some way to tell AmiBroker to also list the "Optimization target" 
> > > without getting into the Custom Backtester?
> > > 
> > > SetCustomBacktestProc("");
> > > 
> > > if (Status("action") == actionPortfolio)
> > > {
> > > bo = GetBacktesterObject();
> > > 
> > > bo.backtest();
> > > 
> > > st = bo.getperformancestats(0);
> > > 
> > > CARTimes100LessMdd = st.getvalue("CAR") * ( 100 - 
> > > abs(st.getvalue("MaxSystemDrawdownPercent")) );
> > > 
> > > bo.addcustommetric("CARTimes100LessMdd", CARTimes100LessMdd);
> > > }
> > > 
> > > Thanks
> > > 
> > > Bert
> > > 
> > > --- In amibroker@yahoogroups.com, "Mike"  wrote:
> > > >
> > > > Go to the Automatic Analysis window, click on the Settings... button, 
> > > > change to the Walk Forward tab, change the value for "Optimization 
> > > > target".
> > > > 
> > > > Mike
> > > > 
> > > > --- In amibroker@yahoogroups.com, "DougOriard"  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?
> > > > >
> > > >
> > >
> >
>




[amibroker] Re: Optimizer target with genetic optimization

2010-08-24 Thread Mike
Bert,

I believe that your understanding is correct in that you must create a custom 
metric to use anything other than the "out of the box" metrics provided by 
AmiBroker.

However, you must provide the name of the custom metric (case sensitive) as the 
optimization target, not the mathematical formula.

In your example you would need to enter CARTimes100LessMdd as the optimization 
target in the settings (i.e. the same value passed as the Title argument to 
bo.addcustommetric).

Mike

--- In amibroker@yahoogroups.com, "bistrader"  wrote:
>
> Mike and others,
> 
> Using this example, I would type the following as the "Optimization target".
> 
> CAR*(100 - abs(MDD))
> 
> Yet, if I want to see these values in the walk forward stats, don't I have to 
> add something like the following to the end of the afl?  Or, is there some 
> way to tell AmiBroker to also list the "Optimization target" without getting 
> into the Custom Backtester?
> 
> SetCustomBacktestProc("");
> 
> if (Status("action") == actionPortfolio)
> {
> bo = GetBacktesterObject();
> 
> bo.backtest();
> 
> st = bo.getperformancestats(0);
> 
> CARTimes100LessMdd = st.getvalue("CAR") * ( 100 - 
> abs(st.getvalue("MaxSystemDrawdownPercent")) );
> 
> bo.addcustommetric("CARTimes100LessMdd", CARTimes100LessMdd);
> }
> 
> Thanks
> 
> Bert
> 
> --- In amibroker@yahoogroups.com, "Mike"  wrote:
> >
> > Go to the Automatic Analysis window, click on the Settings... button, 
> > change to the Walk Forward tab, change the value for "Optimization target".
> > 
> > Mike
> > 
> > --- In amibroker@yahoogroups.com, "DougOriard"  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?
> > >
> >
>




[amibroker] Re: Optimizer target with genetic optimization

2010-08-23 Thread Mike
Go to the Automatic Analysis window, click on the Settings... button, change to 
the Walk Forward tab, change the value for "Optimization target".

Mike

--- In amibroker@yahoogroups.com, "DougOriard"  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?
>




[amibroker] Plotting or otherwise identifying Scale in, Scale out Trade Points

2010-08-22 Thread Mike
I have no difficulty running scale in, scale out systems, but I need to see 
where the scale in scale out points occur, not just the final closed trades.

Anyone have a solution?

Thank you.

Mike



[amibroker] Re: Max. Drawdowns greater than "L. Tot. Loss"?

2010-08-16 Thread Mike
Michael,

One of us is not understanding the other. You said "Loser total loss can't be 
less than max system drawdown (could be equal, but never less)."

Keith's example is proof that loser total loss can indeed be less than max 
system drawdown. Loser total loss is calculated based on the final closing 
value of the trade(s) whereas max system drawdown is based on the running value 
of the trade(s). The number of symbols and/or open trades is irrelevant.

Repeating Keith's example with more detail:

Bar x Spend 100% equity to enter ABC at $10,000
Bar y ABC (and thus total equity) drops to $6,000
Bar z Exit ABC at $9,000

Loser total loss (bar z) = $9,000 - $10,000 = -$1,000
Max system drawdown (bar y) = $10,000 down to $6,000 = -$4,000

So, yes, loser total loss can be less than max system drawdown (in the sense of 
being less negative, an opposite example can also be shown where loser total 
loss is less in the sense of being more negative than max system drawdown).

However, if you feel that you've solved your problem, then no need to reply 
further.

Mike

--- In amibroker@yahoogroups.com, "michaels_musings"  
wrote:
>
> Hi Mike,
> 
> Actually I didn't include enough original data to posit the question and my 
> rebuttal to Keith correctly :(
> 
> The system I'm playing with trades/optimizes a single stock at a time, and is 
> only able to have one trade open at a time (e.g. it must close out a buy with 
> either a profit or loss before opening another trade).  Under this, my 
> original conundrum is perfectly valid.  Loser total loss can't be less than 
> max system drawdown (could be equal, but never less).
> 
> Now, I did find the problem, and unfortunately it is derived because I'm 
> having to jack with AB to get it to recognize all available trades instead of 
> being bound by AB's one bar one trade limitation.
> 
> As the probability is so slight of anyone else even remotely having the same 
> issues, I'm sorry I raised a false flag...
> 
> Best Regards,
> Michael
> 
> 
> --- In amibroker@yahoogroups.com, "Mike"  wrote:
> >
> > Michael,
> > 
> > Keith got it right. I believe that you have missed his point. Your 
> > portfolio (including winners and losers) collectively reached a $2600 loss 
> > before eventually recovering to your final equity level.
> > 
> > Do not confuse the closed trade statistics with the bar by bar running 
> > statistics. The trades that ended as losers might have been winners at the 
> > time of MDD, whereas those that ultimately ended as winners might have been 
> > big losers before bouncing back, etc.
> > 
> > Bottom line: MDD is independent of closed losers. Plot your equity and 
> > identify the date of MDD on the chart. Then look at the charts for each of 
> > the positions that were open at that date to see which symbols were 
> > dragging equity down and which were pulling it up.
> > 
> > Mike
> > 
> > --- In amibroker@yahoogroups.com, "michaels_musings"  
> > wrote:
> > >
> > > Hi Keith,
> > > 
> > > I think you missed what the data is saying.
> > > 
> > > There were 6 total losing trades, stop lossed at 2% ($200 ea.), for a 
> > > maximum total loss of all losing trades of ~$1,200.
> > > 
> > > The MDD can't ever reach ~$2,600 if all the losing trades put together 
> > > only totals $1,200, right?
> > > 
> > > How did it then?,
> > > Michael
> > > 
> > > --- In amibroker@yahoogroups.com, Keith McCombs  wrote:
> > > >
> > > > Michael --
> > > > If you invest $10,000 in a stock and it drops to $6,000, but then 
> > > > returns to $9,000, and then you sell it, that stock has experienced a 
> > > > $4,000 MDD, but only a $1,000 loss.
> > > > 
> > > > -- Keith
> > > > 
> > > > On 8/16/2010 16:25, michaels_musings wrote:
> > > > >
> > > > > Hi All,
> > > > >
> > > > > This has me baffled. I run an optimization and I end up with the Max. 
> > > > > System Drawdown greater than the listed Losers Total Loss. Here's the 
> > > > > fields in question.
> > > > >
> > > > > Capital 100,000.00
> > > > > Trade Size 10,000.00
> > > > >
> > > > > Net Profit 5,315.42
> > > > > Max. Trade Drawdown -2,615.84
> > > > > Max. Trade % Drawdown -26.15
> > > > > Max. Sys Drawdown -2,615.84
> > > > > Max. Sys %

[amibroker] Re: Max. Drawdowns greater than "L. Tot. Loss"?

2010-08-16 Thread Mike
Michael,

Keith got it right. I believe that you have missed his point. Your portfolio 
(including winners and losers) collectively reached a $2600 loss before 
eventually recovering to your final equity level.

Do not confuse the closed trade statistics with the bar by bar running 
statistics. The trades that ended as losers might have been winners at the time 
of MDD, whereas those that ultimately ended as winners might have been big 
losers before bouncing back, etc.

Bottom line: MDD is independent of closed losers. Plot your equity and identify 
the date of MDD on the chart. Then look at the charts for each of the positions 
that were open at that date to see which symbols were dragging equity down and 
which were pulling it up.

Mike

--- In amibroker@yahoogroups.com, "michaels_musings"  
wrote:
>
> Hi Keith,
> 
> I think you missed what the data is saying.
> 
> There were 6 total losing trades, stop lossed at 2% ($200 ea.), for a maximum 
> total loss of all losing trades of ~$1,200.
> 
> The MDD can't ever reach ~$2,600 if all the losing trades put together only 
> totals $1,200, right?
> 
> How did it then?,
> Michael
> 
> --- In amibroker@yahoogroups.com, Keith McCombs  wrote:
> >
> > Michael --
> > If you invest $10,000 in a stock and it drops to $6,000, but then 
> > returns to $9,000, and then you sell it, that stock has experienced a 
> > $4,000 MDD, but only a $1,000 loss.
> > 
> > -- Keith
> > 
> > On 8/16/2010 16:25, michaels_musings wrote:
> > >
> > > Hi All,
> > >
> > > This has me baffled. I run an optimization and I end up with the Max. 
> > > System Drawdown greater than the listed Losers Total Loss. Here's the 
> > > fields in question.
> > >
> > > Capital 100,000.00
> > > Trade Size 10,000.00
> > >
> > > Net Profit 5,315.42
> > > Max. Trade Drawdown -2,615.84
> > > Max. Trade % Drawdown -26.15
> > > Max. Sys Drawdown -2,615.84
> > > Max. Sys % Drawdown -2.49
> > > # Trades 17.00
> > > Avg Profit/Loss 312.67
> > > Avg % Profit/Loss 3.13
> > > # of winners 11.00
> > > % of Winners 64.71
> > > W. Tot. Profit 6,548.24
> > > W. Avg. Profit 595.29
> > > W. Avg % Profit 5.95
> > > # of losers 6.00
> > > % of Losers 35.29
> > > L. Tot. Loss -1,232.81
> > > L. Avg. Loss -205.47
> > > L. Avg % Loss -2.05
> > > Percent Profit 0.06
> > > Percent Stop Loss 0.02
> > >
> > > Net Profit calculates correctly from # Trades, # of winners, W. Avg % 
> > > Profit, # of losers, and L. Avg % Loss.
> > >
> > > So why are Max. Trade Drawdown and Max. Sys Drawdown greater than 
> > > Losers Total Loss??? Isn't that technically impossible?
> > >
> > > Regards,
> > > Michael
> > >
> > > >From AB Guide:
> > > Max. trade drawdown - The largest peak to valley decline experienced 
> > > in any single trade
> > > Max. system drawdown - The largest peak to valley decline experienced 
> > > in portfolio equity
> > > L. Tot. Loss - No Entry. Expected definition: "Total loss from all 
> > > losing trades."
> > >
> > >
> >
>




[amibroker] Re: How to configure CAME to look for a Optimization target MINIMUM

2010-08-08 Thread Mike
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, "Matthias"  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, "Mike"  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-forward-optimization/
> > 
> > Mike
> > 
> > --- In amibroker@yahoogroups.com, "elizabeth19852002"  
> > 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
> > >
> >
>




[amibroker] Re: Formula assistance

2010-08-04 Thread Mike
Hi,

What you're asking for is usually quite difficult to obtain without looking 
into the future. Is your intent strictly for charting, or do you want to trade 
from the signals?

If just charting, looking into the future is valid. If wanting to use for trade 
signals, you will never be able to find the exact pivot points and any backtest 
based on looking into the future will give grossly exagerated results.

Try doing a search in the group for keywords such as pivot, etc. to get an idea 
of how people are handling a similar problem.

Mike

--- In amibroker@yahoogroups.com, "hrbmd22"  wrote:
>
> Hello All,
> 
> I am trying to write a formula in AFL and having some problems.  Basically, I 
> would like to trigger a buy or sell signal when a curve changes direction.  
> For example, a sell signal at the top of a sine wave, and a buy signal at the 
> bottom of the wave.  I've tried slope (rise/run) but that doesn't always 
> provide me with the properly timed signal.
> 
> If anybody has written something like this, I'd appreciate some help.
> 
> Thanks in advance!
> 
> Howard in Elvis' World
>




[amibroker] Re: Exit if L < L of Entry Bar

2010-08-04 Thread Mike
You're right. Sorry, I was not paying close enough attention. That's a pretty 
good reason to experiment with the ApplyStop approach. Though, ApplyStop can be 
difficult to understand at times.

Mike

--- In amibroker@yahoogroups.com, "rise_t575"  wrote:
>
> 
> 
> Thanks a lot Mike.
> 
> Btw - the
> 
> Sell = Low < ValueWhen(ExRem(Buy, Sell), Low);
> 
> solution doesn't work like stated, as the "Sell" variable within the ExRem() 
> function is not initiated before this code line has been executed.
> 
> --- In amibroker@yahoogroups.com, "Mike"  wrote:
> >
> > I believe that your understanding of stopTypeLoss is correct. 
> > stopTypeTrailing will move up over time to hang from from new highest 
> > highs. So no, stopTypeTrailing is not tied to the entry bar values.
> > 
> > Mike
> > 
> > --- In amibroker@yahoogroups.com, "rise_t575"  wrote:
> > >
> > > 
> > > 
> > > Thanks very much for all the help.
> > > 
> > > When looking at the logic of
> > > 
> > > ApplyStop(stopTypeLoss, stopModePoint, BuyPrice - Low, ...);
> > > 
> > > it seems like all variables used for the "Amount" parameter of the 
> > > ApplyStop() function refer to the entry bar (at least when using 
> > > stopTypeLoss - don't know if this is true when using e. g. 
> > > stopTypeTrailing), i. e. BuyPrice = value of BuyPrice array at entry bar, 
> > > and Low = value of Low array at entry bar.
> > > 
> > > Is my understanding of ApplyStop() parameters correct? And: Would this 
> > > statement be true as well when using stopTypeTrailing?
> > > 
> > > --- In amibroker@yahoogroups.com, "Edward Pottasch"  wrote:
> > > >
> > > > Valuewhen has the same issue with redundant signals as Ref does. I was 
> > > > simply answering to the question if Sell = L < Ref(L, - 
> > > > BarsSince(Buy)); is correct.  And it is correct. 
> > > > 
> > > > rgds Ed
> > > > 
> > > > 
> > > > 
> > > > 
> > > > 
> > > > From: Mike 
> > > > Sent: Wednesday, August 04, 2010 9:30 AM
> > > > To: amibroker@yahoogroups.com 
> > > > Subject: [amibroker] Re: Exit if L < L of Entry Bar
> > > > 
> > > > 
> > > >   
> > > > That is true only when you are certain that there are no redundant 
> > > > signals between the actual buy and the actual sell. For example,
> > > > 
> > > > Buy = Cross(High, 50);
> > > > Sell = Cross(50, High);
> > > > 
> > > > will not produce redundant signals (since the opposite cross must occur 
> > > > before a new cross can again occur). However,
> > > > 
> > > > Buy = High >= 50;
> > > > Sell = 50 > High;
> > > > 
> > > > will produce redundant signals (since the price can remain above the 
> > > > threshold for an extended duration) and using BarsSince will not give 
> > > > you the value at the time of the original Buy, but rather at the time 
> > > > of the most recent redundant signal.
> > > > 
> > > > Mike
> > > > 
> > > > --- In amibroker@yahoogroups.com, "Edward Pottasch"  wrote:
> > > > >
> > > > > hi,
> > > > > 
> > > > > yes that is correct.
> > > > > 
> > > > > same result would be:
> > > > > 
> > > > > Sell = L < Valuewhen(Buy,L);
> > > > > 
> > > > > when you make a plot of valuewhen(Buy,L) and Ref(L,-Barssince(Buy)) 
> > > > > you find they give the same result. Ref is a function that supports 
> > > > > variable periods:
> > > > > 
> > > > > http://www.amibroker.com/guide/a_varperiods.html
> > > > > 
> > > > > regards, Ed
> > > > > 
> > > > > 
> > > > > 
> > > > > 
> > > > > From: rise_t575 
> > > > > Sent: Wednesday, August 04, 2010 2:51 AM
> > > > > To: amibroker@yahoogroups.com 
> > > > > Subject: [amibroker] Exit if L < L of Entry Bar
> > > > > 
> > > > > 
> > > > > 
> > > > > Hello,
> > > > > 
> > > > > What would be the correct code for this?
> > > > > 
> > > > > Is this one 100% correct:
> > > > > 
> > > > > Sell = L < Ref(L, - BarsSince(Buy));
> > > > > 
> > > > > Or do I have to use the the EXREM() function somewhere within the 
> > > > > formula (I don't have any experience with this one)?
> > > > > 
> > > > > Thanks in advance!
> > > > >
> > > >
> > >
> >
>




[amibroker] Re: Exit if L < L of Entry Bar

2010-08-04 Thread Mike
I believe that your understanding of stopTypeLoss is correct. stopTypeTrailing 
will move up over time to hang from from new highest highs. So no, 
stopTypeTrailing is not tied to the entry bar values.

Mike

--- In amibroker@yahoogroups.com, "rise_t575"  wrote:
>
> 
> 
> Thanks very much for all the help.
> 
> When looking at the logic of
> 
> ApplyStop(stopTypeLoss, stopModePoint, BuyPrice - Low, ...);
> 
> it seems like all variables used for the "Amount" parameter of the 
> ApplyStop() function refer to the entry bar (at least when using stopTypeLoss 
> - don't know if this is true when using e. g. stopTypeTrailing), i. e. 
> BuyPrice = value of BuyPrice array at entry bar, and Low = value of Low array 
> at entry bar.
> 
> Is my understanding of ApplyStop() parameters correct? And: Would this 
> statement be true as well when using stopTypeTrailing?
> 
> --- In amibroker@yahoogroups.com, "Edward Pottasch"  wrote:
> >
> > Valuewhen has the same issue with redundant signals as Ref does. I was 
> > simply answering to the question if Sell = L < Ref(L, - BarsSince(Buy)); is 
> > correct.  And it is correct. 
> > 
> > rgds Ed
> > 
> > 
> > 
> > 
> > 
> > From: Mike 
> > Sent: Wednesday, August 04, 2010 9:30 AM
> > To: amibroker@yahoogroups.com 
> > Subject: [amibroker] Re: Exit if L < L of Entry Bar
> > 
> > 
> >   
> > That is true only when you are certain that there are no redundant signals 
> > between the actual buy and the actual sell. For example,
> > 
> > Buy = Cross(High, 50);
> > Sell = Cross(50, High);
> > 
> > will not produce redundant signals (since the opposite cross must occur 
> > before a new cross can again occur). However,
> > 
> > Buy = High >= 50;
> > Sell = 50 > High;
> > 
> > will produce redundant signals (since the price can remain above the 
> > threshold for an extended duration) and using BarsSince will not give you 
> > the value at the time of the original Buy, but rather at the time of the 
> > most recent redundant signal.
> > 
> > Mike
> > 
> > --- In amibroker@yahoogroups.com, "Edward Pottasch"  wrote:
> > >
> > > hi,
> > > 
> > > yes that is correct.
> > > 
> > > same result would be:
> > > 
> > > Sell = L < Valuewhen(Buy,L);
> > > 
> > > when you make a plot of valuewhen(Buy,L) and Ref(L,-Barssince(Buy)) you 
> > > find they give the same result. Ref is a function that supports variable 
> > > periods:
> > > 
> > > http://www.amibroker.com/guide/a_varperiods.html
> > > 
> > > regards, Ed
> > > 
> > > 
> > > 
> > > 
> > > From: rise_t575 
> > > Sent: Wednesday, August 04, 2010 2:51 AM
> > > To: amibroker@yahoogroups.com 
> > > Subject: [amibroker] Exit if L < L of Entry Bar
> > > 
> > > 
> > > 
> > > Hello,
> > > 
> > > What would be the correct code for this?
> > > 
> > > Is this one 100% correct:
> > > 
> > > Sell = L < Ref(L, - BarsSince(Buy));
> > > 
> > > Or do I have to use the the EXREM() function somewhere within the formula 
> > > (I don't have any experience with this one)?
> > > 
> > > Thanks in advance!
> > >
> >
>




[amibroker] Re: Query of Data

2010-08-04 Thread Mike
Use Automatic Analysis window to run an Exploration on all quotations of all 
symbols. Then use AddColumn to add whatever columns you want.

http://www.amibroker.com/guide/h_exploration.html

You can use the File button to export as a .csv file.

Mike

--- In amibroker@yahoogroups.com, Vishvesh  wrote:
>
> Hello Friends,
> 
> I am in little hurry if you can just help me out on this.
> 
> I want to run a query/exploration which give me Close,Volume, of each and
> every stock in my data folder from beginning. I know its little difficult
> but even if it stores the data in CSV format that would be fine to me.
> 
> Best Regards,
> Vishvesh
>




[amibroker] Re: Exit if L < L of Entry Bar

2010-08-04 Thread Mike
That is true only when you are certain that there are no redundant signals 
between the actual buy and the actual sell. For example,

Buy = Cross(High, 50);
Sell = Cross(50, High);

will not produce redundant signals (since the opposite cross must occur before 
a new cross can again occur). However,

Buy = High >= 50;
Sell = 50 > High;

will produce redundant signals (since the price can remain above the threshold 
for an extended duration) and using BarsSince will not give you the value at 
the time of the original Buy, but rather at the time of the most recent 
redundant signal.

Mike

--- In amibroker@yahoogroups.com, "Edward Pottasch"  wrote:
>
> hi,
> 
> yes that is correct.
> 
> same result would be:
> 
> Sell = L < Valuewhen(Buy,L);
> 
> when you make a plot of valuewhen(Buy,L) and Ref(L,-Barssince(Buy))  you find 
> they give the same result. Ref is a function that supports variable periods:
> 
> http://www.amibroker.com/guide/a_varperiods.html
> 
> regards, Ed
> 
> 
> 
> 
> From: rise_t575 
> Sent: Wednesday, August 04, 2010 2:51 AM
> To: amibroker@yahoogroups.com 
> Subject: [amibroker] Exit if L < L of Entry Bar
> 
> 
>   
> Hello,
> 
> What would be the correct code for this?
> 
> Is this one 100% correct:
> 
> Sell = L < Ref(L, - BarsSince(Buy));
> 
> Or do I have to use the the EXREM() function somewhere within the formula (I 
> don't have any experience with this one)?
> 
> Thanks in advance!
>




[amibroker] Re: How to close at the same day?

2010-08-04 Thread Mike
Charles,

Basically the same approach, except that you would need the Sell statement to 
be conditional upon recognizing the bar as being the last bar of the day as 
opposed to an absolute.

So, instead of the absolute:

Sell = 1;

You would need:

Sell = ;

I don't trade intra day, so I'm not the best source of information for this. 
However, for backtesting purposes, there are a number of ways to recognize a 
date change, including looking into the future and comparing the day of year, 
day of week, etc. This will not impact your backtest results since in live 
trading you would know that it was in fact the last bar of the day without 
looking into the future.

e.g.
Sell = DayOfYear() != Ref(DayOfYear(), 1); // Look ahead one bar
SellPrice = Close;

Alternatively, you could check for the time of the bar and trade when 
recognized as the closing bar. That might depend on there actually being a new 
bar for that time of day, which for low volume stocks might not happen. Again, 
I'm out of my element on this one. But, there are a number of posts from people 
asking how to trade between time x and time y for a given trading day. You can 
search for those in the forum.

Using timeframe functions might work here too. But again, I haven't played with 
those yet either.

Mike

--- In amibroker@yahoogroups.com, "chuck_win"  wrote:
>
> Mike,
> 
> If I use 5-m data for intraday trading, how to sell at close on same day?
> 
> Thanks.
> 
> Charles
> 
> --- In amibroker@yahoogroups.com, Tony M  wrote:
> >
> > Mike,
> > Thank you very much. That works.
> > TM
> > 
> > 
> > 
> > 
> > From: Mike 
> > To: amibroker@yahoogroups.com
> > Sent: Wed, April 14, 2010 10:28:26 PM
> > Subject: [amibroker] Re: How to close at the same day?
> > 
> >   
> > Are you using end of day data, or intra day? If end of day, try something 
> > like
> > 
> > SetTradeDelays( 0, 0, 0, 0);
> > SetOption("AllowSam eBarExit" , true);
> > 
> > Buy = ...;
> > BuyPrice = Open;
> > 
> > Sell = 1;
> > SellPrice = Close;
> > 
> > Mike
> > 
> > --- In amibro...@yahoogrou ps.com, Tony M  wrote:
> > >
> > > Please help me with a simple exit strategy: when backtesting, I open my 
> > > positions at the open in the morning, how can I close at the close of the 
> > > same day? 
> > > 
> > > I can use ApplyStop( stopTypeNBar, stopModeBars, 1) to close at the 
> > > second day, but I can not figure out a way to close at the same day. 
> > > 
> > > Thanks,
> > > TM
> > >
> >
>




[amibroker] Re: Exit if L < L of Entry Bar

2010-08-04 Thread Mike
You could probably just use ApplyStop with a dynamic stop level.

e.g. (untested)

ApplyStop(stopTypeLoss, stopModePoint, BuyPrice - Low, ...);

Alternatively, you could try ValueWhen combined with ExRem

e.g. (untested)

Sell = Low < ValueWhen(ExRem(Buy, Sell), Low);

Mike

--- In amibroker@yahoogroups.com, "rise_t575"  wrote:
>
> Hello,
> 
> What would be the correct code for this?
> 
> Is this one 100% correct:
> 
> Sell = L < Ref(L, - BarsSince(Buy));
> 
> Or do I have to use the the EXREM() function somewhere within the formula (I 
> don't have any experience with this one)?
> 
> Thanks in advance!
>




[amibroker] Re: FW: 64 bit Results

2010-08-03 Thread Mike
I don't use Mac's. But, I have two servers using the same hardware as the last 
generation Mac Pro. Specifically dual socket quad core (i.e. 2 chips @ 4 cores 
each = 8 physical cores) also known as Harpertown Xeon's. 

http://en.wikipedia.org/wiki/Harpertown_(microprocessor)#Harpertown

One box is using two Xeon E5420 overclocked to 3Ghz the other is using two 
QX9775 (desktop equivalent to Xeon E5482) overclocked to 3.8Ghz. Both boxes are 
screamingly fast, even when handicapped by the fully buffered memory (DDR2 800 
FB-DIMM)

The Nehalem Xeon's are supposed to put the Harpertown's to shame. So I can't 
imagine how incredibly fast that setup would be.

Mike

--- In amibroker@yahoogroups.com, "af_100"  wrote:
>
> Hello,
> 
> Everybody needs more power 
> I've got some unique requirements I have been struggling with. On top of 
> bunch of indicators on four charts (3 monitors, TWS and IB Controller on 
> third monitor) there is a bunch of scripts handling trades (every one runs an 
> entire trade from the very beginning to the very end). Once it is launch I do 
> not touch it. There are usually 5-10 scripts (3500 lines of code each) 
> running simultaneously handling trades (there is no limit on number of 
> trades, with the exception of hardware to handle them). There is one main 
> monitoring and launching script (with gfx menus;I trade off charts)to show 
> what all these trades are doing. All these scripts communicate with one 
> another. Some run overnight. Each maintains its own log, so it can be 
> interrupted, suspended, resumed, ..., etc. 
> I need the right hardware to handle all this stuff. I have been thinking 
> about a new models of Mac Pro running on Xeon processors (available August 
> 2010). I know that some of you have been using Mac Pro and some of you are 
> satisfied, some of you are still short of power. I would appreciate your 
> comments on your experience with Mac Pro and any suggestions on that matter.I 
> look at Mac Pro architecture and the construction. It looks very solid and 
> other workstations do not look as professional as Mac Pro. An alternative 
> would be to build a designated workstation based on Intel i7. What kind of 
> processors to use in my case: more cores or higher speed ?
> Any constructive help will be very appreciated.
> 
> AF
> 
> --- In amibroker@yahoogroups.com, Dennis Brown  wrote:
> >
> > Rob,
> > 
> > I just realized the importance of what you were saying about using AA to 
> > calculate static arrays.  One of the things that I have asked for was the 
> > ability to have a chart that refreshed no more often than once per X time 
> > to slow it down.  Using AA the way you are doing it would give me that 
> > ability.  I will have to experiment with that.  I thought I had no use for 
> > AA, so never really thought about it before.  This could be a good approach 
> > for my needs for the longer timeframe calculations.
> > 
> > Best regards,
> > Dennis
> > 
> > On Aug 3, 2010, at 7:13 AM, Dennis Brown wrote:
> > 
> > > Rob,
> > > 
> > > This is good to know that you made it work for you.  I have the same 
> > > issues and have only kicked around the ideas for implementing them.  One 
> > > minute calculations could be useful to many of my operations.  
> > > 
> > > I did do the reverse at one point before I went with futures trading.  I 
> > > had set up a second chart for very high resolution to eliminate bad 
> > > ticks.  Then I made artificial tickers of the clean data to feed my main 
> > > charts in realtime.  That was before we had static arrays, so it was too 
> > > slow.
> > > 
> > > Yes, I have often wanted to have more control over the number of bars 
> > > used in an array calculation.
> > > 
> > > BR,
> > > Dennis
> > > 
> > > On Aug 3, 2010, at 3:40 AM, Rob wrote:
> > > 
> > >> Dennis,
> > >> 
> > >> I actually already use Herman's technique of running the AA periodically 
> > >> to calculate results that I put into static arrays for access by my 
> > >> other charts. However, for my purposes the static arrays only need to be 
> > >> calculated every minute. I didn't know you could go down to second 
> > >> resolutions in the AA periodic running option.
> > >> 
> > >> Very simply the only reason I use this technique is that it allows me to 
> > >> calculate much longer static arrays than the rest of my charts need from 
> > >> an indicator basis. i.e my drawing code in my charts only requir

[amibroker] Re: Set specific symbol by code to use in optimization?

2010-08-03 Thread Mike
You can work around the disabled reports button by adding a custom entry to 
your Tools menu as follows:

Tools | Customize...
Change to "Tools" tab
Click "New" button (adds entry to list)
Change name from "New" to "Reports" in list
Enter the path to ReportEx.exe for "Command" (e.g. C:\Program 
Files\AmiBroker\ReportEx.exe)
Enter Reports\results.rlst for "Arguments".
Enter the path to AmiBroker root directory for "Initial Directory" (e.g. 
C:\Program Files\AmiBroker)
Click on Close

Now you can open the Reports anytime you want from the Tools menu.

Mike


--- In amibroker@yahoogroups.com, "michaels_musings"  
wrote:
>
> Uhg!
> 
> Still can't get this to do this  (Have tried many variations of the 
> below, these are the last setting just trying to get something to disk...)
> 
> I have set (Automatic Analysis window):
> 
> Settings -> General: 
> Apply to: 'use filter' -> Watchlist 'test01' (contains two symbols)
> 
> Settings -> Report:
> Results list shows: 'Detailed log'
> Checked -> Generate detailed reports for each symbol in individual backtest 
> (slow)
> Checked -> Include trade list in the report
> 
> Settings -> Old:
> Checked -> Overall summary
> Checked -> Settings
> Checked -> Per-Symbol summary
> Checked -> Ind. out of market pos.
> Trade list: -> 'Trade list with prices and pos. size
> Drawdown ->  '...(worst case)'
> 
> Code:
> SetOption("GenerateReport", 1 ); // force generation of full report 
> SetBacktestMode( backtestRegularRawMulti );
> OptimizerSetEngine("cmae");
> SetOption( "PortfolioReportMode", 0 );
> 
> Clicking:
> Optimize -> Old (v4.4) Optimizer
> 
> And I get no reports generated at all.  And worse, once it finishes it greys 
> out the Automatic Analysis window's "Reports" button.  Even though there are 
> other old reports.
> 
> # # # #
> 
> Anyone know what specific switch/code setting I'm missing to have each symbol 
> optimize separately and write the optimization report for each symbol to disk?
> 
> If I have to code it myself through fputs() , can someone link to an existing 
> .afl program?
> 
> Thanks All,
> Michael
> 
> Addition (yeah, I'm getting desperate):
> Oddly this produces two (backtest) reports (one for each individual symbol in 
> test01);
> 
> Clicking:
> Back Test -> Old (v4.4) Optimizer
> 
> ###
> So, have I inadvertently found a bug w/ "Optimize -> Old (v4.4) Optimizer"?
> 
> 
> --- In amibroker@yahoogroups.com, "Mike"  wrote:
> >
> > You do not need any scripting to do that. Just select a watchlist in the AA 
> > window then click on the arrow of the Optimize button to choose the old 
> > backtester (backtests each symbol one by one, generating unique reports 
> > along the way).
> > 
> > Mike
> > 
> > --- In amibroker@yahoogroups.com, "michaels_musings"  
> > wrote:
> > >
> > > Hi All,
> > > 
> > > I'm trying to automate a set of single symbol optimizations.  I want each 
> > > symbol to be optimized separately (e.g. not as a portfolio).
> > > 
> > > I'm thinking the "run_production.py" from  pete@ from the Files area, 
> > > that uses python to run every .afl file in a directory should work.  But, 
> > > I'm stuck on how to programmatically tell the optimizer which individual 
> > > symbol I desire run within each .afl code file.  (Obviously you can go 
> > > change the selected stock in AB, but that sorta kills off the automation 
> > > part ;)  Is there a SetOption I'm not understanding?
> > > 
> > > Anyone know a link to someone who's written up how to do something 
> > > similar?
> > > 
> > > Is there a way to do this within AB without resorting to something 
> > > external?
> > > 
> > > Thanks,
> > > Michael
> > > 
> > > Snipit from  run_production.py:
> > > # Script modified and ported to Python from TJ's sample in the 
> > > documentation by pete@
> > > # File revision: $Revision: 205 $
> > > import os
> > > from datetime import date
> > > from win32com.client import Dispatch
> > > 
> > > # START MODIFY TO FIT YOUR SETUP
> > > AFLFolder = "C:\\Program Files 
> > > (x86)\\AmiBroker\\Formulas\\Custom\\Strategies\\_Production"
> > > ResultFolder = 
> > > "C:\\Home\\Peter\\Documents\\Work\\Trading\\AmiBroker\\_Production"
> > > # END MODIFY TO FIT YOUR SETUP
> > >
> >
>




[amibroker] Re: Set specific symbol by code to use in optimization?

2010-08-03 Thread Mike
Michael,

Sorry, I believe that I have mislead you. I suspect that I was thinking about 
individual backtests, as opposed to individual optimizations.

Mike

--- In amibroker@yahoogroups.com, "michaels_musings"  
wrote:
>
> Uhg!
> 
> Still can't get this to do this  (Have tried many variations of the 
> below, these are the last setting just trying to get something to disk...)
> 
> I have set (Automatic Analysis window):
> 
> Settings -> General: 
> Apply to: 'use filter' -> Watchlist 'test01' (contains two symbols)
> 
> Settings -> Report:
> Results list shows: 'Detailed log'
> Checked -> Generate detailed reports for each symbol in individual backtest 
> (slow)
> Checked -> Include trade list in the report
> 
> Settings -> Old:
> Checked -> Overall summary
> Checked -> Settings
> Checked -> Per-Symbol summary
> Checked -> Ind. out of market pos.
> Trade list: -> 'Trade list with prices and pos. size
> Drawdown ->  '...(worst case)'
> 
> Code:
> SetOption("GenerateReport", 1 ); // force generation of full report 
> SetBacktestMode( backtestRegularRawMulti );
> OptimizerSetEngine("cmae");
> SetOption( "PortfolioReportMode", 0 );
> 
> Clicking:
> Optimize -> Old (v4.4) Optimizer
> 
> And I get no reports generated at all.  And worse, once it finishes it greys 
> out the Automatic Analysis window's "Reports" button.  Even though there are 
> other old reports.
> 
> # # # #
> 
> Anyone know what specific switch/code setting I'm missing to have each symbol 
> optimize separately and write the optimization report for each symbol to disk?
> 
> If I have to code it myself through fputs() , can someone link to an existing 
> .afl program?
> 
> Thanks All,
> Michael
> 
> Addition (yeah, I'm getting desperate):
> Oddly this produces two (backtest) reports (one for each individual symbol in 
> test01);
> 
> Clicking:
> Back Test -> Old (v4.4) Optimizer
> 
> ###
> So, have I inadvertently found a bug w/ "Optimize -> Old (v4.4) Optimizer"?
> 
> 
> --- In amibroker@yahoogroups.com, "Mike"  wrote:
> >
> > You do not need any scripting to do that. Just select a watchlist in the AA 
> > window then click on the arrow of the Optimize button to choose the old 
> > backtester (backtests each symbol one by one, generating unique reports 
> > along the way).
> > 
> > Mike
> > 
> > --- In amibroker@yahoogroups.com, "michaels_musings"  
> > wrote:
> > >
> > > Hi All,
> > > 
> > > I'm trying to automate a set of single symbol optimizations.  I want each 
> > > symbol to be optimized separately (e.g. not as a portfolio).
> > > 
> > > I'm thinking the "run_production.py" from  pete@ from the Files area, 
> > > that uses python to run every .afl file in a directory should work.  But, 
> > > I'm stuck on how to programmatically tell the optimizer which individual 
> > > symbol I desire run within each .afl code file.  (Obviously you can go 
> > > change the selected stock in AB, but that sorta kills off the automation 
> > > part ;)  Is there a SetOption I'm not understanding?
> > > 
> > > Anyone know a link to someone who's written up how to do something 
> > > similar?
> > > 
> > > Is there a way to do this within AB without resorting to something 
> > > external?
> > > 
> > > Thanks,
> > > Michael
> > > 
> > > Snipit from  run_production.py:
> > > # Script modified and ported to Python from TJ's sample in the 
> > > documentation by pete@
> > > # File revision: $Revision: 205 $
> > > import os
> > > from datetime import date
> > > from win32com.client import Dispatch
> > > 
> > > # START MODIFY TO FIT YOUR SETUP
> > > AFLFolder = "C:\\Program Files 
> > > (x86)\\AmiBroker\\Formulas\\Custom\\Strategies\\_Production"
> > > ResultFolder = 
> > > "C:\\Home\\Peter\\Documents\\Work\\Trading\\AmiBroker\\_Production"
> > > # END MODIFY TO FIT YOUR SETUP
> > >
> >
>




[amibroker] Re: OT: Windiws Mail

2010-07-30 Thread Mike
Ed,

I don't use TWS. But, if TWS is 32 bit, are you running with a 32 bit java? 
Likewise for 64 bit java for a 64 bit TWS (if 64 bit TWS even exists).

Mike

--- In amibroker@yahoogroups.com, "Edward Pottasch"  wrote:
>
> yes thanks I have checked that before and it even happened when Java was up 
> to date. 
> 
> Today however I need an update of Java so maybe it helps,
> 
> regards, Ed
> 
> 
> 
> 
> From: Tomasz Janeczko 
> Sent: Friday, July 30, 2010 10:46 AM
> To: amibroker@yahoogroups.com 
> Subject: Re: [amibroker] Re: OT: Windiws Mail
> 
> 
>   
> Hello,
> 
> Interactive Brokers TWS is Java program. If I were you I would first look for 
> appropriate version of Java virtual machine.
> 
> Best regards,
> Tomasz Janeczko
> amibroker.com
> 
> On 2010-07-30 07:47, Edward Pottasch wrote: 
> 
>   thanks for your reply. Will search a bit on the IB board if this TWS 
> vanishing has been reported. It doesn't happen everyday but I have my XP 
> machine running and a new W7 machine and it only happens on de W7 machine. I 
> hear the bells going that AB's real time connection is down and then I find 
> the TWS has completely disappeared,
> 
>   regards, Ed
> 
> 
> 
> 
>   From: danielwardadams 
>   Sent: Friday, July 30, 2010 4:05 AM
>   To: amibroker@yahoogroups.com 
>   Subject: [amibroker] Re: OT: Windiws Mail
> 
> 
> 
>   Ed,
>   This won't make you feel any better but I've also been having some weird 
> problems with a recent Windows 7 installation, e.g., Amibroker hanging 
> problem when trying to start it up. I've also seen it wander off into Visual 
> C++/Basic visual script errors and die.
> 
>   My first report of weirdness was trying to use Amibroker in conjunction 
> with the Intelligent Optimizer. I still haven't been able to get a good IO 
> run since my one success almost two weeks ago.
> 
>   Here is a link to my original post about it:
> 
>   http://finance.groups.yahoo.com/group/amibroker/message/151387
> 
>   I also use IB TWS and started having problems 2-3 weeks ago (can't pin it 
> down because I had been on vacation when they made 2 or 3 releases). It 
> didn't vanish on me but didn't have some functionality it did before 
> (attached stop orders not working properly). After "chatting" with IB support 
> people, I decided to go back to a version I knew worked correctly (end of May 
> TWS build). That has been working okay for me and I'm to be notified if 
> (when) my problem is fixed.
> 
>   Regarding the AB and IO problems I'm suspecting my database is corrupted 
> but I've recreated it (several times with both Quotes Plus and Amiquote) and 
> the problem reoccurs.
> 
>   Dan Adams
> 
>   --- In amibroker@yahoogroups.com, "Edward Pottasch"  wrote:
>   >
>   > hi Ara,
>   > 
>   > doesn't happen every day here. Will look on IB message boards if I can 
> find something. Other strange thing happen on this Window 7 machine as well. 
> Sometimes when I start Amibroker it "hangs". Need to kill it and start it 
> again. Other times when I shut down WIndows 7 it also "hangs" and have to 
> turn switch off to turn the machine of. Things like that ...
>   > 
>   > regards, Ed
>   > 
>   > 
>   > 
>   > 
>   > From: Ara Kaloustian 
>   > Sent: Thursday, July 29, 2010 10:08 PM
>   > To: amibroker@yahoogroups.com 
>   > Subject: Re: [amibroker] OT: Windiws Mail
>   > 
>   > 
>   > 
>   > 
>   > Ed, I have not used TWS much .. but it's bee OK last couple of days that 
> I had it on
>   > 
>   > 
>   > 
>   > From: Edward Pottasch 
>   > Sent: Thursday, July 29, 2010 12:03 PM
>   > To: amibroker@yahoogroups.com 
>   > Subject: Re: [amibroker] OT: Windiws Mail
>   > 
>   > 
>   > 
>   > 
>   > don't know the answer to that but I have a follow up OT question 
>   > 
>   > was just wondering if Windows 7 users have also experienced that the TWS 
> suddenly disappears, vanished, gone. Have to start it up again. Has something 
> to do with Java I believe. What did you do to solve the problem?
>   > 
>   > thanks, Ed
>   > 
>   > 
>   > 
>   > 
>   > From: Ara Kaloustian 
>   > Sent: Wednesday, July 28, 2010 9:53 PM
>   > To: AB-Main 
>   > Subject: [amibroker] OT: Windiws Mail
>   > 
>   > 
>   > 
>   > 
>   > I recently switched to Windows 7 and started using Windows Mail Live...
>   > 
>   > I have noticed that occasionally I do not receive emails sent to me.
>   > 
>   > I am using IMAP protocall with gmail account
>   > 
>   > Wonder if anyone else is having same problem? 
>   > 
>   > - Is it possible to configure it as a POP3 since I don't care about 
> synchronizing with multiple devices? 
>   > - Is POP3 more reliable with gmail?
>   > 
>   > 
>   > TIA
>   > 
>   > Ara
>   >
>




[amibroker] Re: Using BuyStop and SellStop orders - How does it work?

2010-07-30 Thread Mike
Pete,

It is not enough to just set the BuyPrice and SellPrice arrays. You must 
include the logic in your Buy and Sell statements. It is only the Buy and Sell 
statements that will determine whether or not a trade is taken.

e.g.
BuyStop = Ref(H, -1);
BuyPrice = Max(BuyStop, Low)
Buy = ... AND High >= BuyStop;

Mike

--- In amibroker@yahoogroups.com, "pcmoxon"  wrote:
>
> Sorry, I don't think I explained myself very well. The issue I am having is 
> that the BuyStop & SellStop are not being executed in the correct location. 
> It seems that as soon as a new bar is generated the BuyPrice & SellPrice get 
> recalculated meaning the orders are executed at an incorrect price level. Is 
> there some way of keeping the BuyPrice/SellPrice fixed?
> 
> Pete.
> 
> --- In amibroker@yahoogroups.com, cas soni  wrote:
> >
> > Hello pcmoxon,you didn't use PLOT..add this lines  SetChartOptions(0, 
> > chartShowDates); Plot(C,"Close",colorWhite,64);
> > 
> > 
> > 
> > PlotShapes(IIf(Buy , shapeSmallUpTriangle, shapeNone) ,colorGreen, 
> > 0,L,-20); 
> > 
> > PlotShapes(IIf(Sell  , shapeSmallDownTriangle, shapeNone) ,colorRed, 
> > 0,H,-20);
> > 
> > 
> > 
> > Plot(MA1,"\nDynPiv25",ParamColor("Color 
> > 1",ColorRGB(238,174,238)),stylethick);
> > 
> > Plot(MA2,"\nDynPiv50",ParamColor("Color1 
> > 2",ColorRGB(255,20,147)),styleline);
> > and make sure your market start time / end time is correctly set
> > 
> > Thank you
> > --- On Fri, 30/7/10, pcmoxon  wrote:
> > 
> > From: pcmoxon 
> > Subject: [amibroker] Using BuyStop and SellStop orders - How does it work?
> > To: amibroker@yahoogroups.com
> > Date: Friday, 30 July, 2010, 12:01 AM
> > 
> > 
> > 
> > 
> > 
> > 
> > 
> > 
> > 
> > 
> > 
> > 
> > 
> > 
> > 
> >  
> >  
> > 
> > 
> > 
> >   
> > 
> > 
> > 
> >   
> >   
> >   Hi,
> > 
> > 
> > 
> > I am trying to test a simple MA Cross over system that uses Buy-Stop and 
> > Sell-Stop orders. I can't for the life Of me workout how this should work.
> > 
> > 
> > 
> > What I want the system to do is only trade between the 'tstart' & 'tend' 
> > parameter. When there is a MA-Cross set a BuyStop or Sell stop order at the 
> > High/Low of the bar where the MA-Cross ocurred, so the trade is only 
> > entered when the stop order is taken out.
> > 
> > 
> > 
> > I would be very gratefull if someone can take a look at my code below and 
> > point me in the right direction to get this to work.
> > 
> > 
> > 
> > Thanks,
> > 
> > Pete
> > 
> > 
> > 
> > //
> > 
> >//+--+
> > 
> >//| Variable/Parameters Start|
> > 
> >//+--+
> > 
> > //  Set up the lengths for the moving averages
> > 
> > Length1= Param("Fast MA",3,1,20,1);
> > 
> > Length2= Param("Slow MA",30,21,80,1);
> > 
> > // Trade Times
> > 
> > tstart = 07; 
> > 
> > tend   = 15; 
> > 
> > time_valid = TimeNum() >= tstart AND TimeNum() <= tend; 
> > 
> > 
> > 
> > //+--+
> > 
> >//| Buy Sell Logic   |
> > 
> >//+--+
> > 
> > MA1 = MA(C,Length1);
> > 
> > MA2 = MA(C,Length2);
> > 
> > 
> > 
> > Buy   = Ref(Cross(MA1,MA2),-1) AND time_valid;
> > 
> > Short = Ref(Cross(MA2,MA1),-1) AND time_valid;
> > 
> > Sell = Short;
> > 
> > Cover = Buy;
> > 
> > 
> > 
> > BuyStop  = Ref(H,-1);
> > 
> > SellStop = Ref(L,-1);
> > 
> > 
> > 
> > BuyPrice  = Max( BuyStop, Low ); // make sure buy price not less than Low 
> > 
> > SellPrice = Min( SellStop, High ); // make sure sell price not greater than 
> > High 
> > 
> > 
> > 
> > Buy  = ExRem(Buy,Sell);
> > 
> > Sell = ExRem(Sell,Buy);
> >
>




[amibroker] Re: Definition of backtester object properties

2010-07-28 Thread Mike
Ray,

A while ago I had reason to write low level custom backtester code in place of 
the default backtester. I instrumented my code at every step with many _TRACE 
statements, thereby giving me a peak as to what was really going on in the 
backtester.

http://www.amibroker.com/guide/afl/afl_view.php?id=222

I have not yet made an attempt to address the open gains issue. However, I do 
know how I would initially try to solve it. Tomasz once demonstrated that you 
can manually alter the cash property to affect the taking of trades. That might 
be the way to go.

http://finance.groups.yahoo.com/group/amibroker/message/114784

Mike

--- In amibroker@yahoogroups.com, "raymondpconnolly"  
wrote:
>
> 
> 
> Mike,
> 
> thanks for the info I've spent a week trying to get to the bottom of these 
> property relationships and unless I missed something I didn't see any of this 
> in the documentation nor did I get any response from support on the issue.
> 
> So reading between the lines from your posts did you use the detail log of 
> the AA to figure this out?  As useful as the information  you've provided is, 
> perhaps more useful to someone like myself who is trying to gain proficiency 
> in programming this software are any general diagnostic techniques you might 
> be willing to share.
> 
> Back to the .cash issue, have you modeled taking additional positions with 
> open position gain with low level CBT code?  At the moment the basic 
> behaviour will suffice for my systems but I would be interested to know if 
> you've delt with the issue and if so how in general for future reference.
> 
> Ray
> 
> 
> 
> --- In amibroker@yahoogroups.com, "Mike"  wrote:
> >
> > One thing to keep in mind is that open position gains are not added to the 
> > Cash property and are thus not available for taking additional positions 
> > (i.e. the taking of positions is dependent upon the availability of Cash).
> > 
> > http://finance.groups.yahoo.com/group/amibroker/message/148014
> > 
> > Mike
> > 
> > --- In amibroker@yahoogroups.com, "raymondpconnolly"  
> > wrote:
> > >
> > > Thanks Mike...I will go through it...I greatly appreciate your response.
> > > 
> > > Ray
> > > 
> > > --- In amibroker@yahoogroups.com, "Mike"  wrote:
> > > >
> > > > A reply that I made to an earlier thread might be helpful. Note that 
> > > > despite the verbal description in the link below, I seem to recall that 
> > > > AmiBroker stores bo.MarginLoan as a negative number that gets added to 
> > > > equity.
> > > > 
> > > > http://finance.groups.yahoo.com/group/amibroker/message/127764
> > > > 
> > > > Mike
> > > > 
> > > > --- In amibroker@yahoogroups.com, "raymondpconnolly" 
> > > >  wrote:
> > > > >
> > > > > Hi All,
> > > > > 
> > > > > I've written some CBT code to calculate custom metrics   Max_Equity, 
> > > > > Min_Cash, Max_Margin_loan.  The problem I am having Is that I'm not 
> > > > > sure how to interpret the output because I'm uncertain about the 
> > > > > definition of backtester object properties bo.Equity, bo.Cash, 
> > > > > bo.MarginLoan where bo is the bactester object.
> > > > > 
> > > > > From the User Guide topic "Portfolio-level back testing" : "New 
> > > > > backtester works on PORTFOLIO LEVEL, it means that there is single 
> > > > > portfolio equity and positionsizing refers to portfolio equity. 
> > > > > Portfolio equity is equal toavailable cash plus sum of all 
> > > > > simultaneously open positions at given time."
> > > > > 
> > > > > Is it correct to conclude from the above that for a margin account 
> > > > > Portfolio equity includes Marginloan? Therefore if I defined the 
> > > > > equity that I provide as "Owners Equity" vs. the broker provided 
> > > > > "Maginloan" the following would be true:
> > > > > 
> > > > > (1) bo.Equity = Owners Equity + bo.MarginLoan = bo.Cash + sum of all 
> > > > > simultaneously open positions at given time?
> > > > > 
> > > > > (2) bo.Equity = Owners Equity/MarginRate = bo.Cash +  sum of all 
> > > > > simultaneously open positions at given time?
> > > > > 
> > > > > or is it the case that:
> > > > > 
> > > > > (3) bo.Equity = Owners Equity = bo.Cash + sum of all simultaneously 
> > > > > open positions at given time. (and bo.MarginLoan is simply a separate 
> > > > > number)?
> > > > > 
> > > > > or are there other components in Portfolio equity that I've missed 
> > > > > completely?
> > > > > 
> > > > > If anyone can help with this I would really appreciate it.
> > > > > 
> > > > > Regards,
> > > > > Ray
> > > > >
> > > >
> > >
> >
>




[amibroker] Re: Definition of backtester object properties

2010-07-28 Thread Mike
One thing to keep in mind is that open position gains are not added to the Cash 
property and are thus not available for taking additional positions (i.e. the 
taking of positions is dependent upon the availability of Cash).

http://finance.groups.yahoo.com/group/amibroker/message/148014

Mike

--- In amibroker@yahoogroups.com, "raymondpconnolly"  
wrote:
>
> Thanks Mike...I will go through it...I greatly appreciate your response.
> 
> Ray
> 
> --- In amibroker@yahoogroups.com, "Mike"  wrote:
> >
> > A reply that I made to an earlier thread might be helpful. Note that 
> > despite the verbal description in the link below, I seem to recall that 
> > AmiBroker stores bo.MarginLoan as a negative number that gets added to 
> > equity.
> > 
> > http://finance.groups.yahoo.com/group/amibroker/message/127764
> > 
> > Mike
> > 
> > --- In amibroker@yahoogroups.com, "raymondpconnolly"  
> > wrote:
> > >
> > > Hi All,
> > > 
> > > I've written some CBT code to calculate custom metrics   Max_Equity, 
> > > Min_Cash, Max_Margin_loan.  The problem I am having Is that I'm not sure 
> > > how to interpret the output because I'm uncertain about the definition of 
> > > backtester object properties bo.Equity, bo.Cash, bo.MarginLoan where bo 
> > > is the bactester object.
> > > 
> > > From the User Guide topic "Portfolio-level back testing" : "New 
> > > backtester works on PORTFOLIO LEVEL, it means that there is single 
> > > portfolio equity and positionsizing refers to portfolio equity. 
> > > Portfolio equity is equal toavailable cash plus sum of all 
> > > simultaneously open positions at given time."
> > > 
> > > Is it correct to conclude from the above that for a margin account 
> > > Portfolio equity includes Marginloan? Therefore if I defined the equity 
> > > that I provide as "Owners Equity" vs. the broker provided "Maginloan" 
> > > the following would be true:
> > > 
> > > (1) bo.Equity = Owners Equity + bo.MarginLoan = bo.Cash + sum of all 
> > > simultaneously open positions at given time?
> > > 
> > > (2) bo.Equity = Owners Equity/MarginRate = bo.Cash +  sum of all 
> > > simultaneously open positions at given time?
> > > 
> > > or is it the case that:
> > > 
> > > (3) bo.Equity = Owners Equity = bo.Cash + sum of all simultaneously open 
> > > positions at given time. (and bo.MarginLoan is simply a separate number)?
> > > 
> > > or are there other components in Portfolio equity that I've missed 
> > > completely?
> > > 
> > > If anyone can help with this I would really appreciate it.
> > > 
> > > Regards,
> > > Ray
> > >
> >
>




[amibroker] Re: Definition of backtester object properties

2010-07-27 Thread Mike
A reply that I made to an earlier thread might be helpful. Note that despite 
the verbal description in the link below, I seem to recall that AmiBroker 
stores bo.MarginLoan as a negative number that gets added to equity.

http://finance.groups.yahoo.com/group/amibroker/message/127764

Mike

--- In amibroker@yahoogroups.com, "raymondpconnolly"  
wrote:
>
> Hi All,
> 
> I've written some CBT code to calculate custom metrics   Max_Equity, 
> Min_Cash, Max_Margin_loan.  The problem I am having Is that I'm not sure how 
> to interpret the output because I'm uncertain about the definition of 
> backtester object properties bo.Equity, bo.Cash, bo.MarginLoan where bo is 
> the bactester object.
> 
> From the User Guide topic "Portfolio-level back testing" : "New backtester 
> works on PORTFOLIO LEVEL, it means that there is single portfolio equity 
> and positionsizing refers to portfolio equity. Portfolio equity is equal 
> toavailable cash plus sum of all simultaneously open positions at given 
> time."
> 
> Is it correct to conclude from the above that for a margin account 
> Portfolio equity includes Marginloan? Therefore if I defined the equity that 
> I provide as "Owners Equity" vs. the broker provided "Maginloan" the 
> following would be true:
> 
> (1) bo.Equity = Owners Equity + bo.MarginLoan = bo.Cash + sum of all 
> simultaneously open positions at given time?
> 
> (2) bo.Equity = Owners Equity/MarginRate = bo.Cash +  sum of all 
> simultaneously open positions at given time?
> 
> or is it the case that:
> 
> (3) bo.Equity = Owners Equity = bo.Cash + sum of all simultaneously open 
> positions at given time. (and bo.MarginLoan is simply a separate number)?
> 
> or are there other components in Portfolio equity that I've missed 
> completely?
> 
> If anyone can help with this I would really appreciate it.
> 
> Regards,
> Ray
>




[amibroker] Re: question for Custom Backter specialists

2010-07-27 Thread Mike
Ed,

Try moving the calculation of bi_start inside the CBT code.

if (Status("action") == actionPortfolio)
{
  bi_start = ...;
}

Mike

--- In amibroker@yahoogroups.com, "Edward Pottasch"  wrote:
>
> hi,
> 
> I am working on code that allows for the combination of multiple systems. 
> Combining signals leads to situations that you need to cover 1 position and 
> buy 3 positions at the same bar. Therefor in high level AFL you can not 
> define the positionSize properly since it needs a separate size for the cover 
> and buy but you are only allowed to fill 1 array element in the positionSize 
> array.
> 
> So what I did is first define the buy/sell etc arrays and then I defined 
> separate positionSize arrays, positionSizeBuy, PositionSizeSell etc.
> 
> Then I define a dummy positionSize array so that the proper signals are 
> calculated except that in some cases the positionSize is at fault.
> 
> Then I use the "Custom Backtester" CBT to change the positionSize, see code 
> below.
> 
> My question:  the CBT starts to loop through the bars starting at i = 0. 
> However, this index coincides with the start bar of the backtest which you 
> set in the AA window. The arrays in which I have set the positionSize I 
> calculated outside the CBT and have their index starting at the true starting 
> index of the complete data array.
> 
> So then I calculate the index at which the backtest starts and call that 
> bi_start, using:
> 
> bi_start = LastValue(ValueWhen(Status("firstbarintest"),bi));
> 
> This number I want to use inside the CBT code, for instance like: 
> positionSizeBuy[ bi_start + i ], to access the proper positionSize for a 
> certain element.
> 
> But once inside the CBT it does not recognise bi_start, it is set to 0. Why 
> is this?
> 
> thanks, Ed
> 
> 
> snippet of code:
> 
> 
> bi_start = LastValue(ValueWhen(Status("firstbarintest"),bi));
> "";
> "bi_start: " + WriteVal(bi_start);
> "barindex backtest test: " + WriteVal(bi - bi_start);
> "BarIndex(): " + WriteVal(bi);
> 
> // custom backtest. Replace dummy positionSize
> SetCustomBacktestProc("");
> if (Status("action") == actionPortfolio)
> {
> 
> bo = GetBacktesterObject();
> bo.PreProcess(); 
> 
> for (i = 0; i < BarCount; i++)
> {
> 
>  //_TRACE("bi_start");// + " " + bi_start[ i ];
>  
>  for (sig = bo.GetFirstSignal(i); sig; sig = bo.GetNextSignal(i))
>  { 
>  
>   _TRACE("sig: " + sig.IsEntry() + " " + sig.IsExit() + " " + sig.IsLong() + 
> " " + sig.IsScale() + " " + i + " bi_start: " +  bi_start);
>  
>   // buy -1,0,-1,0
>   if (sig.IsEntry() AND !sig.IsExit() AND sig.IsLong() AND !sig.IsScale())
>   {
>//_TRACE("Buy" + i);
> sig.PosSize = positionSizeBuy[ bi_start + i ];
>   }
>   // short -1,0,0,0
>   else if (sig.IsEntry() AND !sig.IsExit() AND !sig.IsLong() AND 
> !sig.IsScale())
>   {
>//_TRACE("Short" + i);
>sig.PosSize = positionSizeShort[ bi_start + i ];
>   }
>   // ScaleIn (long or short) 0,0,-1,-1
>   else if (!sig.IsEntry() AND !sig.IsExit() AND sig.IsLong() AND 
> sig.IsScale())
>   {
>//_TRACE("ScaleIn Long/Short" + i);
>sig.PosSize = Max(positionSizeBuy[ bi_start + i ],positionSizeShort[ 
> bi_start + i ]);
>   }
>   // sell 0,-1,-1,0
>   else if (!sig.IsEntry() AND sig.IsExit() AND sig.IsLong() AND 
> !sig.IsScale())
>   {
>//_TRACE("Sell" + i);
>sig.PosSize = positionSizeSell[ bi_start + i ];
>   }
>   // cover 0,-1,0,0
>   else if (!sig.IsEntry() AND sig.IsExit() AND !sig.IsLong() AND 
> !sig.IsScale())
>   {
>//_TRACE("Cover" + i);
>sig.PosSize = positionSizeCover[ bi_start + i ];
>   }
>   // ScaleOut (long or short) 0,0,0,-1
>   else if (!sig.IsEntry() AND !sig.IsExit() AND !sig.IsLong() AND 
> sig.IsScale())
>   {
>//_TRACE("ScaleOut Long/Short" + i);
>sig.PosSize = Max(positionSizeBuy[ bi_start + i ],positionSizeShort[ 
> bi_start + i ]);
>   }
>  }
>  bo.ProcessTradeSignals(i);
> }
> bo.PostProcess();
> }
>




[amibroker] Re: Trading Systems, Position Sizing and Monte Carlo Analysis

2010-07-26 Thread Mike
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, "Matthias K."  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 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)
> 
>  
&g

[amibroker] Re: New System Question

2010-07-26 Thread Mike
Yup, on one of my builds I have a large side panel fan that sits recessed 
inside the case pulling air from the outside in. The Thermalright's did not fit 
and I had to step down to the Zalmans.

Mike

--- In amibroker@yahoogroups.com, Paul D  wrote:
>
> I actually agree that the Thermalright coolers are the way to go. I happened 
> to 
> have a Zalman laying around from an older build, so I used that but I have 
> read 
> time and time again that the Thermalright coolers are the best in terms of 
> superior temps. I would have switched to this cooler but it is so tall that 
> it 
> is within 1-2mm of not fitting in my case, so I don't want to risk buying it 
> and 
> having it not fit.
> 
> Paul
> 
> 
> 
> 
> 
> From: Mike 
> To: amibroker@yahoogroups.com
> Sent: Sat, July 24, 2010 11:28:23 AM
> Subject: [amibroker] Re: New System Question
> 
>   
> For very little difference in price you can go with Thermalright coolers, 
> instead of Zalman, and get measurably superior temperatures.
> 
> Even when switching to liquid cooling, I was unable to get a better overclock 
> than I got from air cooling using Thermalright Ultra 120 eXtreme.
> 
> http://www.thermalright.com/new_a_page/product_page/product_cpu_cooler_1366.html
> 
> That was almost 2 years ago, but they were unbeatable then, and one heck of a 
> lot cheaper than all the $$$ that I poured into liquid cooling! However, I 
> did 
> have a lot of fun putting together the liquid cooled system ;)
> 
> Mike
> 
> --- In amibroker@yahoogroups.com, Paul D  wrote:
> >
> > Hi Rob and other system builders,
> > 
> > In 2009 I built my own i7 920 and overclocked it to a very very stable 3900 
> > megahertz. I have XP 64 bit on it.
> > 
> > In a Tradestation forums thread I posted a very detailed shopping list from 
> > Newegg of all the parts I used (more or less) and show that it can be done 
> > very 
> >
> > cheap. In my opinion, the 920 version is (or at least was) the most 
> > affordable 
> 
> > in terms of bang for your buck once overclocked. I had some problems 
> > getting 
> > things cool enough with all 8 virtual cores going, so I turned off the 
> > hyperthreading and just run with 4 cores. 
> > 
> > 
> > Attached is a PDF of my shopping list complete with colorful pictures of my 
> > i7 
> 
> > 920 build during and after. FYI, I was going for lowest price rather than 
> > the 
> > very nicest stuff, though I did not skimp on mobo, power supply, CPU, or 
> >memory. 
> >
> > The case, graphics card, and fans were not the best (or quietest). 
> > 
> > 
> > 
> > Hope this helps.
> > 
> > Paul
> > 
> > 
> > 
> > 
> > From: Rob 
> > To: amibroker@yahoogroups.com
> > Sent: Thu, July 22, 2010 2:38:22 AM
> > Subject: [amibroker] New System Question
> > 
> > 
> > Hi TJ,
> > 
> > I am considering building myself a new computer system. Basically I am 
> > running 
> 
> > AB on a Mac Pro right now. 8GB Ram (ram is not one my constraints). I am 
> >running 
> >
> > 2 x quad core Intel Xeon X5365 2.99 Ghz processors.
> > 
> > I use AB for real time day trading... (not backtesting)... but I am pushing 
> > the 
> >
> > core I run AB on to the max pretty much (My performance indicator in AB 
> > runs 
> > pretty consistently between 200 - 260%... I also have another 4 charts 
> > running 
> 
> > on another instance of AB to utilise another core.
> > 
> > Question is, in building a new system, what should I be looking for 
> > maximise AB 
> >
> > performance? Obviously I am looking at the i7 range of processors. 
> > However, 
> >
> > given that I can only utilise one core per instance of AB (and I want to 
> > run as 
> >
> > few instances of AB as possible), should I less concerned with going for 
> > more 
> > cores and more concerned with perhaps overclocking the cores I do have...?
> > 
> > I could go the whole hog and overclock a Intel Core i7-980X Extreme Edition 
> > to 
> 
> > 4Ghz... I don't know if that would be overkill given there would be a lot 
> > of 
> > processing power I couldn't access? (although having 12Mb of onboard 
> > cache 
> 
> > looks attractive since I could run larger DB's in AB more quickly).
> > 
> > Any other critical issues I should be thinking of in terms of speed running 
> > AB...?
> > 
> > Thanks for your time.
> >
>




[amibroker] Re: Yet another new system question/problem

2010-07-24 Thread Mike
Sounds like an overclock gone bad. I wrote my own IO equivalent and came across 
similar errors when running on an 8 core system overclocked to 4.0 Ghz. 
Reducing the overclock (and necessary voltages) down to 3.8 Ghz got me back to 
the races again :)

Mike

--- In amibroker@yahoogroups.com, "danielwardadams"  wrote:
>
> I recently built a new computer and I've been having strange problems running 
> Amibroker together with Intelligent Optimizer (IO) ever since. It seems to 
> work fine for everything else so I'm assuming it's not a hardware or 
> Operating System (64 Bit Windows 7) problem.
> 
> This morning I (mistakingly -- see later) saw in the Amibroker Compatibility 
> Chart in the User's Guide that Quotes Plus isn't compatible with 64 bit 
> Amibroker so I thought my problem might be Quotes Plus database related. So I 
> tried to run my AB/IO combination with a Yahoo Amiquote EOD database instead. 
> I had a similar problem with AB crashing on the second IO invocation (it 
> works fine for the first one).
> 
> When I saw the problem reoccur, I looked closer at the compatibility chart 
> and see that everything (including Quotes Plus) is supposed to run with 32 
> bit AB which is what I have.
> 
> So I'm back to ground zero and it's evidently not a database problem.
> 
> My error text is: "NSBasic Script Error on line 7548. An error number 
> -2147417851 was generated by an ActiveX object." It happens after one 
> optimization has been run but before it can start the next one (my IO batch 
> file has 100 tickers in it).
> 
> I have been making this same run weekly for the past 4-5 years (but formerly 
> with 32 bit XP) so I'm pretty sure my IO setup, my AFL, etc. are okay. Fred 
> Tonetti (father of IO) held my hand for awhile last week and I got one run to 
> work but I have no idea why. Today nothing is working again. Sine it did work 
> once, it seems it has to be some type of setting someplace (??).
> 
> Any help/clues/diagnostic approaches would be appreciated.
> 
> Dan
> 
> (Processor is a quad core AMD Athlon II 930 but it's only running in one 
> core. Running with 4GB RAM, 64 Bit W7, and AB 5.30 Professional).
>




[amibroker] Re: New System Question

2010-07-24 Thread Mike
For very little difference in price you can go with Thermalright coolers, 
instead of Zalman, and get measurably superior temperatures.

Even when switching to liquid cooling, I was unable to get a better overclock 
than I got from air cooling using Thermalright Ultra 120 eXtreme.

http://www.thermalright.com/new_a_page/product_page/product_cpu_cooler_1366.html

That was almost 2 years ago, but they were unbeatable then, and one heck of a 
lot cheaper than all the $$$ that I poured into liquid cooling! However, I did 
have a lot of fun putting together the liquid cooled system ;)

Mike

--- In amibroker@yahoogroups.com, Paul D  wrote:
>
> Hi Rob and other system builders,
> 
> In 2009 I built my own i7 920 and overclocked it to a very very stable 3900 
> megahertz. I have XP 64 bit on it.
> 
> In a Tradestation forums thread I posted a very detailed shopping list from 
> Newegg of all the parts I used (more or less) and show that it can be done 
> very 
> cheap. In my opinion, the 920 version is (or at least was) the most 
> affordable 
> in terms of bang for your buck once overclocked. I had some problems getting 
> things cool enough with all 8 virtual cores going, so I turned off the 
> hyperthreading and just run with 4 cores. 
> 
> 
> Attached is a PDF of my shopping list complete with colorful pictures of my 
> i7 
> 920 build during and after. FYI, I was going for lowest price rather than the 
> very nicest stuff, though I did not skimp on mobo, power supply, CPU, or 
> memory. 
> The case, graphics card, and fans were not the best (or quietest). 
> 
> 
> 
> Hope this helps.
> 
> Paul
> 
> 
> 
> 
> From: Rob 
> To: amibroker@yahoogroups.com
> Sent: Thu, July 22, 2010 2:38:22 AM
> Subject: [amibroker] New System Question
> 
>
> Hi TJ,
> 
> I am considering building myself a new computer system. Basically I am 
> running 
> AB on a Mac Pro right now. 8GB Ram (ram is not one my constraints). I am 
> running 
> 2 x quad core Intel Xeon X5365 2.99 Ghz processors.
> 
> I use AB for real time day trading... (not backtesting)... but I am pushing 
> the 
> core I run AB on to the max pretty much (My performance indicator in AB runs 
> pretty consistently between 200 - 260%... I also have another 4 charts 
> running 
> on another instance of AB to utilise another core.
> 
> Question is, in building a new system, what should I be looking for maximise 
> AB 
> performance? Obviously I am looking at the i7 range of processors. 
> However, 
> given that I can only utilise one core per instance of AB (and I want to run 
> as 
> few instances of AB as possible), should I less concerned with going for more 
> cores and more concerned with perhaps overclocking the cores I do have...?
> 
> I could go the whole hog and overclock a Intel Core i7-980X Extreme Edition 
> to 
> 4Ghz... I don't know if that would be overkill given there would be a lot of 
> processing power I couldn't access? (although having 12Mb of onboard 
> cache 
> looks attractive since I could run larger DB's in AB more quickly).
> 
> Any other critical issues I should be thinking of in terms of speed running 
> AB...?
> 
> Thanks for your time.
>




[amibroker] Re: Just started looking at forex and am frustrated...

2010-07-24 Thread Mike
You can add your own custom metrics and display them with more decimal points.

How to add:
http://www.amibroker.com/guide/a_custommetrics.html

How to control decimal places (sse AddCustomMetric method):
http://www.amibroker.com/guide/a_custombacktest.html

Mike

--- In amibroker@yahoogroups.com, "Owen"  wrote:
>
> that the backtest reports display only two digits after the decimal. When 
> dealing with four-digit prices and trade wins/losses, this makes the report 
> much less useful. Is there any way to get four-digit results? If so, I 
> haven't found it.
> 
> Thanks.
>




[amibroker] Re: Stop loss / Take Profit on same candles

2010-07-23 Thread Mike
Hi,

What is important to realize is that BuyPrice and SellPrice are arrays, with 
elements for each and every bar. By saying:

SellPrice = BuyPrice + 2;

You are actually using *today's* BuyPrice + 2. Every day you are recalculating 
a new SellPrice using the new BuyPrice.

To access an array value at some distinct point in the past, you can use the 
ValueWhen function. Just be sure to strip out redundant values (i.e. ExRem) 
when  using it.

e.g.

UniqueBuys = ExRem(Buy, Sell);
SellPrice = ValueWhen(UniqueBuys, BuyPrice) + 2;

However, for your particular case, you would probably be well served by using 
ApplyStop function. I believe that a profit target stop and a maximum loss stop 
would accomplish what you describe.

http://www.amibroker.com/guide/afl/afl_view.php?id=20

Mike

--- In amibroker@yahoogroups.com, "thomasoxford3rd"  wrote:
>
> hello fellow AB users!
> 
> I'm a new user and forum-participant...amidst the various examples posted on 
> the website, I've seen many wherein a buy signal is entered when, say, 
> Cross(A, B)  [ie, A > B] and you cover when Cross(B, SomethingElse).
> 
> But surprisingly (or maybe i didn't look well enough!), I am having trouble 
> finding something as simple (?) as:
> 1. say, you buy Apple shares prices test a support of $100. This is easy to 
> test: 
> BuyPrice = 100;
> Buy = Ref(Low, -1) > Support AND Low < Support;   [ie, if yesterday we were 
> above support and today we breached below, we enter].  
> 2.  a standard risk-reward ratio is say 1-to-2: ie, stoploss at $99 and take 
> profit at $102. So, what i'm having trouble is finding is some example to do 
> this common strategy. I tried:
> SellPrice = BuyPrice + 2;
> SellStop = BuyPrice - 1;
> 
> Then however, i tried:
> Sell =Ref(Low, 1 ) < SellStop OR SellPrice > High ;  [ie, if 
> tomorrow's low is less than SellStop we get stopped out OR if today high is 
> higher than SellPrice is greater than the high, our take profit is hit] but 
> this does not seem to work.
> 
> Any advise much appreciated!
> thx
> 
> ps
> there is a slight subtlety on how to test if BOTH conditions are true but 
> first i'd like to learn how to walk before can try to run!
>




[amibroker] Re: Set specific symbol by code to use in optimization?

2010-07-22 Thread Mike
If you do want to do it by scripting, just pass the correct argument to the 
Backtest method of the Analysis object and still run against the single 
watchlist of all desired symbols.

Mike

--- In amibroker@yahoogroups.com, "Mike"  wrote:
>
> You do not need any scripting to do that. Just select a watchlist in the AA 
> window then click on the arrow of the Optimize button to choose the old 
> backtester (backtests each symbol one by one, generating unique reports along 
> the way).
> 
> Mike
> 
> --- In amibroker@yahoogroups.com, "michaels_musings"  
> wrote:
> >
> > Hi All,
> > 
> > I'm trying to automate a set of single symbol optimizations.  I want each 
> > symbol to be optimized separately (e.g. not as a portfolio).
> > 
> > I'm thinking the "run_production.py" from  pete@ from the Files area, that 
> > uses python to run every .afl file in a directory should work.  But, I'm 
> > stuck on how to programmatically tell the optimizer which individual symbol 
> > I desire run within each .afl code file.  (Obviously you can go change the 
> > selected stock in AB, but that sorta kills off the automation part ;)  Is 
> > there a SetOption I'm not understanding?
> > 
> > Anyone know a link to someone who's written up how to do something similar?
> > 
> > Is there a way to do this within AB without resorting to something external?
> > 
> > Thanks,
> > Michael
> > 
> > Snipit from  run_production.py:
> > # Script modified and ported to Python from TJ's sample in the 
> > documentation by pete@
> > # File revision: $Revision: 205 $
> > import os
> > from datetime import date
> > from win32com.client import Dispatch
> > 
> > # START MODIFY TO FIT YOUR SETUP
> > AFLFolder = "C:\\Program Files 
> > (x86)\\AmiBroker\\Formulas\\Custom\\Strategies\\_Production"
> > ResultFolder = 
> > "C:\\Home\\Peter\\Documents\\Work\\Trading\\AmiBroker\\_Production"
> > # END MODIFY TO FIT YOUR SETUP
> >
>




[amibroker] Re: Set specific symbol by code to use in optimization?

2010-07-22 Thread Mike
You do not need any scripting to do that. Just select a watchlist in the AA 
window then click on the arrow of the Optimize button to choose the old 
backtester (backtests each symbol one by one, generating unique reports along 
the way).

Mike

--- In amibroker@yahoogroups.com, "michaels_musings"  
wrote:
>
> Hi All,
> 
> I'm trying to automate a set of single symbol optimizations.  I want each 
> symbol to be optimized separately (e.g. not as a portfolio).
> 
> I'm thinking the "run_production.py" from  p...@... from the Files area, that 
> uses python to run every .afl file in a directory should work.  But, I'm 
> stuck on how to programmatically tell the optimizer which individual symbol I 
> desire run within each .afl code file.  (Obviously you can go change the 
> selected stock in AB, but that sorta kills off the automation part ;)  Is 
> there a SetOption I'm not understanding?
> 
> Anyone know a link to someone who's written up how to do something similar?
> 
> Is there a way to do this within AB without resorting to something external?
> 
> Thanks,
> Michael
> 
> Snipit from  run_production.py:
> # Script modified and ported to Python from TJ's sample in the documentation 
> by p...@...
> # File revision: $Revision: 205 $
> import os
> from datetime import date
> from win32com.client import Dispatch
> 
> # START MODIFY TO FIT YOUR SETUP
> AFLFolder = "C:\\Program Files 
> (x86)\\AmiBroker\\Formulas\\Custom\\Strategies\\_Production"
> ResultFolder = 
> "C:\\Home\\Peter\\Documents\\Work\\Trading\\AmiBroker\\_Production"
> # END MODIFY TO FIT YOUR SETUP
>




[amibroker] Re: Help setting a stop loss

2010-07-22 Thread Mike
You will have to express the difference as being relative to your entry.

Let's assume that the Open of day 2 was $50 and the Low of day 1 was $48.

- Your current code is placing a stop at 48 points below your entry.
- You probably want something like Open - Ref(Low, -1). Though, you will want 
to first make sure that the previous Low was actually lower than the Open!

Mike

--- In amibroker@yahoogroups.com, "scottr"  wrote:
>
> I would like to code a maximum stop loss that is triggered if the low of the 
> day hits the low on the day before my entry to a long position.
> 
> For ex, if my signal is generated on Day 1, I then enter a long position at 
> the open on Day 2.  I would like to at that point enter a Stop Loss that is 
> the low on Day 1.
> 
> This is what I'm entering:
> 
> ApplyStop (stopTypeLoss, stopModePoint, Ref(Low,-1), ExitAtStop=1);
> 
> It isn't working.  If anyone has any thoughts as to what I may be doing 
> wrong, I would very much appreciate it.  Thanks.  Scott
>




[amibroker] Re: New System Question

2010-07-22 Thread Mike
Michael,

First, the number suggested by AB to finish the optimization is near useless. 
It typically is a gross over estimate of the actual required time. If you want 
to know the real time, you pretty much just have to let it run.

Second, the licencing restricts the number of machines, not the number of 
cores. There is a trick to leverage multiple cores by a single user, albeit via 
multiple user accounts on the same machine. I'm assuming that this is in 
accordance with licencing since the result is effectively the same as running 
multiple instances under a single user account (except that each instance is 
now uniquely accessible via COM). Refer to MCO in the file section of this 
group for an example.

So, it is already possible to leverage the full power of a multi core machine 
without any disregard of licencing.

I'm not a lawyer, but to my understanding: Using your licence on a more 
powerful single machine, that happens to be owned by Amazon and accessed (by 
one person at a time) over the web, is probably still within the limitations of 
the licence.

Mike

--- In amibroker@yahoogroups.com, "michaels_musings"  
wrote:
>
> --- In amibroker@yahoogroups.com, "Rob"  wrote:
> >
> > But Mike, that would never be realistic for time critical real time usage 
> > such as day trading for example...? 
> 
> Hi Rob,
> 
> While my resultant question was regarding backtesting, for real time trading, 
> my thought would be, "Why not use a cloud?"
> 
> Install whatever software you need (IB, or whatever your brokerage platform 
> is, AB, etc.) onto the cloud and have the cloud be the one connecting to your 
> broker.
> 
> The connection between the cloud and your broker should be more stable and 
> less latent than the connection between where you are now and your broker 
> (Unless you trade from an AT&T data center?).
> 
> The question then becomes, a) are you babysitting your AB to see if it's 
> entering trades correctly?  Or b) are you the one pulling the trigger, based 
> upon AB recommendations?
> 
> a) works great, b) probably won't.
> 
> Best All,
> Michael
> 
> PS:  Mike, I understand your statements about licensing restrictions, but 
> until TJ makes AB multi-core usable they are mute.  Anyone who needs an 
> optimization to happen faster than 62 days (yes that is the actual number AB 
> said it would take for a four variable optimization on a database with ~45 
> stocks, ~100,000 ticks per stock) is going to ignore that clause.  Obviously 
> an Amazon cloud doesn't fulfill "not connected via network," but sorry, no 
> one cares.  At least until the software can get done what needs to be done in 
> a timely manner
>




[amibroker] Re: New System Question

2010-07-22 Thread Mike
If you went the "bare metal" approach, you would have a complete machine all to 
yourself. The bare metal approach is not "multi tenant", meaning that nobody 
else but you has access to the machine, it is not a shared resource. 100% of 
all cores and all CPU cache is yours and yours alone.

You can create and save a server "image" which is a byte for byte reproduction 
of a configured machine, including operating system, registry entries and 
installed software (e.g. a licensed copy of AB). Any time you wanted to use the 
machine, you would "launch" a new server based on your saved image. Once 
launched (about 5 minutes) the machine is yours to use. When done, you shut 
down the machine and stop paying for it.

The machines themselves typically have gigabit internet connections to the 
outside world. Remote access by you to the machine varies by vendor, some use 
VNC others use remote desktop. If that is sufficient for your needs, then it 
would be a viable alternative. I don't do real time trading, so can't answer 
that.

Mike

--- In amibroker@yahoogroups.com, "Rob"  wrote:
>
> But Mike, that would never be realistic for time critical real time usage 
> such as day trading for example...? 
> 
> --- In amibroker@yahoogroups.com, "Mike"  wrote:
> >
> > There are many cloud offerings, ranging from infrastructure as a service 
> > (IaaS) including bare metal rentals, platform as a service (PaaS) and 
> > software as a service (SaaS).
> > 
> > Amazon spans the IaaS/PaaS space, and are not the only (nor even the most 
> > cost effective) player in that space.
> > 
> > AmiBroker will run happily on the equipment of any IaaS vendor. However, 
> > AmiBroker licensing restrictions still apply:
> > 
> > "It is however NOT allowed to use single license to RUN SIMULTANEOUSLY on 
> > MULTIPLE machines connected via network, like for example running 
> > optimization on many machines in parallel. For that you must purchase 
> > license for every machine you are using simultaneously."
> > 
> > http://www.amibroker.com/kb/2008/07/05/single-license-use-on-multiple-computers/
> > 
> > Mike
> > 
> > --- In amibroker@yahoogroups.com, "michaels_musings"  
> > wrote:
> > >
> > > --- In amibroker@yahoogroups.com, "Rob"  wrote:
> > > >
> > > > Hi TJ,
> > > > 
> > > > I am considering building myself a new computer system.
> > > 
> > > Hi TJ/Rob,
> > > 
> > > Has anyone used AB on an Amazon cloud?
> > >  ( http://aws.amazon.com/ec2/ )
> > > 
> > > Not trying to jack the thread, but, the 3-5K for your new system might be 
> > > better off in Amazon rentals?  (Windows/High-CPU Medium ~$0.29 per hour? 
> > > ~$510 per year = 7hours*5days*50weeks)
> > > 
> > > Anyone used AB on a cloud for Optimizations?
> > > 
> > > Best,
> > > Michael
> > >
> >
>




[amibroker] Re: New System Question

2010-07-22 Thread Mike
There are many cloud offerings, ranging from infrastructure as a service (IaaS) 
including bare metal rentals, platform as a service (PaaS) and software as a 
service (SaaS).

Amazon spans the IaaS/PaaS space, and are not the only (nor even the most cost 
effective) player in that space.

AmiBroker will run happily on the equipment of any IaaS vendor. However, 
AmiBroker licensing restrictions still apply:

"It is however NOT allowed to use single license to RUN SIMULTANEOUSLY on 
MULTIPLE machines connected via network, like for example running optimization 
on many machines in parallel. For that you must purchase license for every 
machine you are using simultaneously."

http://www.amibroker.com/kb/2008/07/05/single-license-use-on-multiple-computers/

Mike

--- In amibroker@yahoogroups.com, "michaels_musings"  
wrote:
>
> --- In amibroker@yahoogroups.com, "Rob"  wrote:
> >
> > Hi TJ,
> > 
> > I am considering building myself a new computer system.
> 
> Hi TJ/Rob,
> 
> Has anyone used AB on an Amazon cloud?
>  ( http://aws.amazon.com/ec2/ )
> 
> Not trying to jack the thread, but, the 3-5K for your new system might be 
> better off in Amazon rentals?  (Windows/High-CPU Medium ~$0.29 per hour? 
> ~$510 per year = 7hours*5days*50weeks)
> 
> Anyone used AB on a cloud for Optimizations?
> 
> Best,
> Michael
>




[amibroker] Re: Backtest Report Long/Short trades columns?

2010-07-22 Thread Mike
It might help to review how AmiBroker handles signals:

http://www.amibroker.com/guide/h_portfolio.html

Any time you add more signals, you change the outcome, since holding a position 
will prevent acting on new signals until the original position is exited 
(unless coded otherwise).

long and short = more signals = different positions taken = different redundant 
signals skipped = different outcome.

Mike

--- In amibroker@yahoogroups.com, Keith McCombs  wrote:
>
> Ron --
> You are using portfolio back testing.  So, when your system goes long, 
> it is reinvesting profits from previous long AND short trades.  
> Likewise, when your system goes short, it is reinvesting profits from 
> previous short AND long trades.  Life is good.
> -- Keith
> 
> On 7/22/2010 10:02, Ron wrote:
> >
> >
> > Let me attempt to be more clear,
> >
> > When I run my system in long only I get the total and long columns on 
> > the report for Net Profit of 458.76%,
> >
> > Net Profit % 458.76 % 458.76 % 6.59 %
> >
> > When I run it short I get the total and short columns on the report 
> > for Net Profit of 75.98%,
> >
> > Net Profit % 75.89 % 6.59 % 75.89 %
> >
> > When I run it long and short I get Net Profit total of 821.76%, long 
> > of 612.44% and short of 215.90%,
> >
> > Net Profit % 821.76 % 612.44 % 215.90 %
> >
> > Why is long column for Net Profit% not the same for the long only and 
> > long and short run?
> >
> > And same question for the short column on the short only and long and 
> > short run?
> >
> > Ron
> > --- In amibroker@yahoogroups.com <mailto:amibroker%40yahoogroups.com>, 
> > "Matthias K."  wrote:
> > >
> > > 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:amibroker%40yahoogroups.com> 
> > [mailto:amibroker@yahoogroups.com 
> > <mailto:amibroker%40yahoogroups.com>] On Behalf
> > > Of Ron
> > > Sent: Donnerstag, 22. Juli 2010 06:31
> > > To: amibroker@yahoogroups.com <mailto:amibroker%40yahoogroups.com>
> > > Subject: [amibroker] Backtest Report Long/Short trades columns?
> > >
> > >
> > >
> > >
> > >
> > > I have a strategy that over time is either long or short but not 
> > both

[amibroker] Re: Combining RSI custom and Divergence indicator

2010-07-21 Thread Mike
Bharat,

It's pretty self explanatory. If you're still having trouble, post sample code 
or send it to support.

Mike

--- In amibroker@yahoogroups.com, "bharat"  wrote:
>
> mike,
> If you have tried it in any of your AFL.pl post it here so that I can 
> implement.
> 
> bharat
> 
> --- In amibroker@yahoogroups.com, "Mike"  wrote:
> >
> > You haven't experimented enough ;)
> > Start by setting all plots to styleOwnScale.
> > 
> > Mike
> > 
> > --- In amibroker@yahoogroups.com, "bharat"  wrote:
> > >
> > > I have already experimented with styleOwnScale and styleLeftAxisScale but 
> > > it did not solve my problem so I  have posted my problem here
> > > 
> > > --- In amibroker@yahoogroups.com, "Mike"  wrote:
> > > >
> > > > Read the documentation for Plot and use one of styleOwnScale or 
> > > > styleLeftAxisScale for one of the Plots such that it does not share the 
> > > > same scale as the other.
> > > > 
> > > > http://www.amibroker.com/guide/afl/afl_view.php?id=114
> > > > 
> > > > Mike
> > > > 
> > > > --- In amibroker@yahoogroups.com, Infinity Home Loans  
> > > > wrote:
> > > > >
> > > > > Hi,Can someone please help with combining the two formulas into one 
> > > > > without distorting the chart view.
> > > > > Regardsinfinity
> > > > > --- On Sat, 17/7/10, bharat  wrote:
> > > > > 
> > > > > From: bharat 
> > > > > Subject: [amibroker] Re: Combining RSI custom and Divergence indicator
> > > > > To: amibroker@yahoogroups.com
> > > > > Date: Saturday, 17 July, 2010, 8:46 AM
> > > > > 
> > > > > 
> > > > > 
> > > > > 
> > > > > 
> > > > > 
> > > > > 
> > > > > 
> > > > > 
> > > > > 
> > > > > 
> > > > > 
> > > > > 
> > > > > 
> > > > > 
> > > > >  
> > > > >  
> > > > > 
> > > > > 
> > > > > 
> > > > >   
> > > > > 
> > > > > 
> > > > > 
> > > > >   
> > > > >   
> > > > >   Hi
> > > > > 
> > > > > 
> > > > > 
> > > > > Still facing same problem.
> > > > > 
> > > > > 
> > > > > 
> > > > > I want BB and RSI and OBV on same chart but when I insert code for 
> > > > > RSI,chart gets compressed.How to see BB and RSI in same chart window 
> > > > > without distorting the view?
> > > > > 
> > > > > 
> > > > > 
> > > > > --- In amibroker@yahoogroups.com, reinsley  wrote:
> > > > > 
> > > > > >
> > > > > 
> > > > > > 
> > > > > 
> > > > > > It works fine. Custom RSI followed by Divergence in the same 
> > > > > > formula.
> > > > > 
> > > > > > 
> > > > > 
> > > > > > Best regards
> > > > > 
> > > > > > 
> > > > > 
> > > > > > 
> > > > > 
> > > > > > 
> > > > > 
> > > > > > 
> > > > > 
> > > > > > Le 16/07/2010 16:42, infynhome a écrit :
> > > > > 
> > > > > > > _SECTION_BEGIN("Custom RSI");
> > > > > 
> > > > > > > /*
> > > > > 
> > > > > > > Based on the book "Technical Analysis for the Trading Professional
> > > > > 
> > > > > > >
> > > > > 
> > > > > > > ...
> > > > > 
> > > > > > > */
> > > > > 
> > > > > > > Version(5.00);
> > > > > 
> > > > > > > SetChartBkGradientFill( ParamColor("Backgroud Top Color",
> > > > > 
> > > > > > > colorSeaGreen),ParamColor("Background Bottom Color", 
> > > > > > > colorSeaGreen));
> > > > > 
> > > > > > >
> > > > > 
> > > > > > > periods = Param( "Periods", 14, 1, 200);
> > > > > 
> > > > > > >
> > > > > 
> > > > > > > Plot( RSI( periods), _DEFAULT_NAME(), ParamColor( "Color", 
> > > > > 
> > > > > > > colorDarkBlue ),
> > > > > 
> > > > > > > ParamStyle("Style") );
> > > > > 
> > > > > > >
> > > > > 
> > > > > > > ShowMarket = ParamToggle("Bull Or Bear Market", "Bear|Bull");
> > > > > 
> > > > > > >
> > > > > 
> > > > > > > Plot(40,"",colorRed,styleLine|styleNoLabel);
> > > > > 
> > > > > > > Plot(65,"",colorRed,styleLine|styleNoLabel);
> > > > > 
> > > > > > >
> > > > > 
> > > > > > > _SECTION_END();
> > > > > 
> > > > > > > r = RSI(14);
> > > > > 
> > > > > > > Plot( r, "RSI", colorBlack );
> > > > > 
> > > > > > > PlotOHLC( r,r,50,r, "", IIf( r > 65, colorGreen, IIf (r < 40, 
> > > > > 
> > > > > > > colorRed, colorBlack )), styleCloud | styleClipMinMax, 40, 65 );
> > > > > 
> > > > > >
> > > > >
> > > >
> > >
> >
>




[amibroker] Re: Combining RSI custom and Divergence indicator

2010-07-21 Thread Mike
You haven't experimented enough ;)
Start by setting all plots to styleOwnScale.

Mike

--- In amibroker@yahoogroups.com, "bharat"  wrote:
>
> I have already experimented with styleOwnScale and styleLeftAxisScale but it 
> did not solve my problem so I  have posted my problem here
> 
> --- In amibroker@yahoogroups.com, "Mike"  wrote:
> >
> > Read the documentation for Plot and use one of styleOwnScale or 
> > styleLeftAxisScale for one of the Plots such that it does not share the 
> > same scale as the other.
> > 
> > http://www.amibroker.com/guide/afl/afl_view.php?id=114
> > 
> > Mike
> > 
> > --- In amibroker@yahoogroups.com, Infinity Home Loans  wrote:
> > >
> > > Hi,Can someone please help with combining the two formulas into one 
> > > without distorting the chart view.
> > > Regardsinfinity
> > > --- On Sat, 17/7/10, bharat  wrote:
> > > 
> > > From: bharat 
> > > Subject: [amibroker] Re: Combining RSI custom and Divergence indicator
> > > To: amibroker@yahoogroups.com
> > > Date: Saturday, 17 July, 2010, 8:46 AM
> > > 
> > > 
> > > 
> > > 
> > > 
> > > 
> > > 
> > > 
> > > 
> > > 
> > > 
> > > 
> > > 
> > > 
> > > 
> > >  
> > >  
> > > 
> > > 
> > > 
> > >   
> > > 
> > > 
> > > 
> > >   
> > >   
> > >   Hi
> > > 
> > > 
> > > 
> > > Still facing same problem.
> > > 
> > > 
> > > 
> > > I want BB and RSI and OBV on same chart but when I insert code for 
> > > RSI,chart gets compressed.How to see BB and RSI in same chart window 
> > > without distorting the view?
> > > 
> > > 
> > > 
> > > --- In amibroker@yahoogroups.com, reinsley  wrote:
> > > 
> > > >
> > > 
> > > > 
> > > 
> > > > It works fine. Custom RSI followed by Divergence in the same formula.
> > > 
> > > > 
> > > 
> > > > Best regards
> > > 
> > > > 
> > > 
> > > > 
> > > 
> > > > 
> > > 
> > > > 
> > > 
> > > > Le 16/07/2010 16:42, infynhome a écrit :
> > > 
> > > > > _SECTION_BEGIN("Custom RSI");
> > > 
> > > > > /*
> > > 
> > > > > Based on the book "Technical Analysis for the Trading Professional
> > > 
> > > > >
> > > 
> > > > > ...
> > > 
> > > > > */
> > > 
> > > > > Version(5.00);
> > > 
> > > > > SetChartBkGradientFill( ParamColor("Backgroud Top Color",
> > > 
> > > > > colorSeaGreen),ParamColor("Background Bottom Color", colorSeaGreen));
> > > 
> > > > >
> > > 
> > > > > periods = Param( "Periods", 14, 1, 200);
> > > 
> > > > >
> > > 
> > > > > Plot( RSI( periods), _DEFAULT_NAME(), ParamColor( "Color", 
> > > 
> > > > > colorDarkBlue ),
> > > 
> > > > > ParamStyle("Style") );
> > > 
> > > > >
> > > 
> > > > > ShowMarket = ParamToggle("Bull Or Bear Market", "Bear|Bull");
> > > 
> > > > >
> > > 
> > > > > Plot(40,"",colorRed,styleLine|styleNoLabel);
> > > 
> > > > > Plot(65,"",colorRed,styleLine|styleNoLabel);
> > > 
> > > > >
> > > 
> > > > > _SECTION_END();
> > > 
> > > > > r = RSI(14);
> > > 
> > > > > Plot( r, "RSI", colorBlack );
> > > 
> > > > > PlotOHLC( r,r,50,r, "", IIf( r > 65, colorGreen, IIf (r < 40, 
> > > 
> > > > > colorRed, colorBlack )), styleCloud | styleClipMinMax, 40, 65 );
> > > 
> > > >
> > >
> >
>




[amibroker] Re: How to configure CAME to look for a Optimization target MINIMUM

2010-07-19 Thread Mike
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-forward-optimization/

Mike

--- In amibroker@yahoogroups.com, "elizabeth19852002"  
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
>




[amibroker] Re: pl, give logic

2010-07-19 Thread Mike
BuyPrice = Close;
SellPrice = High;

Note that what you are asking for is not realistic. You can never know what the 
High will be until after it has happened. Any backtest results you get will be 
grossly exaggerated.

Mike

--- In amibroker@yahoogroups.com, "prasantaroy36"  wrote:
>
> 
> 
> --- In amibroker@yahoogroups.com, "prasantaroy36"  wrote:
> >
> > Dear friends,
> > 
> > After fullfill certain condion BUY price will be signal generted bar close 
> > price
> > and exit price will be signal generted bar high price.
> > 
> > So, what will be the afl code to meet above criteria ? Want this code for 
> > backtesting purpose. Pl, help.
> > 
> > Thanks
> >
> 
> 
> pl, help
>




[amibroker] Re: Combining RSI custom and Divergence indicator

2010-07-18 Thread Mike
Read the documentation for Plot and use one of styleOwnScale or 
styleLeftAxisScale for one of the Plots such that it does not share the same 
scale as the other.

http://www.amibroker.com/guide/afl/afl_view.php?id=114

Mike

--- In amibroker@yahoogroups.com, Infinity Home Loans  wrote:
>
> Hi,Can someone please help with combining the two formulas into one without 
> distorting the chart view.
> Regardsinfinity
> --- On Sat, 17/7/10, bharat  wrote:
> 
> From: bharat 
> Subject: [amibroker] Re: Combining RSI custom and Divergence indicator
> To: amibroker@yahoogroups.com
> Date: Saturday, 17 July, 2010, 8:46 AM
> 
> 
> 
> 
> 
> 
> 
> 
> 
> 
> 
> 
> 
> 
> 
>  
>  
> 
> 
> 
>   
> 
> 
> 
>   
>   
>   Hi
> 
> 
> 
> Still facing same problem.
> 
> 
> 
> I want BB and RSI and OBV on same chart but when I insert code for RSI,chart 
> gets compressed.How to see BB and RSI in same chart window without distorting 
> the view?
> 
> 
> 
> --- In amibroker@yahoogroups.com, reinsley  wrote:
> 
> >
> 
> > 
> 
> > It works fine. Custom RSI followed by Divergence in the same formula.
> 
> > 
> 
> > Best regards
> 
> > 
> 
> > 
> 
> > 
> 
> > 
> 
> > Le 16/07/2010 16:42, infynhome a écrit :
> 
> > > _SECTION_BEGIN("Custom RSI");
> 
> > > /*
> 
> > > Based on the book "Technical Analysis for the Trading Professional
> 
> > >
> 
> > > ...
> 
> > > */
> 
> > > Version(5.00);
> 
> > > SetChartBkGradientFill( ParamColor("Backgroud Top Color",
> 
> > > colorSeaGreen),ParamColor("Background Bottom Color", colorSeaGreen));
> 
> > >
> 
> > > periods = Param( "Periods", 14, 1, 200);
> 
> > >
> 
> > > Plot( RSI( periods), _DEFAULT_NAME(), ParamColor( "Color", 
> 
> > > colorDarkBlue ),
> 
> > > ParamStyle("Style") );
> 
> > >
> 
> > > ShowMarket = ParamToggle("Bull Or Bear Market", "Bear|Bull");
> 
> > >
> 
> > > Plot(40,"",colorRed,styleLine|styleNoLabel);
> 
> > > Plot(65,"",colorRed,styleLine|styleNoLabel);
> 
> > >
> 
> > > _SECTION_END();
> 
> > > r = RSI(14);
> 
> > > Plot( r, "RSI", colorBlack );
> 
> > > PlotOHLC( r,r,50,r, "", IIf( r > 65, colorGreen, IIf (r < 40, 
> 
> > > colorRed, colorBlack )), styleCloud | styleClipMinMax, 40, 65 );
> 
> >
>




[amibroker] Re: Sum and Stdev , wierd behaviour of stdev

2010-07-15 Thread Mike
I agree. I never noticed that page in the guide before. Description of the 
parameters at the point of the actual function descriptor would be far more 
discoverable.

Mike

--- In amibroker@yahoogroups.com, "rise_t575"  wrote:
>
> 
> 
> Hello,
> 
> A short definition within each page of the AFL Function Reference/AB manual 
> what type of parameter (scalar/array) is expected/allowed for the 
> corresponding function would be a better place for this old known fact. 
> That's where most people look at in such cases.
> 
> --- In amibroker@yahoogroups.com, Tomasz Janeczko  wrote:
> >
> >   Hello,
> > 
> > It is old, known fact. Some functions accept variable periods. Documented 
> > in the manual:
> > 
> > http://www.amibroker.com/guide/a_varperiods.html
> > 
> > 
> > Best regards,
> > Tomasz Janeczko
> > amibroker.com
> > 
> > On 2010-07-15 08:12, Mike wrote:
> > > Interesting. I ran a quick test and it seems to suggest that Sum does in 
> > > fact take an array as second argument, contrary to expectations.
> > >
> > > It would appear that you are correct, with respect to Sum. Though it is 
> > > not always the case that a function with a "periods" argument will accept 
> > > an array. For those that don't, you will have to find another approach.
> > >
> > > Here's my test:
> > >
> > > Test = Sum(1, Cum(1));
> > > Fixed = Sum(1, 5);
> > >
> > > Plot(Test, "Test", colorRed, styleLine);
> > > Plot(Fixed, "Fixed", colorBlue, styleLine);
> > > Title = "Bar: " + BarIndex() + ", Test: " + Test + ", Fixed: " + Fixed;
> > >
> > > If Sum did not accept an array, but was instead substituting some fixed 
> > > number (e.g. last element of the array), then both Plots should result in 
> > > flat lines. However, the test clearly shows that the Test plot rises at a 
> > > 45 degree angle indicating that the period is different at each bar. 
> > > Compare that to the Fixed plot which is constant at a level of 5.
> > >
> > > Mike
> > >
> > > --- In amibroker@yahoogroups.com, "aaryan111"  wrote:
> > >> I guess, sum() is behaving the ideal way :),
> > >>
> > >> The most important thing here is,
> > >> AMIBROKER being an array processing language, calculates all the 
> > >> elements of array , but at any given active bar, it fetches the current 
> > >> value from the whole arry index and shows it to us,Presumably using some 
> > >> barindex kind of mechanism internally.
> > >>
> > >> When we put close, open or any array in any afl , like ((close + open + 
> > >> High  + Low )/4= MAVG),amibroker produces output based on the current 
> > >> value of that array, we dont need to specify current index of that array 
> > >> (scalar value) to get output at any current bar,it manages it intenally.
> > >>
> > >> Here its impotant to not that, its IRRELEVANT if we use array in a 
> > >> Function or simply put it in any statement in afl, it fetches a scalar 
> > >> value out of that produced array to show it to us.
> > >>
> > >> when I put SUm(close,Barssince()) It ideally fetches the current element 
> > >> of BarsSince array and place it over ther.
> > >>
> > >> This is the ideal way. Sum() is behaving the IDEAL way.
> > >> infact every other function,
> > >> let it be ,
> > >> MA(Close,BarsSince(TimeNum()<  093000));
> > >> or any other function, having Periods, as a second argument.
> > >>
> > >> While in Stdev(),it simply goes against the normal behaviour.
> > >> it should infact, in MUST , point to the current active element of the 
> > >> Barssince(), let it be a 0 or any other value, its irrelevant, its still 
> > >> a scalar.
> > >> and it simply doesnt do that!.
> > >>
> > >> i think i have made my point clear now.
> > >>
> > >> Wave : Lastvalue() will surely fetch the last element of the array, but 
> > >> i cant use it while testing it offline, i will get all future values of 
> > >> that array, its all fine if i have to use it while online updation.
> > >>
> > >>
> > >>
> > >> Regards...
> > >>
> > >>
> > >> --- In amibroker@yahoogroups.com, "wavemechanic" 

[amibroker] Re: Sum and Stdev , wierd behaviour of stdev

2010-07-14 Thread Mike
Interesting. I ran a quick test and it seems to suggest that Sum does in fact 
take an array as second argument, contrary to expectations.

It would appear that you are correct, with respect to Sum. Though it is not 
always the case that a function with a "periods" argument will accept an array. 
For those that don't, you will have to find another approach.

Here's my test:

Test = Sum(1, Cum(1));
Fixed = Sum(1, 5);

Plot(Test, "Test", colorRed, styleLine);
Plot(Fixed, "Fixed", colorBlue, styleLine);
Title = "Bar: " + BarIndex() + ", Test: " + Test + ", Fixed: " + Fixed;

If Sum did not accept an array, but was instead substituting some fixed number 
(e.g. last element of the array), then both Plots should result in flat lines. 
However, the test clearly shows that the Test plot rises at a 45 degree angle 
indicating that the period is different at each bar. Compare that to the Fixed 
plot which is constant at a level of 5.

Mike

--- In amibroker@yahoogroups.com, "aaryan111"  wrote:
>
> I guess, sum() is behaving the ideal way :), 
> 
> The most important thing here is, 
> AMIBROKER being an array processing language, calculates all the elements of 
> array , but at any given active bar, it fetches the current value from the 
> whole arry index and shows it to us,Presumably using some barindex kind of 
> mechanism internally.
> 
> When we put close, open or any array in any afl , like ((close + open + High  
> + Low )/4= MAVG),amibroker produces output based on the current value of that 
> array, we dont need to specify current index of that array (scalar value) to 
> get output at any current bar,it manages it intenally.
> 
> Here its impotant to not that, its IRRELEVANT if we use array in a Function 
> or simply put it in any statement in afl, it fetches a scalar value out of 
> that produced array to show it to us.
>  
> when I put SUm(close,Barssince()) It ideally fetches the current element of 
> BarsSince array and place it over ther. 
> 
> This is the ideal way. Sum() is behaving the IDEAL way. 
> infact every other function,
> let it be , 
> MA(Close,BarsSince(TimeNum() < 093000)); 
> or any other function, having Periods, as a second argument.
> 
> While in Stdev(),it simply goes against the normal behaviour. 
> it should infact, in MUST , point to the current active element of the 
> Barssince(), let it be a 0 or any other value, its irrelevant, its still a 
> scalar.
> and it simply doesnt do that!.
> 
> i think i have made my point clear now.
> 
> Wave : Lastvalue() will surely fetch the last element of the array, but i 
> cant use it while testing it offline, i will get all future values of that 
> array, its all fine if i have to use it while online updation.
> 
> 
> 
> Regards...
> 
> 
> --- In amibroker@yahoogroups.com, "wavemechanic"  wrote:
> >
> > I'm fairly sure that the only way you will get StDev() to accept 
> > BarsSince() in the 2nd argument without complaining is to force the return 
> > of a number by use of LastValue() or SelectedValue().  I don't know why 
> > Sum() is not complaining when BarsSince() is used.  
> > 
> > In the Sum() case, I think that BarsSince( TimeNum ... ) is returning a 
> > constant array based on the bar you select, including the last bar if no 
> > bar is selected.  If so, that would work OK but does not explain why 
> > StDev() does not work.
> > 
> > For Sum(), if you replace TimeNum() with another array generator, for 
> > example, MA( C, 13 ) == , Sum() still does not complain but BarsSince() 
> > returns 0 (I believe) and, hence, Sum() is 0.
> > 
> > You might have stumbled onto a unique situation but I would not assume that 
> > it can be generalized and would always go for ensuring the return of a 
> > number from the 2nd argument whether or not the above is correct.
> > 
> > Bill
> >   - Original Message - 
> >   From: aaryan111 
> >   To: amibroker@yahoogroups.com 
> >   Sent: July 14, 2010 3:08 PM
> >   Subject: [amibroker] Re: Sum and Stdev , wierd behaviour of stdev
> > 
> > 
> >   Hi , thanx for the feedback wave.
> >   its Syntax is basically to put Period as 2nd argument.
> >   When u put an array in SUM() as 2nd argument, it will take the 
> > corresponding scalar frm that array and apply it as a filter.
> > 
> >   i have successfully executed this 
> > 
> >   Sum(Close,BarsSince(TimeNum()>092400));
> > 
> >   regards
> > 
> > 
> >   --- In amibroker@yahoogroups.com, "wavemechanic"  wrote:
> >   >
> >   > Neither takes arr

[amibroker] Re: Sum and Stdev , wierd behaviour of stdev

2010-07-14 Thread Mike
Are you sure that it is not just taking the last value of the array, as opposed 
to the corresponding value. All documented usage shows it taking a scaler. You 
might want to pay very close attention to what you're getting there.

Mike

--- In amibroker@yahoogroups.com, "aaryan111"  wrote:
>
> Hi , thanx for the feedback wave.
> its Syntax is basically to put Period as 2nd argument.
> When u put an array in SUM() as 2nd argument, it will take the corresponding 
> scalar frm that array and apply it as a filter.
> 
> i have successfully executed this 
> 
> Sum(Close,BarsSince(TimeNum()>092400));
> 
> regards
> 
> 
> --- In amibroker@yahoogroups.com, "wavemechanic"  wrote:
> >
> > Neither takes array as 2nd.  See syntax in Users Guide.
> >   - Original Message - 
> >   From: aaryan111 
> >   To: amibroker@yahoogroups.com 
> >   Sent: July 12, 2010 3:41 PM
> >   Subject: [amibroker] Sum and Stdev , wierd behaviour of stdev
> > 
> > 
> >   Hi Everybody, 
> > 
> >   Both Sum() and Stdev() Functions Have same Arguments Structure.but when i 
> > put 
> >   Sum(Close,BarsSince(TimeNum()>092400))
> >   it executes successfully,while 
> >   Stdev(Close,BarsSince(TimeNum()>092400))
> >   gives a warning " Function Expects Different type of argument here " . 
> > 
> >   as far as i understand , both can take array as 2nd argument and 
> > amibroker will automatically fetch the current running index value of that 
> > array as the 2nd argument, same as it does with other functions. 
> > 
> >   one can put any other function returning array like barindex() in 2nd 
> > argument , result will be same. 
> > 
> >   Any suggestions??
> > 
> >   Regards,
> > 
> > 
> > 
> >   
> > 
> >    IMPORTANT PLEASE READ 
> >   This group is for the discussion between users only.
> >   This is *NOT* technical support channel.
> > 
> >   TO GET TECHNICAL SUPPORT send an e-mail directly to 
> >   SUPPORT {at} amibroker.com
> > 
> >   TO SUBMIT SUGGESTIONS please use FEEDBACK CENTER at
> >   http://www.amibroker.com/feedback/
> >   (submissions sent via other channels won't be considered)
> > 
> >   For NEW RELEASE ANNOUNCEMENTS and other news always check DEVLOG:
> >   http://www.amibroker.com/devlog/
> > 
> >   Yahoo! Groups Links
> >
>




[amibroker] Re: Backtest - reference account balance to workout lots size

2010-07-14 Thread Mike
Rise,

It's been a while since I last delved down to that level of detail. So take 
this with a grain of salt. There are a couple of things that can be at play 
here.

Fist is whether or not you have opted to use the previous bar's equity for 
position sizing (AA Settings option or SetOption).

Second, the multiple equity values may be due to beginning and ending equity 
for the bar.

Check to see if the position size makes sense using the final equity of the 
previous bar in the calculation, in which case that would confirm both points 
above.

Mike

--- In amibroker@yahoogroups.com, "rise_t575"  wrote:
>
> 
> 
> 
> 
> 
> Mike,
> 
> I've used your ps formula & switched to "Detailed Log" in the BT settings.
> I've chosen a trade somewhere in the middle of the backtest, so that current 
> equity is not identical to the initial equity.
> 
> I'm getting the following info:
> Trade Date: 2004-07-27
> 
> Enter Long, T, Price: 25.34, Shares: 3448, Commission: 0, Rank: 1, Equity 
> 170338, Margin Loan: 0, Fx rate: 1
> VZ not entered because of insufficient funds
> 2 Open Positions: , RX (+2709), , T (+3448), Equity: 170717, Cash: 16378.3
> 
> Additional info: ATR(20) of ticker symbol "T" on this date is 0.49.
> 
> 1.) Why are there two different equity numbers (170338 and 170717)? It's the 
> same date and I am using EOD data, so there should be no change. And which 
> one is used for position sizing during the backtest?
> 
> 2.) Manually calculating position size for both equity numbers leads to a) 
> 170338 * 0.01 [pctVolaRisk = 1%] / (0.49 * 1) = 3476 units, and b) 170717 * 
> 0.01 / (0.49 * 1) = 3484 units.
> But the log states a position size of 3448 units (so using both equity 
> numbers results in a different position size than the one stated in the log).
> 
> How can this be explained?
>




[amibroker] Re: Req Help me get afl code line for % change in price

2010-07-14 Thread Mike
Have a look at the user guide for ROC

http://www.amibroker.com/guide/afl/afl_view.php?id=126

Mike

--- In amibroker@yahoogroups.com, "ford7k"  wrote:
>
> Hi afl experts
> 
> I run my scan or exploration.
> I get c,close price.
> I cant get % change
> % change = previous close price -current close price
> 
> in a daily change i need previous days close price - current close
> as % change
> 
> Help me by giving right code line for % change in intraday and in eod 
> situation
> 
> advance thanks
> regards
> ford
>




[amibroker] Re: Am I in a trade? Am I long or short?

2010-07-14 Thread Mike
Regardless of the number of symbols, availability of funds is only known by the 
backtester.

Whether a single symbol or a portfolio of symbols, the only 100% reliable way 
to know is by custom backtesting code that iterates through the open positions 
list.

The list is a collection of Trade objects, each of which has a boolean property 
named IsLong (true means long, false means short).

http://www.amibroker.com/guide/a_custombacktest.html

If you want an approximation you can use the Flip function.

Buy = ...;
Sell = ...;
InLongPos = Flip(Buy, Sell); // Will be "1" only for duration of longs.

Same principle for shorts.

Mike

--- In amibroker@yahoogroups.com, "notanaiqgenius"  wrote:
>
> 
> 
> 
> 
> 
> Hi Spacebass,
> 
> It depends on whether you are trading multiple symbols. If you are trading 
> multiple symbols, then you will need to use a custom backtester script to 
> determine if you are long or short.
> 
> Remember that AFL first ranks signals from multiple markets and then executes 
> only some of those signals based on certain parameters such as your maximum 
> positions total and how many existing open positions you currently have. 
> 
> If you are only testing on 1 market, then it is much easier to determine if 
> you are long or short. If you are in Regular Backtest mode (as opposed to 
> scaling or rotational mode), then you can just check the special Buy and 
> Short arrays to see if a particular bar is 1 or 0. You can do something like:
> 
> //BEGIN CODE-
> 
> Buy = Close > Ref(Close,-1) and Ref(Close,-1) > Ref(Close,-2);
> Short = Close < Ref(Close,-1) and Ref(Close,-1) < Ref(Close,-2);
> 
> SetOption( "InitialEquity", 10 );
> 
> Buy = Close > Ref(Close,-1) AND Ref(Close,-1) > Ref(Close,-2);
> Sell = 0;
> Short = Close < Ref(Close,-1) AND Ref(Close,-1) < Ref(Close,-2);
> Cover = 0;
> 
> //remove duplicate Buys after Buy already active or duplicate Shorts after 
> Short already active
> Buy = ExRem(Buy, Short);
> Short = ExRem(Short, Buy);
> 
> Var1 = 0;
> for(i=0;i {
>if(Buy[i]==1)
>   //do something
>   Var1[i] = 0;
>if(Short[i]==1)
>   //do something
>   Var1[i] = 0;
> }
> 
> Plot(Buy,"buy",colorGreen,styleLine);
> Plot(Short,"short",colorRed,styleLine);
> //END CODE-
> 
> Paul
> --- In amibroker@yahoogroups.com, "spacebass5000"  wrote:
> >
> > At any given data-point, is there a way to tell if you are in a trade 
> > within AFL? If so, is there a way to know if you're long/short?
> >
>




[amibroker] Re: checking MA when buying

2010-07-13 Thread Mike
Looks like your revised code should be fine. Are you sure that MAFlag is ever 1 
on the bars that you buy?

For debugging, it is always a good idea to add charting code to visually verify 
your assumptions.

e.g. Add this to the bottom of your code and verify that a vertical bar is 
drawn on the same bar as a green up arrow.

Plot(Close, "Price", colorDarkGrey, styleBar);
Plot(MAFlag, "MAFlag", colorBlue, styleHistogram | styleOwnScale);
PlotShapes(ExRem(Buy, Sell) * shapeUpArrow, colorGreen);
PlotShapes(ExRem(Sell, Buy) * shapeDownArrow, colorRed);

Mike

--- In amibroker@yahoogroups.com, "chuck_win"  wrote:
>
> Hi,
> 
> 1. You are right that my code count more than one time. I don't really know 
> how to capture a data at buy exactly. I just follow  Tomasz's suggestion in 
> his reply to another person.
> 
> 2. According to help file, staticvarget(...) return a number or string.  If 
> it is a static array, how to access its element? I change the CTB block as 
> following and get 0.0 under MAup column.
> 
> if ( Status( "action" ) == actionPortfolio )
> {
>   bo = GetBacktesterObject();
>   //run default back tester
>   bo.Backtest();
>   Dates = DateTime();
>   bi = BarIndex();
>   MAup = 0;
> 
>   //loop on all trades of ONE interation at one time.
>   for ( trade = bo.GetFirstTrade( ); trade; trade = bo.GetNextTrade( ) )
>   {
>   entryBar = LastValue( ValueWhen( trade.EntryDateTime == dates, 
> bi ));
>   //add up MA flag from static var
>   myArray = StaticVarGet("MA_" + trade.symbol);
>   MAup = MAup + myArray[entryBar];
>   _TRACE(trade.Symbol + ": " + MAUp);
>   }
> 
>   //add custom column to optimize result
>   bo.AddCustomMetric("MAUP", MAup);
>   //bo.listTrades();
> } 
> 
> 3. I fixed it. 
> 
> Could you drop couple more lines as you get time?
> 
> All your help were really appreciated! 
> 
> Charles
> 
> --- In amibroker@yahoogroups.com, "Mike"  wrote:
> >
> > Looks like you have a few potential problems:
> > 
> > 1. You are double (triple, quadruple, etc.) counting whenever you have 
> > multiple trades for the same symbol.
> > 
> > 2. I believe that custom backtest metrics need to be scalers (i.e. single 
> > value, not an array).
> > 
> > 3. No need to delay the printing of trades (i.e. bo.Backtest(1)) since you 
> > are not adding individual trade metrics.
> > 
> > Mike
> > 
> > --- In amibroker@yahoogroups.com, "chuck_win"  wrote:
> > >
> > > Hi, 
> > > 
> > > What I am doing is:
> > > 1). count MA(close, 6) < MA(close, 9) at buy when open gap > %x.
> > > 2). show the count on optimize results.
> > > 
> > > I use static var to store MA flag outside CTB, and read it inside CTB. 
> > > the code below doesn't work. 
> > > 
> > > I don't know if I create a single static var or a static array when I 
> > > write: 
> > > StaticVarSet ("MA_" + Name(), MAFlag);
> > > 
> > > It could be wrong in other place.
> > > 
> > > Any help would be greatly appreciated!
> > > 
> > > Charles
> > > 
> > > 
> > > 
> > > 
> > > //= optimize
> > > Perc = Optimize("Perc", 8, 8, 8, 2);
> > > MALen = Optimize("MALen", 6, 6, 6, 1);
> > > 
> > > //= set option
> > > //SetOption("RequireDeclarations", True ); 
> > > //must use it for buyprice = ref(close, -1).
> > > SetOption("PriceBoundChecking", False);
> > > 
> > > //= buy rules
> > > Buyrule1 = TimeNum() == 93000;
> > > Buyrule2 = Close >= Ref(Close, -1) * (1 + Perc/100);
> > > 
> > > Buyrule = Buyrule1 AND Buyrule2;
> > > 
> > > //= set static var to store MA
> > > //check MA steps
> > > MAFlag = IIf(MA(Close, MAlen) < MA(Close, MAlen + 3), 1, 0);
> > > //store MA flag into static var.
> > > StaticVarSet ("MA_" + Name(), MAFlag);
> > > 
> > > //= sell rules
> > > Sellrule1 = TimeNum() == 93000;
> > > Sellrule = Sellrule1;
> > > 
> > > //= trade
> > > Buy = Buyrule;
> > > BuyPrice = Ref(Close, -1);
> > > Sell = Sellrule;
> &g

[amibroker] Re: Backtest - reference account balance to workout lots size

2010-07-13 Thread Mike
1. Are you using ApplyStops? One of the arguments controls when resulting funds 
become available for any entries that occur on the same bar as the stop. That 
might be affecting things.

2. Try adding SetBarsRequired( sbrAll, sbrAll ); to the top of your code and 
see if that makes a difference.

3. See the user guide for adding custom metrics on a trade by trade basis:

http://www.amibroker.com/guide/a_custommetrics.html

Mike

--- In amibroker@yahoogroups.com, "rise_t575"  wrote:
>
> Hi Mike,
> 
> Your math is obviously correct.
> 
> Nonetheless, I've found a small mistake in your SetPositionSize formula; the 
> SetPositionSize function expects the percentage value (e. g. for 50%) in the 
> format "50", whereas the formula you've described ("P") has a result with the 
> format "0.50". So one has to multipy P with 100 to get it to work with 
> SetPositionsize.
> 
> This gets us into the right direction (i. e. the position sizes are "nearly" 
> correct), but unfortunately, there are still 2 issues present.
> 
> 1.) Using SetPositionSize, the position sizes seem to always differ a couple 
> of units/shares from what I get when I take a chart of the stock with signal 
> and ATR and calculate PS by hand (with the CBT code, the values seem to be 
> exactly correct). Don't know where this stems from, and if there are some 
> rounding issues involved along the way (I've set "Min. Shares" to 1 in the 
> backtester settings; within the CBT code, I use the INT function for rounding 
> down units).
> 
> 2.) What I find to be rather stunning is the fact that I get different 
> *trades* by just switching the ps formula between SetPositionSize and the CBT 
> version of the formula. At the very least, the very first trade should be the 
> same (which is not the case), as at that point in time, Current Equity is 
> still equal to Initial Equity. Later on during the backtesting process, there 
> might be some differences between to 2 formulas regarding taken trades, as 
> current equity changes differ with the 2 formulas because the potential 
> rounding issues mentioned above might accumulate.
> 
> Any ideas?
> 
> Additional question: Is there a way (e. g. using CBT) to include additional 
> columns for the list of trades in the Automatic Analysis Results window? This 
> would make debugging / checking correct calculation of position sizes 
> somewhat easier.
> 
> Btw, you can check the exact CBT code I'm using at 
> http://www.amibroker.com/members/library/detail.php?id=1307
> 
> 
> --- In amibroker@yahoogroups.com, "Mike"  wrote:
> >
> > No offence taken.
> > 
> > Check my math since I've written this out quickly. But...
> > 
> > You have said:
> > a) TotalPos = psUnits * Price
> > 
> > You have also said:
> > b) psUnits = currEquity * [(pctVolaRisk / 100) / (ATR * PointVal)]
> > 
> > Substituting b into a you get:
> > c) TotalPos = {currEquity * [(pctVolaRisk / 100) / (ATR * PointVal)]} * 
> > Price
> > 
> > Which is identical to:
> > d) TotalPos = currEquity * {[(pctVolaRisk / 100) / (ATR * PointVal)] * 
> > Price}
> > 
> > If you set P as the second argument:
> > e) P = {[(pctVolaRisk / 100) / (ATR * PointVal)] * Price};
> > 
> > You can then say:
> > f) TotalPos = currEquity * P
> > 
> > Which is expressed in AFL as
> > g) SetPositionSize(P, spsPercentOfEquity);
> > 
> > I haven't run any testing, so check it for yourself. Check also if 
> > AmiBroker still behaves if P >= 1.
> > 
> > Mike
> > 
> > 
> > --- In amibroker@yahoogroups.com, "rise_t575"  wrote:
> > > 
> > > Mike,
> > > 
> > > Thanks for your reply (I hope I did not say anything upsetting you, as 
> > > this definitely wasn't my intention - how could I - you've helped me many 
> > > times here on the forum).
> > > 
> > > The result of formula (1) is in units, the result of formula (2) is a 
> > > percentage of equity. Thus, in formula (1) I have to multiply the number 
> > > of units with price (price = 100) in order to get to the position size in 
> > > USD, whereas in formula (2), I have to multiply the percentage with the 
> > > current equity in order to get the position size in USD. I don't realize 
> > > where my thinking goes wrong here, but I am open for corrections.
> > > 
> > > I obviously see that your most recent SetPositionSize formula comes to 
> > > the same result in this example, but I'm getting *very* d

[amibroker] Re: back testing formula: please help me

2010-07-13 Thread Mike
The formula that you copied probably only has Buy/Sell. But, your AmiBroker 
settings are probably set for Long and Short, meaning that AmiBroker expects to 
see code for Short/Cover also.

The solution is to either add the following code to the top of your formula:

Buy = Sell = Short = Cover = False;

Or to change your settings to be Long only. Same arugment applies for Short 
only formulas.

Mike

--- In amibroker@yahoogroups.com, "s.momtaz"  wrote:
>
> hi. i am new in amibroker and also amibroker group. today i want to put a 
> formula copied from afl library of amibroker.com
> 
> but when i was testing it the message appeared: 
> 
> "missing buy/sell variable assigments. check user's guide: tutorial: 
> back-testing your trading ideas for the details." 
> 
> now what can i do? i have checked the related topic in user guide, but don't 
> understand anything. please help!
> 
> shaheen
>




[amibroker] Re: Coding question

2010-07-13 Thread Mike
Buy = Sum(Close > EMA(Close, 50), 5) == 5;

Same idea for Sell.

Mike

--- In amibroker@yahoogroups.com, "jhjh"  wrote:
>
> How would I go about creating code to establish that my indicator must be X 
> for Y days before having the appropriate output?
> 
> Simple example, buy = close above 50 EMA (after holding there for 5 days 
> continuously).
> 
> Sell when close is below 50 EMA (after holding there for 5 days 
> consecutively).
> 
> Is it just using an AND function?  
> 
> Muchos gracias.
>




[amibroker] Re: checking MA when buying

2010-07-12 Thread Mike
Looks like you have a few potential problems:

1. You are double (triple, quadruple, etc.) counting whenever you have multiple 
trades for the same symbol.

2. I believe that custom backtest metrics need to be scalers (i.e. single 
value, not an array).

3. No need to delay the printing of trades (i.e. bo.Backtest(1)) since you are 
not adding individual trade metrics.

Mike

--- In amibroker@yahoogroups.com, "chuck_win"  wrote:
>
> Hi, 
> 
> What I am doing is:
> 1). count MA(close, 6) < MA(close, 9) at buy when open gap > %x.
> 2). show the count on optimize results.
> 
> I use static var to store MA flag outside CTB, and read it inside CTB. the 
> code below doesn't work. 
> 
> I don't know if I create a single static var or a static array when I write: 
> StaticVarSet ("MA_" + Name(), MAFlag);
> 
> It could be wrong in other place.
> 
> Any help would be greatly appreciated!
> 
> Charles
> 
> 
> 
> 
> //= optimize
> Perc = Optimize("Perc", 8, 8, 8, 2);
> MALen = Optimize("MALen", 6, 6, 6, 1);
> 
> //= set option
> //SetOption("RequireDeclarations", True ); 
> //must use it for buyprice = ref(close, -1).
> SetOption("PriceBoundChecking", False);
> 
> //= buy rules
> Buyrule1 = TimeNum() == 93000;
> Buyrule2 = Close >= Ref(Close, -1) * (1 + Perc/100);
> 
> Buyrule = Buyrule1 AND Buyrule2;
> 
> //= set static var to store MA
> //check MA steps
> MAFlag = IIf(MA(Close, MAlen) < MA(Close, MAlen + 3), 1, 0);
> //store MA flag into static var.
> StaticVarSet ("MA_" + Name(), MAFlag);
> 
> //= sell rules
> Sellrule1 = TimeNum() == 93000;
> Sellrule = Sellrule1;
> 
> //= trade
> Buy = Buyrule;
> BuyPrice = Ref(Close, -1);
> Sell = Sellrule;
> SellPrice = Close;
> 
> // custom back tester
> SetCustomBacktestProc( "" );
> 
> if ( Status( "action" ) == actionPortfolio )
> {
>   bo = GetBacktesterObject();
>   //run default back tester
>   bo.Backtest(1);
>   MAup = 0;
> 
>   //loop on all trades of ONE interation at one time.
>   for ( trade = bo.GetFirstTrade( ); trade; trade = bo.GetNextTrade( ) )
>   {
>   //add up MA flag from static var
>   MAup = MAup + StaticVarGet("MA_" + trade.symbol);
>   _TRACE(trade.Symbol + ": " + MAUp);
>   }
> 
>   //add custom column to optimize result
>   bo.AddCustomMetric("MAUP", MAup);
>   bo.listTrades();
> } 
> 
> --- In amibroker@yahoogroups.com, "chuck_win"  wrote:
> >
> > Thanks so much Mike for your help. It works on backtester now. I will try 
> > to make it work on optimize next.
> > 
> > Charles
> > 
> > 
> > 
> > --- In amibroker@yahoogroups.com, "Mike"  wrote:
> > >
> > > Charles,
> > > 
> > > You got scared away from the earlier example that I referred you to ( 
> > > http://finance.groups.yahoo.com/group/amibroker/message/146164 ). Yet, 
> > > with a one line change, it would give you exactly what you want.
> > > 
> > > Just change:
> > > 
> > > foreignATR = ATR( 14 );
> > > 
> > > To
> > > 
> > > foreignATR = MA( Close, 6 );
> > > 
> > > Do this and, I believe, you would have exactly what you're asking for. 
> > > You would likely then want to change the names and output strings to 
> > > refer to MA instead of ATR. But, there would be no further change in 
> > > logic other than that one line.
> > > 
> > > Mike
> > > 
> > > --- In amibroker@yahoogroups.com, "chuck_win"  wrote:
> > > >
> > > > Hi Mike,
> > > > 
> > > > I need to run optimize, and have spent a lot of time to add a custom 
> > > > column of MA on optimize result list and no luck so far. 
> > > > 
> > > > Is it possible to find the bar index or bar number of buying and use 
> > > > the number to refer the MA like
> > > > 
> > > > myMA = ref(MA(close, 6), -17);
> > > > 
> > > > Thank you very much!
> > > > 
> > > > Charles
> > > > 
> > > >  
> > > > 
> > > >

[amibroker] Re: Backtest - reference account balance to workout lots size

2010-07-12 Thread Mike
No offence taken.

Check my math since I've written this out quickly. But...

You have said:
a) TotalPos = psUnits * Price

You have also said:
b) psUnits = currEquity * [(pctVolaRisk / 100) / (ATR * PointVal)]

Substituting b into a you get:
c) TotalPos = {currEquity * [(pctVolaRisk / 100) / (ATR * PointVal)]} * Price

Which is identical to:
d) TotalPos = currEquity * {[(pctVolaRisk / 100) / (ATR * PointVal)] * Price}

If you set P as the second argument:
e) P = {[(pctVolaRisk / 100) / (ATR * PointVal)] * Price};

You can then say:
f) TotalPos = currEquity * P

Which is expressed in AFL as
g) SetPositionSize(P, spsPercentOfEquity);

I haven't run any testing, so check it for yourself. Check also if AmiBroker 
still behaves if P >= 1.

Mike


--- In amibroker@yahoogroups.com, "rise_t575"  wrote:
> 
> Mike,
> 
> Thanks for your reply (I hope I did not say anything upsetting you, as this 
> definitely wasn't my intention - how could I - you've helped me many times 
> here on the forum).
> 
> The result of formula (1) is in units, the result of formula (2) is a 
> percentage of equity. Thus, in formula (1) I have to multiply the number of 
> units with price (price = 100) in order to get to the position size in USD, 
> whereas in formula (2), I have to multiply the percentage with the current 
> equity in order to get the position size in USD. I don't realize where my 
> thinking goes wrong here, but I am open for corrections.
> 
> I obviously see that your most recent SetPositionSize formula comes to the 
> same result in this example, but I'm getting *very* different results when 
> backtesting with the CBT code and the (updated) SetPositionSize formula (and 
> the results of the CBT code look much more realistic). I've used "Close" as 
> the price, so the formula I've used is
> SetPositionSize( C * ( pctVolaRisk /100 ) / ( ATR( pctVolaAtr )* 1 ), 
> spsPercentOfEquity );
> 
> Thanks for pointing out that PositionSize is an array itself, as I've been 
> unaware of this indeed.
> 
> --- In amibroker@yahoogroups.com, "Mike"  wrote:
> >
> > Hi,
> > 
> > Your examples are not valid. In the first you did an additional 
> > multiplication by 100, the second you did not.
> > 
> > Adjusting your second example to match the first you get:
> > 
> > 2.) Suggested non-CBT solution using spsPercentOfEquity:
> >  
> > SetPositionSize(Price * ( pctVolaRisk / 100 ) / ( ATR(period) * pointVal , 
> > spsPercentOfEquity);
> > 
> > psPercentOfEquity = 100 * ( 1 / 100 ) / ( 1.5 * 1 )
> > psPercentOfEquity = 0.667 %
> >  
> > Size of total position = 100,000 * 0.667 % = 66700 USD exactly as expected.
> > 
> > As for your remaining comments, you are not understanding how the AmiBroker 
> > arrays work in conjunction with position size. PositionSize itself is an 
> > array. So, when assigning ATR as part of the calculation of position size, 
> > it is the ATR on a bar by bar basis, NOT a static value. Also, the position 
> > size is calculated symbol by symbol, NOT once for all.
> > 
> > Run the test using the proper fraction (i.e. including the price 
> > multiplier) and you should get what you are wanting.
> > 
> > Mike
> > 
> > --- In amibroker@yahoogroups.com, "rise_t575"  wrote:
> > >
> > > 
> > > 
> > > Taking another look at the results, I've just noticed that Mike's formula 
> > > would "theoretically" work in this special case, if you alter it to
> > > 
> > > SetPositionSize( pctVolaRisk / ( ATR(period) * pointVal ), 
> > > spsPercentOfEquity);
> > > 
> > > I say theoretically, as there seems to be another problem; when coding it 
> > > this way (which to me has a touch of thinking-backwards, but is working 
> > > on paper nonetheless), the volatility (i. e. ATR value) will end up being 
> > > fixed in this case during the backtest, i. e. ATR wouldn't be adjusted 
> > > for a) the underlying instrument for each entry, and b) the actual entry 
> > > bar (as for the correct way of doing this, the ATR value used for the ps 
> > > calculation should be the actual ATR value of that specific entry bar).
> > > 
> > > In order to change this, I guess you'd end up using CBT as well.
> > > 
> > > 
> > > --- In amibroker@yahoogroups.com, "rise_t575"  wrote:
> > > >
> > > > 
> > > > 
> > > > Mike, Tomasz, anyone:
> > > > 
> > > > Many thanks for your reply, Mike (as well as for all the other probl

[amibroker] Re: Backtest - reference account balance to workout lots size

2010-07-12 Thread Mike
Hi,

Your examples are not valid. In the first you did an additional multiplication 
by 100, the second you did not.

Adjusting your second example to match the first you get:

2.) Suggested non-CBT solution using spsPercentOfEquity:
 
SetPositionSize(Price * ( pctVolaRisk / 100 ) / ( ATR(period) * pointVal , 
spsPercentOfEquity);

psPercentOfEquity = 100 * ( 1 / 100 ) / ( 1.5 * 1 )
psPercentOfEquity = 0.667 %
 
Size of total position = 100,000 * 0.667 % = 66700 USD exactly as expected.

As for your remaining comments, you are not understanding how the AmiBroker 
arrays work in conjunction with position size. PositionSize itself is an array. 
So, when assigning ATR as part of the calculation of position size, it is the 
ATR on a bar by bar basis, NOT a static value. Also, the position size is 
calculated symbol by symbol, NOT once for all.

Run the test using the proper fraction (i.e. including the price multiplier) 
and you should get what you are wanting.

Mike

--- In amibroker@yahoogroups.com, "rise_t575"  wrote:
>
> 
> 
> Taking another look at the results, I've just noticed that Mike's formula 
> would "theoretically" work in this special case, if you alter it to
> 
> SetPositionSize( pctVolaRisk / ( ATR(period) * pointVal ), 
> spsPercentOfEquity);
> 
> I say theoretically, as there seems to be another problem; when coding it 
> this way (which to me has a touch of thinking-backwards, but is working on 
> paper nonetheless), the volatility (i. e. ATR value) will end up being fixed 
> in this case during the backtest, i. e. ATR wouldn't be adjusted for a) the 
> underlying instrument for each entry, and b) the actual entry bar (as for the 
> correct way of doing this, the ATR value used for the ps calculation should 
> be the actual ATR value of that specific entry bar).
> 
> In order to change this, I guess you'd end up using CBT as well.
> 
> 
> --- In amibroker@yahoogroups.com, "rise_t575"  wrote:
> >
> > 
> > 
> > Mike, Tomasz, anyone:
> > 
> > Many thanks for your reply, Mike (as well as for all the other problems you 
> > have helped me with in the past) - but unfortunatley, I don't think it will 
> > work that way.
> > 
> > While I am relatively new to AmiBroker, I believe that I know a thing or 
> > two about proper position sizing algorithms and risk management.
> > In this regard, I believe to have found quite a few misconceptions 
> > regarding those topics on the AB forums, which are mirrored by AB's 
> > out-of-the-box functionality and manual.
> > 
> > Virtually all of the better ps algorithms use a fraction of equity as 
> > *risk* (not as the overall size of the position), and this - if I am 
> > correct here - is impossible to code in AB without using the CBT.
> > [One can take this one step further by using different models for defining 
> > current equity, e. g. Total Equity, Core Equity, Closed Equity. As far as I 
> > know, these can be difficult (I don't say impossible) to code on AB as 
> > well, as it lacks build-in backtesting functionality for the concept of 
> > Open Risk - defined as the difference between the last price and the 
> > nearest stop, adjusted for slippage, for all positions].
> > 
> > Let's take the ps formula I've mentioned. This is the exact Percent 
> > Volatility position sizing model as used by Richard Dennis' Turtles, 
> > described by Van Tharp, etc:
> > 
> > psUnits = int( currEquity * ( pctVolaRisk / 100 ) / ( ATR (period) * 
> > pointVal ));
> > 
> > The intention here is to equalize the volatility of all traded instruments 
> > by adjusting the position size for each instrument.
> > 
> > This is simply done by
> > 
> > 1.) Defining risk as a fraction of current equity (e. g. risk = 1 % of 
> > equity)
> > 2.) Dividing risk by volatility (i. e. ATR), adjusted for the point value 
> > of the traded instrument
> > 
> > So let's do the calculation of an example:
> > 
> > currEquity = 100,000 USD
> > pctVolaRisk = 1 (i. e. 1%)
> > ATR(20) = 1.5 USD
> > pointVal = 1 USD
> > price = 100 USD
> > 
> > 1.) Correct calculation of Percent Volatility Model:
> > 
> > psUnits = int( currEquity * ( pctVolaRisk / 100 ) / ( ATR (period) * 
> > pointVal ));
> > psUnits = int( 10 * ( 1 / 100 ) / ( 1.5 * 1))
> > psUnits = 666 Units
> > 
> > Size of total position = 666 Units * 100 USD = 66600 USD
> > 
> > 2.) Suggested non-CBT solution using spsPercentOfEquity:
> > 
> > SetPositionSize(( pctVolaRisk / 100 ) / ( ATR(period) * pointVal ), 
> > sp

[amibroker] Re: How to buy at the open the next day?

2010-07-12 Thread Mike
1. SetTradeDelays http://www.amibroker.com/guide/afl/afl_view.php?id=137

2. N-bar stop http://www.amibroker.com/guide/afl/afl_view.php?name=applystop

3. User guide main index (also Help from AmiBroker itself) 
http://www.amibroker.com/guide/

Mike

--- In amibroker@yahoogroups.com, "scottr"  wrote:
>
> I apologise if this has been addressed elsewhere - I've searched the forum 
> and the help files and cannot find the answer.
> 
> (1) I'd like to know how to run a scan/backtest where I enter a position at 
> the open on the day after my buy criteria has been met.  So, for example, if 
> I want to buy every stock that closes up 10% in one day (I'll be buying it 
> the next day), how would I code that?
> 
> The below line of code expresses what I'm looking for, but I can't figure out 
> how to tell the program to then buy the stock at the open the next day
> 
> Buy = Close > 1.1*Ref(Close,-1);
> 
> (2) How can I tell the program to sell a position at the open 20 days from 
> when I purchased it?  In the above example, what I would like to do is buy 
> the stock the day after my criteria are met and then sell it 20 days later.
> 
> (3) Is there some resource that answers these basic "How do I?..." type 
> questions?
> 
> Thanks very much for any assistance
> Scott
>




[amibroker] Re: checking MA when buying

2010-07-11 Thread Mike
Charles,

You got scared away from the earlier example that I referred you to ( 
http://finance.groups.yahoo.com/group/amibroker/message/146164 ). Yet, with a 
one line change, it would give you exactly what you want.

Just change:

foreignATR = ATR( 14 );

To

foreignATR = MA( Close, 6 );

Do this and, I believe, you would have exactly what you're asking for. You 
would likely then want to change the names and output strings to refer to MA 
instead of ATR. But, there would be no further change in logic other than that 
one line.

Mike

--- In amibroker@yahoogroups.com, "chuck_win"  wrote:
>
> Hi Mike,
> 
> I need to run optimize, and have spent a lot of time to add a custom column 
> of MA on optimize result list and no luck so far. 
> 
> Is it possible to find the bar index or bar number of buying and use the 
> number to refer the MA like
> 
> myMA = ref(MA(close, 6), -17);
> 
> Thank you very much!
> 
> Charles
> 
>  
> 
> --- In amibroker@yahoogroups.com, "Mike"  wrote:
> >
> > Hi,
> > 
> > There are a couple of problems:
> > 
> > 1. When trying to do an equivalence test, use the equivalence operator '==' 
> > not the assignment operator '='.
> > 
> > 2. buyrule is an array. You cannot use the if statement on an array.
> > 
> > If you just want to see what the value is, then run an exploration:
> > 
> > Filter = buyrule;
> > AddColumn(MA(Close, 6), "MA(6)");
> > 
> > http://www.amibroker.com/guide/h_exploration.html
> > 
> > Otherwise, add a custom metric to your backtest.
> > 
> > Mike
> > 
> > --- In amibroker@yahoogroups.com, "chuck_win"  wrote:
> > >
> > > Hi,
> > > 
> > > I do backtesting, and want to check MA at the time of buying.
> > > 
> > > My code looks like 
> > > 
> > > buyrule = cross(MACD, signal);
> > > buy = buyrule;
> > > buyprice = close;
> > > sellrule = cross(signal, MACD);
> > > sell = sellrule;
> > > sellprice = close;
> > > if (buyrule = true) {
> > >  str = StrFormat("%0.2f", MA(Close,6));
> > >  _TRACE(NumToStr( DateTime(), formatDateTime ) + ", " + str);
> > > 
> > > }
> > > 
> > > I always get the MA at the ending time of last bar instead. 
> > > 
> > > Thanks for any help!
> > > 
> > > Charles
> > >
> >
>




[amibroker] Re: checking MA when buying

2010-07-11 Thread Mike
Hi,

There are a couple of problems:

1. When trying to do an equivalence test, use the equivalence operator '==' not 
the assignment operator '='.

2. buyrule is an array. You cannot use the if statement on an array.

If you just want to see what the value is, then run an exploration:

Filter = buyrule;
AddColumn(MA(Close, 6), "MA(6)");

http://www.amibroker.com/guide/h_exploration.html

Otherwise, add a custom metric to your backtest.

Mike

--- In amibroker@yahoogroups.com, "chuck_win"  wrote:
>
> Hi,
> 
> I do backtesting, and want to check MA at the time of buying.
> 
> My code looks like 
> 
> buyrule = cross(MACD, signal);
> buy = buyrule;
> buyprice = close;
> sellrule = cross(signal, MACD);
> sell = sellrule;
> sellprice = close;
> if (buyrule = true) {
>  str = StrFormat("%0.2f", MA(Close,6));
>  _TRACE(NumToStr( DateTime(), formatDateTime ) + ", " + str);
> 
> }
> 
> I always get the MA at the ending time of last bar instead. 
> 
> Thanks for any help!
> 
> Charles
>




[amibroker] Re: Optimization issues

2010-07-11 Thread Mike
Also, if you are using a non exhaustive optimizer (e.g. CMAE, Tribes, etc.) 
there is no guarantee that the optimal solution will be found.

Mike

--- In amibroker@yahoogroups.com, Howard B  wrote:
>
> Hi AJ --
> 
> Are the settings the same?
> 
> Are the issues being tested the same?
> 
> Are the individual values that give good results in the backtest included
> within the ranges of the optimization variables?
> 
> 
> 
> Thanks,
> Howard
> 
> 
> On Sat, Jul 10, 2010 at 12:04 PM, AJ  wrote:
> 
> >
> >
> > Good morning,
> > I'm working on a small project where I have 4 variables. If I do a backtest
> > with certain values I get the correct answer (in my particular case 60% gain
> > 10%drawdown). However, when I do an optimization with these variables (the
> > values that I used to get the right answer are within the values that I
> > usein the optimization) the only result I get is 0 calmar, and the gains are
> > 5%. Is there any reason why I would gt the right answer doing backtesting
> > and completely diffrent results when optimizing? did I forget to set
> > something? Thanks for your help,
> > Augusto
> >
> >  
> >
>




[amibroker] Re: Can NOT access MA inside CustomBacktestProc?

2010-07-10 Thread Mike
The current symbol during custom backtesting is ~~~Equity.

If you want to make function calls using the symbol of the trade, then you must 
either save the result as a static array before entering the custom backtesting 
code, else use Foreign or SetForeign/RestorePriceArrays within the custom 
backtester code.

Read the following thread, including Tomasz's descriptions of static arrays, 
for examples:

http://finance.groups.yahoo.com/group/amibroker/message/146164

Mike

--- In amibroker@yahoogroups.com, "chuck_win"  wrote:
>
> I try to check MA inside Custom back test proc, and get 0 always. It seems 
> like only those stats are accessible and any others are not.
> 
> Thanks very much for any help in advance.
> 
> Charles
> 
> // iterate through all closed trades.
> for (trade = bo.getFirstTrade(); trade; trade = bo.GetNextTrade()) {
>   numTrades++;
> 
>   gapsup = MA(Close, MAlen) > Ref(MA(Close, MALen), -1);
> 
>   _TRACE( "MA: " + MA(Close, 6)); 
> 
>   if (gapsup = True) {
>  upCount++; 
>   }
> }
>




[amibroker] Re: Embarrassing question...

2010-07-10 Thread Mike
Your assumption is mistaken. Unless explicitly stated otherwise, the scope of 
the variable is dictated by where it first appears. Since test_sig first 
appears within your procedure, it defaults to local to that procedure. You can 
override that by declaring it global from within the procedure, or move the 
main initialization above the procedure usage.

http://www.amibroker.com/guide/a_userfunctions.html

Mike

--- In amibroker@yahoogroups.com, "sidhartha70"  wrote:
>
> I'm going to shame myself by asking a very simple question... why does the 
> following code produce an error...? Namely that 'test_sig' has been used 
> without being initialized.
> 
> procedure Test()
> {
>if( test_sig ) _TRACE("Hello");
> }
> 
> test_sig = 0;
> 
> Test();
> 
> I was under the impression that defining test_sig after the procedure (i.e. I 
> always put my functions & procedure definitions before the main body of my 
> code) it was automatically assigned "global" status?
> 
> Thanks
>




[amibroker] Re: Backtest - reference account balance to workout lots size

2010-07-10 Thread Mike
I believe that you will get what you want simply by using a dynamic value 
passed to SetPositionSize, expressed as a percentage of equity.

AmiBroker will use the current value of equity, on a bar by bar basis, when 
resolving the calculation. The situations that require CBT are when you need to 
know how many positions are already in place, how much cash is available, or 
any other information that is only available during the actual backtest (as 
opposed to during the calculation of signsls).

If you're calculations are based just on equity as a whole, you can usually use 
SetPositionSize.

If I am understanding your example correctly, the end result is just a fraction 
multiplied by the equity, which is the equivalent of using spsPercentOfEquity 
in SetPositionSize. AmiBroker will do the calculation for how many shares that 
translates to, using the minimum shares size in the AA Settings when rounding.

SetPositionSize(( pctVolaRisk / 100 ) / ( ATR(period) * pointVal ), 
spsPercentOfEquity);

Mike

--- In amibroker@yahoogroups.com, "rise_t575"  wrote:
> Mike,
> 
> Just out of interest (as I've already solved this using CBT):
> Is it possible to code the following exact position sizing formula without 
> using CBT? I think not, as one needs the updated current equity during the 
> backtest (as with all PS models):
> 
> psUnits = int( currEquity * ( pctVolaRisk / 100 ) / ( ATR(period) * pointVal 
> ) );
> 
> Thanks in advance!
> 
> --- In amibroker@yahoogroups.com, "Mike"  wrote:
> >
> > SetPositionSize((Risk * 0.01) / (ContractSize * ATR()), spsPercentOfEquity);
> > 
> > Mike
> > 
> > --- In amibroker@yahoogroups.com, "pcmoxon"  wrote:
> > >
> > > Hi,
> > > 
> > > I am trying to write some AFL so I can backtest various trading systems 
> > > for forex.
> > > 
> > > One part of the system is to workout how much equity to use for each 
> > > trade.
> > > 
> > > Below is the pseudo logic I want to use but I am not sure how to 
> > > reference the current 'AccountBalance'. I thought of using 'EQUITY(0)' 
> > > but on reading the online help it seems this is for something else.
> > > 
> > >Lots = Risk * 0.01 * AccountBalance / (ContractSize * ATR)
> > > 
> > > Any help will be appreciated.
> > > 
> > > Regards,
> > > Pete
> > >
> >
>




[amibroker] Re: How to add extra fields to the back test report(s) & Results window

2010-07-10 Thread Mike
And, perhaps more directly to your question:

http://finance.groups.yahoo.com/group/amibroker/message/146164

Though, if using a newer version of AB, you can use static arrays as mentioned 
by Tomasz in the the thread.

Mike

--- In amibroker@yahoogroups.com, "Mike"  wrote:
>
> Same answer as 5 hours ago ;)
> 
> http://finance.groups.yahoo.com/group/amibroker/message/150894
> 
> Mike
> 
> --- In amibroker@yahoogroups.com, "pcmoxon"  wrote:
> >
> > Hi, can anyone tell me how to add extra fields to a backtest trade list 
> > report and results window?
> > 
> > For example, I would like to see the ATR value at the time of the trade 
> > open and trade close. Also, the stop level used when a system sets the stop 
> > level using the ApplyStop() funtion.
> > 
> > 
> > Thanks,
> > Pete
> >
>




[amibroker] Re: How to add extra fields to the back test report(s) & Results window

2010-07-10 Thread Mike
Same answer as 5 hours ago ;)

http://finance.groups.yahoo.com/group/amibroker/message/150894

Mike

--- In amibroker@yahoogroups.com, "pcmoxon"  wrote:
>
> Hi, can anyone tell me how to add extra fields to a backtest trade list 
> report and results window?
> 
> For example, I would like to see the ATR value at the time of the trade open 
> and trade close. Also, the stop level used when a system sets the stop level 
> using the ApplyStop() funtion.
> 
> 
> Thanks,
> Pete
>




[amibroker] Re: Defining logical range

2010-07-09 Thread Mike
Sorry, the predefined example should have read:

varA = a[i];
varB = b[i];
varC = c[i];

not 

varA = a[index];
...

Mike

--- In amibroker@yahoogroups.com, "Mike"  wrote:
>
> To get you on your way to the more important stuff, the quick and dirty 
> solution would be to just add the constraints to your Buy logic. 
> 
> e.g.
> 
> Valid = A < B AND B < C AND ...;
> Buy = ... AND Valid;
> 
> Your optimization will blindly evaluate unnecessary combinations. But, if the 
> optimization time is not a factor, then this is a foolproof way to get you to 
> the next step without dickering around with clever coding.
> 
> Otherwise, you can try to derive the later values as a function of the 
> earlier values and reduce the number of optimized variables.
> 
> e.g.
> b = 3 * a;
> 
> Similarly, if you know that you will have enough bars in the optimization 
> period you could reduce the optimized variables to a single index into 
> predefined arrays.
> 
> Regardless of whether or not you use the elements, predefined arrays can have 
> at most as many elements as there are bars under study. So, if your range is 
> 3 bars wide, you can only have 3 values in your a,b,c arrays.
> 
> e.g.
> a[0] = 5; b[0] = 32; c[0] = 123;
> ...
> a[9] = 14; b[9] = 41; c[9] = 132;
>  
> i = Optimize("index", 0, 0, 9, 1);
> 
> varA = a[index];
> varB = b[index];
> varC = c[index];
> 
> Or, use file operations fopen, fgets, fclose to read the values from file 
> based on a single optimized variable (e.g. index). This would probably kill 
> performance though.
> 
> Mike
> 
> --- In amibroker@yahoogroups.com, "jhjh"  wrote:
> >
> > Suggestions on how to program the following?
> > 
> > "a must be less than b, which must be less than c, etc."
> > 
> > I'm optimizing a, b, c, and d, but the numerical value of each must be from 
> > smallest to largest, otherwise the optimization is worthless.  Therefore 
> > it's either true or false, and only optimizes values of the variables that 
> > maintain the "true" nature of the increasing value of each variable.
> > 
> > Thanks for any suggestions.
> > 
> > J
> >
>




[amibroker] Re: AddColumn to optimize results?

2010-07-09 Thread Mike
http://www.amibroker.com/guide/a_custommetrics.html

Mike

--- In amibroker@yahoogroups.com, "chuck_win"  wrote:
>
> I try to collect stats of an optimize by adding a custom column to the 
> results window. 
> 
> Thanks very much in advance.
> 
> Charles
>




[amibroker] Re: Defining logical range

2010-07-09 Thread Mike
To get you on your way to the more important stuff, the quick and dirty 
solution would be to just add the constraints to your Buy logic. 

e.g.

Valid = A < B AND B < C AND ...;
Buy = ... AND Valid;

Your optimization will blindly evaluate unnecessary combinations. But, if the 
optimization time is not a factor, then this is a foolproof way to get you to 
the next step without dickering around with clever coding.

Otherwise, you can try to derive the later values as a function of the earlier 
values and reduce the number of optimized variables.

e.g.
b = 3 * a;

Similarly, if you know that you will have enough bars in the optimization 
period you could reduce the optimized variables to a single index into 
predefined arrays.

Regardless of whether or not you use the elements, predefined arrays can have 
at most as many elements as there are bars under study. So, if your range is 3 
bars wide, you can only have 3 values in your a,b,c arrays.

e.g.
a[0] = 5; b[0] = 32; c[0] = 123;
...
a[9] = 14; b[9] = 41; c[9] = 132;
 
i = Optimize("index", 0, 0, 9, 1);

varA = a[index];
varB = b[index];
varC = c[index];

Or, use file operations fopen, fgets, fclose to read the values from file based 
on a single optimized variable (e.g. index). This would probably kill 
performance though.

Mike

--- In amibroker@yahoogroups.com, "jhjh"  wrote:
>
> Suggestions on how to program the following?
> 
> "a must be less than b, which must be less than c, etc."
> 
> I'm optimizing a, b, c, and d, but the numerical value of each must be from 
> smallest to largest, otherwise the optimization is worthless.  Therefore it's 
> either true or false, and only optimizes values of the variables that 
> maintain the "true" nature of the increasing value of each variable.
> 
> Thanks for any suggestions.
> 
> J
>




[amibroker] Re: Usage of BuyPrice = False and SellPrice = False?

2010-07-09 Thread Mike
False is a predefined constant set to the value 0.

By setting BuyPrice/SellPrice to False you are saying that you want to 
purchase/sell the active symbol for $0.

If the Low of the bar for that symbol is greater than your BuyPrice, AmiBroker 
will automatically alter the BuyPrice to be within the trading range (using the 
Low, I think, in this case), unless you have disabled this option via 
SetOption("PriceBoundChecking", False). Similarly your exit price will be 
affected.

When not including these lines, AmiBroker will use whatever values you have set 
in your AA Settings for entry/exit (e.g. Open). In the first case you would 
effectively be entering/exiting at the Low. In the latter case you would be 
entering/exiting at perhaps the Open, depending on your settings.

Naturally, this would affect the performance and the availability of funds for 
later trades.

Mike

--- In amibroker@yahoogroups.com, "michaels_musings"  
wrote:
>
> Hi All,
> 
> I ran across this while doing code exploration.  If I add
> 
> > BuyPrice = False;
> > SellPrice = False;
> 
> to my .afl, then I get a different number of trades (and profits, etc.).  
> With it I get 56 trades and without it I get 25 trades.
> 
> Obviously I'd like to know if it should be included/excluded to get proper 
> results, but I'm more curious about the underlying reasons for the different 
> results.  So I can understand what to do and not to do in the future.
> 
> My thanks to everyone on this list for being so knowledgeable and helpful,
> Michael
> 
> 
> Code in question :
> ...
> // Setup Arrays
> Sell = False;  // Initialize "Sell" array
> Buy = False;  // Initialize "Buy" array
> BuyPrice = False;
> SellPrice = False;
> openPos = False; // No open positions to start with
> lastLow = False; // Just initialize it
> 
> ...
> // Start this Pig...
> for ( i = 0; i < BarCount; i++ ) // Loop over all bars in the chart
> {
>   for ( j = 0; j < numBuyPoints; j++ ) // Loop over all Buy points
>   {
> if ( openPos[j] ) // Have an open position, check to sell it
> {
>   if ( Low[i] < myStopLosss[j] ) // Check for Stops First
>   {
> Buy[stickBuySellAt] = True;
> BuyPrice[stickBuySellAt] = buyPrices[j];  // To override AA Trades 
> tab, You must set Prices after Flagging
> stickBuySellAt = stickBuySellAt + 1;
> Sell[stickBuySellAt] = True;
> SellPrice[stickBuySellAt] = myStopLosss[j];
> stickBuySellAt = stickBuySellAt + 1;
> openPos[j] = False; // No longer have open position
> lastLow[j] = iif( Close[i] < SellPrice[i], Close[i], SellPrice[i] ); 
> // ReSet lastLow[j] for Buy Check
> if ( writeLog == TRUE )
> ...
>




[amibroker] Re: Request: How to Open a Chart and Apply an AFL via OLE

2010-07-09 Thread Mike
Does it have to be a chart? If you can accomplish the same thing via a 
scan/exploration/backtest you can use the LoadFormula function on the Analysis 
object. Similarly, the Commentary object has a LoadFormula function.

I don't see a LoadFormula equivalent for charting. But perhaps you can emulate 
it as per 3b by loading a predefined layout or template?

The Application object has a LoadLayout function. You could perhaps then grab 
the Application.ActiveDocument and set its Name property to the desired ticker.

Similarly, the Application has an ActiveWindow property. The Window object has 
a LoadTemplate function and a Document property. Again, set the Name property 
of the Document to change the symbol.

Mike

--- In amibroker@yahoogroups.com, Progster  wrote:
>
> Hi.
> 
> Using OLE/jscript, I would like to do the following:
> 
> 1.Start AB
> 2.Choose a database
> 
> In a loop across multiple symbols (symbol names known in advance):
> 
> 3a.Open a chart and apply an AFL
> 
>  or
> 
> 3b.Open a saved layout that has a given AFL applied
> 
> 4.Quit AB
> 
> 
> I've done a good amount of both Googling and experimenting, but I 
> haven't hit on the right sequence yet to accomplish this.
> 
> It is only step 3 that I'm having a problem with.   My problem is not 
> executing the loop.  That seems fine.
> 
> However, nothing I have found or tried opens/loads a chart and 
> applies/runs an AFL.
> 
> Below is skeleton code that runs.
> 
> If someone is able to be so kind as to fill in the missing bit, I'd 
> really appreciate it.   If there's more than one way to do it, 
> alternative solutions are very welcome.
> 
> Thanks.
> 
> ---
> 
> 
> /*
>  LoopDemo_01.js
> 
>  _01201007089Initial "empty" skeleton by Progster
> 
>  It is recommended to run this file in a command window, like so:
> 
>  >cscript LoopDemo_01.js
> 
>  Lines commented with //*** will need to be edited to reflect 
> the local environment
> 
>  Goals:
> 
>  1.Start AB
>  2.Choose a database
> 
>  In a loop across multiple symbols (symbol names known in advance):
> 
>  3a.Open a chart and apply an AFL
>  or
>  3b.Open a saved layout that has a given AFL applied
> 
>  4.Quit AB
> 
> 
> */
> 
> function pausecomp(millis)
> {
> var date = new Date();
> var curDate = null;
> 
> do { curDate = new Date(); }
> while(curDate-date < millis);
> }
> 
> //General paths and setup definitions
> Settings_Directory = "C:\\Amibroker_Formula_Root\\";// ***
> SettingsFileName = "Futures_01.ABS";// ***
> 
> Layout_Directory = "C:\\AmiBroker_Data\\US-PremiumData\\Layouts\\"
> //***
> LayoutFileName = "MyLayout.ALY";//***
> 
> SettingsFile = Settings_Directory + SettingsFileName;
> WScript.Echo( "SettingsFile: "  + SettingsFile );
> 
> LayoutFile = Layout_Directory + LayoutFileName;
> WScript.Echo( "LayoutFile: "  + LayoutFile );
> 
> AFL_Directory = "C:\\Amibroker_Formula_Root\\Custom\\";// ***
> 
> // Create AmiBroker object
> AB = new ActiveXObject("Broker.Application");
> 
> // Load Database
> AB.LoadDatabase("C:\\Amibroker_Data\\US-PremiumData");//***
> 
> //Test of changing symbols//***
> var symbols = new Array(4);
> symbols[0] = "$SPX" ;
> symbols[1] = "GOOG" ;
> symbols[2] = "AAPL" ;
> symbols[3] = "SPY" ;
> //symbols[] = "" ;
> 
> for (idx = 0; idx <= 3; idx++)
> {
>  next_symbol = symbols[idx];
>  WScript.Echo( "Working on: " + next_symbol);
> 
>  //Aim is to load a chart here, and load code (which will run 
> and generate the desired result)
> 
>  ChartFileName = "My_Chart_File.afl";// ***
>  ChartFile = AFL_Directory + ChartFileName;
>  WScript.Echo(ChartFile);
> 
>  pausecomp( 1000 ) ;
> }
> 
> AB.SaveDatabase();
> AB.RefreshAll();
> 
> pausecomp( 1000 ) ;
> 
> WScript.Echo("Closing AmiBroker");
> AB.Quit();
> 
> WScript.Echo("Pipeline is Done.");
>




[amibroker] Re: Backtest - reference account balance to workout lots size

2010-07-09 Thread Mike
SetPositionSize((Risk * 0.01) / (ContractSize * ATR()), spsPercentOfEquity);

Mike

--- In amibroker@yahoogroups.com, "pcmoxon"  wrote:
>
> Hi,
> 
> I am trying to write some AFL so I can backtest various trading systems for 
> forex.
> 
> One part of the system is to workout how much equity to use for each trade.
> 
> Below is the pseudo logic I want to use but I am not sure how to reference 
> the current 'AccountBalance'. I thought of using 'EQUITY(0)' but on reading 
> the online help it seems this is for something else.
> 
>Lots = Risk * 0.01 * AccountBalance / (ContractSize * ATR)
> 
> Any help will be appreciated.
> 
> Regards,
> Pete
>




[amibroker] Re: AmiBroker 5.30.1 64-bit edition (experimental)

2010-07-08 Thread Mike
Dubi,

According to Tomasz, CMAE is available in 64 bit.

http://finance.groups.yahoo.com/group/amibroker/message/150820

Mike

--- In amibroker@yahoogroups.com, "dubi1974"  wrote:
>
> Hi Mike,
> 
> Same machine, same optimization.
> I am using Windows 7x64bit. CPU is Intel i7 920. 6GB DDRAM3.
> And I compared the same optimization of a formula on Amibroker 32bit and 
> Amibroker 64bit.
> 
> Regarding exhaustive optimizer. There is not exhaustive optimizer for 64bit. 
> That's why I did neither use it for the 32bit and the 64bit. That's why I 
> asked Tomasz if a exhaustive optimizer 64bit plugin is planed.
> 
> Regards, dubi
> 
> 
> --- In amibroker@yahoogroups.com, "Mike"  wrote:
> >
> > Did you perform your test using an exhaustive optimization on identical 
> > machines (or better yet, the same machine), differing only by 32 bit 
> > windows vs. 64 bit windows? If not, your test is comparing apples to 
> > oranges.
> > 
> > 1. If using different machines, the hardware will play a very large role in 
> > the performance. My high end 64bit server takes 20 seconds to compute what 
> > my low end 32bit laptop does in 8 minutes. I can assure you it has very 
> > little to do with the operating system!
> > 
> > 2. If using a non exhaustive optimizer, the built-in randomness of the 
> > optimizer can result in a different number of actual backtest operations. 
> > An optimization will take some period of time to converge. Immediately 
> > running the same optimization again on the same machine may converge sooner 
> > or take longer. The timing is not fixed, as it would be for an exhaustive 
> > optimization that will always perform exactly the same number of backtests.
> > 
> > Mike
> > 
> > --- In amibroker@yahoogroups.com, "dubi1974"  wrote:
> > >
> > > Hi,
> > > 
> > > I tested it and compared an normal optimization process between 32bit and 
> > > 64 bit. On the same formula Amibroker 32-bit took more than 8 hours for 
> > > the optimization process, and Amibroker 64-bit just 4h:50min.
> > > 
> > > So my experience shows me, that it's much faster. My question is, could 
> > > you Tomasz provide us the optimizer.dll in 64-bit? Like cmae or tribes? 
> > > For testing purpose.
> > > 
> > > Many thanks.
> > > 
> > > Regards, dubi
> > > 
> > > --- In amibroker@yahoogroups.com, Tomasz Janeczko  wrote:
> > > >
> > > > Hello,
> > > > 
> > > > AmiBroker 5.30.1 64-bit edition (experimental) is now available for 
> > > > download from:
> > > > http://www.amibroker.com/x64/
> > > > 
> > > > This is experimental version *only* for people running 64-bit Windows 
> > > > and wanting to utilise *more* than 4GB of memory. 64-bit version does 
> > > > NOT offer anything more, just ability to access more memory.  It can 
> > > > (and should) be installed into *separate* folder, so it does not 
> > > > overwrite 32-bit edition (if installed). This version includes only 2 
> > > > plugins: CMAE and IB (interactive brokers) plugin.   64-bit version of 
> > > > IQFeed plugin is in the works
> > > > and it will arrive later.
> > > > 
> > > > Note that regular users, even running 64-bit Windows should rather run 
> > > > regular, 32-bit version of AmiBroker as it offers more compatibility 
> > > > and 
> > > > was tested on way more installations.
> > > > 
> > > > Please note that 64-bit version has BETA/experimental status and in 
> > > > case 
> > > > of problems you should use 32-bit version instead.
> > > > 
> > > > Best regards,
> > > > Tomasz Janeczko
> > > > amibroker.com
> > > >
> > >
> >
>




[amibroker] Re: AmiBroker 5.30.1 64-bit edition (experimental)

2010-07-08 Thread Mike
Bruce,

Thanks for the info. I haven't got around to dissecting that optimizer yet. 
And, yes, I completely agree that a fixed seed option would be very useful.

Mike

--- In amibroker@yahoogroups.com, "Bruce"  wrote:
>
> Mike -
> 
> Minor correction and maybe more than you are interested in, but SPSO appears 
> to initialize its random number generator with a fixed seed on each 
> optimization, so the search sequence is the same - so, SPSO runs are 
> reproducible.
> 
> This is actually useful in certain cases.  I found that I wished that all of 
> the opt DLL's would have had fixed init OR random timer init as an option, so 
> I added it.
> 
> -- Bruce
> 
> 
> --- In amibroker@yahoogroups.com, "Mike"  wrote:
> >
> > Did you perform your test using an exhaustive optimization on identical 
> > machines (or better yet, the same machine), differing only by 32 bit 
> > windows vs. 64 bit windows? If not, your test is comparing apples to 
> > oranges.
> > 
> > 1. If using different machines, the hardware will play a very large role in 
> > the performance. My high end 64bit server takes 20 seconds to compute what 
> > my low end 32bit laptop does in 8 minutes. I can assure you it has very 
> > little to do with the operating system!
> > 
> > 2. If using a non exhaustive optimizer, the built-in randomness of the 
> > optimizer can result in a different number of actual backtest operations. 
> > An optimization will take some period of time to converge. Immediately 
> > running the same optimization again on the same machine may converge sooner 
> > or take longer. The timing is not fixed, as it would be for an exhaustive 
> > optimization that will always perform exactly the same number of backtests.
> > 
> > Mike
> > 
> > --- In amibroker@yahoogroups.com, "dubi1974"  wrote:
> > >
> > > Hi,
> > > 
> > > I tested it and compared an normal optimization process between 32bit and 
> > > 64 bit. On the same formula Amibroker 32-bit took more than 8 hours for 
> > > the optimization process, and Amibroker 64-bit just 4h:50min.
> > > 
> > > So my experience shows me, that it's much faster. My question is, could 
> > > you Tomasz provide us the optimizer.dll in 64-bit? Like cmae or tribes? 
> > > For testing purpose.
> > > 
> > > Many thanks.
> > > 
> > > Regards, dubi
> > > 
> > > --- In amibroker@yahoogroups.com, Tomasz Janeczko  wrote:
> > > >
> > > > Hello,
> > > > 
> > > > AmiBroker 5.30.1 64-bit edition (experimental) is now available for 
> > > > download from:
> > > > http://www.amibroker.com/x64/
> > > > 
> > > > This is experimental version *only* for people running 64-bit Windows 
> > > > and wanting to utilise *more* than 4GB of memory. 64-bit version does 
> > > > NOT offer anything more, just ability to access more memory.  It can 
> > > > (and should) be installed into *separate* folder, so it does not 
> > > > overwrite 32-bit edition (if installed). This version includes only 2 
> > > > plugins: CMAE and IB (interactive brokers) plugin.   64-bit version of 
> > > > IQFeed plugin is in the works
> > > > and it will arrive later.
> > > > 
> > > > Note that regular users, even running 64-bit Windows should rather run 
> > > > regular, 32-bit version of AmiBroker as it offers more compatibility 
> > > > and 
> > > > was tested on way more installations.
> > > > 
> > > > Please note that 64-bit version has BETA/experimental status and in 
> > > > case 
> > > > of problems you should use 32-bit version instead.
> > > > 
> > > > Best regards,
> > > > Tomasz Janeczko
> > > > amibroker.com
> > > >
> > >
> >
>




[amibroker] Re: AmiBroker 5.30.1 64-bit edition (experimental)

2010-07-08 Thread Mike
Did you perform your test using an exhaustive optimization on identical 
machines (or better yet, the same machine), differing only by 32 bit windows 
vs. 64 bit windows? If not, your test is comparing apples to oranges.

1. If using different machines, the hardware will play a very large role in the 
performance. My high end 64bit server takes 20 seconds to compute what my low 
end 32bit laptop does in 8 minutes. I can assure you it has very little to do 
with the operating system!

2. If using a non exhaustive optimizer, the built-in randomness of the 
optimizer can result in a different number of actual backtest operations. An 
optimization will take some period of time to converge. Immediately running the 
same optimization again on the same machine may converge sooner or take longer. 
The timing is not fixed, as it would be for an exhaustive optimization that 
will always perform exactly the same number of backtests.

Mike

--- In amibroker@yahoogroups.com, "dubi1974"  wrote:
>
> Hi,
> 
> I tested it and compared an normal optimization process between 32bit and 64 
> bit. On the same formula Amibroker 32-bit took more than 8 hours for the 
> optimization process, and Amibroker 64-bit just 4h:50min.
> 
> So my experience shows me, that it's much faster. My question is, could you 
> Tomasz provide us the optimizer.dll in 64-bit? Like cmae or tribes? For 
> testing purpose.
> 
> Many thanks.
> 
> Regards, dubi
> 
> --- In amibroker@yahoogroups.com, Tomasz Janeczko  wrote:
> >
> > Hello,
> > 
> > AmiBroker 5.30.1 64-bit edition (experimental) is now available for 
> > download from:
> > http://www.amibroker.com/x64/
> > 
> > This is experimental version *only* for people running 64-bit Windows 
> > and wanting to utilise *more* than 4GB of memory. 64-bit version does 
> > NOT offer anything more, just ability to access more memory.  It can 
> > (and should) be installed into *separate* folder, so it does not 
> > overwrite 32-bit edition (if installed). This version includes only 2 
> > plugins: CMAE and IB (interactive brokers) plugin.   64-bit version of 
> > IQFeed plugin is in the works
> > and it will arrive later.
> > 
> > Note that regular users, even running 64-bit Windows should rather run 
> > regular, 32-bit version of AmiBroker as it offers more compatibility and 
> > was tested on way more installations.
> > 
> > Please note that 64-bit version has BETA/experimental status and in case 
> > of problems you should use 32-bit version instead.
> > 
> > Best regards,
> > Tomasz Janeczko
> > amibroker.com
> >
>




[amibroker] Re: More precise CAGR calculation

2010-07-08 Thread Mike
Seems like you are defeating the purpose of the metric. Assume you're given 2 x 
$1,000 on Jan 1, 2006 to invest for 3 years; $1,000 for each of 2 systems.

- System A generates its first trade immediately on Jan 1, 2006 and finishes 
the 3 year period up $500.

- System B does not generate its first trade until Jan 1, 2007 and also 
finishes the 3 year period up $500.

The intent of CAGR is to compare different systems over the same period of 
time. With respect to CAGR, the two systems are identical. Your proposal would 
artificially inflate the value of System B concluding that it was superior to 
A, which is not at all the case.

http://www.investorglossary.com/compound-annual-return.htm

Mike

--- In amibroker@yahoogroups.com, "engineering_returns"  
wrote:
>
> Hello AmiBroker - Experts,
> often i do test strategies within a specific date range. The strategy
> backtest report (Annual Return %) doesn't consider the date of the first
> trade for calculation. It's using the date of the first bar for
> calculation, hence the "Annual Return%" is wrong. Do you have the same
> problem?
> I've written the following CBT code to account for this problem. Any
> feedback / comment is very much appreciated
>  bo2   = GetBacktesterObject();trade = bo2.GetFirstTrade();
> Entryd= trade.entrydatetime;bo2.AddCustomMetric( "FirstTrade",
> NumToStr( Entryd, formatDateTime ) );Text  = StrRight(NumToStr(
> Entryd, formatDateTime ),4);Years = Year()- StrToNum(text) + 1;   
> bo2.AddCustomMetric( "Years", NumToStr(Years,0) );Ratio = 
> stats.getvalue("EndingCapital") / stats.getvalue("InitialCapital");
> CAGR  = (Ratio ^ (1/Years)-1)*100;bo2.AddCustomMetric( "CAGR",
> NumToStr(Cagr,1.2) );
> 
> Frank
> engineering-returns.com <http://engineering-returns.com/>
>




*[amibroker] Re: Does Portfolio Backtester always use signal price?

2010-07-07 Thread Mike
Unless, of course, the police yell "ExitAtStop set to 2!" In which case that's 
exactly what it means :)

"ExitAtStop = 2 - check High-Low prices but exit NEXT BAR on regular trade 
price."

Mike

--- In amibroker@yahoogroups.com, Keith McCombs  wrote:
>
> 'Stops' are supposed to sell (or buy, short, or cover) on same bar.  
> That is why they are called 'Stops'.  Stop right NOW, I'm out of here.  
> If the police yell, "Stop, or I'll shoot", they surely don't mean stop 
> tomorrow.
> 
> On 7/7/2010 13:40, graphman27 wrote:
> >
> > Keith: Well, let's say for example that I use exchange-traded funds 
> > that trade intraday. Let's also say I use hourly bars. If my code says 
> > to buy or sell NEXT BAR after the signal comes, then there is a delay. 
> > Now, if that purchase later gets stopped out, does Portfolio 
> > Backtester use the signal buy price OR the real buy price (which is 
> > next bar). For some reason, I think the portfolio backtester is 
> > changing the time stamp and price. No solid proof yet, but that's what 
> > it looks like. My regular (no stops) buys and sells are next bar, but 
> > any buy that eventually got stopped out has the buy price as same bar.
> >
> > Steve.
> >
> > --- In amibroker@yahoogroups.com <mailto:amibroker%40yahoogroups.com>, 
> > Keith McCombs  wrote:
> > >
> > > You should not be using Stops at all for mutual funds. A Stop means
> > > stop right NOW. Do not wait one second more.
> > >
> > > But for mutual funds you HAVE to wait. So, just use Sell.
> > >
> > > On 7/7/2010 11:39, graphman27 wrote:
> > > >
> > > > I'm wondering if the Portfolio Backtester always uses signal price,
> > > > regardless of what the settings/coding is for when to buy (next bar,
> > > > etc.)?
> > > >
> > > > When I look at a portfolio backtest report of trades, I notice that
> > > > all my "regular" (no stop triggered) matched buys and sells actually
> > > > bought and sold the securities on the proper date and at the proper
> > > > price (in my case, CLOSE+1 or next bar - with EOD data). I get a
> > > > signal to buy on Monday night and the trade is completed Tuesday at
> > > > the close. This is perfect.
> > > >
> > > > However, if I own a security and a stop gets triggered Wednesday 
> > night
> > > > at the close and the security is sold NEXT BAR (in my case, with EOD
> > > > mutual fund trades, the next day's close) or on Thursday at the 
> > close,
> > > > I notice that the buy date and price is actually the signal date and
> > > > price, NOT the next bar (Next day for mutual funds). This creates an
> > > > enormous problem. I can't get an EOD signal to buy something, say on
> > > > Monday NIGHT and then say that I purchased it Monday AT THE CLOSE!
> > > > That's a physical impossibility. The market already was closed Monday
> > > > night. Why are my stopped out trades, in Portfolio Backtester, 
> > using a
> > > > buy date of CLOSE+0, but when I have a signal triggered sell (no stop
> > > > triggered), the buy date and price is what it should be for me, which
> > > > is CLOSE+1 bar delay? This doesn't make any sense.
> > > >
> > > > If this is the case, which is obviously wrong, is there a simple fix?
> > > >
> > > > Thanks!
> > > >
> > > >
> > >
> >
> >
>




[amibroker] Re: Optimizer and Backtester losing trades

2010-07-07 Thread Mike
You have not indicated how you generated your log file (or at least it is not 
showing up on the web forum). But, the backtester will reject trades due to a 
number of settings that your log would appear not to be considering; e.g. max 
positions, insufficient funds, position size shrinking, redundant signals, etc. 
etc.

AmiBroker is a very mature product with thousands of users. When something is 
not working out the way you expect, 99.9% of the time it's going to be because 
of something we the users are doing incorrectly, rather than what AmiBroker is 
doing incorrectly ;)

Run your backtest with detailed reporting (see AA Settings) and you will get a 
bar by bar breakdown of signals, entries, exits and reason for rejections.

Mike

--- In amibroker@yahoogroups.com, "michaels_musings"  
wrote:
>
> Anyone know how to get the Backtester and Optimizer to include all trades in 
> their results?  The code below (firstSystemPostCopy.afl) initiates trades 
> that get captured by the logfile, but they don't show up or get accumulated 
> in the Backtester or Optimizer.  The results are from ~six months of 1-minute 
> bars of FAS.  The Backtester shows 16 trades with profit of $7,110.38.  Per 
> the logfile there were 24 trades with profit of $3,751.29.
> 
> Anyone know why the extra 8 trades weren't included in the Backtester?
> 
> Thanks,
> Michael
> 
> First few trades from Backtester:
> Ticker Trade Entry Exit 
> FAS Long 11/30/2009 2:53:00 PM 25.03 12/8/2009 7:32:00 AM 23.52 
> FAS Long 12/23/2009 7:27:00 AM 25.03 1/5/2010 2:42:00 PM 27.03 
> FAS Long 2/16/2010 2:31:00 PM 23.18 2/22/2010 1:24:00 PM 25.03 
> FAS Long 3/5/2010 9:44:00 AM 27.03 3/10/2010 9:10:00 AM 29.19 
> 
> 
> First few trades from Log File:
> Symbol, Action, Date, Time, Buy point, Entry, Exit
> FAS, Bought, 2009-11-30, 14:53:00, 5, 25.0300
> FAS, StopLoss, 2009-12-08, 07:32:00, 5, 25.0300, 23.5200
> FAS, Bought, 2009-12-23, 07:27:00, 5, 25.0300
> FAS, Profit, 2010-01-05, 14:42:00, 5, 25.0300, 27.0300
> FAS, Bought, 2010-01-05, 14:42:00, 6, 27.0300
> FAS, StopLoss, 2010-01-22, 06:11:00, 6, 27.0300, 25.4000
> FAS, Bought, 2010-02-16, 14:31:00, 4, 23.1800
> FAS, Profit, 2010-02-22, 13:24:00, 4, 23.1800, 25.0300
> 
> [Since no one wants a 1,000 line email, full files are at:  
> http://michaels-musings.com/amibroker-optimizer-and-backtester-losing-trades.html
>  ]
> 
> firstSystemPostCopy.afl - Script I'm running
> trades.html - Backtester trade list
> settings.html - Backtester settings
> stats.html - Backtester stats
> firstSystemLog.txt - Log File created by firstSystemPostCopy.afl
> AmiBrokerLostTrades.xls - Trade list from log file w/ computed Profit
>




[amibroker] Re: Does Portfolio Backtester always use signal price?

2010-07-07 Thread Mike
Trade delays apply only to Buy/Sell/Short/Cover, not stops. The exitatstop 
argument of ApplyStop dictates the timing of the stop.

Mike

--- In amibroker@yahoogroups.com, "graphman27"  wrote:
>
> Keith:  Well, let's say for example that I use exchange-traded funds that 
> trade intraday.  Let's also say I use hourly bars.  If my code says to buy or 
> sell NEXT BAR after the signal comes, then there is a delay.  Now, if that 
> purchase later gets stopped out, does Portfolio Backtester use the signal buy 
> price OR the real buy price (which is next bar).  For some reason, I think 
> the portfolio backtester is changing the time stamp and price.  No solid 
> proof yet, but that's what it looks like.  My regular (no stops) buys and 
> sells are next bar, but any buy that eventually got stopped out has the buy 
> price as same bar.
> 
> Steve.
> 
> --- In amibroker@yahoogroups.com, Keith McCombs  wrote:
> >
> > You should not be using Stops at all for mutual funds.  A Stop means 
> > stop right NOW.  Do not wait one second more.
> > 
> > But for mutual funds you HAVE to wait.  So, just use Sell.
> > 
> > On 7/7/2010 11:39, graphman27 wrote:
> > >
> > > I'm wondering if the Portfolio Backtester always uses signal price, 
> > > regardless of what the settings/coding is for when to buy (next bar, 
> > > etc.)?
> > >
> > > When I look at a portfolio backtest report of trades, I notice that 
> > > all my "regular" (no stop triggered) matched buys and sells actually 
> > > bought and sold the securities on the proper date and at the proper 
> > > price (in my case, CLOSE+1 or next bar - with EOD data). I get a 
> > > signal to buy on Monday night and the trade is completed Tuesday at 
> > > the close. This is perfect.
> > >
> > > However, if I own a security and a stop gets triggered Wednesday night 
> > > at the close and the security is sold NEXT BAR (in my case, with EOD 
> > > mutual fund trades, the next day's close) or on Thursday at the close, 
> > > I notice that the buy date and price is actually the signal date and 
> > > price, NOT the next bar (Next day for mutual funds). This creates an 
> > > enormous problem. I can't get an EOD signal to buy something, say on 
> > > Monday NIGHT and then say that I purchased it Monday AT THE CLOSE! 
> > > That's a physical impossibility. The market already was closed Monday 
> > > night. Why are my stopped out trades, in Portfolio Backtester, using a 
> > > buy date of CLOSE+0, but when I have a signal triggered sell (no stop 
> > > triggered), the buy date and price is what it should be for me, which 
> > > is CLOSE+1 bar delay? This doesn't make any sense.
> > >
> > > If this is the case, which is obviously wrong, is there a simple fix?
> > >
> > > Thanks!
> > >
> > >
> >
>




[amibroker] Re: Random Entries and Exits?

2010-07-06 Thread Mike
Try this:

SetTradeDelays( 1, 1, 1, 1 );
SetPositionSize(2, spsPercentOfEquity);

BuyPrice = O;
SellPrice = O;

Buy = mtRandomA() <= 0.4;   // 40% chance of buy
Sell = mtRandomA() <= 0.2;  // 20% chance of sell


Mike

--- In amibroker@yahoogroups.com, "spacebass5000"  wrote:
>
> Hey all,
> 
> I need to formulate a way to create an algo that randomly enters and exits a 
> given stock. I have devised the following (to no avail):
> 
> // start code ==
> 
> SetTradeDelays(1,1,1,1);
> 
> BuyPrice = O;
> SellPrice = O;
> ShortPrice = O;
> CoverPrice = O;
> 
> RandomNum = floor(mtRandom() * 1);
> 
> printf("\nRandomNum = %5.2f\n", RandomNum);
> 
> while(RandomNum >= BarCount)
> {
>   RandomNum = floor(mtRandom() * 1);
>   printf("RandomNum = %5.2f\n", RandomNum);
> }
> 
> SetOption("HoldMinBars", RandomNum );
> 
> CoinFlip = floor(mtRandom() * 10);
> 
> printf("\nCoinFlip = %5.2f\n", CoinFlip);
> 
> if(CoinFlip >= 5)
> {
>   Buy = True;
>   Sell = False;
>   Short = Sell;   
>   Cover = Buy;
>   
> }
> else
> {
>   Buy = False;
>   Sell = True;
>   Short = Sell;   
>   Cover = Buy;
> }
> 
> Buy = ExRem(Buy, Sell);
> Sell = ExRem(Sell, Buy);
> 
> Short = ExRem(Short, Cover);
> Cover = ExRem(Cover, Short);
> 
> // end code ==
> 
> I am planning at looking at 15 years of daily data... the reason to multiply 
> the random number by 1. Granted, this hasn't really seemed to work out 
> for me yet. I don't really see really small numbers generated from mtRandom 
> so most of my holding times are really long. 
> 
> Any comments related to created random entries/exits and/or the code I have 
> whipped up are surely welcome.
>




[amibroker] Re: Does running multiple instances of AB increase processing power?

2010-07-02 Thread Mike
The OS will bounce the instances around between cores in whatever way it sees 
fit. If you want to *hint* that a process should stay on a specific core, you 
can manually set the affinity:

http://www.addictivetips.com/windows-tips/how-to-set-processor-affinity-to-an-application-in-windows/

Probably not much to be gained by doing so. There are examples of older 
software that did not perform well in a multi core environment, in which case 
setting the affinity was the solution.

More info:

http://en.wikipedia.org/wiki/Processor_affinity

Mike

--- In amibroker@yahoogroups.com, "Rob"  wrote:
>
> 
> The OS will take care of all that... I've never seen a case where opening a 
> separate instance of AB, it wasn't assigned to a different core.
>




[amibroker] Re: How To Extend Arrays Into The Future?

2010-07-02 Thread Mike
Have a look at this link:

http://finance.groups.yahoo.com/group/amibroker/message/133629

Mike

--- In amibroker@yahoogroups.com, "michaels_musings"  
wrote:
>
> Hi Dave,
> 
> As I understand it, you can't.  
> 
> The number of bars defines how large any array can be in AB.  That said, you 
> can probably create a new var and shift it's values by shifting it's index.  
> ( eg newVar[i-10] = ... )
> 
> Post the code for what you want to calculate and there's a good chance 
> someone here can get done what you're trying to get done...
> 
> Regards,
> Michael
> 
> 
> --- In amibroker@yahoogroups.com, "nxnbid"  wrote:
> >
> > I want to calculate some indicators beyond the end of my data - i.e. for 
> > the next 10 days say.
> > How can I extend the various arrays to include those dates?
> > 
> > Dave
> >
>




[amibroker] Re: Difference between raw and actual signals

2010-07-02 Thread Mike
http://www.amibroker.com/guide/h_portfolio.html

Mike

--- In amibroker@yahoogroups.com, "rus"  wrote:
>
> Hello there AB people,
> 
> Could anyone point out the difference between raw and actual signals 
> generated by the backtest code?
> 
> Thanks,
> Dre
>




[amibroker] Re: How to mix systems

2010-07-01 Thread Mike
What I described was aimed at backtesting multiple systems to emulate how you 
trade in real life (i.e. generate statistics for how you would have traded, as 
opposed to what you should trade next).

I suspect that the approach that I outlined would not help generate trades for 
you in real time since by definition the backtest acts on bars that have 
already closed.

I don't auto trade, so I'll leave that advice for others to offer. However, I 
can point you to some links that can get you started.

Your first point of research should probably be the User's Knowledge Base. 
Herman and Al have written extensively there:

http://www.amibroker.org/userkb/

Next, there is a dedicated Yahoo group for AmiBroker auto trading: 

http://finance.groups.yahoo.com/group/AmiBroker-at/?yguid=83897329

A member of that group, Barry, has posted a skeleton auto trading system to the 
AFL Library which may be useful:

http://www.amibroker.com/members/library/detail.php?id=1225


Mike

--- In amibroker@yahoogroups.com, "Matthias"  wrote:
>
> Keith and Mike,
> 
> thank you very much for your helpful postings. Looks like I'll have a long 
> weekend :).
> 
> Obviously I need to absorb and test what you've just said in great detail 
> which will require time. I shall keep you posted. Just wondering if this is 
> such an akward "out-of-the-world" problem. Things start to get complex here 
> real quick (for me at least) and whatever approach I take, it seems to be 
> error-prone if not done/checked ultra-carefully. Maybe this one could be 
> implemented a little easier in future versions of Ami so that one could spend 
> more time on system development or portfolio composition rather than spending 
> hours n days to tailor simple AFL's into 1 complex 
> "multi-AFL-combined-and-custom-backtest-proc-afl"
> 
> Regarding Keith's post e):
> 
> //
>  I don't know if AB can properly handle long and short positions 
> simultaneously in the same stock or contract.  That will require a simple 
> experiment on your part. If AB can't, then simply export your symbol of 
> choice, import into a spread sheet or text editor, change the symbol to 
> something unique like symbol_SO, and import back into your data base.  Now 
> you have two separate symbols, which we know AB can handle properly.
> 
> ///
> 
> Just by reading it, I figured that one would require an external source, such 
> as Excel. Problem here is that this is supposed to work in RT environment 
> doing autotrading, anyways I'll look into it.
> 
> 
> 
> Regarding Mike's post:
> 
> ///
> I haven't actually tried any of the above, and do not know how well
> it would translate into auto trading 
> ///
> 
> Sounds like this is something extraordinary, but are there so little user 
> asking about this multiple-system concept? Look, I don't have an account to 
> autotrade yet, but if I figured out a way on how to do this, this would be 
> run in AA window, "backtesting" the system, so to say - run that piece of 
> code every xx minutes, is that correct? I remember somebody from Amibroker 
> support told me to program it like a scan and think of autotrading like I 
> would just scan for signals. Not sure if I understand the concept, but does 
> scan include custom backtest proc?
> 
> I'll see what goes, but out curiosity: just wondering if the execution speed 
> of this code would be proefficient.
> 
> 
> Thanks again.
>




[amibroker] Re: How to make stops trigger as CLOSE +1

2010-07-01 Thread Mike
I believe that it will solve your signal price problem. I don't actually use 
ApplyStop, so my comments are based on what I've read rather than what I've 
used.

If you rely on the backtester to generate trades, the code provided may not 
work, since you will need to already have a bar for Tuesday in order to see the 
trade based on Monday's signal. Perhaps a snapshot prior to Tuesday's close.

An exploration would work, since you would have the Monday data and could 
search on BuyTrigger instead of Buy, as indicated in my last reply. You could 
probably write a master exploration that #include each of the multiple rule 
sets.

Worse case scenario; remove the ApplyStop functionality from your existing 
script and keep running it in the backtester for signal generation. Just be 
sure to use the revised one for actual backtesting  when doing system analysis.

Mike

--- In amibroker@yahoogroups.com, "graphman27"  wrote:
>
> You are the man again Mike.  I will make these changes and give it a test.
> 
> When you say trade intraday, I just wanted to remind you that I only trade 
> mutual funds.
> 
> Will this acutally fix the problem of the stop levels using the signal date 
> price and not the purchase date pirce, which is CLOSE+1?
> 
> Lastly, I think we've gone through this before, but I use the backtester to 
> get live signals.  I only trade around 12 symbols and they are typically 
> within the portfolio backtester.  An example would be a portfolio with 6 
> different signals for 6 different symbols.  It seems to be the easiest and 
> fastest way to get the signals each day.  Otherwise, I would have to run 
> 12-15 different individual symbols, instead of 3 portfolios.
> 
> --- In amibroker@yahoogroups.com, "Mike"  wrote:
> >
> > Steve,
> > In response to both this post and your prior one:
> > 1.  Ref(Array, -1)  means "what was the value of Array on the bar
> > previous to this one?".2.  BuyPrice = Close means "set the purchase
> > price to this bar's close".
> > On Monday you are getting a signal. On Tuesday you want to trade that
> > signal using Tuesday's Close. That is easily modeled using the two
> > points above:
> > BuyTrigger = ...;Buy = Ref(BuyTrigger, -1);  // 1. If Monday had a
> > signal, then buy it today (Tuesday).BuyPrice = Close; // Use today's
> > (Tuesday) Close as the purchase price.
> > This sets you up perfectly for Scenario 2 of ApplyStop which says that
> > you trade on today's Close (Tuesday) and want to exit intraday from that
> > point on (i.e. you have a stop loss order with your broker that will
> > stop you out anytime the price falls below your stated max loss). The
> > ApplyStop is independent of your Sell logic. Your Sell will still exit
> > at the Close, but your stop may exit intraday.
> > Completing your code sample gives the following:
> > /*
> > Scenario 2:
> > You trade on today's close and want to exit intraday on stop price
> > 
> > Correct settings:
> > A. ActivateStopsImmediately turned OFF
> > B. ExitAtStop = 1
> > C. Trade delays set to zero
> > D. Trade price set to close
> > */
> > 
> > SetOption("ActivateStopsImmediately", false);  // A.
> > ActivateStopsImmediately turned OFF
> > SetTradeDelays(0, 0, 0, 0);  // C. Trade delays set to zero
> > 
> > BuyTrigger =  Cross(StochFinal, Trigger) AND (EMA(Close, EMAShort) >
> > EMA(Close, EMALong));
> > Buy = Ref(BuyTrigger, -1);
> > BuyPrice = Close;  // D. Trade price set to close
> > 
> > SellTrigger =  Cross(Trigger, StochFinal) AND (EMA(Close, EMAShort) <
> > EMA(Close, EMALong));
> > Sell = Ref(SellTrigger, -1);
> > SellPrice = Close;  // D. Trade price set to close
> > 
> > ApplyStop(   stopTypeLoss,
> >   stopModePercent,
> >   Optimize("max. loss stop level", 2, 2, 10, 2),
> >   1,  // B. ExitAtStop = 1
> >   False);
> > 
> > 
> > I can't fully test your code since your assignments for StochFinal and
> > Trigger were not provided. But, I believe that the above will solve your
> > problem.
> > If you want to run an Exploration each night to see what you should be
> > trading the next day, just use AddColumn to output the values of
> > BuyTrigger and SellTrigger instead of Buy and Sell respectively.
> > Mike
> > 
> > --- In amibroker@yahoogroups.com, "graphman27"  wrote:
> > >
> > > I want to simplify my life, believe me.  I'm having a bit of
> > difficulty following what you're saying t

[amibroker] Re: How to make stops trigger as CLOSE +1

2010-07-01 Thread Mike
Steve,
In response to both this post and your prior one:
1.  Ref(Array, -1)  means "what was the value of Array on the bar
previous to this one?".2.  BuyPrice = Close means "set the purchase
price to this bar's close".
On Monday you are getting a signal. On Tuesday you want to trade that
signal using Tuesday's Close. That is easily modeled using the two
points above:
BuyTrigger = ...;Buy = Ref(BuyTrigger, -1);  // 1. If Monday had a
signal, then buy it today (Tuesday).BuyPrice = Close; // Use today's
(Tuesday) Close as the purchase price.
This sets you up perfectly for Scenario 2 of ApplyStop which says that
you trade on today's Close (Tuesday) and want to exit intraday from that
point on (i.e. you have a stop loss order with your broker that will
stop you out anytime the price falls below your stated max loss). The
ApplyStop is independent of your Sell logic. Your Sell will still exit
at the Close, but your stop may exit intraday.
Completing your code sample gives the following:
/*
Scenario 2:
You trade on today's close and want to exit intraday on stop price

Correct settings:
A. ActivateStopsImmediately turned OFF
B. ExitAtStop = 1
C. Trade delays set to zero
D. Trade price set to close
*/

SetOption("ActivateStopsImmediately", false);  // A.
ActivateStopsImmediately turned OFF
SetTradeDelays(0, 0, 0, 0);  // C. Trade delays set to zero

BuyTrigger =  Cross(StochFinal, Trigger) AND (EMA(Close, EMAShort) >
EMA(Close, EMALong));
Buy = Ref(BuyTrigger, -1);
BuyPrice = Close;  // D. Trade price set to close

SellTrigger =  Cross(Trigger, StochFinal) AND (EMA(Close, EMAShort) <
EMA(Close, EMALong));
Sell = Ref(SellTrigger, -1);
SellPrice = Close;  // D. Trade price set to close

ApplyStop(   stopTypeLoss,
  stopModePercent,
  Optimize("max. loss stop level", 2, 2, 10, 2),
  1,  // B. ExitAtStop = 1
  False);


I can't fully test your code since your assignments for StochFinal and
Trigger were not provided. But, I believe that the above will solve your
problem.
If you want to run an Exploration each night to see what you should be
trading the next day, just use AddColumn to output the values of
BuyTrigger and SellTrigger instead of Buy and Sell respectively.
Mike

--- In amibroker@yahoogroups.com, "graphman27"  wrote:
>
> I want to simplify my life, believe me.  I'm having a bit of
difficulty following what you're saying to do.  Here is some sample
code, just in case I'm not being clear:
>
> Buy = Cross(StochFinal,Trigger) AND (EMA( Close,EMAShort ) > EMA(
Close,EMALong ));
>
> Sell = Cross(Trigger,StochFinal) AND (EMA( Close,EMAShort ) < EMA(
Close,EMALong ));
>
> Plot( EMA ( Close,2 ),"Short EMA", colorGreen, styleThick );
> Plot( EMA ( Close,10 ),"Long EMA", colorRed, styleThick );
> Plot( StochFinal ,"Period", colorGreen, styleThick );
>
> /* max loss stop optimization */
>
> ApplyStop(stopTypeLoss,
>  stopModePercent,
>  Optimize( "max. loss stop level", 2, 2, 10, 2 ),
>2,
>  False );
>
> What do I need to do to make sure:
>
> 1.  All buys and sells are done as CLOSE+1 (I only use EOD data for
mutual funds).
> 2.  Make sure stops are triggered based on the purchase price, not the
price on the -1 signal date.
>
> Right now, under settings, I have Buys and Sells set to CLOSE +1.
>
> Thanks!
>
> --- In amibroker@yahoogroups.com, "Mike" sfclimbers@ wrote:
> >
> > Hi,
> >
> > Since you are trading the Close, you could simplify your life by
following one of the well defined scenarios from the ApplyStop
documentation:
> >
> > http://www.amibroker.com/guide/afl/afl_view.php?id=20
> >
> > In your case, follow scenario 2 and take your trades based on
yesterday's signal.
> >
> > e.g.
> >
> > SetTradeDelays(0, 0, 0, 0);
> >
> > Trigger = ...;
> > Buy = Ref(Trigger, -1);
> > BuyPrice = Close;
> >
> > Your signal still shows up Monday night. But, you don't act on it
until Tuesday Close. That's what you're doing in real life anyway, so
just make your code show the same.
> >
> > Mike
> >
> > --- In amibroker@yahoogroups.com, "graphman27"  wrote:
> > >
> > > Question:  When stops are coded afl instead of setup under
settings, do they disregard the system settings for Buy Price and Buy
Delay?   Currently, I have the latter set to Buy Price = Close+1 Day Buy
Delay.  For a new strategy I am working on, I notice that during live
testing something doesn't jive.  Here is an example...
> > >
> > > Note:  I always use EOD data and CLOSE +1, to get "tradable"
signals for mutual funds and indices:
> > >
> > &

[amibroker] Re: How to make stops trigger as CLOSE +1

2010-06-30 Thread Mike
Hi,

Since you are trading the Close, you could simplify your life by following one 
of the well defined scenarios from the ApplyStop documentation:

http://www.amibroker.com/guide/afl/afl_view.php?id=20

In your case, follow scenario 2 and take your trades based on yesterday's 
signal.

e.g.

SetTradeDelays(0, 0, 0, 0);

Trigger = ...;
Buy = Ref(Trigger, -1);
BuyPrice = Close;

Your signal still shows up Monday night. But, you don't act on it until Tuesday 
Close. That's what you're doing in real life anyway, so just make your code 
show the same.

Mike

--- In amibroker@yahoogroups.com, "graphman27"  wrote:
>
> Question:  When stops are coded afl instead of setup under settings, do they 
> disregard the system settings for Buy Price and Buy Delay?   Currently, I 
> have the latter set to Buy Price = Close+1 Day Buy Delay.  For a new strategy 
> I am working on, I notice that during live testing something doesn't jive.  
> Here is an example...
> 
> Note:  I always use EOD data and CLOSE +1, to get "tradable" signals for 
> mutual funds and indices:
> 
> Monday Night:  Formula gave buy signal for Emerging Markets after the close.  
> With CLOSE+1 Day delay, that would mean buy at Tuesday's Close.
> 
> Tuesday Night:  Max Loss Stop is triggered because of a -3.5% drop in the 
> Emerging Markets on Tuesday.
> 
> Wednesday at the close, mutual fund is sold.
> 
> Question:  How could a Max Loss Stop be triggered if that fund wasn't 
> purchased until AFTER Tuesday's big drop?  Since it was purchased AFTER the 
> drop, there was no loss of -3.5% going into Wednesday.
> 
> Here is an example of a typical mutual fund compatible coded stop:
> 
> ApplyStop(stopTypeLoss, 
>  stopModePercent, 
>  Optimize( "max. loss stop level", 2, 2, 10, 2 ), 
>  False );
> 
> Do I have to code something else to make sure the STOP is triggered based on 
> the CLOSE+1 purchase price and NOT the BUY SIGNAL Price?  Or, do I need to 
> code the Buys and Sells inside the formula as CLOSE+1 instead of relying on 
> system settings?  OR, none of the above?
> 
> Thanks in advance for your help, as usual!
> 
> Steve.
>




[amibroker] Re: Percent Volatility Position Sizing

2010-06-29 Thread Mike
No. Order doesn't make a difference.

Function declarations must come first, before they can be used. Backtesting 
code does not suffer the same restriction.

Mike

--- In amibroker@yahoogroups.com, "rise_t575"  wrote:
>
> 
> 
> Ok - one last question (sorry ;-) ) - I've just noticed that you put the 
> system code in front of the custom backtester code.
> I was thinking that the custom backtest code has to come *first*.
> Could that be the culprit of the problem?
> 
> --- In amibroker@yahoogroups.com, "Mike"  wrote:
> >
> > Works fine for me. I've added a simple trading system to your code (as
> > well as a date to your Trace output).
> > Running it against the AmiBroker trial version database with a watchlist
> > of (AA, CAT, ^DJI) works fine. Note that trades are never taken for ^DJI
> > since there is insufficient equity (initial equity set to 10,000).
> > _SECTION_BEGIN( "Money Manager: Percent Volatility" );
> > systemMMVolatilityPercent = Param( "Percent", 2, 0.1, 10, 0.1 );
> > systemMMVolatilityATR = Param( "ATR Period", 20, 1, 250, 1 );
> > _SECTION_END();
> > 
> > StaticVarSet( "MyAtr" + Name( ), ATR( systemMMVolatilityATR ) );
> > 
> > fast =  MA( Close, 5 );
> > slow = MA( Close, 50 );
> > Buy = Cross( fast, slow );
> > Sell = Cross( slow, fast );
> > SetPositionSize( 2, spsPercentOfEquity );
> > 
> > SetCustomBacktestProc( "" );
> > 
> > if ( Status( "action" ) == actionPortfolio )
> > {
> >  bo = GetBacktesterObject();
> >  bo.PreProcess();
> >  dates = DateTime();
> > 
> >   for ( bar = 0; bar < BarCount; bar++ )
> >  {
> >  for ( sig = bo.GetFirstSignal( bar ); sig; sig =
> > bo.GetNextSignal( bar ) )
> >  {
> >  if ( sig.IsEntry() )
> >  {
> >  CurrentEquity = bo.Equity;
> >  Test = StaticVarGet( "MyAtr" + sig.Symbol );
> >  _TRACE( NumToStr( dates[bar], formatDatetime ) + " " +
> > sig.symbol + " " + NumToStr( Test[bar] ) + " " + " " + NumToStr( bar )
> > );
> > // units = CurrentEquity * ( systemMMVolatilityPercent / 100 ) /
> > Test[bar];
> > // sig.PosSize = sig.Price * units;
> >  }
> >  }
> > 
> >  bo.ProcessTradeSignals( bar );
> >  }
> > 
> >  bo.PostProcess();
> > }
> > Mike
> > --- In amibroker@yahoogroups.com, "rise_t575"  wrote:
> > >
> > > Thank you Mike.
> > >
> > > My knowledge of the custom backtester is still pretty limited (my
> > first
> > > try), although I have been readining everything I could get my hands
> > on.
> > >
> > > Now the ticker symbols the _TRACE window is giving me are completely
> > > different (exclusive) than the ticker symbols that come up in the
> > > backtesting window.
> > >
> > > Could someone look over the code & tell me what is wrong here?
> > >
> > > Thanks in advance!
> > >
> > >
> > > _SECTION_BEGIN( "Money Manager: Percent Volatility" );
> > > systemMMVolatilityPercent = Param( "Percent", 2, 0.1, 10, 0.1 );
> > > systemMMVolatilityATR = Param( "ATR Period", 20, 1, 250, 1 );
> > > _SECTION_END();
> > >
> > > StaticVarSet( "MyAtr"+Name( ), ATR(systemMMVolatilityATR) );
> > >
> > > SetCustomBacktestProc("");
> > >
> > > if ( Status( "action" ) == actionPortfolio )
> > > {
> > >  bo = GetBacktesterObject();
> > >  bo.PreProcess();
> > >
> > >  for ( bar = 0; bar < BarCount; bar++ )
> > >  {
> > >  for ( sig = bo.GetFirstSignal( bar ); sig; sig =
> > > bo.GetNextSignal( bar ) )
> > >  {
> > >  if(sig.IsEntry())
> > >  {
> > >  CurrentEquity = bo.Equity;
> > >  Test = StaticVarGet( "MyAtr"+sig.Symbol);
> > >  _TRACE(sig.symbol + " " + NumToStr(Test[bar])+" " + "
> > "
> > > + NumToStr(bar));
> > > //units = CurrentEquity * ( systemMMVolatilityPercent
> > /
> > > 100 ) / Test[bar];
> > > //sig.PosSize = sig.Price * units;
> > >  }
> > >  }
> > >  bo.ProcessTradeSignals( bar );
> > >  }
> > >  bo.PostProcess();
> > >
> >
>




[amibroker] Re: Simple Question regading OOP

2010-06-29 Thread Mike
It keeps the old value.

Mike

--- In amibroker@yahoogroups.com, "rise_t575"  wrote:
>
> For my better understanding of OOP:
> 
> When I copy an object property...
> 
> e. g.
> 
> CurrentEquity = bo.Equity;
> 
> ... if the bo.Equity property changes afterwards, does the variable 
> CurrentEquity change with it, or does it contain the old value?
> 
> Thanks in advance!
>




[amibroker] Re: Percent Volatility Position Sizing

2010-06-29 Thread Mike
Works fine for me. I've added a simple trading system to your code (as
well as a date to your Trace output).
Running it against the AmiBroker trial version database with a watchlist
of (AA, CAT, ^DJI) works fine. Note that trades are never taken for ^DJI
since there is insufficient equity (initial equity set to 10,000).
_SECTION_BEGIN( "Money Manager: Percent Volatility" );
systemMMVolatilityPercent = Param( "Percent", 2, 0.1, 10, 0.1 );
systemMMVolatilityATR = Param( "ATR Period", 20, 1, 250, 1 );
_SECTION_END();

StaticVarSet( "MyAtr" + Name( ), ATR( systemMMVolatilityATR ) );

fast =  MA( Close, 5 );
slow = MA( Close, 50 );
Buy = Cross( fast, slow );
Sell = Cross( slow, fast );
SetPositionSize( 2, spsPercentOfEquity );

SetCustomBacktestProc( "" );

if ( Status( "action" ) == actionPortfolio )
{
 bo = GetBacktesterObject();
 bo.PreProcess();
 dates = DateTime();

  for ( bar = 0; bar < BarCount; bar++ )
 {
 for ( sig = bo.GetFirstSignal( bar ); sig; sig =
bo.GetNextSignal( bar ) )
 {
 if ( sig.IsEntry() )
 {
 CurrentEquity = bo.Equity;
 Test = StaticVarGet( "MyAtr" + sig.Symbol );
 _TRACE( NumToStr( dates[bar], formatDatetime ) + " " +
sig.symbol + " " + NumToStr( Test[bar] ) + " " + " " + NumToStr( bar )
);
// units = CurrentEquity * ( systemMMVolatilityPercent / 100 ) /
Test[bar];
// sig.PosSize = sig.Price * units;
 }
 }

 bo.ProcessTradeSignals( bar );
 }

 bo.PostProcess();
}
Mike
--- In amibroker@yahoogroups.com, "rise_t575"  wrote:
>
> Thank you Mike.
>
> My knowledge of the custom backtester is still pretty limited (my
first
> try), although I have been readining everything I could get my hands
on.
>
> Now the ticker symbols the _TRACE window is giving me are completely
> different (exclusive) than the ticker symbols that come up in the
> backtesting window.
>
> Could someone look over the code & tell me what is wrong here?
>
> Thanks in advance!
>
>
> _SECTION_BEGIN( "Money Manager: Percent Volatility" );
> systemMMVolatilityPercent = Param( "Percent", 2, 0.1, 10, 0.1 );
> systemMMVolatilityATR = Param( "ATR Period", 20, 1, 250, 1 );
> _SECTION_END();
>
> StaticVarSet( "MyAtr"+Name( ), ATR(systemMMVolatilityATR) );
>
> SetCustomBacktestProc("");
>
> if ( Status( "action" ) == actionPortfolio )
> {
>  bo = GetBacktesterObject();
>  bo.PreProcess();
>
>  for ( bar = 0; bar < BarCount; bar++ )
>  {
>  for ( sig = bo.GetFirstSignal( bar ); sig; sig =
> bo.GetNextSignal( bar ) )
>  {
>  if(sig.IsEntry())
>  {
>  CurrentEquity = bo.Equity;
>  Test = StaticVarGet( "MyAtr"+sig.Symbol);
>  _TRACE(sig.symbol + " " + NumToStr(Test[bar])+" " + "
"
> + NumToStr(bar));
> //units = CurrentEquity * ( systemMMVolatilityPercent
/
> 100 ) / Test[bar];
> //sig.PosSize = sig.Price * units;
>  }
>  }
>  bo.ProcessTradeSignals( bar );
>  }
>  bo.PostProcess();
>



[amibroker] Re: normalized plot question

2010-06-29 Thread Mike
I think that you're asking for this:

firstbar = Status("firstvisiblebar");
Plot(Close / Close[firstbar], "Buy & Hold", colorDarkGrey, styleLine);

Mike

--- In amibroker@yahoogroups.com, "Chris DePuy"  wrote:
>
> 
> 
> I'm trying to plot the (close / first visible bar) of the selected ticker so 
> that it begins from the left side of the chart at 1.0 and if it were to 
> advance 2%, it would show 1.02 on the right side of the chart.  I am pretty 
> close, but I'm getting some confusing behavior that I think has to do with 
> QuickAFL.  Can someone cut and paste this code and tell me what is happening, 
> please?
> 
> 
> function GetVisibleBarCount2() 
> 
> { 
> 
> lvb2 = Status("lastvisiblebar"); 
> 
> fvb2 = Status("firstvisiblebar"); 
> 
> return Min( Lvb2 - fvb2, BarCount - fvb2 ); 
> 
> } 
> 
> barcnt2=getvisiblebarcount2();
> 
> Plot(barcnt2,"barcnt2",colorViolet,styleOwnScale);
> 
> Lkb2k=barcnt2;
> 
> normalizedC= C/ ValueWhen(BarIndex()==Lkb2k,C);
> 
> Plot(normalizedC,"normalizedC",colorBlue,styleOwnScale);
> 
> ?/*I've tried this with and without SetBarsRequired*/
> 
> SetBarsRequired(sbrAll, sbrAll );
>




[amibroker] Re: Percent Volatility Position Sizing

2010-06-29 Thread Mike
What you are generating is the information regarding the *signals*. What the 
backtest window lists are *trades*.

The two will not always be the same. Position size, max open positions, 
remaining equity, etc. all will play a role in allowing some signals to be 
traded while filtering out others.

Mike

--- In amibroker@yahoogroups.com, "rise_t575"  wrote:
>
> Thank you Mike.
> 
> My knowledge of the custom backtester is still pretty limited (my first
> try), although I have been readining everything I could get my hands on.
> 
> Now the ticker symbols the _TRACE window is giving me are completely
> different (exclusive) than the ticker symbols that come up in the
> backtesting window.
> 
> Could someone look over the code & tell me what is wrong here?
> 
> Thanks in advance!
> 
> 
> _SECTION_BEGIN( "Money Manager: Percent Volatility" );
> systemMMVolatilityPercent = Param( "Percent", 2, 0.1, 10, 0.1 );
> systemMMVolatilityATR = Param( "ATR Period", 20, 1, 250, 1 );
> _SECTION_END();
> 
> StaticVarSet( "MyAtr"+Name( ), ATR(systemMMVolatilityATR) );
> 
> SetCustomBacktestProc("");
> 
> if ( Status( "action" ) == actionPortfolio )
> {
>  bo = GetBacktesterObject();
>  bo.PreProcess();
> 
>  for ( bar = 0; bar < BarCount; bar++ )
>  {
>  for ( sig = bo.GetFirstSignal( bar ); sig; sig =
> bo.GetNextSignal( bar ) )
>  {
>  if(sig.IsEntry())
>  {
>  CurrentEquity = bo.Equity;
>  Test = StaticVarGet( "MyAtr"+sig.Symbol);
>  _TRACE(sig.symbol + " " + NumToStr(Test[bar])+" " + " "
> + NumToStr(bar));
> //units = CurrentEquity * ( systemMMVolatilityPercent /
> 100 ) / Test[bar];
> //sig.PosSize = sig.Price * units;
>  }
>  }
>  bo.ProcessTradeSignals( bar );
>  }
>  bo.PostProcess();
>




[amibroker] Re: Percent Volatility Position Sizing

2010-06-28 Thread Mike
Hi,

You can access ATR, and any other operation you want, from within the custom 
backtester. If you have a recent copy you can use static arrays, otherwise 
create a dynamic variable on the fly.

Have a look at the following thread:

http://finance.groups.yahoo.com/group/amibroker/message/146164

Similarly, Signal.PosSize will hold whatever you put in it. Reread the 
documentation for SetPositionSize:

http://www.amibroker.com/guide/afl/afl_view.php?id=272

If you want shares, then use spsShares. The value will appear as -2000 - the 
number of shares specified (e.g. 100 shares is -2100).

Mike

--- In amibroker@yahoogroups.com, "rise_t575"  wrote:
>
> Hello,
> 
> I'm *slightly* frustrated here, as I am trying to implement correct Percent 
> Volatility Position Sizing into AB (let alone Percent Risk Position Sizing 
> which should be even harder to code if implimented correctly & in a 
> non-specific, general way).
> 
> The formula for the example of Volatility Position Sizing in the AB manual is 
> wrong as this is rather some undefined mixture of a) Percent Volatility 
> Position Sizing and b) a volatility stop (as Van himself has confirmed). 
> Volatility PS is completely separate from stops; in fact, one of its best 
> uses is in systems without any hard stops.
> 
> I'm trying to code correct implementations of some basic position sizing 
> algorithms like Percent Volatility, Percent Risk (= Fixed Fractional), etc 
> with a nice & easy "Parameter" GUI as I intend to put them into AB's code 
> library for the benefit of newer users like myself.
> 
> Some of these seem to be harder to implement on AB (at least for a novice) 
> than I initially thought, as there are no "out-of-the-box" variables/object 
> properties like Position.Risk.Open, Group.Risk.Open, System.Risk.Open (= 
> Portfolio Heat), Long.Risk.Open, Short.Risk.Open, etc.
> 
> As well, I think it's slightly strange & unneccesarily cumbersome that 
> sig.PosSize doesn't define the position size as *units* (= shares, contracts, 
> etc), as this is the basic definition of "position size", and gives the user 
> the greatest flexibility. If one wants percentages, dollar amounts or 
> whatever, one can calculate this from the units in some separate lines of 
> code.
> 
> What adds to the confusion is the fact that the different examples in AB's 
> manuals switch between PositionSize and SetPositionSize in rather random 
> fashion (I guess the latter is the newer one).
> 
> Don't get me wrong, I really like AB as it has many advantages and appreciate 
> Tomasz' work, but that position sizing & risk managment thing can be 
> implemented more logically, more flexible, and thus easier for the user.
> 
> I've been using AB just for a couple of months now, so I am no AFL wizz - but 
> you shouldn't have to be one for some basic position sizing algorithms.
> 
> Ok - enough of my little rant - here's my code. I don't know if I did it 
> completely wrong or just slightly wrong.
> 
> As it seems like I cannot use ATRs in the custom backtester, I've used the 
> AddToComposite function (if anyone has a simpler & faster solution, I am all 
> for it).
> But when I run a backtest, the backtester seems to check the composite array 
> for signals (?), which looks rather strange, takes rather long, and makes AB 
> crash after 2 runs.
> 
> Any help is appreciated (any improvements to AB in this regard as well), and 
> - as I said - I'll put it into the code library for the benefit of all when 
> I'm done.
> 
> Thanks in advance!
> 
> 
> // Money Manager: Percent Volatility
> 
> _SECTION_BEGIN( "Money Manager: Percent Volatility" );
> systemMMVolatilityPercent = Param( "Percent", 2, 0.1, 10, 0.1 );
> systemMMVolatilityATR = Param( "ATR Period", 20, 1, 250, 1 );
> _SECTION_END();
> 
> AddToComposite(ATR(systemMMVolatilityATR), "~atr_"+Name(), "1", 
> atcFlagDefaults|atcFlagEnableInBacktest);
> 
> SetCustomBacktestProc("");
> 
> if ( Status( "action" ) == actionPortfolio )
> {
> bo = GetBacktesterObject();
> bo.PreProcess();
> 
> for ( bar = 0; bar < BarCount; bar++ )
> {
>   CurrentEquity = bo.Equity;
> 
> for ( sig = bo.GetFirstSignal( bar ); sig; sig = bo.GetNextSignal( 
> bar ) )
> {
>   if(sig.IsEntry())
>   {
>   MMatr = Foreign("~atr_"+sig.Symbol, "1");
>   units = CurrentEquity * ( 
> systemMMVolatilityPercent / 100 ) / MMatr[bar];
>   sig.PosSize = sig.Price * units;
>   }
> }
> bo.ProcessTradeSignals( bar );
> }
> bo.PostProcess();
> }
>




[amibroker] Re: New 3rd party toolset for AmiBroker

2010-06-24 Thread Mike
I disagree.

End of day data is free on Yahoo and Google. Does that mean that paid data 
providers are a rip off? No, because the paid services add value in the form of 
cleaning up the data. To some, that effort is not worth the price. To others, 
it is.

Many trading ideas have been coded in a variety of programming languages and 
made available for free. However, there is some effort required to collect 
those ideas, convert them to AFL, verify that the implementations are 
*correct*, and package them in an easy to use format.

As an experienced software developer, I can assure you that many of those free 
implementations are poorly written and filled with bugs.

I have not reviewed the software being advertised. So, I will not comment on 
its usefulness or quality, other than to say that it appears that a legitimate 
effort was put into its construction. 

AmiBroker users are a diverse group with varying ability to write or evaluate 
code for themselves. To some, the package may represent added value. To others, 
perhaps not.

Either way, it is, in my opinion, not helpful to offer a critique without 
having at least done a proper evaluation of the software. A review based on 
actual usage would be a far more useful contribution to the forum.

Mike

--- In amibroker@yahoogroups.com, "Anthony Faragasso"  wrote:
>
> I agree...all are freely availableThere are other(s) doing the same 
> thing...
> 
> Do you think any monetary considerations are given to original authors ? NOPE
> 
> 
> I will make available on CD indicators / explorations in my toolbox for a 
> fee :') HA..HA..
> 
> 
> 
> 
> - Original Message - 
>   From: Mubashar Virk 
>   To: amibroker@yahoogroups.com 
>   Sent: Thursday, June 24, 2010 3:36 PM
>   Subject: Re: [amibroker] New 3rd party toolset for AmiBroker
> 
> 
> 
>   This guy must be a great genius: Adding some color codes and selling other 
> peoples' freely available work for US$ 299.00 is supremely fantastic.
> 
>   On 6/24/2010 5:34 PM, Tomasz Janeczko wrote: 
> 
>   
> Hello,
> 
> I have just received the following notice about new 3rd party tool for 
> AmiBroker, that you may find useful:
> 
> ---
> www.wisetradertoolbox.com has released an advanced indicator toolset for 
> Amibroker. This includes advanced pattern exploration: Gartley, Head And 
> Shoulders, Trendlines, Triangles, Double Bottoms and Tops and Fibonnacci 
> Retracements. The toolbox also includes a large number adaptive and 
> reduced lag indicators with 5 smoothers and 7 adaptors to choose from. 
> It also includes a number of other unique indicators just visit 
> www.wisetradertoolbox.com for more information.
> 
> Those who purchase before the 30th of June 2010 will receive the Neural 
> Network addon free when it is released in the coming weeks.
> ---
> 
> This is informational notice only. AmiBroker.com does not endorse any 
> 3rd party products.
> 
> Best regards,
> Tomasz Janeczko
> amibroker.com
>




  1   2   3   4   5   6   7   8   9   10   >