| Overall Statistics |
|
Total Trades 286 Average Win 1.95% Average Loss -2.15% Compounding Annual Return -23.968% Drawdown 35.300% Expectancy -0.092 Net Profit -28.237% Sharpe Ratio -0.671 Loss Rate 52% Win Rate 48% Profit-Loss Ratio 0.91 Alpha -0.158 Beta -0.036 Annual Standard Deviation 0.24 Annual Variance 0.057 Information Ratio -0.963 Tracking Error 0.262 Treynor Ratio 4.525 Total Fees $0.00 |
namespace QuantConnect
{
/*
* Basic Template Algorithm
*
* The underlying QCAlgorithm class has many methods which enable you to use QuantConnect.
* We have explained some of these here, but the full base class can be found at:
* https://github.com/QuantConnect/Lean/tree/master/Algorithm
*/
public class BasicTemplateAlgorithm : QCAlgorithm
{
private Security _oil;
private SimpleMovingAverage _sma14;
private RelativeStrengthIndex _rsi14;
public override void Initialize()
{
SetBrokerageModel(BrokerageName.OandaBrokerage);
// backtest parameters
SetStartDate(2016, 1, 1);
SetEndDate(DateTime.Now);
// cash allocation
SetCash(10000);
// request specific equities
// including forex. Options and futures in beta.
_oil = AddCfd("BCOUSD", Resolution.Minute, Market.Oanda);
//AddForex("EURUSD", Resolution.Minute);
_sma14 = SMA(_oil.Symbol, 14);
_rsi14 = RSI(_oil.Symbol, 14);
}
/*
* New data arrives here.
* The "Slice" data represents a slice of time, it has all the data you need for a moment.
*/
public override void OnData(Slice data)
{
// slice has lots of useful information
TradeBars bars = data.Bars;
Splits splits = data.Splits;
Dividends dividends = data.Dividends;
if (_oil.Holdings.HoldStock)
{
ExitLogic();
}
else
{
EntryLogic();
}
}
private int GetHour()
{
//TODO: needs to be fixed to handle timelight savings
return Time.ToUniversalTime().Hour + 2;
}
private void ExitLogic()
{
if (GetHour() >= 15)
{
Liquidate(_oil.Symbol);
}
}
private void EntryLogic()
{
if (GetHour() >= 13)
return;
if (_oil.Price > _sma14)
{
if (_rsi14 > 50)
{
SetHoldings(_oil.Symbol, 1);
}
}
else
{
if (_rsi14 < 40)
{
SetHoldings(_oil.Symbol, -1);
}
}
}
}
}