Hello there,
Issues with enabling fully automated orders during live testing. I have looked at the documentation, but not entirely certain on how to activate automated ordering in C#. I saw one code structure where you input ' if(live mode) ', but not sure were to place it, or even if that is all that is needed. My personal strategy is developed, but just having an issue with the full automation of the orders. I am currently learning the platform. Currently using basic forex algorithm with a basic strategy to test things out. Also, is this even a feature in the demo area, as in does it need to be real money to do fully automated? No problems with running backtests, as in it reports where trades are opened/closed and plots correctly. Any help would be appreciated!
Michael Manus
check the "live trading servers" - line:
:)
Steven Steady
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);
}
}
}
Jared Broad
about placing fully automated trades.
The material on this website is provided for informational purposes only and does not constitute an offer to sell, a solicitation to buy, or a recommendation or endorsement for any security or strategy, nor does it constitute an offer to provide investment advisory services by QuantConnect. In addition, the material offers no opinion with respect to the suitability of any security or specific investment. QuantConnect makes no guarantees as to the accuracy or completeness of the views expressed in the website. The views are subject to change, and may have become unreliable for various reasons, including changes in market conditions or economic circumstances. All investments involve risk, including loss of principal. You should consult with an investment professional before making any investment decisions.
Steven Steady
I will get it eventually.
Steven Steady
The material on this website is provided for informational purposes only and does not constitute an offer to sell, a solicitation to buy, or a recommendation or endorsement for any security or strategy, nor does it constitute an offer to provide investment advisory services by QuantConnect. In addition, the material offers no opinion with respect to the suitability of any security or specific investment. QuantConnect makes no guarantees as to the accuracy or completeness of the views expressed in the website. The views are subject to change, and may have become unreliable for various reasons, including changes in market conditions or economic circumstances. All investments involve risk, including loss of principal. You should consult with an investment professional before making any investment decisions.
To unlock posting to the community forums please complete at least 30% of Boot Camp.
You can continue your Boot Camp training progress from the terminal. We hope to see you in the community soon!