Posted By: Dalla
Implementation of e-ratio in Zorro - 01/07/18 07:43
I´ve tried to implement the e-ratio (edge ratio) in Zorro. Basically it compares the MFE to the MAE for your trades, and calculates the ratio between them.
A more detailed description can be found here at the Build Alpha site:https://www.buildalpha.com/eratio/
I typically run it in the EXITRUN like this
As you can see a TradeVar is used which holds the ATR, so you also need to setup a TMF that records the ATR when the trade is closed
You can also put the calculation in an objective function and "optimize" over LifeTime to get a feeling for how the eratio changes with the length of your trades:
You could probably implement something along the lines of plotPriceProfile() as well, but I haven't looked into that.
Happy to hear comments and suggestions for improvement!
A more detailed description can be found here at the Build Alpha site:https://www.buildalpha.com/eratio/
I typically run it in the EXITRUN like this
Code:
if(is(EXITRUN)) { var cumMfeNorm = 0; var cumMaeNorm = 0; string CurrentAlgo = Algo; for(all_trades) { if(strstr(TradeAlgo,CurrentAlgo)) { cumMfeNorm += TradeMFE/TradeVar[0]; cumMaeNorm += TradeMAE/TradeVar[0]; } } var averageMfeNorm = cumMfeNorm/(NumWinLong+NumLossLong); var averageMaeNorm = cumMaeNorm/(NumWinLong+NumLossLong); var eratio = averageMfeNorm/averageMaeNorm; printf("nE-ratio for %s is %.3f%",Algo, eratio); }
As you can see a TradeVar is used which holds the ATR, so you also need to setup a TMF that records the ATR when the trade is closed
Code:
int recordAtr() { if(TradeIsClosed) { // trade is closing? TradeVar[0] = ATR(20); } return 0; }
You can also put the calculation in an objective function and "optimize" over LifeTime to get a feeling for how the eratio changes with the length of your trades:
Code:
var objective() { var cumMfeNorm = 0; var cumMaeNorm = 0; string CurrentAlgo = Algo; for(all_trades) { if(strstr(TradeAlgo,CurrentAlgo)) { cumMfeNorm += TradeMFE/TradeVar[0]; cumMaeNorm += TradeMAE/TradeVar[0]; } } var averageMfeNorm = cumMfeNorm/(NumWinLong+NumLossLong); var averageMaeNorm = cumMaeNorm/(NumWinLong+NumLossLong); var eratio = averageMfeNorm/averageMaeNorm; return eratio; }
You could probably implement something along the lines of plotPriceProfile() as well, but I haven't looked into that.
Happy to hear comments and suggestions for improvement!