I checked the 'Live trading server', not exactly sure what you meant. Below is a basic algorithm with a basic strategy, am I missing something related to fully automated orders? The backtest displays orders filled, but when switched to 'go live', it only responds to a manually input order (wanting this action completed automatically, without per trade inputs from myself). When developing my personal strategy, I never actually learned to automate orders, only to collect/analize/plot the data. Came to this platform to try to figure that part out. Scouring through the github got me a little further, but to full automation. I think I have followed the documentation, if not, where do I need to delve a bit deeper? The **'d section is where I am thinking I have done something incorrectly, but not really certain, and am stuck on what to do.
using System;
using System.Linq;
using QuantConnect.Indicators;
using QuantConnect.Models;
namespace QuantConnect.Algorithm.CSharp
{
public class FirstLiveTest : QCAlgorithm
{
Symbol _nzd;
RelativeStrengthIndex _rsi;
ExponentialMovingAverage _emaLong;
ExponentialMovingAverage _emaShort;
OrderTicket _limitTicket;
OrderTicket _stopMarketTicket;
OrderTicket _stopLimitTicket;
public override void Initialize()
{
SetStartDate(2017, 12, 04); //Set Start Date
SetEndDate(2018, 02, 23); //Set End Date
SetCash(1000); //Set Strategy Cash
_nzd = AddForex("NZDUSD", Resolution.Hour, Market.Oanda).Symbol;
_rsi = RSI("NZDUSD", 14, MovingAverageType.Simple, Resolution.Hour);
_emaShort = EMA("NZDUSD", 10, Resolution.Hour);
_emaLong = EMA("NZDUSD", 17, Resolution.Hour);
}
*******************************************************************************************
*******************************************************************************************
public override void OnData(Slice data)
{
if (!_emaLong.IsReady) return;
var quantity = Portfolio["NZDUSD"].Quantity;
if (_rsi > 70 && quantity == 0 && _emaShort > _emaLong)
{
SetHoldings("NZDUSD", 5);
Debug("Purchased NZDUSD");
}
else if (_rsi < 30 && quantity > 0)
{
Liquidate();
Debug("Liquidate NZDUSD");
}
if (_limitTicket == null)
{
MarketOrder(_nzd, 100, tag: "market order");
_limitTicket = LimitOrder(_nzd, 100, data["NZDUSD"].Close * 0.99m, tag: "limit order");
_stopMarketTicket = StopMarketOrder(_nzd, -100, data["NZDUSD"].Close + 0.95m, tag: "stop market");
_stopLimitTicket = StopLimitOrder(_nzd, -100, data["NZDUSD"].Close * 0.90m, data["NZDUSD"].Close * 0.80m, tag: "stop limit");
}
}
public override void OnEndOfDay() {
Plot("RSI", _rsi);
Plot("EMA", _emaLong, _emaShort);
if (_limitTicket == null) return;
Plot("Order Tickets", "NZDUSD", Portfolio[_nzd].Price);
if (_stopMarketTicket.Status != OrderStatus.Filled)
Plot("Order Tickets", "Stop Price", _stopMarketTicket.Get(OrderField.StopPrice));
if (_stopLimitTicket.Status != OrderStatus.Filled)
Plot("Order Tickets", "Limit Price", _stopLimitTicket.Get(OrderField.LimitPrice));
}
*****************************************************************************************************************
*****************************************************************************************************************
public override void OnOrderEvent(OrderEvent orderEvent)
{
if (orderEvent.FillQuantity == 0) return;
var fetched = Transactions.GetOrderById(orderEvent.OrderId);
Debug(fetched.Type + " was filled: Symbol: " + orderEvent.Symbol + " Quantity: " + orderEvent.FillQuantity + " Direction: " + orderEvent.Direction);
}
}
}