2

I need some help. TIME FRAME = 5 mins. I want an indicator to plot the open and high till the first opposite color candle. Basically:

First candle positive and second candle negative, then plot high and low for the first 10 mins (price range of first two candles).

First candle positive and second candle positive and third candle negative, then plot high and low for the first 15 mins (price range of first two candles).

First candle is positive and second candle positive and third candle positive and the fourth candle is negative, then plot high and low for the first 20 mins (price range of first 4 candles).

I am getting the error: Mismatched input 'if' expecting 'end of line without line continuation'


// Declare a variable to track if the first red candle has been found
first_red_candle = false
// Declare variables to store the high and low of the day after the first red candle
high_after_first_red = na
low_after_first_red = na
// Iterate through the candles
for i = 0 to bar_index
 // Check if the current candle is red
 if close[i] < open[i]
 // Check if this is the first red candle
 if not first_red_candle
 // Set the first red candle flag to true
 first_red_candle = true
 // Otherwise, update the high and low of the day after the first red candle
 else
 high_after_first_red := max(high_after_first_red, high[i])
 low_after_first_red := min(low_after_first_red, low[i])
// Plot the high and low of the day after the first red candle
plot(high_after_first_red)
plot(low_after_first_red)
2
  • This is chatGPT generated, isn't it? Commented Dec 25, 2022 at 7:34
  • @vitruvius yes have been working on this indicator since the last 7 days but to no avail. So I tried this as well Commented Dec 25, 2022 at 8:31

2 Answers 2

2

The indentation in your actual code is made of 2 spaces, instead you must use a TAB indentation.
I tested your code with tabulation indentation and no errors.

answered Dec 25, 2022 at 9:55
Sign up to request clarification or add additional context in comments.

1 Comment

Thank you for your response. However, I am still getting errors. Would you be kind enough to paste the code after making the required changes? Would really help!
0

//@version=5 
indicator("Script") 
bar_index=1000
bool first_red_candle = false 
float high_after_first_red = 1
float low_after_first_red = 1
for i = 0 to bar_index
 bool cond = ((close[i] < open[i]) and not first_red_candle)
 if not cond
 high_after_first_red := math.max(high_after_first_red, high[i])
 low_after_first_red := math.min(low_after_first_red, low[i]) 
 else
 first_red_candle := not first_red_candle 
 
c_1 = high_after_first_red ? color.red : low_after_first_red ? color.gray : color.red
c_2 = low_after_first_red ? color.red : high_after_first_red ? color.green : color.red
plot(high_after_first_red, style=plot.style_line, linewidth=2, color=c_1) 
plot(low_after_first_red, style=plot.style_line, linewidth=2, color=c_2) 

enter image description

answered Dec 28, 2022 at 23:31

1 Comment

thank you for your response. However, the high is changing as new high are formed throughout the day. I want to plot just the first high after the first red candle.

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.