| Overall Statistics |
|
Total Trades 3 Average Win 0.95% Average Loss 0% Compounding Annual Return 90.522% Drawdown 16.700% Expectancy 0 Net Profit 4.100% Sharpe Ratio 1.09 Loss Rate 0% Win Rate 100% Profit-Loss Ratio 0 Alpha 2.065 Beta -90.17 Annual Standard Deviation 0.638 Annual Variance 0.408 Information Ratio 1.066 Tracking Error 0.638 Treynor Ratio -0.008 Total Fees $0.00 |
namespace QuantConnect
{
public class indicator_res_test : QCAlgorithm
{
private OrderTicket EntryOrder { get; set; }
private Func<QCAlgorithm, string, decimal, OneCancelsOtherTicketSet> OnOrderFilledEvent { get; set; }
private OneCancelsOtherTicketSet ProfitLossOrders { get; set; }
public override void Initialize()
{
SetStartDate(2011, 6, 9);
SetEndDate(2011, 7, 1);
SetCash(10000);
AddSecurity(SecurityType.Forex, "EURUSD", Resolution.Minute, true, 50.0m, false);
}
public void OnData(TradeBars data)
{
if (!Portfolio.Invested && Time.TimeOfDay.Hours == 08)
{
this.OnOrderFilledEvent = (algo, symbol, filledPrice) =>
{
return new OneCancelsOtherTicketSet(
algo.LimitOrder(symbol, -45000, filledPrice + 0.00212m, "Profit Target"),
algo.StopMarketOrder(symbol, -45000, filledPrice - 0.00212m, "Stop Loss"));
};
this.EntryOrder = MarketOrder("EURUSD", 45000, false, "Entry");
}
}
public override void OnOrderEvent(OrderEvent orderEvent)
{
if (EntryOrder != null)
{
this.EntryOrder = null;
}
if (orderEvent.Status == OrderStatus.Filled || orderEvent.Status == OrderStatus.PartiallyFilled)
{
if (this.OnOrderFilledEvent != null)
{
this.ProfitLossOrders = OnOrderFilledEvent(this, orderEvent.Symbol, orderEvent.FillPrice);
OnOrderFilledEvent = null;
}
else if (this.ProfitLossOrders != null)
{
this.ProfitLossOrders.Filled();
Log("Profit/Loss Filled" + "Portfolio Invested Check: =" + Portfolio.Invested);
this.ProfitLossOrders = null;
}
}
}
}
}namespace QuantConnect {
public class OneCancelsOtherTicketSet
{
public OneCancelsOtherTicketSet(params OrderTicket[] orderTickets)
{
this.OrderTickets = orderTickets;
}
private OrderTicket[] OrderTickets { get; set; }
public void Filled()
{
// Cancel all the outstanding tickets.
foreach (var orderTicket in this.OrderTickets)
{
if (orderTicket.Status == OrderStatus.Submitted)
{
orderTicket.Cancel();
}
}
}
}
}