| Overall Statistics |
|
Total Trades 1 Average Win 0.00% Average Loss -12.30% Annual Return -5.363% Drawdown 26.000% Expectancy -1.000 Net Profit -12.300% Sharpe Ratio -0.3 Loss Rate 100% Win Rate 0% Profit-Loss Ratio 0.00 Trade Frequency Weekly trades |
-no value-
using System;
using System.Collections;
using System.Collections.Generic;
using System.Text;
using System.Threading.Tasks;
using QuantConnect.Indicator;
namespace QuantConnect
{
using QuantConnect.Securities;
using QuantConnect.Models;
public class BasicTemplateAlgorithm : QCAlgorithm, IAlgorithm
{
ExponentialMovingAverage ema10 = new ExponentialMovingAverage(10);
ExponentialMovingAverage ema50 = new ExponentialMovingAverage(30);
//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(2011, 06, 01);
SetEndDate(2012, 12, 30);
SetCash(30000); //Starting Cash in USD.
AddSecurity(SecurityType.Equity, "IBM", Resolution.Minute); //Minute, Second or 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)
{
ema10.Push(Securities["IBM"].Close);
ema50.Push(Securities["IBM"].Close);
if (ema10.EMA > ema50.EMA)
{
Order("IBM", 50); //symbol, quantity
return;
}
else
{
Order("IBM", -50); //symbol, quantity
return;
}
}
//Handle Tick Events
public override void OnTick(Dictionary<string, List<Tick>> ticks)
{
if (Portfolio["IBM"].HoldStock == false)
{
Order("IBM", 5);
}
}
}
}/*
Created July 2013 by Cheng Yan
*/
/**********************************************************
* USING NAMESPACES
**********************************************************/
using System;
using System.Collections;
using System.Collections.Generic;
using System.Text;
using System.Threading.Tasks;
using System.Linq;
using QuantConnect;
using QuantConnect.Models;
namespace QuantConnect.Indicator
{
/********************************************************
* CLASS DEFINITIONS
*********************************************************/
/// <summary>
/// An indicator shows the average value of secuitry's price
/// over a set period
/// </summary>
public class ExponentialMovingAverage : QCAlgorithm
{
/********************************************************
* CLASS VARIABLES
*********************************************************/
private int _period;
private decimal _ema;
private bool flag;
private Queue <decimal>_data = new Queue <decimal> ();
/********************************************************
* CLASS PUBLIC VARIABLES
*********************************************************/
public decimal EMA
{
get{ return _ema;}
}
public decimal GetExpConst
{
get{ return (decimal) 2/(_period +1);}
}
/********************************************************
* CLASS CONSTRUCTOR
*********************************************************/
/// <summary>
/// Initialise the Algorithm
/// </summary>
public ExponentialMovingAverage(int period)
{
_period = period;
_ema = 0;
flag = false;
}
/********************************************************
* CLASS METHODS
*********************************************************/
/// <summary>
/// Calculate the exponential moving average
/// </summary>
public void Push(decimal quote)
{
_data.Enqueue(quote);
}
/// <summary>
/// Calculate the exponential moving average
/// </summary>
public void GetEMA(decimal quote)
{
Push(quote);
if(_data.Count < _period)
{
return;
}
else
{
if(!flag)
{
_ema = _data.Average();
flag = true;
}
else
{
_ema = (1-GetExpConst) * _ema +GetExpConst * quote;
}
}
}
}
}/// <summary>
/// Basic Template v0.1 :: Rolling Average
/// </summary>
using System;
using System.Collections;
using System.Collections.Generic;
namespace QuantConnect {
/// <summary>
/// Example Helper Class: Basic Math Routines.
/// Using the QCS you can create subfolders, classes.
/// All the code is compiled into your algorithm.
/// </summary>
public partial class MathAverage {
public int iSamplePeriod = 10;
public decimal dCurrentAverage = 0;
/// <summary>
/// Example helper class: Add a new sample to a rolling average.
/// </summary>
/// <param name="dNewSample">Decimal new sample value</param>
/// <returns>decimal current rolling average.</returns>
public static decimal RollingAverage(decimal dNewSample) {
Random cRand = new Random();
return dNewSample * ((decimal)cRand.NextDouble());
}
}
}