My visual effect afl collection.

yasu222

Active Member
#41
Tradesender afl code

The following code can be pasted at the end of the afl but

condition 1 = Buy and Sell should be assigned in original afl.
condition2 = Should run "New Analysis" for the AFL which have following tradesender code.


AlertIf(Buy,"exec tsalertif.exe","BUY",1);
AlertIf(Sell,"exec tsalertif.exe","SELL",1);

then you get sms to the registered mobile (Android/windows/i phone)

:thumb:
 

yasu222

Active Member
#42
Pivot System

_SECTION_BEGIN("PIVOTS");
GraphXSpace = 5 ;
SetChartOptions(0,chartShowArrows|chartShowDates);
ppl = ParamToggle("Plot Pivot Levels","Off|On",1);
numbars = LastValue(Cum(Status("barvisible")));
fraction= IIf(StrRight(Name(),3) == "", 3.2, 3.2);
hts = -33.5;

/* This code calculates the previous days high, low and close */
Hi1 = IIf(Day()!=Ref(Day(),-1),Ref(HighestSince(Day()!=Ref(Day(),-1),H,1),-1),0);
Hi = ValueWhen(Day()!=Ref(Day(),-1),Hi1,1);
Lo1 = IIf(Day()!=Ref(Day(),-1),Ref(LowestSince(Day()!=Ref(Day(),-1),L,1),-1),0);
Lo = ValueWhen(Day()!=Ref(Day(),-1),Lo1,1);
Cl1 = IIf(Day()!=Ref(Day(),-1),Ref(C,-1),0);
C1 = ValueWhen(Day()!=Ref(Day(),-1),Cl1,1);

//----------------------------------------------------------------------------------

/* This code calculates Daily Piovts */

rg = (Hi - Lo);
bp = (Hi + Lo + C1)/3; bpI = LastValue (bp,1);
r1 = (bp*2)-Lo; r1I = LastValue (r1,1);
r12 = (bp+r1)/2;
s1 = (bp*2)-Hi; s1I = LastValue (s1,1);
s12 = (bp+s1)/2;
r2 = bp + r1 - s1; r2I = LastValue (r2,1);
r23 = (r1+r2)/2;
s2 = bp - r1 + s1; s2I = LastValue (s2,1);
s23 = (s1+s2)/2;
//r3 = bp + r2 - s1; r3I = LastValue (r3,1);
//s3 = bp - r2 + s1; s3I = LastValue (s3,1);
//r4 = bp + r2 - s2; r4I = LastValue (r4,1);
//s4 = bp - r2 + s2; s4I = LastValue (s4,1);

//Condition for BUY Signals at Lines//
Bcond1 = Cross(s12,L);
Bcond2 = Cross(S1,L);
Bcond3 = Cross(s23,L);
//Condition for Sell Signals at Lines//
Scond1 = Cross(H,r12);
Scond2 = Cross(H,r1);
Scond3 = Cross(H,r23);
Buy1 = (Bcond1+Bcond2+Bcond3);
Sell1 = (Scond1+Scond2+Scond3);
Buy=ExRem(Buy1,Sell1);
Sell=ExRem(Sell1,Buy1);
Short=Sell ;
Cover=Buy;
PlotShapes(Buy1*shapeUpArrow,colorPink,0,L,-20);
PlotShapes(Sell1*shapeDownArrow,colorBrightGreen,0,H,-35);
if(ppl==1) {
Plot(bp,"",colorWhite,styleLine|styleDots|styleNoRescale);
Plot(s1,"",colorWhite,styleLine|styleNoRescale);
Plot(s12,"",colorWhite,styleLine|styleNoRescale);
//Plot(s2,"",colorWhite,styleLine|styleNoRescale);
Plot(s23,"",colorWhite,styleLine|styleNoRescale);
//Plot(s3,"",colorRed,styleLine|styleNoRescale);
//Plot(s4,"",colorRed,styleLine|styleNoRescale);
Plot(r1,"",colorYellow,styleLine|styleNoRescale);
Plot(r12,"",colorYellow,styleLine|styleNoRescale);
//Plot(r2,"",colorYellow,styleLine|styleNoRescale);
Plot(r23,"",colorYellow,styleLine|styleNoRescale);
//Plot(r3,"",colorGreen,styleLine|styleNoRescale);
//Plot(r4,"",colorGreen,styleLine|styleNoRescale);
PlotText(" Pivot = " + WriteVal(bp,fraction), LastValue(BarIndex())-(numbars/Hts), bpI +0.05, colorWhite);
PlotText(" r12 = " + WriteVal(r1,fraction), LastValue(BarIndex())-(numbars/Hts), r1I +0.05, colorBrightGreen);
PlotText(" r1 = " + WriteVal(r1,fraction), LastValue(BarIndex())-(numbars/Hts), r1I +0.05, colorBrightGreen);
PlotText(" r23 = " + WriteVal(r1,fraction), LastValue(BarIndex())-(numbars/Hts), r1I +0.05, colorBrightGreen);
//PlotText(" r2 = " + WriteVal(r2,fraction), LastValue(BarIndex())-(numbars/Hts), r2I +0.05, colorBrightGreen);
PlotText(" s12 = " + WriteVal(s1,fraction), LastValue(BarIndex())-(numbars/Hts), s1I +0.05, colorPink);
PlotText(" s1 = " + WriteVal(s1,fraction), LastValue(BarIndex())-(numbars/Hts), s1I +0.05, colorPink);
PlotText(" s23 = " + WriteVal(s1,fraction), LastValue(BarIndex())-(numbars/Hts), s1I +0.05, colorPink);
//PlotText(" s2 = " + WriteVal(s2,fraction), LastValue(BarIndex())-(numbars/Hts), s2I +0.05, colorPink);
//PlotText(" r3 = " + WriteVal(r3,fraction), LastValue(BarIndex())-(numbars/Hts), r3I +0.05, colorGreen);
//PlotText(" s3 = " + WriteVal(s3,fraction), LastValue(BarIndex())-(numbars/Hts), s3I +0.05, colorRed);
//PlotText(" r4 = " + WriteVal(r4,fraction), LastValue(BarIndex())-(numbars/Hts), r4I +0.05, colorGreen);
//PlotText(" s4 = " + WriteVal(s4,fraction), LastValue(BarIndex())-(numbars/Hts), s4I +0.05, colorRed);
}

//--end----------------------------------------------------------------------------
_SECTION_END();
 
Last edited:

yasu222

Active Member
#43
Stochastic Bar Chart

//Stochastic Bar Chart//
_SECTION_BEGIN("Stochastic Bar Chart");
V1 = Param("periods",5,3,50,1);
uptrend = IIf( StochK(V1,3) > StochD(V1,3,3), 1, 0 );
downtrend = IIf( StochK(V1,3)<StochD(V1,3,3), 1, 0 );
V11 = Param("Variable_Band",20,5,50,1);
LowBand = (0+V11);
UpBand = (100-V11);

BuyV = uptrend AND Ref(uptrend, -1) AND (H > ( Ref(H, -1)))AND (StochD(V1,5,3) < LowBand);
SellV = downtrend AND Ref(downtrend,-1) AND (L > ( Ref(L, -1)))AND (StochD(V1,5,3) > UpBand);

BuySB = BarsSince(Ref(BuyV,-1));
SellSB = BarsSince(Ref(SellV,-1));

Buy = BuyV AND BuySB > SellSB ;
Sell = SellV AND BuySB < SellSB ;
Cover = Buy ;
Short = Sell ;

PlotShapes( shapeSquare * Buy, colorBrightGreen,0,L,-12);
PlotShapes( shapeSquare * Sell, colorPink,0,H,-12);
_SECTION_END();
 

yasu222

Active Member
#44
Sms from amibroker to mobile/desktop/laptop

If you have access to Net on phone then go for "PushBullet"
Its free and very fast.
I have tested it and signals flashes almost immediately on phone(Iphone/Android)+DeskTop(Chrome)
If you need assistance on how to configure then here's the process:

1)Download Pushbullet Android/IOS App according to your smartphone device where you to receive push notification from Amibroker Software. If you wanna recieve alerts in your Desktop or Browser or to receive alerts from someone else Pushbullet channel you can download the Browser extention from the link here

2)Sign in with Pushbullet using your Google Login.

3)Once Signed in click over your profile pic and goto account settings. Now copy the Access Token which is unique code to communicate with your device and keep it safe.

4)Now make sure that your Trading System supports Buy/Sell Variables minimum to pass Buy/Sell Alerts. If you need to send Short/Cover/any other variables then you need to build your own custom code according to your requirements. In this example we focused only on alerting with simple Buy/Sell Variable.

5)Copy the AFL code and save it as pushbullet.afl code in your //Amibroker//Formulas//system folder

6)Now Replace xxxxxxxxxxxxxx in line 25 with your Secure Access token

7)Now Drag and Drop the pushbullet.afl code to your Trading System Charts which contains Buy/Sell Variables. Note you have to do a drag and drop to your existing trading system annd not to insert the afl code

8)Bingo you are done now get alerts to your mobile/desktop/laptop devices(one or multiple devices) and stay connected with your trading system even you are out of your trading system

_SECTION_BEGIN("PushBullet");

EnableScript("VBScript");

<%

Public Sub pushbullet(Message_Text)
Dim Message

'Your Message
Message = Message_Text

Dim objXmlHttpMain , URL

strJSONToSend = "{""type"": ""note"", ""title"": ""Alert"", ""body"":""" &Message_Text&"""}"

URL="https://api.pushbullet.com/v2/pushes"
Set objXmlHttpMain = CreateObject("Msxml2.ServerXMLHTTP")
on error resume next
objXmlHttpMain.open "POST",URL, False
objXmlHttpMain.setRequestHeader "Authorization", "Bearer xxxxxxxxxxxxxxxxxxx"
objXmlHttpMain.setRequestHeader "Content-Type", "application/json"


objXmlHttpMain.send strJSONToSend

set objJSONDoc = nothing
set objResult = nothing

'Store response
'msgbox(objXmlHttpMain.responseText)
'response.Write (objXmlHttpMain.responseText)
alert("Hi")
End Sub

%>

pb = GetScriptObject();



if (LastValue(ValueWhen(Ref(Buy,-1),BarIndex())==BarIndex()) AND StaticVarGet(Name()+GetChartID()+"buyAlert")==0 )
{
pb.PushBullet("Buy Alert in " +Name() + " : BuyPrice Value is " + BuyPrice + " Time " + TimeNum());
StaticVarSet(Name()+ GetChartID() + "buyAlertBar", LastValue(TimeNum()));
}

if (LastValue(TimeNum()) == StaticVarGet(Name()+GetChartID()+"buyAlertBar"))

StaticVarSet(Name()+GetChartID()+"buyAlert",1); //alert was triggered, no more alerts on this bar
else
StaticVarSet(Name()+GetChartID()+"buyAlert",0); // new bar formed, and alerts can be trigered.

if (LastValue(ValueWhen(Ref(Sell,-1),BarIndex())==BarIndex()) AND StaticVarGet(Name()+GetChartID()+"buyAlert")==0 )
{
pb.PushBullet("Sell Alert in " +Name() + " : SellPrice Value is " + SellPrice + " Time " + TimeNum());
StaticVarSet(Name()+ GetChartID() + "sellAlertBar", LastValue(TimeNum()));
}

if (LastValue(TimeNum()) == StaticVarGet(Name()+GetChartID()+"sellAlertBar"))

StaticVarSet(Name()+GetChartID()+"sellAlert",1); //alert was triggered, no more alerts on this bar
else
StaticVarSet(Name()+GetChartID()+"sellAlert",0); // new bar formed, and alerts can be trigered.

_SECTION_END();
 

yasu222

Active Member
#45
HULL-MA-X-Roads

_SECTION_BEGIN("HULL-MA-X-Roads");
Period1 = Param("Period:", 20, 1, 200,1);
SqrtPeriod1 = Param("Square Root of Period1:", 4,1,20,1);
Period2 = Param("Period2:", 22, 1, 200,1);
SqrtPeriod2 = Param("Square Root of Period2:", 4,1,20,1);
HullMA1 = WMA(2 * WMA(C, Period1 / 2) - WMA(C, Period1), SqrtPeriod1);
HullMA2 = WMA(2 * WMA(C, Period2 / 2) - WMA(C, Period2), SqrtPeriod2);
Buy1=Cross(HullMA1,HullMA2);
Sell1=Cross(HullMA2,HullMA1);
Buy=ExRem(Buy1,Sell1);
Sell=ExRem(Sell1,Buy1);
Short=Sell ;
Cover=Buy;
Plot(HullMa1, _DEFAULT_NAME(), ParamColor("Hull Moving Average Color1", colorYellow));
Plot(HullMa2, _DEFAULT_NAME(), ParamColor("Hull Moving Average Color2", colorWhite));
PlotShapes(Buy*shapeUpArrow,colorBrightGreen,0,L,-25);
PlotShapes(Sell*shapeDownArrow,colorPink,0,H,-20);
AlertIf( Buy, "SOUND C:\\Windows\\Media\\Ding.chimes", "Audio alert", 2 );
AlertIf( Sell, "SOUND C:\\Windows\\Media\\Ding.wav", "Audio alert", 2 );
_SECTION_END();
 

yasu222

Active Member
#46
as MetaStock%Trailing Stop Loss

_SECTION_BEGIN("BETTER CANDLE");
dojidiv =5;
CloseEqualOpen = ( High - Low ) / dojidiv > abs( Open - Close );
RefC = Ref( C, -1 );
RefO = Ref( O, -1 );
Up = C > O;
Down = C < O ;
UpDoji = CloseEqualOpen AND RefC > RefO;
DownDoji = CloseEqualOpen AND RefC < RefO;
colcond = IIf( up || updoji, colorBrightGreen, colorRed );
SetBarFillColor( colcond );
Plot( C, "Price", colcond, styleCandle );
_SECTION_END();

_SECTION_BEGIN("as MetaStock%Trailing Stop Loss");
per = Param("Bars",2,2,100,1);
mult = Param("Trailing Loss %",0.5,0.01,10,0.01);
tr = (Ref(C,-PER)*(mult/100));

trailArray[ 0 ] = C[ 0 ]; // initialize
for( i = 1; i < BarCount; i++ )
{
prev = trailArray[ i - 1 ];

if (C[ i ] > prev AND C[ i - 1 ] > prev)
{
trailArray[ i ] = Max(prev,C[ i ] - tr[ i ]);
}
else if (C[ i ] < prev AND C[ i - 1 ] < prev)
{
trailArray[ i ] = Min(prev,C[ i ] + tr[ i ]);
}
else if (C[ i ] > prev)
{
trailArray[ i ] = C[ i ] - tr[ i ];
}
else
{
trailArray[ i ] = C[ i ] + tr[ i ];
}
}
trailArray = Ref(trailArray,-1);

SetChartBkColor( ParamColor("ColorBG", ColorRGB( 0, 0, 0 ) ) );
GraphXSpace = 5;
SetChartOptions(0, chartShowDates);
Plot(trailArray,"\ntrailArray",ParamColor("ColorTr ail",ColorRGB(255,255,255)),styleStaircase);
_SECTION_END();
 

yasu222

Active Member
#47
As Metastock ATR Stoploss Firmula

// from Metastock formula, link: http://stocata.org/metastock/stop_trail_atr.html
per = Param("per",20, 5, 150, 1);
mult = Param("mult",2, 1, 4, 0.05);
tr = mult * ATR(per);

trailArray[ 0 ] = C[ 0 ]; // initialize
for( i = 1; i < BarCount; i++ )
{
prev = trailArray[ i - 1 ];

if (C[ i ] > prev AND C[ i - 1 ] > prev)
{
trailArray[ i ] = Max(prev,C[ i ] - tr[ i ]);
}
else if (C[ i ] < prev AND C[ i - 1 ] < prev)
{
trailArray[ i ] = Min(prev,C[ i ] + tr[ i ]);
}
else if (C[ i ] > prev)
{
trailArray[ i ] = C[ i ] - tr[ i ];
}
else
{
trailArray[ i ] = C[ i ] + tr[ i ];
}
}
trailArray = Ref(trailArray,-1);

SetChartBkColor( ParamColor("ColorBG", ColorRGB( 0, 0, 0 ) ) );
GraphXSpace = 5;
SetChartOptions(0, chartShowDates);
Plot(trailArray,"\ntrailArray",ParamColor("ColorTr ail",ColorRGB(255,255,255)),styleStaircase);
Plot( C, "\nCandle",colorWhite, styleCandle );
 

yasu222

Active Member
#48
Re: Sms from amibroker to mobile/desktop/laptop

If you have access to Net on phone then go for "PushBullet"
Its free and very fast.
I have tested it and signals flashes almost immediately on phone(Iphone/Android)+DeskTop(Chrome)
If you need assistance on how to configure then here's the process:

1)Download Pushbullet Android/IOS App according to your smartphone device where you to receive push notification from Amibroker Software. If you wanna recieve alerts in your Desktop or Browser or to receive alerts from someone else Pushbullet channel you can download the Browser extention from the link here

2)Sign in with Pushbullet using your Google Login.

3)Once Signed in click over your profile pic and goto account settings. Now copy the Access Token which is unique code to communicate with your device and keep it safe.

4)Now make sure that your Trading System supports Buy/Sell Variables minimum to pass Buy/Sell Alerts. If you need to send Short/Cover/any other variables then you need to build your own custom code according to your requirements. In this example we focused only on alerting with simple Buy/Sell Variable.

5)Copy the AFL code and save it as pushbullet.afl code in your //Amibroker//Formulas//system folder

6)Now Replace xxxxxxxxxxxxxx in line 25 with your Secure Access token

7)Now Drag and Drop the pushbullet.afl code to your Trading System Charts which contains Buy/Sell Variables. Note you have to do a drag and drop to your existing trading system annd not to insert the afl code

8)Bingo you are done now get alerts to your mobile/desktop/laptop devices(one or multiple devices) and stay connected with your trading system even you are out of your trading system

_SECTION_BEGIN("PushBullet");

EnableScript("VBScript");

<%

Public Sub pushbullet(Message_Text)
Dim Message

'Your Message
Message = Message_Text

Dim objXmlHttpMain , URL

strJSONToSend = "{""type"": ""note"", ""title"": ""Alert"", ""body"":""" &Message_Text&"""}"

URL="https://api.pushbullet.com/v2/pushes"
Set objXmlHttpMain = CreateObject("Msxml2.ServerXMLHTTP")
on error resume next
objXmlHttpMain.open "POST",URL, False
objXmlHttpMain.setRequestHeader "Authorization", "Bearer xxxxxxxxxxxxxxxxxxx"
objXmlHttpMain.setRequestHeader "Content-Type", "application/json"


objXmlHttpMain.send strJSONToSend

set objJSONDoc = nothing
set objResult = nothing

'Store response
'msgbox(objXmlHttpMain.responseText)
'response.Write (objXmlHttpMain.responseText)
alert("Hi")
End Sub

%>

pb = GetScriptObject();



if (LastValue(ValueWhen(Ref(Buy,-1),BarIndex())==BarIndex()) AND StaticVarGet(Name()+GetChartID()+"buyAlert")==0 )
{
pb.PushBullet("Buy Alert in " +Name() + " : BuyPrice Value is " + BuyPrice + " Time " + TimeNum());
StaticVarSet(Name()+ GetChartID() + "buyAlertBar", LastValue(TimeNum()));
}

if (LastValue(TimeNum()) == StaticVarGet(Name()+GetChartID()+"buyAlertBar"))

StaticVarSet(Name()+GetChartID()+"buyAlert",1); //alert was triggered, no more alerts on this bar
else
StaticVarSet(Name()+GetChartID()+"buyAlert",0); // new bar formed, and alerts can be trigered.

if (LastValue(ValueWhen(Ref(Sell,-1),BarIndex())==BarIndex()) AND StaticVarGet(Name()+GetChartID()+"buyAlert")==0 )
{
pb.PushBullet("Sell Alert in " +Name() + " : SellPrice Value is " + SellPrice + " Time " + TimeNum());
StaticVarSet(Name()+ GetChartID() + "sellAlertBar", LastValue(TimeNum()));
}

if (LastValue(TimeNum()) == StaticVarGet(Name()+GetChartID()+"sellAlertBar"))

StaticVarSet(Name()+GetChartID()+"sellAlert",1); //alert was triggered, no more alerts on this bar
else
StaticVarSet(Name()+GetChartID()+"sellAlert",0); // new bar formed, and alerts can be trigered.

_SECTION_END();
Correct Code as follows -

_SECTION_BEGIN("PushBullet");

EnableScript("VBScript");

<%

Public Sub pushbullet(Message_Text)
Dim Message

'Your Message
Message = Message_Text

Dim objXmlHttpMain , URL

strJSONToSend = "{""type"": ""note"", ""title"": ""Alert"", ""body"":""" &Message_Text&"""}"

URL="https://api.pushbullet.com/v2/pushes"
Set objXmlHttpMain = CreateObject("Msxml2.ServerXMLHTTP")
on error resume next
objXmlHttpMain.open "POST",URL, False
objXmlHttpMain.setRequestHeader "Authorization", "Bearer xxxxxxxxxxxxxxxxxxxxxxxxx"
objXmlHttpMain.setRequestHeader "Content-Type", "application/json"


objXmlHttpMain.send strJSONToSend

set objJSONDoc = nothing
set objResult = nothing

'Store response
'msgbox(objXmlHttpMain.responseText)
'response.Write (objXmlHttpMain.responseText)
alert("Hi")
End Sub

%>

pb = GetScriptObject();



if (LastValue(ValueWhen(Ref(Buy,-1),BarIndex())==BarIndex()) AND StaticVarGet(Name()+GetChartID()+"buyAlert")==0 )
{
pb.PushBullet("Buy Alert in " +Name() + " : BuyPrice Value is " + BuyPrice + " Time " + TimeNum());
StaticVarSet(Name()+ GetChartID() + "buyAlertBar", LastValue(TimeNum()));
}

if (LastValue(TimeNum()) == StaticVarGet(Name()+GetChartID()+"buyAlertBar"))

StaticVarSet(Name()+GetChartID()+"buyAlert",1); //alert was triggered, no more alerts on this bar
else
StaticVarSet(Name()+GetChartID()+"buyAlert",0); // new bar formed, and alerts can be trigered.



if (LastValue(ValueWhen(Ref(Sell,-1),BarIndex())==BarIndex()) AND StaticVarGet(Name()+GetChartID()+"sellAlert")==0 )
{
pb.PushBullet("Sell Alert in " +Name() + " : SellPrice Value is " + SellPrice + " Time " + TimeNum());
StaticVarSet(Name()+ GetChartID() + "sellAlertBar", LastValue(TimeNum()));
}

if (LastValue(TimeNum()) == StaticVarGet(Name()+GetChartID()+"sellAlertBar"))

StaticVarSet(Name()+GetChartID()+"sellAlert",1); //alert was triggered, no more alerts on this bar
else
StaticVarSet(Name()+GetChartID()+"sellAlert",0); // new bar formed, and alerts can be trigered.

_SECTION_END();
 

yasu222

Active Member
#49
Target, slippage conditions in afl

Here with Attached the partial AFL code which allows you,
1) How to add Trailing stoploss to your AFL either by percentage or target points exit method.
2) Slippage added so that existing positions will be exit with perfect price or position may be reversed.
Here "cond1" means your buy/sell logic.


p4 = ParamList( "Trg Method", "Percentage,Amount" ) ;
p5 = Param( "Target", 1, .05 , 2000, .05 ) ;
p7 = Param( "Slip", 0, 0 , 1000, .05 ) ;

T11 = Param( "OPEN", 090000, 0 , 235959, 1 ) ;
T12 = Param( "CLOSE", 223000, 0 , 235959, 1 ) ;
T13 = (T12 - (Interval()*2));

C3 = ValueWhen(C1,H,1) ;
C4 = ValueWhen(C1,L,1) ;
C5 = (COND1 > C3 + p7) ;
C6 = (COND2 < C4 - p7) ;
C7 = 0 ;

if( p4 == "Percentage" ) C7 = (C3+p7)+((C3+p7)*(p5/100));
if( p4 == "Amount" ) C7 = (C3+p7)+(p5);
C8 = 0 ;
if( p4 == "Percentage" ) C8 = (C4-p7)-((C4-p7)*(p5/100));
if( p4 == "Amount" ) C8 = (C4-p7)-(p5);

B = C5 AND TimeNum() < T13 AND TimeNum() > T11;
BE1 = L < Ref(C4,-1) OR C6 OR (H > C7) OR TimeNum() > T13 ;

Sh1 = C6 AND TimeNum() < T13 AND TimeNum() > T11;
SE1 = H > Ref(C3,-1) OR C5 OR (L < C8) OR TimeNum() > T13 ;

Buy1 =ExRem(B,BE1);
Sell1 =ExRem(BE1,B);
Cover1=ExRem(Se1,Sh1) ;
Short1= ExRem(Sh1,Se1) ;
 
Last edited:

yasu222

Active Member
#50
Performance Metrics Terminology

These are some of the metrics I look at when evaluating a trading system. The interpretation of these metrics will vary based on the type of system (trend vs. mean reversion) and the person who's trading. I trade MR and prefer a high winning %. Exposure is not that important, so I don't mind staying in cash as I wait for signals. I look for systems that have very low volatility and I will even sacrifice performance if it means I can sleep better at night.

Win% - percentage of trades with a net profit > 0. Above 60% is good. The higher the better.

Avg% – average percentage return of all trades. Obviously, as high as possible

MaxDD% – max. percentage intraday draw down. Important as an isolated number, but the length of time the DD lasts is just as important. What's worse: A 20% draw down that lasts 2 weeks or a 5% draw down that lasts 4 months?

CAR% – annualized percentage return.

RAR% - CAR % divided by exposure%. RAR% takes time into account.

Sharpe Ratio - measures of risk adjusted return of investment. Above 1.0 is good, above 2.0 is great.

R2 – measures the straight line fit of the equity curve. Outcome can be anywhere from 0 to 1. Having a 1 means 100% fit of the equity curve to a straight line. The fewer draw downs the system has the higher R2 .
DVR - combines R2 and Sharpe Ratio by multiplying. This David Varadi's idea; see his excellent blog.

Recovery Factor - Net Profit divided Max System Draw down. Measures how fast the system recovers from draw downs. The higher the better, definitely above 2.

Profit Factor - Profit of winners divided by profit of losers. Above 2 is great. Above 3 is excellent!

Payoff Ratio = average win/average loss. Above 1 please.

Avg. Max Favorable Excursion = MFE is the maximum profit that the trade had before the trade closed. The average gives me an idea of the average positive move the trade makes.

Avg. Max Adverse Excursion = MAE is the maximum loss that the trade had before the trade closed. The average gives me an idea of the average loss move the trade makes.

Trades # – number of trades. Important to look at. How often do I have to trade this thing to make money?

or
To view the report of last backest simply click Report button in the automatic analysis window. To view results of ALL past backtest, click drop down arrow on the Report button and choose Report Explorer option. This will display the Report Explorer window that will show the list of all backtests performed. If you double click on the line - detailed report will be shown.

New report is hugely enhanced compared to old one. It includes separate statistics for all, long and short sides as well as large number of new metrics. You can get short help on given figure by hovering your mouse over given field name. You will see the description in the tooltip. Short explanations are provided also below:

Exposure % - 'Market exposure of the trading system calculated on bar by bar basis. Sum of bar exposures divided by number of bars. Single bar exposure is the value of open positions divided by portfolio equity.

Net Risk Adjusted Return % - Net profit % divided by Exposure %

Annual Return % - Compounded Annual Return % (CAR)

Risk Adjusted Return % - Annual return % divided by Exposure %

Avg. Profit/Loss, also known as Expectancy ($) - (Profit of winners + Loss of losers)/(number of trades), represents expected dollar gain/loss per trade

Avg. Profit/Loss %, also known as Expectancy (%) - '(% Profit of winners + % Loss of losers)/(number of trades), represents expected percent gain/loss per trade

Avg. Bars Held - sum of bars in trades / number of trades

Max. trade drawdown - The largest peak to valley decline experienced in any single trade. The lower the better

Max. trade % drawdown - The largest peak to valley percentage decline experienced in any single trade. The lower the better

Max. system drawdown - The largest peak to valley decline experienced in portfolio equity. The lower the better

Max. system % drawdown - The largest peak to valley percentage decline experienced in portfolio equity. The lower the better

Recovery Factor - Net profit divided by Max. system drawdown

CAR/MaxDD - Compound Annual % Return divided by Max. system % drawdown. Good if bigger than 2

RAR/MaxDD - Risk Adjusted Return divided by Max. system % drawdown. Good if bigger than 2.

Profit Factor - Profit of winners divided by loss of losers

Payoff Ratio - Ratio average win / average loss

Standard Error - Standard error measures chopiness of equity line. The lower the better.

Risk-Reward Ratio - Measure of the relation between the risk inherent in a trading the system compared to its potential gain. Higher is better. Calculated as slope of equity line (expected annual return) divided by its standard error.

Ulcer Index - Square root of sum of squared drawdowns divided by number of bars

Ulcer Performance Index - (Annual profit - Tresury notes profit)/Ulcer Index'>Ulcer Performance Index. Currently tresury notes profit is hardcoded at 5.4. In future version there will be user-setting for this.

Sharpe Ratio of trades - Measure of risk adjusted return of investment. Above 1.0 is good, more than 2.0 is very good. More information stanford.edu/~wfsharpe/art/sr/sr.htm. Calculation: first average percentage return and standard deviation of returns is calculated. Then these two figures are annualized by multipling them by ratio (NumberOfBarsPerYear)/(AvgNumberOfBarsPerTrade). Then the risk free rate of return is subtracted (currently hard-coded 5) from annualized average return and then divided by annualized standard deviation of returns.

K-Ratio - Detects inconsistency in returns. Should be 1.0 or more. The higher K ratio is the more consistent return you may expect from the system. Linear regression slope of equity line multiplied by square root of sum of squared deviations of bar number divided by standard error of equity line multiplied by square root of number of bars. More information: Stocks & Commodities V14:3 (115-118): Measuring System Performance by Lars N. Kestner
 

Similar threads