Overall Statistics
Total Trades
45
Average Win
0.32%
Average Loss
-0.42%
Compounding Annual Return
-2.732%
Drawdown
3.100%
Expectancy
-0.280
Net Profit
-2.608%
Sharpe Ratio
-0.978
Loss Rate
59%
Win Rate
41%
Profit-Loss Ratio
0.76
Alpha
0
Beta
0
Annual Standard Deviation
0.022
Annual Variance
0.001
Information Ratio
0
Tracking Error
0
Treynor Ratio
0
Total Fees
$90.00
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);
            }
        }
    }
    
}