PureBytes Links
Trading Reference Links
|
I am trying to get the highest and lowest values during the trade,
however it returns 0. maybe something is wrong. can someone check. I
dont want the MFE and MAE from the backtester objects.
bo.PreProcess(); // initialize the backtester
myHigh=0;
myLow=100000000;
entryEnabled=false;
exitEnabled=false;
for( bar=0;bar<BarCount;bar++){ // loop thro all the bars
for (sig = bo.GetFirstSignal(bar); sig; sig =
bo.GetNextSignal(bar))
{ // Loop through all signals at this
bar
if (sig.IsEntry() &&
sig.IsLong()) // Process long entries
{
bo.EnterTrade(bar, sig.Symbol, True,
EntryPrice ,sig.possize);
entryEnabled=true;
_TRACE
("ABTest: "+ GetChartID() + " entryEnabled=true; " );
}
else
{
if (sig.IsExit() &&
sig.IsLong()) // Process long exits
{
bo.ExitTrade(bar, sig.Symbol,Exitprice);
exitEnabled=true;
_TRACE("ABTest: "+ GetChartID() + " exitEnabled=true; " );
}
}
if (sig.IsEntry() && !
sig.IsLong()) // Process short entries. WATCH IT SAYS NOT ISLONG.
{
bo.EnterTrade(bar, sig.Symbol, True,
EntryPrice ,sig.possize);
_TRACE
("ABTest: "+ GetChartID() + " is short entry
entryEnabled=true; " );
entryEnabled=true;
}
else
{
if (sig.IsExit() && !
sig.IsLong()) // Process short exits
{
bo.ExitTrade(bar, sig.Symbol,Exitprice);
exitEnabled=true;
_TRACE
("ABTest: "+ GetChartID() + " exitEnabled=true; is short exit " );
}
}
}// End of for loop over signals at
this bar
bo.HandleStops(bar); // Handle programmed
stops at this bar
for (trade = bo.GetFirstOpenPos(); trade;
trade = bo.GetNextOpenPos())
{ // Loop through all open positions
if (trade.GetProfit() >=
trade.GetEntryValue()) // If time to scale-in
{
scaleSize =
trade.GetEntryValue() / 2; // Scale-in the trade
bo.ScaleTrade
(bar, trade.Symbol, True, trade.GetPrice(bar, "C"),
DEFAULT_POSITION_SIZE);
}
} // End of for loop over trades at
this bar
bo.UpdateStats(bar, 1); // Update MAE/MFE
stats for bar
bo.UpdateStats(bar, 2); // Update stats at
bar's end
if((entryEnabled==true) &&
(exitEnabled==false)){
if(H[bar]>=myHigh){
myHigh=H[bar];
_TRACE("ABTest: "+ GetChartID()
+ "new high" + writeval(H[bar]));
}
if(L[bar]<=myLow){
myLow=L[bar];
_TRACE("ABTest: "+ GetChartID()
+ "new low ");
}
}
} // End of for loop over bars
// pull custom metrics for backtester
// iterate through closed trades first
for( trade = bo.GetFirstTrade(); trade; trade = bo.GetNextTrade() )
{// go thro each trade
trade.AddCustomMetric("MAE $", StrFormat( "%.4f",
trade.GetMAE()) );
trade.AddCustomMetric("MFE $", StrFormat( "%.4f", trade.GetMFE
() ) );
trade.AddCustomMetric("Highhest high", myHigh);
//trade.AddCustomMetric("Total Drawdown ", StrFormat
( "%.4f", trade.getvalue("MaxTradeDrawdown") ) );
}// end of iterating thro trades
//bo.ListTrades(); this is not needed for custom advanced
backtester
// end of pulling custom metrics
bo.PostProcess(); // Do post-processing
}// end of check for inside backtester
// end of custom backtester
Please note that this group is for discussion between users only.
To get support from AmiBroker please send an e-mail directly to
SUPPORT {at} amibroker.com
For NEW RELEASE ANNOUNCEMENTS and other news always check DEVLOG:
http://www.amibroker.com/devlog/
For other support material please check also:
http://www.amibroker.com/support.html
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/
|