[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

RE: [amibroker] Strange things are happening here



PureBytes Links

Trading Reference Links

Alex,

 

Just an observation: the ValueWhen() function will assign a value to every
bar.  Since you are summing your risk and reward variables using the Cum()
function, I think you only want the bars at your buys and sells to have
values and all the other bars to be 0.  Your code should be something like:

 

rsk = IIf(Buy,LongStopBuy - LongStop, 0); 

tmprwd = ValueWhen(Sell,SellPrice) - ValueWhen(Buy,BuyPrice); 

rwd = IIf(Sell,tmprwd,0);

 

Regards,

 

David

 

  _____  

From: amibroker@xxxxxxxxxxxxxxx [mailto:amibroker@xxxxxxxxxxxxxxx] On Behalf
Of dralexchambers
Sent: 02/20/2007 7:09 AM
To: amibroker@xxxxxxxxxxxxxxx
Subject: [amibroker] Strange things are happening here

 

Hi,

I am writing some AFL that outputs a Risk:Reward ratio for each trade 
to an HTML file. I also output an overall Win:Loss ratio.

I am using the AFL code at the bottom of this email.

However, the code outputs trades and ratios correctly from 2001-mid 
2006, then trails off at the end, round the 10/08/2006. This is 
strange, as I have trades entering and exiting up to 2007. You can 
see this HTML output here:

http://alexandercha
<http://alexanderchambers.freewebspace.com/AdvancedTradeOutput.html>
mbers.freewebspace.com/AdvancedTradeOutput.html

If anyone could try this code out and advise I'd be really grateful.

Alex

============

a = "<html><body><table border='1'><tr><td>Direction</td><td>In</
td><td>Out</td><td>Risk:Reward</td></tr>";

dtBuy = ValueWhen(Buy,DateTime());
dtSell= ValueWhen(Sell,DateTime());
rsk = ValueWhen(Buy,LongStopBuy) - ValueWhen(Buy, LongStop); 
rwd = ValueWhen(Sell,SellPrice) - ValueWhen(Buy,BuyPrice); 

rrwd = abs(rwd/rsk); //This is Risk:Reward ratio per trade: works 
correctly

winr = IIf(sign(rwd)>=0,1,0); // This is overall number of Win 
trades

for (i=1; i<BarCount; i++)
{
if (Sell[i]==1)
{ 
a = a + "<tr><td>BUY</td><td>"+DateTimeToStr(dtBuy[i])+"</
td><td>"+DateTimeToStr(dtSell[i])+"</td><td>"+rrwd[i]+"</td></tr>";
}
}

tradecnt = Cum(Sell); // total number of trades

a = a + "</table><br>Overall Risk:Reward = "+(Cum(rwd) / Cum(rsk));
a = a + "<br><br>Win:Loss Ratio = "+(Cum(winr) / tradecnt)+"</body></
html>";

fh = fopen("D:\AdvancedTradeOutput.html", "w"); 
if( fh ) 
{ 
fputs(a, fh); 
} 

 


Content-Description: "AVG certification"
No virus found in this incoming message.
Checked by AVG Free Edition.
Version: 7.5.441 / Virus Database: 268.18.3/693 - Release Date: 2/19/2007 5:01 PM