Search code examples
tradestation

Error 1; Description: Numerical expression expected here; EasyLanguage


I am new to EasyLanguage and still trying to learn. I have a momentum indicator code that calculates the oscillator values using the True Momentum Oscillator formula and moving averages. Not sure why I am getting this error:Error 1; Description: Numerical expression expected here; Location: #reply_func; Line: 7

I am assuming it has to do with defining "length" input but I got stuck and not sure how to solve it.

Here is the full code:

inputs: length(14), calcLength(5), smoothLength(3);

vars: s(0), MA(0), Main(0), Signal(0), ss(0);

s = 0; 
for ss = 0 to (length - 1) begin
    s = s + (close > open[ss]) - (close < open[ss]);
end

MA = XAverage(s, calcLength);
Main = XAverage(MA, smoothLength);
Signal = XAverage(Main, smoothLength);

plot1(Main, "Main", iff(Main > Signal, green, red));
plot2(Signal, "Signal", iff(Main > Signal, green, red));
plot3(0, "ZeroLine", gray);

plot4(length, "UpperLine", red);
plot5(-length, "LowerLine", green);

plot6(length * 0.7, "Overbought", gray);
plot7(-length * 0.7, "Oversold", gray);

fillPlot(plot4, plot5, "Range", iff(Main > Signal, green, red), 90);
fillPlot(plot6, plot4, "Overbought", red, 90);
fillPlot(plot7, plot5, "Oversold", green, 90);

Solution

  • The iff statement only likes to return numbers. You could always put the conditional outside the fillplot statement.

    mycolor = red;
    if Main > Signal then mycolor = green;
    fillPlot(plot4, plot5, "Range", mycolor, 90);