#### danwilks12

##### New member
Basically title. Both codes are the same except for the appropriate variables changed (I think) to make the 2nd code a short trade. Is there any glaringly obvious problem here? 1st code is the working long trade and second is the not working short trade. Pic is the long trade being opened and closed properly (opened on -2 deviations and closed on the middleline) and then when the condition to open the short trade is hit (price is >= +1 deviation), nothing happens. I'm also running this on the SPY which should be shortable? Any help is greatly appreciated, thanks.

LONG CODE:

#Inputs

input price = close;
input deviations = 2.0;
input fullRange = Yes;
input length = 21;

#Define

def regression;
def stdDeviation;
if (fullRange) {
regression = InertiaAll(price);
stdDeviation = StDevAll(price);
} else {
regression = InertiaAll(price, length);
stdDeviation = StDevAll(price, length);
}

def UpperLine = regression + deviations * stdDeviation;
def MiddleLine = regression;
def LowerLine = regression - deviations * stdDeviation;

#Signal

def Condition1 = if
price <= LowerLine
then 1 else Double.NaN;

#Orders

SHORT CODE:

#Inputs

input price = close;
input deviations = 1.0;
input fullRange = Yes;
input length = 21;

#Define

def regression;
def stdDeviation;
if (fullRange) {
regression = InertiaAll(price);
stdDeviation = StDevAll(price);
} else {
regression = InertiaAll(price, length);
stdDeviation = StDevAll(price, length);
}

def UpperLine = regression + deviations * stdDeviation;
def MiddleLine = regression;
def LowerLine = regression - deviations * stdDeviation;

#Signal

def Condition1 = if
price >= Upperline
then 1 else Double.NaN;

#Orders 