PlusEVTrades
New member
I have a strategy script I'm writing and the code periodically thinks the price is $1. It uses two criteria to place a buy order. I've tested a script before that uses two criteria so I don't think that is causing the problem. However, I'm new to this so forgive me it probably has lots of mistakes. The variables seem to be affecting what TOS thinks the price is.
Here is the code, it includes williams alligator and MACD. The buy order should execute an open when price close is above teeth and macd diff is greater than 0. Close is simply when macd diff is below 0. Code works fine if I remove one of the two conditions, so for some reason together they aren't working. Any help appreciated!
In the chart I scaled SPY to show how it's marking a buy order at $1, and also not sure if relevant but it seems to have all the variables showing there including both average types for the different studies together.
Here is the code, it includes williams alligator and MACD. The buy order should execute an open when price close is above teeth and macd diff is greater than 0. Close is simply when macd diff is below 0. Code works fine if I remove one of the two conditions, so for some reason together they aren't working. Any help appreciated!
Code:
input length = 14;
input pricealli = hl2;
input jawLength = 13;
input teethLength = 8;
input lipsLength = 5;
input jawDisplace = -8;
input teethDisplace = -5;
input lipsDisplace = -3;
input averageType = AverageType.WILDERS;
input fastLength = 12;
input slowLength = 26;
input macdLength = 9;
input averageTypemac = AverageType.EXPONENTIAL;
input price = close;
def diff = reference MACD(fastLength, slowLength, macdLength, averageTypemac).Diff;
def Jaw = MovingAverage(averageType, pricealli[-jawDisplace], jawLength);
def Teeth = MovingAverage(averageType, pricealli[-teethDisplace], teethLength);
def Lips = MovingAverage(averageType, pricealli[-lipsDisplace], lipsLength);
AddOrder(OrderType.BUY_TO_OPEN, diff crosses above 0, price is greater than teeth, tickcolor = GetColor(0), arrowcolor = GetColor(0), name = "BUYalli");
AddOrder(OrderType.SELL_TO_CLOSE, diff crosses below 0, tickcolor = GetColor(1), arrowcolor = GetColor(1), name = "Sellalli");
In the chart I scaled SPY to show how it's marking a buy order at $1, and also not sure if relevant but it seems to have all the variables showing there including both average types for the different studies together.

