PureBytes Links
Trading Reference Links
|
Yes it's possible. I have included some code below that looks for
consecutive wins and losses and counts the maximum and current winning
and losing trade streaks. You can adapt this code or keep asking for
volunteers, etc. I don't do contract work.
Regards,
Terry
/* ++++++++++++++++++++++++++++ WIN/LOSS STATISTICS
++++++++++++++++++++++++++++++++++
Programming note: onBuy and onSell are my variables for Buy Sell conditions
Short = Sell, Cover = Buy. onBuy and onSell are my variables for keeping
track of when
the code is on a Buy signal or on a Sell signal (or inCash) */
StatPeriod = Param("Statistics Trading Years from
Selection",2,0.5,20,0.5) * 252;
_N(stats = "");
if (ParamToggle("Show Trade Statistics","No|Yes",0))
{
stats = "Stats for last " + NumToStr(StatPeriod,1.0) + " trading days
from selected bar!";
//Count number of days on right side of market
DaysInSync = IIf( (Ref(Onbuy,-1) AND C > Ref(C,-1)) OR (Ref(Onsell,-1)
AND C < Ref(C,-1)) ,1,0); //Can also test gain > 0 to see % days equity
is up
stats = stats + "\nWinning days = " +
NumToStr(Sum(DaysInSync,StatPeriod)/StatPeriod*100,1.0) + "%";
//Count number of winning Buys
WinningBuys = IIf(Sell AND gain > 0,1,0); //SellPrice >
ValueWhen(Buy,BuyPrice,1),1,0);
stats = stats + "\nWinning Buys = " +
NumToStr(Sum(WinningBuys,StatPeriod),1.0) + " out of " +
NumToStr(Sum(IIf(Sell,1,0),StatPeriod),1.0);
//Plot(WinningBuys,"\nWinning Buys",colorGreen,styleHistogram |
styleOwnScale,0,2);
//Count number of winning Shorts
WinningShorts = IIf(Cover AND gain > 0,1,0); //CoverPrice <
ValueWhen(Short,ShortPrice,1),1,0);
stats = stats + "\nWinning Shorts = " +
NumToStr(Sum(WinningShorts,StatPeriod),1.0) + " out of " +
NumToStr(Sum(IIf(Cover,1,0),StatPeriod),1.0);
//Find Max consecutive winning trades - long and short combined
MaxWins = MaxLoss = CurWins = CurLoss = NowWins = NowLoss = xw = xl = 0;
WinOrLoss = ""; //Initialize string variable
k = SelectedValue(BarIndex());
for (j = k; j > Max(0, k - StatPeriod); j--)
{
if ((Sell[j] OR Cover[j]) AND gain[j] > 0)
{
if (xw == 0) xw = j; //Remember 1st winning exit
if (MaxLoss == 0) NowLoss = CurLoss; //Remember 1st loss streak
value
CurWins = CurWins + 1;
MaxLoss = Max(MaxLoss,CurLoss);
CurLoss = 0;
}
if ((Sell[j] OR Cover[j]) AND gain[j] < 0)
{
if (xl == 0) xl = j; //Remember 1st losing exit
if (MaxWins == 0) NowWins = CurWins; //Remember 1st win streak value
CurLoss = CurLoss + 1;
MaxWins = Max(MaxWins,CurWins);
CurWins = 0;
}
}
if (xw > xl) WinOrLoss = NumToStr(NowWins,1.0) + " Win" +
WriteIf(NowWins > 1,"s","");
else WinOrLoss = NumToStr(NowLoss,1.0) + " Loss" + WriteIf(NowLoss >
1,"es","");
stats = stats + "\nMax consecutive wins = " + NumToStr(MaxWins,1.0);
stats = stats + "\nMax consecutive losses = " + NumToStr(MaxLoss,1.0);
stats = stats + "\nCurrent streak = " + WinOrLoss;
stats = stats + "\n(Stats do NOT include commissions.)\n";
}
stats;
/* ++++++++++++++++++++++++++++ END WIN/LOSS STATISTICS
++++++++++++++++++++++++++++++++++ */
avnerkk wrote:
>
>I would like to use AFL to ask questions like:
>
>In the last 10 years find occurrences of the Nasdaq TRIN lower than 0.5
>for two days running.
>
>and then: Alert me if the above happened today (that is today's TRIN
>was the second day of a Nasdaq TRIN lower than 0.5)
>
>Is that possible at all using AFL?
>
>or another one:
>
>Find all occurrences of increasing SPY volume 4 days.
>
>and then: Alert me if that occurred today.(meaning - today was the
>fourth day in which SPY volume increased)
>
>If it's possible I'd appreciate any help and I'm ready to pay any AFL
>and Amibroker expert who can help me with that and many more such
>queries.
>
>Thanks
>
>
>
>
>
>
>
>
>
>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 other support material please check also:
>http://www.amibroker.com/support.html
>
>
>Yahoo! Groups Links
>
>
>
>
>
>
>
>
>
>
------------------------ Yahoo! Groups Sponsor --------------------~-->
Has someone you know been affected by illness or disease?
Network for Good is THE place to support health awareness efforts!
http://us.click.yahoo.com/Rcy2bD/UOnJAA/cosFAA/GHeqlB/TM
--------------------------------------------------------------------~->
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 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/
<*> 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/
|