Pine script – declaration variable overruling reassignment operator

I think I’m trying to write a loop. I am trying to switch the value of ims_dir (and eventually ms_dir too) depending on fulfillments of two if statements. I’ve tried declaring ims_dir = na, and then having the first if statement also accept ims_dir == na, but that messes with the if statements function. Really I’m just looking for a way to switch between these two if statements indefinitely depending on when they meet the criteria, but having to declare the variable that acts as the switch so I can have the if statements re-assign it’s value is messing with the if statements. I added <<<< on the right so you can easily find it, hope it helps.

Pretty sure this is an easy fix, but not sure how to do it. Thanks so much for your help!!!!

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
<code>indicator('WP Market Structure', 'WP MS', true, format.price, max_bars_back=5000)
//
//
//
startpoint = input.time(timestamp('21 Nov 2022 00:00'), 'start', confirm=true)
start_dir = input.int (1, 'Direction', [1, -1])
highest = ta.highest(3)
lowest = ta.lowest (3)
//
//
//
var line [] lines = array.new_line()
// var line [] lines = array.new_line()
// var line [] lines = array.new_line()
//
//
//
ms_management(start_point, array_lines) =>
//
if (array.size(array_lines) > 0)
//
double_close_dn = (close<open and (close<open)[1])
double_close_up = (close>open and (close>open)[1])
int ms_dir = na //THIS <<<<
int ims_dir = na //THIS <<<<
//
//
//
if ms_dir==1
if ims_dir==1 //THIS <<<<
if not double_close_dn
line.set_xy2(array.get(array_lines, 0), time, highest)
//
if double_close_dn
line.set_xy2(array.get(array_lines, 0), time, highest)
array.unshift(lines, line.new(time, highest, time, low, xloc=xloc.bar_time, extend=extend.none, style=line.style_solid, width=1, color=color.red) )
ims_dir := -1 //Swtich variable to -1 so other if block will take over <<<<
//
//
if ims_dir==-1 //THIS <<<<
if not double_close_up
line.set_xy2(array.get(array_lines, 0), time, lowest)
//
if double_close_up
line.set_xy2(array.get(array_lines, 0), time, lowest)
array.unshift(lines, line.new(time, lowest, time, high, xloc=xloc.bar_time, extend=extend.none, style=line.style_solid, width=1, color=color.green) )
ims_dir := 1 //Swtich variable to 1 so other if block will take over <<<<
//
//
label.new(bar_index, close, str.tostring(ims_dir))
//
if false //ms_dir==-1 //Havent gotten to this part yet
if not double_close_up
line.set_xy2(array.get(array_lines, 0), time, low)
else if double_close_up
line.set_xy2(array.get(array_lines, 0), time, lowest)
array.unshift(lines, line.new(time, low, time, high, xloc=xloc.bar_time, extend=extend.none, style=line.style_solid, width=1, color=color.blue) )
//
//
//
//
//
if time == startpoint
array.unshift(lines, line.new(time, low, time, high + 10000, xloc=xloc.bar_time, extend=extend.none, style=line.style_solid, width=1, color=color.blue) )
//
//
//
ms_management(startpoint, lines)
//
//
//
</code>
<code>indicator('WP Market Structure', 'WP MS', true, format.price, max_bars_back=5000) // // // startpoint = input.time(timestamp('21 Nov 2022 00:00'), 'start', confirm=true) start_dir = input.int (1, 'Direction', [1, -1]) highest = ta.highest(3) lowest = ta.lowest (3) // // // var line [] lines = array.new_line() // var line [] lines = array.new_line() // var line [] lines = array.new_line() // // // ms_management(start_point, array_lines) => // if (array.size(array_lines) > 0) // double_close_dn = (close<open and (close<open)[1]) double_close_up = (close>open and (close>open)[1]) int ms_dir = na //THIS <<<< int ims_dir = na //THIS <<<< // // // if ms_dir==1 if ims_dir==1 //THIS <<<< if not double_close_dn line.set_xy2(array.get(array_lines, 0), time, highest) // if double_close_dn line.set_xy2(array.get(array_lines, 0), time, highest) array.unshift(lines, line.new(time, highest, time, low, xloc=xloc.bar_time, extend=extend.none, style=line.style_solid, width=1, color=color.red) ) ims_dir := -1 //Swtich variable to -1 so other if block will take over <<<< // // if ims_dir==-1 //THIS <<<< if not double_close_up line.set_xy2(array.get(array_lines, 0), time, lowest) // if double_close_up line.set_xy2(array.get(array_lines, 0), time, lowest) array.unshift(lines, line.new(time, lowest, time, high, xloc=xloc.bar_time, extend=extend.none, style=line.style_solid, width=1, color=color.green) ) ims_dir := 1 //Swtich variable to 1 so other if block will take over <<<< // // label.new(bar_index, close, str.tostring(ims_dir)) // if false //ms_dir==-1 //Havent gotten to this part yet if not double_close_up line.set_xy2(array.get(array_lines, 0), time, low) else if double_close_up line.set_xy2(array.get(array_lines, 0), time, lowest) array.unshift(lines, line.new(time, low, time, high, xloc=xloc.bar_time, extend=extend.none, style=line.style_solid, width=1, color=color.blue) ) // // // // // if time == startpoint array.unshift(lines, line.new(time, low, time, high + 10000, xloc=xloc.bar_time, extend=extend.none, style=line.style_solid, width=1, color=color.blue) ) // // // ms_management(startpoint, lines) // // // </code>
indicator('WP Market Structure', 'WP MS', true, format.price, max_bars_back=5000)
//
//
//
startpoint = input.time(timestamp('21 Nov 2022 00:00'), 'start', confirm=true)
start_dir  = input.int (1, 'Direction', [1, -1])


highest = ta.highest(3)
lowest  = ta.lowest (3)
//
//
//
var line [] lines = array.new_line()
// var line [] lines = array.new_line()
// var line [] lines = array.new_line()
//
//
//
ms_management(start_point, array_lines) =>
    //
    if (array.size(array_lines) > 0)
        //
        double_close_dn = (close<open and (close<open)[1])
        double_close_up = (close>open and (close>open)[1])
        int ms_dir  = na //THIS                                                             <<<<
        int ims_dir = na //THIS                                                             <<<<
        //
        //
        //
        if ms_dir==1
            if ims_dir==1 //THIS                                                            <<<<
                if not double_close_dn
                    line.set_xy2(array.get(array_lines, 0), time, highest)
                    //
                if double_close_dn
                    line.set_xy2(array.get(array_lines, 0), time, highest)
                    array.unshift(lines, line.new(time, highest, time, low, xloc=xloc.bar_time, extend=extend.none, style=line.style_solid, width=1, color=color.red) )
                    ims_dir := -1 //Swtich variable to -1 so other if block will take over  <<<<
                    //
                //
            if ims_dir==-1 //THIS                                                           <<<<
                if not double_close_up
                    line.set_xy2(array.get(array_lines, 0), time, lowest)
                    //
                if double_close_up
                    line.set_xy2(array.get(array_lines, 0), time, lowest)
                    array.unshift(lines, line.new(time, lowest, time, high, xloc=xloc.bar_time, extend=extend.none, style=line.style_solid, width=1, color=color.green) )
                    ims_dir := 1 //Swtich variable to 1 so other if block will take over    <<<<
                    //
                //
        label.new(bar_index, close, str.tostring(ims_dir))
            //
        if false //ms_dir==-1 //Havent gotten to this part yet
            if not double_close_up
                line.set_xy2(array.get(array_lines, 0), time, low)
            else if double_close_up
                line.set_xy2(array.get(array_lines, 0), time, lowest)
                array.unshift(lines, line.new(time, low, time, high, xloc=xloc.bar_time, extend=extend.none, style=line.style_solid, width=1, color=color.blue) )
        
        //
    //
//
//
//
if time == startpoint
    array.unshift(lines, line.new(time, low, time, high + 10000, xloc=xloc.bar_time, extend=extend.none, style=line.style_solid, width=1, color=color.blue) )
//
// 
//
ms_management(startpoint, lines)
//
//
//

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật