| Overall Statistics |
|
Total Trades 0 Average Win 0% Average Loss 0% Compounding Annual Return 0% Drawdown 0% Expectancy 0 Net Profit 0% Sharpe Ratio 0 Probabilistic Sharpe Ratio 0% Loss Rate 0% Win Rate 0% Profit-Loss Ratio 0 Alpha 0 Beta 0 Annual Standard Deviation 0 Annual Variance 0 Information Ratio -0.768 Tracking Error 0.163 Treynor Ratio 0 Total Fees $0.00 Estimated Strategy Capacity $0 |
namespace QuantConnect
{
/// <summary>
/// QCU How do I create Custom Charts?
///
/// The entire charting system of quantconnect is adaptable. You can adjust it to draw whatever you'd like.
///
/// Charts can be stacked, or overlayed on each other.
/// Series can be candles, lines or scatter plots.
///
/// Even the default behaviours of QuantConnect can be overridden
///
/// </summary>
public class CustomChartingAlgorithm : QCAlgorithm
{
//Initializers:
int dayCount = 0;
bool tradedToday = false;
SimpleMovingAverage _sma;
RelativeStrengthIndex _rsi;
TradeBars prices = new TradeBars();
public override void Initialize()
{
SetStartDate(2013, 1, 1);
SetStartDate(2015, 1, 1);
AddSecurity(SecurityType.Forex, "EURUSD", resolution: Resolution.Minute);
//#5 - Stock Plotter with Trades
Chart plotter = new Chart("Plotter");
plotter.AddSeries(new Series("EURUSD", SeriesType.Line, index:0));
plotter.AddSeries(new Series("EURUSD-200MA", SeriesType.Line, index:0));
plotter.AddSeries(new Series("Buy", SeriesType.Scatter, index:0));
plotter.AddSeries(new Series("Sell", SeriesType.Scatter, index:0));
plotter.AddSeries(new Series("EURUSD-RSI", SeriesType.Line, index:1));
AddChart(plotter);
_sma = SMA("EURUSD", 7, Resolution.Daily);
_rsi = RSI("EURUSD", 7, MovingAverageType.Simple, Resolution.Daily);
}
/// <summary>
/// New Trade Bar Event Handler
/// </summary>
public void OnData(TradeBars data)
{
try
{
//Save price data:
foreach (string symbol in data.Keys)
{
if (!prices.ContainsKey(symbol))
{
prices.Add(symbol, data[symbol]);
} else {
prices[symbol] = data[symbol];
}
}
//Every 7th day go long everything:
if ( !Portfolio.Invested && (dayCount % 7 == 0) && !tradedToday )
{
SetHoldings( "SPY" , 0.25 );
SetHoldings( "EURUSD" , 0.25 );
if (prices.ContainsKey("EURUSD")) Plot("Plotter", "Buy", prices["EURUSD"].Price);
tradedToday = true;
}
//Every 13th day close out portfolio:
if ( Portfolio.Invested && (dayCount % 13 == 0) && !tradedToday )
{
Liquidate();
if (prices.ContainsKey("EURUSD")) Plot("Plotter", "Sell", prices["EURUSD"].Price);
tradedToday = true;
}
}
catch (Exception err)
{
Error("OnData Err: " + err.Message);
}
}
public override void OnEndOfDay()
{
try
{
//Track # of Days:
dayCount++;
tradedToday = false;
//#5 Manual Stock Plotter: Plot price once per day:
if (prices.ContainsKey("EURUSD") && _sma.IsReady && _rsi.IsReady) {
Plot("Plotter", "EURUSD", prices["EURUSD"].Price);
Plot("Plotter", "EURUSD-200MA", _sma);
Plot("Plotter", "EURUSD-RSI", _rsi);
}
}
catch (Exception err)
{
Error("OnEndOfDay Err:" + err.Message);
}
}
}
}