PureBytes Links
Trading Reference Links
|
SetForeign has no impact on user defined arrays (e.g. MyRisk). It only affects the arrays of the current symbol (e.g. Buy, Sell, BuyPrice, SellPrice, etc.).
So, take whatever code you used to calculate MyRisk and move it directly into the custom backtester between the SetForeign and RestorePriceArrays.
In other words, calculate MyRisk on the fly. You cannot access it after the fact.
Alternatively, you could write to composite symbols or static arrays. But, it's probably easier to do it in the custom backtest code.
Mike
--- In amibroker@xxxxxxxxxxxxxxx, "jeffarcherjr" <jeffarcherjr@xxx> wrote:
>
>
>
> Mike:
>
> Thanks for your reply. I've had a go at implementing that, but there's a devil in the details somewhere.
>
> I defined a variable MyRisk, which shows up correctly when I run an Exploration, however custombacktestproc appears unable to find it when I do a Backtest.
>
> The custommetrics involving MyRisk all result in zero, everything else about the code below appears to give correct results, including MyClose giving me the correct close price for the symbol/date which I put in there in case I had made a syntax error, and my trade count giving the correct number of trades.
>
> Any suggestions would be much appreciated!
>
> Jeff
>
> Code:
>
>
> //custom backtest indicators to measure system performance
> SetOption("UseCustomBacktestProc", True );
> SetCustomBacktestProc("",True);
> if( Status("action") == actionPortfolio ) // point to correct iteration of backtest engine
> {
> //initialize custom backtest engine
> backtestobject = GetBacktesterObject();
>
> // run the standard backtest
> backtestobject.Backtest(1);
>
> // pointers to find specific trades
> bars = BarIndex();
> dates = DateTime();
>
> // intialize variables for SQN Calculations
> SumR = 0;
> SumR2 = 0;
> Trades = 0;
> expectancyR = 0;
> stdDevR = 0;
> SQN = 0;
> R = 0;
>
> //add data to trade list, starting with closed trades
> for( trade = backtestobject.GetFirstTrade(); trade; trade = backtestobject.GetNextTrade() )
> {
> SetForeign( trade.Symbol, True, True );
> entryBar = LastValue( ValueWhen( trade.EntryDateTime == dates, bars ) );
> R = MyRisk[entryBar];
> trade.addcustommetric("MyRisk",R);
> trade.addcustommetric("MyClose",Close[entrybar]);
> sumR += R;
> sumR2 += R^2;
> Trades++;
> RestorePriceArrays(True);
> }
>
> //add data for trades still open at end of process
> for( trade = backtestobject.GetFirstOpenPos(); trade; trade = backtestobject.GetNextOpenPos() )
> {
> SetForeign( trade.Symbol, True, True );
> entryBar = LastValue( ValueWhen( trade.EntryDateTime == dates, bars ) );
> R = MyRisk[entryBar];
> trade.addcustommetric("MyRisk",R);
> trade.addcustommetric("MyClose",Close[entrybar]);
> sumR += R;
> sumR2 += R^2;
> Trades++;
> RestorePriceArrays(True);
> }
>
> //SQN calculations
> if (Trades > 0)
> {
> testcalc = Trades * 2;
> expectancyR = sumR / Trades;
> stdDevR = sqrt((sumR2 - (sumR^2 / Trades)) / (Trades - 1));
> SQN = ((expectancyR / stdDevR) * sqrt(Min(100, Trades)));
> }
>
> //display results
> backtestobject.AddCustomMetric("TestCalc", testcalc);
> backtestobject.AddCustomMetric("Trades", Trades);
> backtestobject.AddCustomMetric("sumR", SumR);
> backtestobject.AddCustomMetric("sumR2", SumR2);
> backtestobject.AddCustomMetric("ExpectancyR ($)", expectancyR);
> backtestobject.AddCustomMetric("StdDevR", stdDevR);
> backtestobject.AddCustomMetric("SQN", SQN);
> backtestobject.ListTrades();
>
> }
>
------------------------------------
**** 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
<*> To visit your group on the web, go to:
http://groups.yahoo.com/group/amibroker/
<*> Your email settings:
Individual Email | Traditional
<*> To change settings online go to:
http://groups.yahoo.com/group/amibroker/join
(Yahoo! ID required)
<*> To change settings via email:
mailto:amibroker-digest@xxxxxxxxxxxxxxx
mailto:amibroker-fullfeatured@xxxxxxxxxxxxxxx
<*> To unsubscribe from this group, send an email to:
amibroker-unsubscribe@xxxxxxxxxxxxxxx
<*> Your use of Yahoo! Groups is subject to:
http://docs.yahoo.com/info/terms/
|