InfamousCookie
New member
While doing some testing with live trading, I was having an issue with conditional sell orders not triggering. I'm using Accumulation Swing Index as my sell study. The code is posted below. I have it set up to sell the stock when asiplot is below smaplot but doesn't seem to always trigger. Seems like the trigger rate is about 30% or so. I'm currently looking at a stock that should have sold mid day yesterday using this conditional selling code but it's still sitting there despite the chart clearly showing that the asiplot is below the smaplot. I have checked to make sure the times on the chart and condition are the same as well as the input parameters are the same. Any idea what I'm missing? Thanks for the help.
Code:
#TOS Accumulation_Swing_Index
declare lower;
input smaLength = 10;
input averageType = AverageType.WILDERS;
def limit = 30;
def AbsHighClose = AbsValue(high - close[1]);
def AbsLowClose = AbsValue(low - close[1]);
def AbsCloseOpen = AbsValue(close[1] - open[1]);
def K = If(AbsHighClose >= AbsLowClose, AbsHighClose, AbsLowClose);
def R = If(AbsHighClose >= AbsLowClose,
If(AbsHighClose >= (high - low), AbsHighClose - 0.5 * AbsLowClose + 0.25 * AbsCloseOpen, (high - low) + 0.25 * AbsCloseOpen),
If(AbsLowClose >= (high - low), AbsLowClose - 0.5 * AbsHighClose + 0.25 * AbsCloseOpen, (high - low) + 0.25 * AbsCloseOpen));
def nRes = If(R != 0,
(50 * (((close - close[1]) + 0.50 * (close - open) + 0.25 * (close[1] - open[1])) / R ) * K / limit) + if !IsNaN(nRes[1]) then nRes[1] else 0,
0 + if !IsNaN(nRes[1]) then nRes[1] else 0);
def asi = nRes;
def sma = Movingaverage(averagetype, asi, smaLength);
def ASI_crossesbelow = asi crosses below sma ;
plot asiplot = asi;
plot smaplot = sma;