William's alligator crossover with ADX threshold

kjagadevan

New member
I am getting the following errors on the code below. Any help to fix it will be really appreciated. This is the logic.

On a 5- min candles, For AMZN, SPX and TSLA, BUY a Call at the next resistance when ADX indicator crosses above 25, Stock Price is above the three lines of William's Alligator Indicator, Three lines 5 SMA, 8 SMA and 13 SMA in Willliam's Alligator indicator not touching each other, Enter the position when the candle is closing which is ADX crossover, Calculate the stop loss to be below the Blue line and exit when it it is breached. Close the Position when profit is 50% or trails to 20%. On a 5- min candles, For AMZN, SPX and TSLA, BUY a PUT at the next Support, when ADX indicator crosses above 25, Stock Price is below the three lines of William's Alligator Indicator, Three lines 5 SMA, 8 SMA and 13 SMA in Willliam's Alligator indicator not touching each other, Enter the position when the candle is closing which is ADX crossover, Calculate the stop loss to be above the Blue line and exit when it it is breached. Close the Position when profit is 50% or trails to 20%. We should see Buy and sell arrows when these conditions meet.

Syntax error: An 'else' block expected at 23:1
Syntax error: Semicolon expected at 23:1
Invalid statement: } at 36:1
Syntax error: An 'else' block expected at 42:1
Syntax error: Semicolon expected at 42:1
Syntax error: Semicolon expected at 42:1
Invalid statement: alligatorTeethLine at 66:1



# Set the parameters for the strategy
input ADX_threshold = 25;
input profit_target_percentage = 50;
input stop_loss_percentage = 20;

# Declare the Alligator indicator variables
def alligatorJaw = sma(5);
def alligatorTeeth = sma(8);
def alligatorLips = sma(13);

# Check if the stock price is above the Alligator lines
def priceAboveAlligator = close > alligatorJaw and close > alligatorTeeth and close > alligatorLips;
def priceBelowAlligator = close < alligatorJaw and close < alligatorTeeth and close < alligatorLips;

# Check if the Alligator lines are touching each other
def alligatorLinesTouching = alligatorJaw == alligatorTeeth or alligatorTeeth == alligatorLips or alligatorJaw == alligatorLips;

# Set the position variables to 0
def longPosition = 0;
def shortPosition = 0;

# Check if the ADX is above the threshold and the stock price is above the Alligator lines
if (adx() > ADX_threshold and !priceBelowAlligator and !alligatorLinesTouching) {
# Calculate the stop loss price
def stopLossPrice = close * (1 - stop_loss_percentage/100);
# Set the long position to 1
longPosition = 1;
}

# Check if the ADX is above the threshold and the stock price is below the Alligator lines
if (adx() > ADX_threshold and !priceAboveAlligator and !alligatorLinesTouching) {
# Calculate the stop loss price
def stopLossPrice = close * (1 + stop_loss_percentage/100);
# Set the short position to 1
shortPosition = 1;
}

# Calculate the profit target price
def profitTargetPrice = close * (1 + profit_target_percentage/100);

# Check if the long position should be closed
if (longPosition == 1 and (close < stopLossPrice or close > profitTargetPrice)) {
# Set the long position to 0
longPosition = 0;
}

# Check if the short position should be closed
if (shortPosition == 1 and (close > stopLossPrice or close < profitTargetPrice)) {
# Set the short position to 0
shortPosition = 0;
}

# Plot the long and short positions on the chart
plot longArrow = if longPosition == 1 then high else double.nan;
plot shortArrow = if shortPosition == 1 then low else double.nan;
longArrow.SetDefaultColor(color.green);
shortArrow.SetDefaultColor(color.red);
longArrow.SetPaintingStrategy(PaintingStrategy.ARROW_UP);
shortArrow.SetPaintingStrategy(PaintingStrategy.ARROW_DOWN);

# Add the Alligator lines to the chart
plot alligatorJawLine = alligatorJaw;
plot alligatorTeethLine = alligatorTeeth;
plot alligatorLipsLine = alligatorLips;
alligatorJawLine.SetDefaultColor(color.red);
alligatorTeethLine.SetDefault
 
Solution
I am getting the following errors on the code below. Any help to fix it will be really appreciated. This is the logic.

On a 5- min candles, For AMZN, SPX and TSLA, BUY a Call at the next resistance when ADX indicator crosses above 25, Stock Price is above the three lines of William's Alligator Indicator, Three lines 5 SMA, 8 SMA and 13 SMA in Willliam's Alligator indicator not touching each other, Enter the position when the candle is closing which is ADX crossover, Calculate the stop loss to be below the Blue line and exit when it it is breached. Close the Position when profit is 50% or trails to 20%. On a 5- min candles, For AMZN, SPX and TSLA, BUY a PUT at the next Support, when ADX indicator crosses above 25, Stock Price is...
I am getting the following errors on the code below. Any help to fix it will be really appreciated. This is the logic.

On a 5- min candles, For AMZN, SPX and TSLA, BUY a Call at the next resistance when ADX indicator crosses above 25, Stock Price is above the three lines of William's Alligator Indicator, Three lines 5 SMA, 8 SMA and 13 SMA in Willliam's Alligator indicator not touching each other, Enter the position when the candle is closing which is ADX crossover, Calculate the stop loss to be below the Blue line and exit when it it is breached. Close the Position when profit is 50% or trails to 20%. On a 5- min candles, For AMZN, SPX and TSLA, BUY a PUT at the next Support, when ADX indicator crosses above 25, Stock Price is below the three lines of William's Alligator Indicator, Three lines 5 SMA, 8 SMA and 13 SMA in Willliam's Alligator indicator not touching each other, Enter the position when the candle is closing which is ADX crossover, Calculate the stop loss to be above the Blue line and exit when it it is breached. Close the Position when profit is 50% or trails to 20%. We should see Buy and sell arrows when these conditions meet.

Syntax error: An 'else' block expected at 23:1
Syntax error: Semicolon expected at 23:1
Invalid statement: } at 36:1
Syntax error: An 'else' block expected at 42:1
Syntax error: Semicolon expected at 42:1
Syntax error: Semicolon expected at 42:1
Invalid statement: alligatorTeethLine at 66:1



# Set the parameters for the strategy
input ADX_threshold = 25;
input profit_target_percentage = 50;
input stop_loss_percentage = 20;

# Declare the Alligator indicator variables
def alligatorJaw = sma(5);
def alligatorTeeth = sma(8);
def alligatorLips = sma(13);

# Check if the stock price is above the Alligator lines
def priceAboveAlligator = close > alligatorJaw and close > alligatorTeeth and close > alligatorLips;
def priceBelowAlligator = close < alligatorJaw and close < alligatorTeeth and close < alligatorLips;

# Check if the Alligator lines are touching each other
def alligatorLinesTouching = alligatorJaw == alligatorTeeth or alligatorTeeth == alligatorLips or alligatorJaw == alligatorLips;

# Set the position variables to 0
def longPosition = 0;
def shortPosition = 0;

# Check if the ADX is above the threshold and the stock price is above the Alligator lines
if (adx() > ADX_threshold and !priceBelowAlligator and !alligatorLinesTouching) {
# Calculate the stop loss price
def stopLossPrice = close * (1 - stop_loss_percentage/100);
# Set the long position to 1
longPosition = 1;
}

# Check if the ADX is above the threshold and the stock price is below the Alligator lines
if (adx() > ADX_threshold and !priceAboveAlligator and !alligatorLinesTouching) {
# Calculate the stop loss price
def stopLossPrice = close * (1 + stop_loss_percentage/100);
# Set the short position to 1
shortPosition = 1;
}

# Calculate the profit target price
def profitTargetPrice = close * (1 + profit_target_percentage/100);

# Check if the long position should be closed
if (longPosition == 1 and (close < stopLossPrice or close > profitTargetPrice)) {
# Set the long position to 0
longPosition = 0;
}

# Check if the short position should be closed
if (shortPosition == 1 and (close > stopLossPrice or close < profitTargetPrice)) {
# Set the short position to 0
shortPosition = 0;
}

# Plot the long and short positions on the chart
plot longArrow = if longPosition == 1 then high else double.nan;
plot shortArrow = if shortPosition == 1 then low else double.nan;
longArrow.SetDefaultColor(color.green);
shortArrow.SetDefaultColor(color.red);
longArrow.SetPaintingStrategy(PaintingStrategy.ARROW_UP);
shortArrow.SetPaintingStrategy(PaintingStrategy.ARROW_DOWN);

# Add the Alligator lines to the chart
plot alligatorJawLine = alligatorJaw;
plot alligatorTeethLine = alligatorTeeth;
plot alligatorLipsLine = alligatorLips;
alligatorJawLine.SetDefaultColor(color.red);
alligatorTeethLine.SetDefault


it helps others to know what code you started with.
what are the links to the original codes that you started with.

this code is a mess. it would take awhile to sort out all the rules and fix the code. here is something to get you started.

let's take a look at the errors and try to figure them out.
most of the time they tell you what is wrong, just have to look at it...


errors

#Syntax error: An 'else' block expected at 23:1
#Syntax error: Semicolon expected at 23:1
#Invalid statement: } at 36:1
#Syntax error: An 'else' block expected at 42:1
#Syntax error: Semicolon expected at 42:1
#Syntax error: Semicolon expected at 42:1
#Invalid statement: alligatorTeethLine at 66:1


23, 36
if then brackets ,

# Check if the ADX is above the threshold and the stock price is above the Alligator lines
def longPosition = 0;
def shortPosition = 0;
if (ADX() > ADX_threshold and !priceBelowAlligator and !alligatorLinesTouching) {
# Calculate the stop loss price
def stopLossPrice = close * (1 - stop_loss_percentage / 100);
# Set the long position to 1
longPosition = 1;
}


when using 'if then' brackets,
1.. don't set a variable to a value before the first if
. def longPosition = 0;
. put a ; after the variable
. def longPosition;
. add an if line to set initial values


2..missing an } else {
longPosition = 0;
}



42
if (longPosition == 1 and (close < stopLossPrice or close > profitTargetPrice)) {
# Set the long position to 0
longPosition = 0;
}

1. missing
. } else {
. before longPosition = 0;



66
alligatorTeethLine.SetDefault
incomplete code line , not sure what it should be?


--------------------

unlisted errors
after you fix the other errors, these will show up red, as an error.

7,8,9
def alligatorJaw = sma(5);
def alligatorTeeth = sma(8);
def alligatorLips = sma(13);

sma() letters are light gray. there is no function sma().
need to look up and use a valid average function
https://tlc.thinkorswim.com/center/reference/thinkScript/Functions/Tech-Analysis/MovingAverage
 
Solution

Join useThinkScript to post your question to a community of 21,000+ developers and traders.

I am getting the following errors on the code below. Any help to fix it will be really appreciated. This is the logic.

On a 5- min candles, For AMZN, SPX and TSLA, BUY a Call at the next resistance when ADX indicator crosses above 25, Stock Price is above the three lines of William's Alligator Indicator, Three lines 5 SMA, 8 SMA and 13 SMA in Willliam's Alligator indicator not touching each other, Enter the position when the candle is closing which is ADX crossover, Calculate the stop loss to be below the Blue line and exit when it it is breached. Close the Position when profit is 50% or trails to 20%. On a 5- min candles, For AMZN, SPX and TSLA, BUY a PUT at the next Support, when ADX indicator crosses above 25, Stock Price is below the three lines of William's Alligator Indicator, Three lines 5 SMA, 8 SMA and 13 SMA in Willliam's Alligator indicator not touching each other, Enter the position when the candle is closing which is ADX crossover, Calculate the stop loss to be above the Blue line and exit when it it is breached. Close the Position when profit is 50% or trails to 20%. We should see Buy and sell arrows when these conditions meet.

Syntax error: An 'else' block expected at 23:1
Syntax error: Semicolon expected at 23:1
Invalid statement: } at 36:1
Syntax error: An 'else' block expected at 42:1
Syntax error: Semicolon expected at 42:1
Syntax error: Semicolon expected at 42:1
Invalid statement: alligatorTeethLine at 66:1



# Set the parameters for the strategy
input ADX_threshold = 25;
input profit_target_percentage = 50;
input stop_loss_percentage = 20;

# Declare the Alligator indicator variables
def alligatorJaw = sma(5);
def alligatorTeeth = sma(8);
def alligatorLips = sma(13);

# Check if the stock price is above the Alligator lines
def priceAboveAlligator = close > alligatorJaw and close > alligatorTeeth and close > alligatorLips;
def priceBelowAlligator = close < alligatorJaw and close < alligatorTeeth and close < alligatorLips;

# Check if the Alligator lines are touching each other
def alligatorLinesTouching = alligatorJaw == alligatorTeeth or alligatorTeeth == alligatorLips or alligatorJaw == alligatorLips;

# Set the position variables to 0
def longPosition = 0;
def shortPosition = 0;

# Check if the ADX is above the threshold and the stock price is above the Alligator lines
if (adx() > ADX_threshold and !priceBelowAlligator and !alligatorLinesTouching) {
# Calculate the stop loss price
def stopLossPrice = close * (1 - stop_loss_percentage/100);
# Set the long position to 1
longPosition = 1;
}

# Check if the ADX is above the threshold and the stock price is below the Alligator lines
if (adx() > ADX_threshold and !priceAboveAlligator and !alligatorLinesTouching) {
# Calculate the stop loss price
def stopLossPrice = close * (1 + stop_loss_percentage/100);
# Set the short position to 1
shortPosition = 1;
}

# Calculate the profit target price
def profitTargetPrice = close * (1 + profit_target_percentage/100);

# Check if the long position should be closed
if (longPosition == 1 and (close < stopLossPrice or close > profitTargetPrice)) {
# Set the long position to 0
longPosition = 0;
}

# Check if the short position should be closed
if (shortPosition == 1 and (close > stopLossPrice or close < profitTargetPrice)) {
# Set the short position to 0
shortPosition = 0;
}

# Plot the long and short positions on the chart
plot longArrow = if longPosition == 1 then high else double.nan;
plot shortArrow = if shortPosition == 1 then low else double.nan;
longArrow.SetDefaultColor(color.green);
shortArrow.SetDefaultColor(color.red);
longArrow.SetPaintingStrategy(PaintingStrategy.ARROW_UP);
shortArrow.SetPaintingStrategy(PaintingStrategy.ARROW_DOWN);

# Add the Alligator lines to the chart
plot alligatorJawLine = alligatorJaw;
plot alligatorTeethLine = alligatorTeeth;
plot alligatorLipsLine = alligatorLips;
alligatorJawLine.SetDefaultColor(color.red);
alligatorTeethLine.SetDefault

i removed the errors, but i didn't check the logic.
i made some guesses, set some variables to 0, so still needs some fixing.


Code:
# alligator_thing_00

#https://usethinkscript.com/threads/williams-alligator-crossover-with-adx-threshold.13772/
#William's alligator crossover with ADX threshold


# Set the parameters for the strategy
input ADX_threshold = 25;
input profit_target_percentage = 50;
input stop_loss_percentage = 20;

# Declare the Alligator indicator variables
#def alligatorJaw = sma(5);
#def alligatorTeeth = sma(8);
#def alligatorLips = sma(13);

def price = close;
input ma1_len = 5;
input ma1_type =  AverageType.simple;
def alligatorJaw  = MovingAverage(ma1_type, price, ma1_len);

input ma2_len = 8;
input ma2_type =  AverageType.simple;
def alligatorTeeth = MovingAverage(ma2_type, price, ma2_len);

input ma3_len = 13;
input ma3_type =  AverageType.simple;
def alligatorLips = MovingAverage(ma3_type, price, ma3_len);




# Check if the stock price is above the Alligator lines
def priceAboveAlligator = close > alligatorJaw and close > alligatorTeeth and close > alligatorLips;
def priceBelowAlligator = close < alligatorJaw and close < alligatorTeeth and close < alligatorLips;

# Check if the Alligator lines are touching each other
def alligatorLinesTouching = alligatorJaw == alligatorTeeth or alligatorTeeth == alligatorLips or alligatorJaw == alligatorLips;

# Set the position variables to 0
def longPosition;
def shortPosition;

# Check if the ADX is above the threshold and the stock price is above the Alligator lines
if (ADX() > ADX_threshold and !priceBelowAlligator and !alligatorLinesTouching) {
# Calculate the stop loss price
#  def stopLossPrice = close * (1 - stop_loss_percentage / 100);
# Set the long position to 1
    longPosition = 1;
} else {
# ?? verify this
 longPosition = 0;
}


# Check if the ADX is above the threshold and the stock price is below the Alligator lines
if (adx() > ADX_threshold and !priceAboveAlligator and !alligatorLinesTouching) {
# Calculate the stop loss price
#def stopLossPrice = close * (1 + stop_loss_percentage/100);
# Set the short position to 1
    shortPosition = 1;
} else {
# ?? verify this
 shortPosition = 0;
}


def stopLossPrice;
if (ADX() > ADX_threshold and !priceBelowAlligator and !alligatorLinesTouching) {
 stopLossPrice = close * (1 - stop_loss_percentage / 100);
} else {
 stopLossPrice = close * (1 + stop_loss_percentage/100);
}



# Calculate the profit target price
def profitTargetPrice = close * (1 + profit_target_percentage/100);



# Check if the long position should be closed
def long1;
    if (longPosition[1] == 1 and (close < stopLossPrice or close > profitTargetPrice)) {
# Set the long position to 0
      #  longPosition = 0;
   long1 = 0;
    } else { 
long1 = 0;
}



# Check if the short position should be closed
def short1;
if (shortPosition == 1 and (close > stopLossPrice or close < profitTargetPrice)) {
# Set the short position to 0
 #shortPosition = 0;
 short1 = 0;
} else {
 short1 = 0;
    }




# Plot the long and short positions on the chart
plot longArrow = if longPosition == 1 then high else double.nan;
        plot shortArrow = if shortPosition == 1 then low else Double.NaN;
        longArrow.SetDefaultColor(Color.GREEN);
        shortArrow.SetDefaultColor(Color.RED);
        longArrow.SetPaintingStrategy(PaintingStrategy.ARROW_UP);
        shortArrow.SetPaintingStrategy(PaintingStrategy.ARROW_DOWN);

# Add the Alligator lines to the chart
        plot alligatorJawLine = alligatorJaw;
        plot alligatorTeethLine = alligatorTeeth;
        plot alligatorLipsLine = alligatorLips;
        alligatorJawLine.SetDefaultColor(Color.RED);
 #       alligatorTeethLine.SetDefault

#
 
Thank you for the awesome reply to help with fixing the code. I understand the complications in the above code. I kind of took a step back to simplify to see the alerts for just two of the indicators instead of complicating. The code below shows alerts correctly for Bearish trend but not showing most of the alerts for Bullish trend. Where I noted 1, 2 and 3, I was expecting an arrow but didn't see one. Unable to identify why.

Logic for the code below is very simple.

Generates a buy alert on the chart for William's alligator indicator when a candle closes above 8-sma line and then 8-sma line crosses the next candle above the midline of the candle in 3 minutes candle, the price is above 20-sma on 5 & 10 min candles and sell alert on the chart for William's alligator indicator when a candle closes below 8-sma line and then 8-sma line crosses the next candle below the midline of the candle, the price is below 20-sma on 5 & 10 min candles.


Code:
# Define the moving averages for the Williams Alligator indicator
def median = (highest(high, 13) + lowest(low, 13)) / 2;
def alligatorJaw = median;
def alligatorTeeth = (highest(high, 8) + lowest(low, 8)) / 2;
def alligatorLips = (highest(high, 5) + lowest(low, 5)) / 2;

# Define the 8-period simple moving average (SMA)
def sma8 = average(close, 8);

# Define the 20-period SMA
def sma20 = average(close, 20);

# Plot the Williams Alligator indicator
plot AlligatorJawPlot = alligatorJaw;
plot AlligatorTeethPlot = alligatorTeeth;
plot AlligatorLipsPlot = alligatorLips;
AlligatorJawPlot.SetStyle(Curve.SHORT_DASH);
AlligatorTeethPlot.SetStyle(Curve.MEDIUM_DASH);
AlligatorLipsPlot.SetStyle(Curve.LONG_DASH);

# Define the 5-minute and 10-minute charts
def minute5 = if barNumber() < 2 then barNumber() + 1 else if (getTime() - getTime()[1]) > 3*60 then 1 else barNumber()[1] + 1;
def minute10 = if barNumber() < 5 then barNumber() + 1 else if (getTime() - getTime()[1]) > 6*60 then 1 else barNumber()[1] + 1;

# Define the buy and sell alerts
def buyAlert3 = if (getValue(close, 0) > getValue(sma8, 0)) and (getValue(sma8, 0) > getValue(sma8, 1)) and (getValue(sma8, 0) > getValue(sma8, 2)) and (getValue(sma8, 0) crosses above getValue(sma8, 1)) and (getValue(close, minute5) > getValue(sma20, minute5)) and (getValue(close, minute10) > getValue(sma20, minute10)) then 1 else 0;
def sellAlert3 = if (getValue(close, 0) < getValue(sma8, 0)) and (getValue(sma8, 0) < getValue(sma8, 1)) and (getValue(sma8, 0) < getValue(sma8, 2)) and (getValue(sma8, 0) crosses below getValue(sma8, 1)) and (getValue(close, minute5) < getValue(sma20, minute5)) and (getValue(close, minute10) < getValue(sma20, minute10)) then 1 else 0;


# Plot the alerts on the chart
plot Buy = buyAlert3;
plot Sell = sellAlert3;
Buy.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_UP);
Sell.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_DOWN);
 
Thank you for the awesome reply to help with fixing the code. I understand the complications in the above code. I kind of took a step back to simplify to see the alerts for just two of the indicators instead of complicating. The code below shows alerts correctly for Bearish trend but not showing most of the alerts for Bullish trend. Where I noted 1, 2 and 3, I was expecting an arrow but didn't see one. Unable to identify why.

Logic for the code below is very simple.

Generates a buy alert on the chart for William's alligator indicator when a candle closes above 8-sma line and then 8-sma line crosses the next candle above the midline of the candle in 3 minutes candle, the price is above 20-sma on 5 & 10 min candles and sell alert on the chart for William's alligator indicator when a candle closes below 8-sma line and then 8-sma line crosses the next candle below the midline of the candle, the price is below 20-sma on 5 & 10 min candles.

Code:
# Define the moving averages for the Williams Alligator indicator
def median = (highest(high, 13) + lowest(low, 13)) / 2;
def alligatorJaw = median;
def alligatorTeeth = (highest(high, 8) + lowest(low, 8)) / 2;
def alligatorLips = (highest(high, 5) + lowest(low, 5)) / 2;

# Define the 8-period simple moving average (SMA)
def sma8 = average(close, 8);

# Define the 20-period SMA
def sma20 = average(close, 20);

# Plot the Williams Alligator indicator
plot AlligatorJawPlot = alligatorJaw;
plot AlligatorTeethPlot = alligatorTeeth;
plot AlligatorLipsPlot = alligatorLips;
AlligatorJawPlot.SetStyle(Curve.SHORT_DASH);
AlligatorTeethPlot.SetStyle(Curve.MEDIUM_DASH);
AlligatorLipsPlot.SetStyle(Curve.LONG_DASH);

# Define the 5-minute and 10-minute charts
def minute5 = if barNumber() < 2 then barNumber() + 1 else if (getTime() - getTime()[1]) > 3*60 then 1 else barNumber()[1] + 1;
def minute10 = if barNumber() < 5 then barNumber() + 1 else if (getTime() - getTime()[1]) > 6*60 then 1 else barNumber()[1] + 1;

# Define the buy and sell alerts
def buyAlert3 = if (getValue(close, 0) > getValue(sma8, 0)) and (getValue(sma8, 0) > getValue(sma8, 1)) and (getValue(sma8, 0) > getValue(sma8, 2)) and (getValue(sma8, 0) crosses above getValue(sma8, 1)) and (getValue(close, minute5) > getValue(sma20, minute5)) and (getValue(close, minute10) > getValue(sma20, minute10)) then 1 else 0;
def sellAlert3 = if (getValue(close, 0) < getValue(sma8, 0)) and (getValue(sma8, 0) < getValue(sma8, 1)) and (getValue(sma8, 0) < getValue(sma8, 2)) and (getValue(sma8, 0) crosses below getValue(sma8, 1)) and (getValue(close, minute5) < getValue(sma20, minute5)) and (getValue(close, minute10) < getValue(sma20, minute10)) then 1 else 0;


# Plot the alerts on the chart
plot Buy = buyAlert3;
plot Sell = sellAlert3;
Buy.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_UP);
Sell.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_DOWN);


here is some commentary of post4
this isn't a fix. there are too many questions to be be answered.
the primary task would be to review and accurately list the conditions.


this isn't meant to be criticism, just an observation after reading many posts,
your post4 is a another example of someone not understanding the word 'simple'...


when listing out your conditions, list them as short statements , like this. not as a very long , never ending sentence.
your words list out 4 rules/conditions,

buy alert
1. candle closes above 8-sma line,
2. then 8-sma line crosses the next candle above the midline of the candle in 3 minutes candle,
3. the price is above 20-sma on 5 min candles
4. the price is above 20-sma on 10 min candles



and your formula has 6 conditions, and doesn't mention midline.
you aren't using 5 minute and 10 minute data, you are reading data from a bar or 2 back.
if the chart is 3 minutes, you can't read 5 or 10 minute data. the minutes have to be a factor of the chart time. you could read 6 or 9 minutes.

def buyAlert3 = if (getValue(close, 0) > getValue(sma8, 0)) and (getValue(sma8, 0) > getValue(sma8, 1)) and (getValue(sma8, 0) > getValue(sma8, 2)) and (getValue(sma8, 0) crosses above getValue(sma8, 1)) and (getValue(close, minute5) > getValue(sma20, minute5)) and (getValue(close, minute10) > getValue(sma20, minute10)) then 1 else 0;


no need to use getvalue() on most of those variables.
here it is , rewritten
Code:
def buyAlert3 =
 if (close > sma8 and
 sma8 > sma8[1] and
 sma8 > sma8[2] and
 sma8 crosses above sma8[1]) and
 (getValue(close, minute5) > getValue(sma20, minute5)) and
 (getValue(close, minute10) > getValue(sma20, minute10))
 then 1 else 0;



here is a bubble to show all the conditions
a \n code causes the following text to be on a new line
Code:
input buy_cond_bubble = no;
addchartbubble(buy_cond_bubble, low*0.997,
 (close > sma8) + "\n" +
 (sma8 > sma8[1]) + "\n" +
 (sma8 > sma8[2]) + "\n" +
 (sma8 crosses above sma8[1]) + "\n" +
 (getValue(close, minute5) > getValue(sma20, minute5)) + "\n" +
 (getValue(close, minute10) > getValue(sma20, minute10))
, ( if buyAlert3 then color.yellow else color.gray), no);

7sGeWC6.jpg




i've never used crosses above to compare the same variable.
but it seems to work?
here is a bubble to verify the values
Code:
def ma8x = (sma8 crosses above sma8[1]);
input ma_cross_bubbles = no;
addchartbubble(ma_cross_bubbles, low*0.997,
 round(sma8,2) + " ma8\n" +
 ma8x + " cross\n" +
 (sma8 > sma8[1]) + " >"
, (if ma8x then color.yellow else color.gray), no);

SDtO2qv.jpg




i'm not sure what you are trying to do with these?
during the first couple of bars they have numbers > 1. then they are = 1 to for all the other bars.
this isn't how to read data from a different time.

# Define the 5-minute and 10-minute charts
def minute5 = if barNumber() < 2 then barNumber() + 1 else if (getTime() - getTime()[1]) > 3*60 then 1 else barNumber()[1] + 1;
def minute10 = if barNumber() < 5 then barNumber() + 1 else if (getTime() - getTime()[1]) > 6*60 then 1 else barNumber()[1] + 1;


here is a test bubble to verify the values
Code:
input minute_bubbles = yes;
addchartbubble(minute_bubbles, low*0.998,
bn + "\n" +
minute5 + "\n" +
minute10
, color.yellow, no);

3UErNXh.jpg
 
Last edited:
here is some commentary of post4
this isn't a fix. there are too many questions to be be answered.
the primary task would be to review and accurately list the conditions.


this isn't meant to be criticism, just an observation after reading many posts,
your post4 is a another example of someone not understanding the word 'simple'...


when listing out your conditions, list them as short statements , like this. not as a very long , never ending sentence.
your words list out 4 rules/conditions,

buy alert
1. candle closes above 8-sma line,
2. then 8-sma line crosses the next candle above the midline of the candle in 3 minutes candle,
3. the price is above 20-sma on 5 min candles
4. the price is above 20-sma on 10 min candles



and your formula has 6 conditions, and doesn't mention midline.
you aren't using 5 minute and 10 minute data, you are reading data from a bar or 2 back.
if the chart is 3 minutes, you can't read 5 or 10 minute data. the minutes have to be a factor of the chart time. you could read 6 or 9 minutes.

def buyAlert3 = if (getValue(close, 0) > getValue(sma8, 0)) and (getValue(sma8, 0) > getValue(sma8, 1)) and (getValue(sma8, 0) > getValue(sma8, 2)) and (getValue(sma8, 0) crosses above getValue(sma8, 1)) and (getValue(close, minute5) > getValue(sma20, minute5)) and (getValue(close, minute10) > getValue(sma20, minute10)) then 1 else 0;


no need to use getvalue() on most of those variables.
here it is , rewritten
Code:
def buyAlert3 =
 if (close > sma8 and
 sma8 > sma8[1] and
 sma8 > sma8[2] and
 sma8 crosses above sma8[1]) and
 (getValue(close, minute5) > getValue(sma20, minute5)) and
 (getValue(close, minute10) > getValue(sma20, minute10))
 then 1 else 0;



here is a bubble to show all the conditions
a \n code causes the following text to be on a new line
Code:
input buy_cond_bubble = no;
addchartbubble(buy_cond_bubble, low*0.997,
 (close > sma8) + "\n" +
 (sma8 > sma8[1]) + "\n" +
 (sma8 > sma8[2]) + "\n" +
 (sma8 crosses above sma8[1]) + "\n" +
 (getValue(close, minute5) > getValue(sma20, minute5)) + "\n" +
 (getValue(close, minute10) > getValue(sma20, minute10))
, ( if buyAlert3 then color.yellow else color.gray), no);

7sGeWC6.jpg




i've never used crosses above to compare the same variable.
but it seems to work?
here is a bubble to verify the values
Code:
def ma8x = (sma8 crosses above sma8[1]);
input ma_cross_bubbles = no;
addchartbubble(ma_cross_bubbles, low*0.997,
 round(sma8,2) + " ma8\n" +
 ma8x + " cross\n" +
 (sma8 > sma8[1]) + " >"
, (if ma8x then color.yellow else color.gray), no);

SDtO2qv.jpg




i'm not sure what you are trying to do with these?
during the first couple of bars they have numbers > 1. then they are = 1 to for all the other bars.
this isn't how to read data from a different time.

# Define the 5-minute and 10-minute charts
def minute5 = if barNumber() < 2 then barNumber() + 1 else if (getTime() - getTime()[1]) > 3*60 then 1 else barNumber()[1] + 1;
def minute10 = if barNumber() < 5 then barNumber() + 1 else if (getTime() - getTime()[1]) > 6*60 then 1 else barNumber()[1] + 1;


here is a test bubble to verify the values
Code:
input minute_bubbles = yes;
addchartbubble(minute_bubbles, low*0.998,
bn + "\n" +
minute5 + "\n" +
minute10
, color.yellow, no);

3UErNXh.jpg
Thank you so much for the response. This is very helpful.
With William's SMA crossover Indicator, it is too late to enter the positions when 5-sma crosses 8 and 13. Instead using 8-sma for confirmation to enter a little early, it helps. 20-SMA on Bollinger band on 5-min and 10-min candles gives the trend while using William's Indicator on 3 min or 2 min timeframe. This helps with limiting fake alerts to enter.
 
I personally find most of the above exchange along with the associated code cognitively impenetrable. I apologize for my density. My personal limitations aside, a question from a simple man, why not just use the ADX indicator directly as an overlay on the Williams Alligator to see the rise in signifcant movement to total movement above say 25% net to allow the chartists to observe when traction and trending is taking place>? The TOS indicator allows the user to be more or less agressive by choosing a time as well as a type of moving average. Also a second option, although a bit convoluted is to utilize a separate chart and use the Perry Kaufman adaptive moving average (KAMA) designed to account for market volatility.. My personal trading philosphy is to make the charts as personally interactive as possible so that that decision maker is always the discretionary trader (not a mechanical system!)- too often I am of the opinion that pieces of reality in the form of electronic signals configured by high speed computation- while they can calculate and technically control in a laboratory environment invert the trader for whom all this is created -for profit!- becomes a means himself in the service of means. If you follow my drift, Bottom line there is no Holy Grail of Indicators and you need to trust your self the execute the trade. Best to all
 

Similar threads

Not the exact question you're looking for?

Start a new thread and receive assistance from our community.

87k+ Posts
469 Online
Create Post

Similar threads

Similar threads

The Market Trading Game Changer

Join 2,500+ subscribers inside the useThinkScript VIP Membership Club
  • Exclusive indicators
  • Proven strategies & setups
  • Private Discord community
  • ‘Buy The Dip’ signal alerts
  • Exclusive members-only content
  • Add-ons and resources
  • 1 full year of unlimited support

Frequently Asked Questions

What is useThinkScript?

useThinkScript is the #1 community of stock market investors using indicators and other tools to power their trading strategies. Traders of all skill levels use our forums to learn about scripting and indicators, help each other, and discover new ways to gain an edge in the markets.

How do I get started?

We get it. Our forum can be intimidating, if not overwhelming. With thousands of topics, tens of thousands of posts, our community has created an incredibly deep knowledge base for stock traders. No one can ever exhaust every resource provided on our site.

If you are new, or just looking for guidance, here are some helpful links to get you started.

What are the benefits of VIP Membership?
VIP members get exclusive access to these proven and tested premium indicators: Buy the Dip, Advanced Market Moves 2.0, Take Profit, and Volatility Trading Range. In addition, VIP members get access to over 50 VIP-only custom indicators, add-ons, and strategies, private VIP-only forums, private Discord channel to discuss trades and strategies in real-time, customer support, trade alerts, and much more. Learn all about VIP membership here.
How can I access the premium indicators?
To access the premium indicators, which are plug and play ready, sign up for VIP membership here.
Back
Top