would love to get help writing a simple 10 steps moving average for last 9 full 1M Bars close price + last tick price quote (total 10)
working by ticks of course
thanks,
Eyal.
QUANTCONNECT COMMUNITY
would love to get help writing a simple 10 steps moving average for last 9 full 1M Bars close price + last tick price quote (total 10)
working by ticks of course
thanks,
Eyal.
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.
Gustavo Avilés
if( CurrentSample >= 100 ) { // Add to the queue ValuesQueue.Enqueue( CurrentPrice ); // sum the price SumAvg = SumAvg + CurrentPrice; // deduct the oldest element inserted in the queue decimal dequeue = ValuesQueue.Dequeue(); SumAvg = SumAvg - dequeue; } else { ValuesQueue.Enqueue( CurrentPrice ); SumAvg = SumAvg + CurrentPrice; }
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.
Gustavo Avilés
public override void OnTick(Dictionary ticks)
{
try
{
/*
* The dictionary have the securities that you select in Initialize() function
* and you can select them using the string of their respective symbol.
* ticks[" Symbol "]
*/
}
catch (Exception err)
{
Error("This is an error handler." + err.Message);
}
}
The tick documentationThe 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.
Jared Broad
Dictionary archive = new Dictionary();
public OnTradeBar(Dictionary data) {
archive.Add(data["EURUSD"].Time, data["EURUSD"].Close);
decimal last9min = (from time in archive
where time.Key > Time.AddMinutes(-10) && time.Key < Time.AddMinute(-1)
select time.Values.Close).Average();
decimal floatingAvg = 0.1m * data["EURUSD"].Close + 0.9 * last9min;
//Trim Array length:
archive = (from kvp in archive
where kvp.Key > Time.AddMinutes(-11)
select kvp).ToDictionary();
}
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.
Eyal Zach
Gustavo Avilés
public override void OnTradeBar(Dictionary data) {
/*
* Your Code
*/
}
Another error that I found is the data can only be sended to one type of resolution. So if you want to work with tick data you have to convert the tick data to a trade bar.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.
Jared Broad
// Inline method for capturing tick into minute or second bars: public class Aggregator { public DateTime Time; public TimeSpan SpanOfBar; public string Symbol = ""; public decimal Open = -1; public decimal High = 0; public decimal Low = 0; public decimal Close = 0; public long Volume = 0; public int Count = 0; public Aggregator(DateTime newCandleTime, TimeSpan timeframe, string symbol) { Time = newCandleTime; SpanOfBar = timeframe; Symbol = symbol; } public bool HasData { get { return (Count > 0); } } //Add the tick, return false if out of time allocation: public bool AddTick(decimal price, DateTime newTickTime, long size) { if (newTickTime > (Time + SpanOfBar)) return true; //Add the data Count++; Volume += size; if (Open == -1) Open = price; if (price > High || High == 0) High = price; if (price < Low || Low == 0) Low = price; Close = price; return false; } //Return the current tradebar: public TradeBar GetBar() { return new TradeBar(Time, Symbol, Open, High, Low, Close, Volume); } } // End of Aggregator
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.
Ric
Jared Broad
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.
DavidBallantyne
Jared Broad
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.
Ysos
if (newTickTime > (Time + SpanOfBar)) return true;
return true, it's not quiteif (newTickTime > (Time + SpanOfBar)) return false;
and in the method end line :return true;
Jared Broad
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.
Eyal Zach
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!