Hello,
Couple of newbie questions...
How do I get the Exponential moving average of the prior day / time period ?
For example, something like:=
Avg1 = XAverage(close,40);
And then we can compare Avg1 with Avg1[1]...
(Where Avg1 is current and Avg1[1] is prior)
And, how can I setup a stop loss order ? I see that there is a StopMarketOrder class,
Is that what I have to use ?
I would like to set a stop using the average true range.
I am using the clone of the exponential moving average cross-over
strategy as a starting point.
Thanks
Nicholas Stein
private RollingWindow Avg1;
Then you canAvg1.Add(new IndicatorDataPoint(this.time, XAverage.Current.Value);
and access it withif (Avg[0].Value == Avg[1].Value){ // do something }
Michael Handschuh
var ema = EMA("SPY", 40);
We can put the old emas into a rolling window as suggested by @Nicholas:int historyLength = 10; var window = new RollingWindow(historyLength);
// this next line says each time we get a new ema value, add it to our window
ema.Updated += (sender, args) => window.Add(args);
Now we can access and compare the way @Nicholas shows:// if today's ema is greater than yesterday's ema if (window[0] > window[1]){ // do something magic }
Nicholas Stein
Mark Axmann
I know this is an old thread, but would this code go in the initialize or the OnData event. Specifically for the .Updated event to fire. Does that happen no matter where you call EMA()? Thanks
Michael Manus
on the right there are some examples provided by the QC team.
check them out
there is for example one file called MovingAverageCrossAlgorithm. which you can copy paste into the algo lab and play with that.
(its an ema crossover example)
Roger Doss
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!