I'm trying to create a scan for the following script:
#User inputs:
input length = 3;
input trendabove = 25;
input trendbelow = -25;
#Aggregate data for a linear regression over the length above
rec Regression = Inertia(close, length);
#Determine the angle of the lower end of the line and plot it in an oscillator
plot Data = ATan((Regression - Regression[(length - 1)]) / (length - 1)) * 180 / Double.Pi;
#Plot your indicator lines
plot above = trendabove;
plot below = trendbelow;
input cutoffLength = 20;
input mode = {"Trend Following", default "Reversal"};
def crossAbove = Data > Data[1];
def crossBelow = Data < Data[1];
def buy;
def sell;
switch (mode) {
case "Trend Following":
buy = crossAbove;
sell = crossBelow;
case "Reversal":
buy = crossBelow;
sell = crossAbove;
}
AddOrder(OrderType.BUY_AUTO, buy, tickcolor = GetColor(2), arrowcolor = GetColor(2), name = "UniversalOscillatorStratLE");
AddOrder(OrderType.SELL_AUTO, sell, tickcolor = GetColor(1), arrowcolor = GetColor(1), name = "UniversalOscillatorStratSE");
def BuyAlert = buy == 1;
rec count = if BuyAlert == 1 and count[1] == 0 then 1 else 0;
rec count1 = if BuyAlert == 0 and count1[1] >= 1 then count1[1] + 1 else 0;
def PrimaryBuyAlert = BuyAlert == 1 and count == 1;
#---Alerts
Alert( BuyAlert, "PrimaryBuyAlert", Alert.BAR, Sound.Ring);
#EndofCode
I'm wanting to scan for when there's a buy signal using the "Reversal" mode. Any suggestions?
#User inputs:
input length = 3;
input trendabove = 25;
input trendbelow = -25;
#Aggregate data for a linear regression over the length above
rec Regression = Inertia(close, length);
#Determine the angle of the lower end of the line and plot it in an oscillator
plot Data = ATan((Regression - Regression[(length - 1)]) / (length - 1)) * 180 / Double.Pi;
#Plot your indicator lines
plot above = trendabove;
plot below = trendbelow;
input cutoffLength = 20;
input mode = {"Trend Following", default "Reversal"};
def crossAbove = Data > Data[1];
def crossBelow = Data < Data[1];
def buy;
def sell;
switch (mode) {
case "Trend Following":
buy = crossAbove;
sell = crossBelow;
case "Reversal":
buy = crossBelow;
sell = crossAbove;
}
AddOrder(OrderType.BUY_AUTO, buy, tickcolor = GetColor(2), arrowcolor = GetColor(2), name = "UniversalOscillatorStratLE");
AddOrder(OrderType.SELL_AUTO, sell, tickcolor = GetColor(1), arrowcolor = GetColor(1), name = "UniversalOscillatorStratSE");
def BuyAlert = buy == 1;
rec count = if BuyAlert == 1 and count[1] == 0 then 1 else 0;
rec count1 = if BuyAlert == 0 and count1[1] >= 1 then count1[1] + 1 else 0;
def PrimaryBuyAlert = BuyAlert == 1 and count == 1;
#---Alerts
Alert( BuyAlert, "PrimaryBuyAlert", Alert.BAR, Sound.Ring);
#EndofCode
I'm wanting to scan for when there's a buy signal using the "Reversal" mode. Any suggestions?