| Overall Statistics |
|
Total Trades 20 Average Win 0.00% Average Loss -0.01% Compounding Annual Return -0.799% Drawdown 0.100% Expectancy -0.931 Net Profit -0.132% Sharpe Ratio -8.763 Loss Rate 95% Win Rate 5% Profit-Loss Ratio 0.30 Alpha -0.005 Beta 0 Annual Standard Deviation 0.001 Annual Variance 0 Information Ratio -1.022 Tracking Error 0.112 Treynor Ratio -12 Total Fees $40.00 |
namespace QuantConnect
{
/*
* QuantConnect University: Full Basic Template:
*
* The underlying QCAlgorithm class is full of helper methods which enable you to use QuantConnect.
* We have explained some of these here, but the full algorithm can be found at:
* https://github.com/QuantConnect/QCAlgorithm/blob/master/QuantConnect.Algorithm/QCAlgorithm.cs
*/
public class FXTestAlgorithm : QCAlgorithm, IAlgorithm
{
string symbol = "EURUSD";
// SimpleMovingAverage smaShort;
// SimpleMovingAverage smaLong;
ExponentialMovingAverage smaShort;
ExponentialMovingAverage smaLong;
DateTime Today = DateTime.Now;
decimal valueFX;
public override void Initialize()
{
//Start and End Date range for the backtest:
SetStartDate(2015, 1, 1);
SetEndDate(2015, 3, 1);
//Cash allocation
SetCash(30000);
//Add as many securities as you like. All the data will be passed into the event handler:
AddSecurity(SecurityType.Forex, symbol, Resolution.Minute);
// SetRunMode(RunMode.Series);
// smaShort = SMA(symbol, 10, Resolution.Minute);
// smaLong = SMA(symbol, 50, Resolution.Minute);
smaShort = EMA(symbol, 10, Resolution.Minute);
smaLong = EMA(symbol, 50, Resolution.Minute);
}
public void OnData(TradeBars data)
{
if(!smaShort.IsReady || !smaLong.IsReady) return;
if(Today.Date == data[symbol].Time.Date) return;
Today = data[symbol].Time.Date;
valueFX = data[symbol].Close;
int holdings = Portfolio[symbol].Quantity;
if(holdings == 0 || holdings < 0){
if(smaShort > smaLong){
MarketOrder("EURUSD", (Math.Abs(holdings) + 100));
Debug("Purchased EURUSD on " + Time.ToShortDateString());
}
} else if(holdings == 0 || holdings > 0){
if(smaLong > smaShort){
MarketOrder("EURUSD", -(100 + holdings));
Debug("Sold EURUSD on " + Time.ToShortDateString());
}
}
}
}
}