I am obviously having a bit of misunderstanding here. Why is this code giving me an error?
CODE:
TimeSeries roc_aema = new TimeSeries(bars.DateTimes, 0); roc_aema = ROC(aema, roc_period);
QUOTE:
39: Non-invocable member 'ROC' cannot be used like a method.
Rename
In the WL8 framework ROC (like any other indicator) is a .NET class. So you can't use it as if it were a method or function.
You can use the Series method or the new operator to get an instance of ROC. The Series method has an advantage because it uses caching to see if that ROC instance already exists, so it can avoid potential duplicate instances.
You can use the Series method or the new operator to get an instance of ROC. The Series method has an advantage because it uses caching to see if that ROC instance already exists, so it can avoid potential duplicate instances.
CODE:
ROC myROC1 = ROC.Series(bars.Close, 4); ROC myROC2 = new ROC(bars.Close, 4);
ROC is a class. You need to use new. You don't need to create a TimeSeries only to clobber the TimeSeries you just created. I'm not trying to be mean when I say this, but I'm trying to be helpful. From some questions you have asked, I get the impression you may want to brush up on your C#.
In any case, here is what you want. Get rid of creating the TimeSeries. Just do this and adjust the constructor parameters for your needs...
In any case, here is what you want. Get rid of creating the TimeSeries. Just do this and adjust the constructor parameters for your needs...
CODE:
ROC roc_aema = new ROC(bars.Close, 8);
Thanks Glitch!
paul1986,
I am just now learning C#. I am an old C programmer who did not need to learn the newer versions (C++, C#) since programming was no longer my responsibility. There is a LOT I need to learn obviously. :(
QUOTE:
I get the impression you may want to brush up on your C#.
I am just now learning C#. I am an old C programmer who did not need to learn the newer versions (C++, C#) since programming was no longer my responsibility. There is a LOT I need to learn obviously. :(
Carova,
I've always liked the C# In a Nutshell books by Joseph Albahari: https://www.oreilly.com/library/view/c-12-in/9781098147433/
Each edition (latest is for C# version 12), I believe, is pretty succinct so you can get through any new concepts fairly quickly.
I've always liked the C# In a Nutshell books by Joseph Albahari: https://www.oreilly.com/library/view/c-12-in/9781098147433/
Each edition (latest is for C# version 12), I believe, is pretty succinct so you can get through any new concepts fairly quickly.
Thanks Paul! I have been using some of the online resources, but they are not too good IMO.
Next stumbling block...
Now, what am I missing?
CODE:
public override void Initialize(BarHistory bars) { int period = Parameters[0].AsInt; double minAlpha = Parameters[1].AsDouble; double maxAlpha = Parameters[2].AsDouble; double sensitivity = Parameters[3].AsDouble; int Lookback = Parameters[4].AsInt; StartIndex = 101; aema = new TimeSeries(bars.DateTimes, 0); aema = ImprovedAdaptiveEMA(bars, period, minAlpha, maxAlpha, sensitivity); ROC roc_aema = ROC.Series(aema, Lookback); PlotTimeSeries(aema, "Improved Adaptive EMA", "Price", WLColor.Orange, PlotStyle.Line); PlotTimeSeries(roc_aema, "ROC of Improved Adaptive EMA", "ROC",WLColor.Red, PlotStyle.Line); } public override void Execute(BarHistory bars, int idx) { if (!HasOpenPosition(bars, PositionType.Long)) { if (aema[idx] > aema[idx - 1]) { Transaction t = PlaceTrade(bars, TransactionType.Buy, OrderType.Market); // t.Weight = 100d*(aema[idx] - aema[idx - Lookback]) / aema[idx - Lookback]; // Works fine t.Weight = roc_aema[idx]; // Causes runtime errors } } else { if (aema[idx] < aema[idx - 1]) PlaceTrade(bars, TransactionType.Sell, OrderType.Market); } } //declare private variables below private TimeSeries aema; private ROC roc_aema; private int Lookback;
Now, what am I missing?
In your Initialize method you are declaring a local copy of the variable roc_aema.
ROC roc_aema = ROC.Series(aema, Lookback);
This is because you specified the type (ROC) before the variable. When you do this, C# creates a local copy of that variable that's available in the Initialize method only. When the Execute gets called, the roc_aema that is declared in your private section still isn't created, so you get the error.
Instead, you should leave off the type specifier so C# will use the roc_aema that you declared in the private section instead.
roc_aema = ROC.Series(aema, Lookback);
ROC roc_aema = ROC.Series(aema, Lookback);
This is because you specified the type (ROC) before the variable. When you do this, C# creates a local copy of that variable that's available in the Initialize method only. When the Execute gets called, the roc_aema that is declared in your private section still isn't created, so you get the error.
Instead, you should leave off the type specifier so C# will use the roc_aema that you declared in the private section instead.
roc_aema = ROC.Series(aema, Lookback);
Thanks Glitch! I am having a difficult time understanding what I am doing is sometimes local and sometimes global. But progress is being made, even if it is slow! ;)
Your Response
Post
Edit Post
Login is required