Stiffness Indicator Strategy


Category:
0
0

I’ve found a new strategy called the Stiffness Indicator. I’m trying to turn this into a scan but getting rejected at line7:1.Here’s  the code and you help.

input price = close;
input length = 60;
input averageLength = 100;

def avg = Average(price, averageLength) – 0.2 * StDev(price, averageLength);
plot Stiffness = Sum(price > avg, length) * averageLength / length;
}

input price = close;
input length = 60;
input averageLength = 100;
input exitLength = 84;
input entryStiffnessLevel = 90.0;
input exitStiffnessLevel = 50.0;
input marketIndex = “SPY”;

def ema = ExpAverage(close(marketIndex), averageLength);
def stiffness = Stiffness(price, averageLength);
def entryPrice = EntryPrice();
def afterEntryCount = if IsNaN(entryPrice[1]) and !IsNaN(entryPrice) then 1 else if !IsNaN(entryPrice) then afterEntryCount[1] + 1 else Double.NaN;

AddOrder(OrderType.BUY_TO_OPEN, stiffness crosses above entryStiffnessLevel and ema >= ema[2], tickcolor = GetColor(6), arrowcolor = GetColor(6), name = “StiffnessLE”);
AddOrder(OrderType.SELL_TO_CLOSE, stiffness crosses below exitStiffnessLevel, tickcolor = GetColor(5), arrowcolor = GetColor(5), name = “StiffnessLX”);
AddOrder(OrderType.SELL_TO_CLOSE, afterEntryCount > exitLength, tickcolor = GetColor(4), arrowcolor = GetColor(4), name = “StiffnessTimeLX”);

Marked as spam
Posted by (Questions: 6, Answers: 3)
Asked on January 23, 2019 3:38 pm
228 views
0
Private answer

Holy cow this code is a disaster. It seems as though this code was an attempt to combine two separate studies. I doubt that after these changes you will end up with the intended result. There is no way this code can work as a strategy. The same errors preventing it working as a scan will also prevent it working anywhere else on the platform.

Line 7 contains a “}”. This is invalid in the given context. Remove this symbol from the code.

You also have three input statements which are duplicated. Remove the second set of inputs named: price, length and averageLength.

The variable named “Stiffness” is declared twice. Once as a plot and once as a def. Remove the one declared as a plot statement because scans can only contain one plot.

AddOrder statements are not permitted in a scan. Remove those AddOrder statements from the bottom of the code.

Lastly, your code is lacking a true/false plot statement which determines the exact conditions you want the scan to find.

 

Marked as spam
Posted by (Questions: 37, Answers: 4118)
Answered on January 23, 2019 5:18 pm
0

Thanks for the advice will try to see if I can work it. The Strategy does work in TOS

( at January 24, 2019 7:53 am)
0

No, the code does not work in a strategy at all. I just copy/pasted the code you provided into a new custom strategy and all the same errors are present just like I explained.

( at January 24, 2019 8:32 am)