pine script strategy.exit() stop not working on a live chart

On historical bars the stop works fine but on a live chart the stop doesnt work correctly. If the stop level is met it will close on bar close. The take profit exits at the correct limit price, but its like the stop is acting like a market on bar close instead of a limit. I have a large code section to give as much detail on the relevant section of the code as possible.

// calc_on_every_tick = true

// Strategy {

// global vars {

bool in_long = strategy.position_size > 0
bool in_short = strategy.position_size < 0
bool in_trade = strategy.position_size != 0
bool no_trade = strategy.position_size == 0

bool state_up = base_signal == 1
bool state_down = base_signal == 2
bool state_neutral = base_signal == 3

bool up_or_neutral = state_up or state_neutral
bool down_or_neutral = state_down or state_neutral

float take_profit_price = syminfo.mintick * take_profit_value
float stop_loss_price = syminfo.mintick * stop_loss_value
float break_even_price = syminfo.mintick * break_even_value
float breaK_even_ticks = syminfo.mintick * break_even_level

// end global vars }

// trade vars {

var int cue_state = 0
var bool long_cued = false
var bool short_cued = false
var bool neutral_cued = false

var float tp_price = na
var float entry_price = na
var float stop_price = na
var bool broke_even = false

bool stop_continuation = false

// end trade vars }

// strategy execution {

if barstate.isconfirmed
    if no_trade 
        broke_even := false
        tp_price := na
        entry_price := na
        stop_price := na
        strategy.cancel_all()

        if enable_reversal
            if reversal_up and (base_signal == 2 or base_signal == 3) and enable_long
                cue_state := base_signal
                long_cued := true
                short_cued := false
                neutral_cued := false

            if reversal_down and (base_signal == 1 or base_signal == 3) and enable_short
                cue_state := base_signal
                long_cued := false
                short_cued := true
                neutral_cued := false

            if reversal_neutral and enable_neutral and no_trade
                cue_state := base_signal

                if state_neutral 
                    long_cued := false
                    short_cued := false
                    neutral_cued := true

                if state_up and enable_short
                    long_cued := false
                    short_cued := true
                    neutral_cued := false

                if state_down and enable_long
                    long_cued := true
                    short_cued := false
                    neutral_cued := false

            if cue_state == 3
                if long_cued and state_down
                    long_cued := false
                    cue_state := 0

                if short_cued and state_up
                    short_cued := false
                    cue_state := 0

            if cancel_on_continue
                if long_cued and continuation_down
                    stop_continuation := true
                    long_cued := false
                    neutral_cued := false
                    cue_state := 0

                if short_cued and continuation_up
                    stop_continuation := true
                    short_cued := false
                    neutral_cued := false
                    cue_state := 0

            if reset_on_repaint and repaint_siginal
                if long_cued and trend == -1 and continuation
                    long_cued := false
                    cue_state := 0

                if short_cued and trend == 1 and continuation
                    short_cued := false
                    cue_state := 0
            if long_cued
                bool cue_condition = cue_state == 2 ? up_or_neutral : state_up

                if cue_condition
                    tp_price := close + take_profit_price
                    entry_price := close
                    stop_price := close - stop_loss_price

                    strategy.entry("Long", strategy.long, alert_message = buy_string)
                    strategy.exit("Long Exit", "Long", stop = stop_price, limit = tp_price, alert_profit = close_trade, alert_loss = close_trade)

                    cue_state := 0
                    long_cued := false

            if short_cued
                bool cue_condition = cue_state == 1 ? down_or_neutral : state_down

                if cue_condition
                    tp_price := close - take_profit_price
                    entry_price := close
                    stop_price := close + stop_loss_price

                    strategy.entry("Short", strategy.short, alert_message = sell_string)
                    strategy.exit("Short Exit", "Short", stop = stop_price, limit = tp_price, alert_profit = close_trade, alert_loss = close_trade)


                    cue_state := 0
                    short_cued := false

            if neutral_cued
                if state_up
                    tp_price := close + take_profit_price
                    entry_price := close
                    stop_price := close - stop_loss_price

                    strategy.entry("Long", strategy.long, alert_message = buy_string)
                    strategy.exit("Long Exit", "Long", stop = stop_price, limit = tp_price, alert_profit = close_trade, alert_loss = close_trade)

                    cue_state := 0
                    neutral_cued := false

                if state_down
                    tp_price := close - take_profit_price
                    entry_price := close
                    stop_price := close + stop_loss_price

                    strategy.entry("Short", strategy.short, alert_message = sell_string)
                    strategy.exit("Short Exit", "Short", stop = stop_price, limit = tp_price, alert_profit = close_trade, alert_loss = close_trade)

                    cue_state := 0
                    neutral_cued := false

        if enable_continuation and not stop_continuation
            if continuation_up and state_up and enable_long
                tp_price := close + take_profit_price
                entry_price := close
                stop_price := close - stop_loss_price

                strategy.entry("Long", strategy.long, alert_message = buy_string)
                strategy.exit("Long Exit", "Long", stop = stop_price, limit = tp_price, alert_profit = close_trade, alert_loss = close_trade)

                cue_state := 0
                long_cued := false
                short_cued := false
                neutral_cued := false

            if continuation_down and state_down and enable_short
                tp_price := close - take_profit_price
                entry_price := close
                stop_price := close + stop_loss_price

                strategy.entry("Short", strategy.short, alert_message = sell_string)
                strategy.exit("Short Exit", "Short", stop = stop_price, limit = tp_price, alert_profit = close_trade, alert_loss = close_trade)

                cue_state := 0
                long_cued := false
                short_cued := false
                neutral_cued := false

if in_trade and enable_break_even and not broke_even
    if in_long and high >= (entry_price + break_even_price)
        stop_price := entry_price + breaK_even_ticks
        strategy.exit("Long Exit", "Long", stop = stop_price, limit = tp_price, alert_profit = close_trade, alert_loss = close_trade)
        broke_even := true

    if in_short and low <= (entry_price - break_even_price)
        stop_price := entry_price - breaK_even_ticks
        strategy.exit("Short Exit", "Short", stop = stop_price, limit = tp_price, alert_profit = close_trade, alert_loss = close_trade)
        broke_even := true

// end strategy execution }```


I was trying to have a stop loss limit order but what I got was a stop loss level that acted like a market order on bar close. 

New contributor

Jesse is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.

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