Thank you Alexander,
The issue I have is moving from my own framework that is very Oanda based to Lean, I basically have to relearn. Something I really want to do is to be able to run an algorithm on schedule on the cloud, I have a paid hosting on azure. I wanted to do something like the code below running under a timer to get data:
class Program
{
#region Methods
static void Main(string[] args)
{
var algorithm = new MyAlgorithm();
algorithm.Initialize();
algorithm.OnData(new Slice(DateTime.UtcNow,
new List<TradeBar> { new TradeBar(DateTime.UtcNow, MyAlgorithm._eurusd, 1.01m, 1.01m, 1.01m, 1.01m, 1, TimeSpan.FromMinutes(1)) }));
}
#endregion
}
public class MyAlgorithm : QCAlgorithm
{
#region Static Fields
public static readonly Symbol _eurusd = QuantConnect.Symbol.Create("EURUSD", SecurityType.Forex, Market.Oanda);
#endregion
#region Fields
TradeBarConsolidator _consolidator;
private Security forexSecuriy;
#endregion
#region Public Methods and Operators
/// <summary>
/// Initialise the data and resolution required, as well as the cash and start-end dates for your algorithm. All
/// algorithms must initialized.
/// </summary>
public override void Initialize()
{
this.SetStartDate(2014, 01, 01); //Set Start Date
this.SetEndDate(2014, 01, 01); //Set End Date
this.SetCash(5000);
//Specify the Oanda Brokerage.
this.SetBrokerageModel(BrokerageName.OandaBrokerage);
//Add as many securities as you like. All the data will be passed into the event handler:
this.forexSecuriy = this.AddSecurity(SecurityType.Forex, _eurusd.Value, Resolution.Minute);
this.SetBrokerageModel(BrokerageName.OandaBrokerage, AccountType.Margin);
this._consolidator = new TradeBarConsolidator(TimeSpan.FromMinutes(2));
this._consolidator.DataConsolidated += this.SpyFourHours;
var easternTimeZone = DateTimeZoneProviders.Tzdb["America/New_York"];
this.SubscriptionManager.Add(_eurusd, Resolution.Minute, easternTimeZone, easternTimeZone, false, false, false);
this.SubscriptionManager.AddConsolidator(_eurusd, this._consolidator);
}
/// <summary>
/// OnData event is the primary entry point for your algorithm. Each new data point will be pumped in here.
/// </summary>
/// <param name="data">Slice object keyed by symbol containing the stock data</param>
public override void OnData(Slice data)
{
var bar = data.Bars.ContainsKey(_eurusd) ? data.Bars[_eurusd] : null;
var holdings = this.Portfolio[_eurusd.Value].Quantity;
this.forexSecuriy.SetMarketPrice(new Tick(DateTime.UtcNow, _eurusd, 1.01m, 1.01m));
this.TradeBuilder.SetMarketPrice(_eurusd, this.forexSecuriy.Price);
if (this.Portfolio.Invested) return;
OrderTicket newOrder = this.MarketOrder(_eurusd, 1);
var stopLossTicket = this.StopMarketOrder(_eurusd, 1, 1.01m);
this.Debug("Purchased Stock");
}
public void SpyFourHours(object o, TradeBar bar)
{
this.Log(this.Time.ToString("u") + " Close Price: " + bar.Close);
}
#endregion
}
I encoutered several issues doing this, I have no idea how is that the security gets the price, or how to place a stop loss, how to place a trailing stop, how to setup Oanda credentials.
I think QuantConnect is wonderful because all the indicators, the support, the backtesting, but my need is to be able to get the core of the algorithm and be able to execute it under something similar to a console application under a single thread.
For example, in my platform I passed the transaction processor as a dependency to the algorithm, so the order execution is made by the algorith itself, but it seems that with lean I'll have to execute the orders after the algorithm has executed. Do you think it is worth pursuing the implementation under Lean? I'll appreciate the advise. Thank you again for your help!!