-3

I'm trying to find pine script lcm.

Masters, can you please help? I could not be successful. It should be very simple for you. Please help me

//@version=5



indicator(title='1', overlay=false, precision=2, timeframe='')

x = input(15)

y = input(30)



z =math.max (x,y)



e2=while ((z % x == 0) and (z % y == 0))

lcm:= z

break

z += 1

plot(lcm, color=color.new(color.black, 0))
  • What have you tried so far? Finding the least common multiple is not so different from any other language. – vitruvius Jan 30 '22 at 15:55
  • Thanks for the response. But I used all my means. I watched, I read. I did not have success. Maybe such a thing is not possible in the universe. ``//@version=5 indicator(title='1', overlay=false, precision=2, timeframe='') x = input(15) y = input(30) z =math.max (x,y) e2=while ((z % x == 0) and (z % y == 0)) lcm:= z break z += 1 plot(lcm, color=color.new(color.black, 0))`` – Mavi Beyaz Gökyüzü Jan 30 '22 at 22:47
  • This code does not even compile. – vitruvius Jan 31 '22 at 07:46

1 Answers1

0

Your while condition should be an if check inside an infinite while loop.

This will do:

//@version=5
indicator(title='1', overlay=false, precision=2, timeframe='')

x = input(15)
y = input(30)

z =math.max (x,y)
lcm = 0

while (1)
    if ((z % x == 0) and (z % y == 0))
        lcm := z
        break
    z += 1

plot(lcm, color=color.new(color.black, 0))
vitruvius
  • 15,740
  • 3
  • 16
  • 26