dear mike,

i understood where you want me to direct. for you reference i am giving full 
afl for my system which works fine giving me two extra coloms of initial risk & 
expectancy/trade coloumwise. but when i try to change risk perameter as shown 
in following afl i get blnak colom of initial risk & expectancy/trade. so i wnt 
to know how to get initial risk coloum when using risk = enty - stop value.

afl.
Capital = 100000;
SetOption("InitialEquity", Capital );
RoundLotSize = 1; 
possize = 0.8*Capital; 
allocationrisk = 0.8; // max capital employed per trade
risk = 0.05*Capital; //  % max risk per trade
/* calling custom backtest*/
SetCustomBacktestProc("");
if( Status("action") == actionPortfolio )
{
   bo = GetBacktesterObject();
   bo.backtest(1);
 Sumprofitperrisk = 0;
 numtrades = 0;
 // iterate for closed trades
 for( trade = bo.getfirsttrade(); trade; trade = bo.getnexttrade() )
 {
  rmultiple = trade.getprofit()/risk;
  trade.addcustommetric("initial risk $" , risk );
  trade.addcustommetric("R-multiple" , rmultiple );
  Sumprofitperrisk = Sumprofitperrisk + rmultiple ;
  numtrades++;
 }
  expectancy3 = Sumprofitperrisk / numtrades ;
  bo.addcustommetric( "Expectancy (per risk)", expectancy3 );
  bo.listtrades();
}

xb = IIf(C > EMA(C,7),20,0);
xs = IIf(C < EMA(C,7),-20,0);
y = TimeFrameGetPrice("h",inMonthly,-1);
z = TimeFrameGetPrice("h",inMonthly,-2);
p = TimeFrameGetPrice("l",inMonthly,-1);
q = TimeFrameGetPrice("l",inMonthly,-2);
r = TimeFrameGetPrice("h",inMonthly);
s = TimeFrameGetPrice("l",inMonthly);
wz = Max(y,z);
zb = IIf(r > wz ,30,0);
wq = Min(p,q);
zs = IIf(s < wq,-30,0);
yw = TimeFrameGetPrice("h",inWeekly,-1);
zw = TimeFrameGetPrice("h",inWeekly,-2);
pw = TimeFrameGetPrice("l",inWeekly,-1);
qw = TimeFrameGetPrice("l",inWeekly,-2);
rw = TimeFrameGetPrice("h",inWeekly);
sw = TimeFrameGetPrice("l",inWeekly);
wzs = Max(yw,zw);
yb = IIf(rw > wzs ,25,0);
wqs = Min(pw,qw);
ys = IIf(sw < wqs,-25,0);
score = xb+yb+zb+xs+ys+zs;
avrage = MA(V,30);
diffvol = (V-avrage)/avrage;
Buy = C > Ref(HHV(H,2),-1) AND C>O AND score > 70 ;
BuyPrice = C;
bstopamount = BuyPrice-(wqs - 1);
Sell = L < wqs;
SellPrice = wqs - 1;
ExRem(Buy,Sell);
Short = C < Ref(LLV(L,2),-1) AND C<O AND score < -70 ;
ShortPrice = C ;
sstopamount = (wzs +1) - ShortPrice;
Cover = rw > wzs ;
CoverPrice = wzs + 1;
SetPositionSize( 100, spsShares ) ;
ExRem(Short,Cover);
//PositionSize =IIf(Buy, 
Min((risk/bstopamount)*BuyPrice,possize),Min((risk/sstopamount)*ShortPrice,possize));
//PositionScore = PositionSize ; //(V- MA(V,7))/MA(V,7) ; OR ma(v,5)/ma(v,20);  
prefer stocks that High vol thrust;
//ApplyStop(0,1,4,1);

thisk works fine.

but following chane gives blank coloum.

Capital = 100000;
SetOption("InitialEquity", Capital );
RoundLotSize = 1; 
xb = IIf(C > EMA(C,7),20,0);
xs = IIf(C < EMA(C,7),-20,0);
y = TimeFrameGetPrice("h",inMonthly,-1);
z = TimeFrameGetPrice("h",inMonthly,-2);
p = TimeFrameGetPrice("l",inMonthly,-1);
q = TimeFrameGetPrice("l",inMonthly,-2);
r = TimeFrameGetPrice("h",inMonthly);
s = TimeFrameGetPrice("l",inMonthly);
wz = Max(y,z);
zb = IIf(r > wz ,30,0);
wq = Min(p,q);
zs = IIf(s < wq,-30,0);
yw = TimeFrameGetPrice("h",inWeekly,-1);
zw = TimeFrameGetPrice("h",inWeekly,-2);
pw = TimeFrameGetPrice("l",inWeekly,-1);
qw = TimeFrameGetPrice("l",inWeekly,-2);
rw = TimeFrameGetPrice("h",inWeekly);
sw = TimeFrameGetPrice("l",inWeekly);
wzs = Max(yw,zw);
yb = IIf(rw > wzs ,25,0);
wqs = Min(pw,qw);
ys = IIf(sw < wqs,-25,0);
score = xb+yb+zb+xs+ys+zs;
avrage = MA(V,30);
diffvol = (V-avrage)/avrage;
Buy = C > Ref(HHV(H,2),-1) AND C>O AND score > 70 ;
BuyPrice = C;
bstopamount = BuyPrice-(wqs - 1);
Sell = L < wqs;
SellPrice = wqs - 1;
ExRem(Buy,Sell);
Short = C < Ref(LLV(L,2),-1) AND C<O AND score < -70 ;
ShortPrice = C ;
sstopamount = (wzs +1) - ShortPrice;
Cover = rw > wzs ;
CoverPrice = wzs + 1;
SetPositionSize( 100, spsShares ) ;
ExRem(Short,Cover);
risk = IIf(Buy, bstopamount*BuyPrice,sstopamount*ShortPrice); //  max risk per 
trade
/* calling custom backtest*/
SetCustomBacktestProc("");
if( Status("action") == actionPortfolio )
{
   bo = GetBacktesterObject();
   bo.backtest(1);
 Sumprofitperrisk = 0;
 numtrades = 0;
 // iterate for closed trades
 for( trade = bo.getfirsttrade(); trade; trade = bo.getnexttrade() )
 {
  rmultiple = trade.getprofit()/risk;
  trade.addcustommetric("initial risk $" , risk );
  trade.addcustommetric("R-multiple" , rmultiple );
  Sumprofitperrisk = Sumprofitperrisk + rmultiple ;
  numtrades++;
 }
  expectancy3 = Sumprofitperrisk / numtrades ;
  bo.addcustommetric( "Expectancy (per risk)", expectancy3 );
  bo.listtrades();
}

can any one help.

asit.

--- In [email protected], "Mike" <sfclimb...@...> wrote:
>
> See "custom metrics" in the user guide:
> 
> http://www.amibroker.com/guide/a_custommetrics.html
> 
> Mike
> 
> --- In [email protected], "asitasu" <asitasu@> wrote:
> >
> > dear frieds,
> > 
> > i want to add extra collume of risk(no % risk) in backtest report how to 
> > add this by use of afl? i want risk to be calculated on base of trade
> > entry & stop loss price. say for example i enter at Rs 2515 and at time of 
> > entry my stop loss is Rs 2375.50, than risk per unit is 139.5(ie 2515 - 
> > 2375.50).
> > 
> > help me.
> > 
> > asit.
> >
>


Reply via email to