Overall Statistics
Total Trades
113
Average Win
1.34%
Average Loss
-0.06%
Annual Return
116.452%
Drawdown
34.400%
Expectancy
17.520
Net Profit
250.926%
Sharpe Ratio
1.7
Loss Rate
15%
Win Rate
85%
Profit-Loss Ratio
20.80
Trade Frequency
Weekly trades
using System;
using System.Collections;
using System.Collections.Generic; 
using QuantConnect.Securities;  
using QuantConnect.Models;   

namespace QuantConnect { 
    
    public class BasicTemplateAlgorithm : QCAlgorithm
    {
        //Initialize the data and resolution you require for your strategy:
        public override void Initialize()
        {
            //Initialize the start, end dates for simulation; cash and data required.
            SetStartDate(2013, 1, 1);         
            SetEndDate(DateTime.Now.Date.AddDays(-1)); 
            SetCash(25000); //Starting Cash in USD.
            AddSecurity(SecurityType.Equity, "VXX", Resolution.Minute); //Minute,Second - Tick
            SetRunMode(RunMode.Series); //Series or Parallel for intraday strategies.
        }
        //Handle TradeBar Events: a TradeBar occurs on every time-interval
        public override void OnTradeBar(Dictionary<string, TradeBar> data) 
        {   
            float data_diff = (float)(data["VXX"].High / data["VXX"].Low);

            if ((data_diff > 1.001)) {
                Order("VXX", -1*(int)Math.Floor(Portfolio.Cash / data["VXX"].Close) );
            }
            else if ((data_diff < 1.00001)) {
               // Order("VXX", 1*(int)Math.Floor(Portfolio.Cash / data["VXX"].Close));
               Liquidate("VXX");
            }
            /*
            else {
                Liquidate("VXX");
            }
            */
        }
    }
}