Description
Greetings Traders,
In an effort to enhance your trading experience, I am excited to share a couple of methods that can be integrated into your cBots for the purpose of exporting key performance metrics such as Profit Factors, Sharpe Ratios, and Net Profits after running an optimization. The aim is to provide you with a comprehensive overview of your trading strategies' performance, assisting you in making informed decisions.
Additionally, I am thrilled to introduce a unique application that I have developed. This application utilizes the power of Hypothesis Testing to evaluate the profitability of your trading strategies' premise. It provides a simple yet robust approach to understanding the potential success of your strategies.
this application is entirely free to use! However, if you find it beneficial and it contributes to your success, I kindly encourage you to consider making a small donation to our website. Your support will greatly help us continue to develop and provide helpful tools like this to the trading community.
Should you have any questions, suggestions, or need further assistance, please don't hesitate to reach out to me at info@sinalgolab.com. Your feedback is greatly appreciated and will help us improve and cater to your needs better.
Thank you for your continued support and happy trading!
Check my Blog about Hypothesis-Testing of Trading Strategies Here:
Check my Blog about Backtesting and Overfitting Here
Download the Application for free Here
Check my Divergence Indicator Here
Check my Candlestick Patterns Indicator Here
Check our Website here: sinalgolab.com
Mo from Singularity Algo Lab
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using cAlgo.API;
using cAlgo.API.Collections;
using cAlgo.API.Indicators;
using cAlgo.API.Internals;
using System.IO;
namespace cAlgo.Robots
{
[Robot(AccessRights = AccessRights.None)]
public class ExportMetrics : Robot
{
[Parameter(DefaultValue = "Hello world!")]
public string Message { get; set; }
protected override void OnStart()
{
// To learn more about cTrader Automate visit our Help Center:
// https://help.ctrader.com/ctrader-automate
Print(Message);
}
protected override void OnTick()
{
// Handle price updates here
}
protected override void OnStop()
{
WriteProfitFactorToCSV();
WriteSharpeRatioToCSV();
WriteNetProfitToCSV();
}
public void WriteProfitFactorToCSV()
{
// Calculate Gross Profit and Gross Loss
double grossProfit = 0.0;
double grossLoss = 0.0;
foreach (var trade in History)
{
if (trade.NetProfit > 0)
grossProfit += trade.NetProfit;
else
grossLoss -= trade.NetProfit;
}
double profitFactor = grossProfit / grossLoss;
// Define the CSV file path
string csvFilePath = "C:\\Profit_Factors.csv";
// Check if the CSV file exists
if (!File.Exists(csvFilePath))
{
// If the file doesn't exist, create it and write the header
using (StreamWriter sw = File.CreateText(csvFilePath))
{
sw.WriteLine("Profit Factor");
}
}
// Write the Profit Factor to the CSV file
using (StreamWriter sw = File.AppendText(csvFilePath))
{
sw.WriteLine(profitFactor.ToString());
}
Print("Profit Factor written to CSV file.");
}
public void WriteNetProfitToCSV()
{
// Calculate Net Profit
double netProfit = History.Sum(trade => trade.NetProfit);
// Define the CSV file path
string csvFilePath = "C:\\Net_Profits.csv";
// Check if the CSV file exists
if (!File.Exists(csvFilePath))
{
// If the file doesn't exist, create it and write the header
using (StreamWriter sw = File.CreateText(csvFilePath))
{
sw.WriteLine("Net Profit");
}
}
// Write the Net Profit to the CSV file
using (StreamWriter sw = File.AppendText(csvFilePath))
{
sw.WriteLine(netProfit.ToString());
}
Print("Net Profit written to CSV file.");
}
public void WriteSharpeRatioToCSV()
{
// Calculate average return and standard deviation of returns
double avgReturn = History.Average(trade => trade.NetProfit);
double returnStDev = Math.Sqrt(History.Sum(trade => Math.Pow(trade.NetProfit - avgReturn, 2)) / (History.Count - 1));
double sharpeRatio = avgReturn / returnStDev;
// Define the CSV file path
string csvFilePath = "C:\\Sharpe_Ratios.csv";
// Check if the CSV file exists
if (!File.Exists(csvFilePath))
{
// If the file doesn't exist, create it and write the header
using (StreamWriter sw = File.CreateText(csvFilePath))
{
sw.WriteLine("Sharpe Ratio");
}
}
// Write the Sharpe Ratio to the CSV file
using (StreamWriter sw = File.AppendText(csvFilePath))
{
sw.WriteLine(sharpeRatio.ToString());
}
Print("Sharpe Ratio written to CSV file.");
}
}
}
mh.abualsoud@gmail.com
Joined on 18.07.2018
- Distribution: Free
- Language: C#
- Trading platform: cTrader Automate
- File name: Export Metrics.algo
- Rating: 0
- Installs: 539
- Modified: 20/05/2023 21:55