- ago
Equation is not able to process by the compiler. How do you resolve this equation ?

CODE:
//   FullStochastic = FullStochK-FullStochD indicator5 =    ((EMA.Series(_StochK, 3)) - (EMA.Series(_smoothedStochK, 3));       



0
410
Solved
8 Replies

Reply

Bookmark

Sort
- ago
#1
You're missing a paren on the end. But, you don't need all those parens anyhow. Just...

indicator5 = EMA.Series(_StochK, 3) - EMA.Series(_smoothedStochK, 3);
1
- ago
#2
It is not working. It is giving the same error Line: 55
It may need casting or another class
0
- ago
#3
Compiler suggests that you should use TimeSeries and not IndicatorBase:
CODE:
TimeSeries indicator5 = ((EMA.Series(_StochK, 3)) - EMA.Series(_smoothedStochK, 3));


Or specifically:
CODE:
TimeSeries indicator5; ... indicator5 = ((EMA.Series(_StochK, 3)) - EMA.Series(_smoothedStochK, 3));
0
Best Answer
Cone8
 ( 24.57% )
- ago
#4
A TimeSeries is the result of a math operation between Indicators or TimeSeries. And then when you plot it, use PlotTimeSeries or PlotTimeSeriesLine instead of PlotIndicator. You'll need to specify a pane and a label - check the QuickRef.
1
- ago
#5
The parens are still not balanced.

Also, indicator5 is of type IndicatorBase. The result of the expression is of type TimeSeries. Class IndicatorBase is a subclass of TimeSeries. Hence, while an IndicatorBase is a TimeSeries, a TimeSeries is not necessarily an IndicatorBase. You should not cast the result of the expression to be an IndicatorBase because there is no guarantee that the expression result, being actually of type TimeSeries, contains all of the members of type IndicatorBase.

One quick way to work around this, and still keep indicator5 as type IndicatorBase, and to leave your PlotIndicator call as-is...

indicator5 = SMA.Series(EMA.Series(_StochK, 3) - EMA.Series(_smoothedStochK, 3), 1);

Of course, indicator5 will be an SMA, but that is of type IndicatorBase.
1
- ago
#6
QUOTE:
A TimeSeries is the result of a math operation between Indicators or TimeSeries.

Right, so just declare it in the MyStrategy class
CODE:
TimeSeries indicator5; //to share it _across_ procedures
And then in Initialize()
CODE:
indicator5 = EMA.Series(_StochK, 3) - EMA.Series(_smoothedStochK, 3); PlotTimeSeries(indicator5, ...);
But more importantly, understand why it's done this way; otherwise, you remain lost. If this looks like black magic to you, ask more questions or review your C# book. It's not hard, buy understanding "why" is very important.

The method outlined in Reply# 5 also works, but it's slower because you have to reform the indicator, which is unnecessary since you can plot "indicator5" as a simple TimeSeries instead.
1
- ago
#7
It is not compiling due to an error. Reviewed Wiki page but was not able to progress. What should I do to resolve this error ? Any suggestions


CODE:
using WealthLab.Backtest; using System; using WealthLab.Core; using WealthLab.Indicators; using System.Collections.Generic; namespace WealthScript36 {    public class MyStrategy : UserStrategyBase    {       public MyStrategy() : base()       {       }       public override void Initialize(BarHistory bars)       {          indicator = new StochD(bars, 10, 3);          indicator.MassageColors = true;                    indicator2 = new StochK(bars, 10);          indicator2.MassageColors = true;          indicator3 = new StochK(bars, 10);          indicator3.MassageColors = true;          _StochK = StochK.Series(bars, 10);          _smoothedStochK = EMA.Series(_StochK, 3);                    indicator4 = new StochD(bars, 10, 3);          indicator4 = EMA.Series(_smoothedStochK, 3);                     TimeSeries indicator5 = new StochK(bars, 10); // indicator5.MassageColors = true;                    //*Not Working          indicator5 =    ((EMA.Series(_StochK, 3)) - (EMA.Series(_smoothedStochK, 3)));          PlotTimeSeriesOscillator(indicator5, "FSD.Histogram", indicator4.PaneTag, 40, 60, WLColor.Black, WLColor.Blue, WLColor.Red, 10);       //   PlotTimeSeries(indicator5, WLColor.FromArgb(255,0,128,0), PlotStyle.HistogramTwoColor);          StartIndex = 0;       }       public override void Execute(BarHistory bars, int idx)       {          int index = idx;          Position foundPosition0 = FindOpenPosition(0);          bool condition0;                               if (foundPosition0 == null)          {             condition0 = false; // Line 74             {                if (indicator5.TurnsUp(index))                {                      condition0 = true;                                   }             }             if (condition0)             {                _transaction = PlaceTrade(bars, TransactionType.Buy, OrderType.Market, 0, 0, "Buy At Market (1)");             }          }          else          {             condition0 = false;             {                condition0 = true;             }             if (condition0)             {                Backtester.CancelationCode = 66;                ClosePosition(foundPosition0, OrderType.Market, 0, "Sell At Market (1)");             }          }       }       public override void NewWFOInterval(BarHistory bars)       {          indicator = new StochD(bars, 10, 3);          indicator2 = new StochK(bars, 10);          indicator3 = new StochD(bars, 10, 3);          indicator4 = new StochK(bars, 10);          indicator5 = new StochK(bars, 10);       }       private IndicatorBase indicator;       private IndicatorBase indicator2;       private IndicatorBase indicator3;       private IndicatorBase indicator4;       private IndicatorBase indicator5;       private Transaction _transaction;       StochK _StochK;       EMA _smoothedStochK;    } }
0
- ago
#8
Change
CODE:
bool condition0;
to
CODE:
bool condition0 = false;

And then you "might" be able to remove line 74 altogether.

This code is totally weird. Was it created by a WL blocks-to-code conversion? I would code it to avoid all the Boolean variables like a human programmer would; otherwise, it's too confusing to follow. And it would run slightly faster too.

What's going on here? You set condition0 to "false" then "true". Why? Clean up the code.
CODE:
else { condition0 = false; { condition0 = true; }

I think if you recode it to remove all the Boolean conditions, it will work much better and everyone--including you--may be able to catch some of the errors we may be missing now because the code is too confusing for us to follow.
0

Reply

Bookmark

Sort