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
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