LevelsManager
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © sosso_bott

//@version=5

// @description TODO: Track up to 6 TakeProfits and 1 StopLoss achievement for one or many of your buy/sell conditions.
library("LevelsManager")
// ——————————————————————————— \\
// ▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼ \\

// ▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲ \\
// ——————————————————————————— \\

// ******************=========================== Function @manageTrade  ==============================************************** \\
// -------- PARAMS ---------|----- TYPE -----|------------------------------- DESCRIPTION && DETAILS -----------------------------|----------- TIPS ------------|
// @param useSignal         : (series bool)  |  TO ACTIVATE OR DEACTIVATE Trade Management                                        |           [INPUT]           |
// @param b_gameOVer        : (series bool)  |  BUY CONDITION                                                                     |       Pinesript logic       |
// @param s_gameOver        : (series bool)  |  SELL CONDITION                                                                    |       Pinesript logic       |
// @param bName             : (series string)|  BUY CONDITION string ID (Make it small 3 characters max or dont listen to me lol) | Hardcode it on funtion call |
// @param sName             : (series string)|  SELL CONDITION string ID (Make it small 3 characters max or dont listen to me lol)| Hardcode it on funtion call |
// @param buyEntrySource    : (series float) |  ENTRY LEVEL FOR BUY CONDITION                                                     |[INPUT OR NOT IT'S UP TO YOU]|
// @param sellEntrySource   : (series float) |  ENTRY LEVEL FOR SELL CONDITION                                                    |[INPUT OR NOT IT'S UP TO YOU]|
// @param useTp1            : (series bool)  |  USE THE TP LEVEL OR NOT                                                           |            [INPUT]          |
// @param useTp2            : (series bool)  |  USE THE TP LEVEL OR NOT                                                           |            [INPUT]          |
// @param useTp3            : (series bool)  |  USE THE TP LEVEL OR NOT                                                           |            [INPUT]          |
// @param useTp4            : (series bool)  |  USE THE TP LEVEL OR NOT                                                           |            [INPUT]          |
// @param useTp5            : (series bool)  |  USE THE TP LEVEL OR NOT                                                           |            [INPUT]          |
// @param useTp6            : (series bool)  |  USE THE TP LEVEL OR NOT                                                           |            [INPUT]          |
// @param tp1x              : (series float) |  PERCENTAGE FOR THIS TP LEVEL ACHIEVMENT                                           |            [INPUT]          |
// @param tp2x              : (series float) |  PERCENTAGE FOR THIS TP LEVEL ACHIEVMENT                                           |            [INPUT]          |
// @param tp3x              : (series float) |  PERCENTAGE FOR THIS TP LEVEL ACHIEVMENT                                           |            [INPUT]          |
// @param tp4x              : (series float) |  PERCENTAGE FOR THIS TP LEVEL ACHIEVMENT                                           |            [INPUT]          |
// @param tp5x              : (series float) |  PERCENTAGE FOR THIS TP LEVEL ACHIEVMENT                                           |            [INPUT]          |
// @param tp6x              : (series float) |  PERCENTAGE FOR THIS TP LEVEL ACHIEVMENT                                           |            [INPUT]          |
// @param slx               : (series float) |  PERCENTAGE FOR STOPLOSS LEVEL ACHIEVMENT                                          |            [INPUT]          |


// -------- RETURN ---------|----- TYPE -----|------------------------------- BEHAVIOR -----------------------------|
// entry_touched            : (series bool)  |  PLOTTED      (Role: Showing if entry is hit)
// entry1                   : (series float) |  NOT PLOTTED  (Use it for alerts)
// tp1                      : (series float) |  NOT PLOTTED  (Use it for alerts)
// tp2                      : (series float) |  NOT PLOTTED  (Use it for alerts)
// tp3                      : (series float) |  NOT PLOTTED  (Use it for alerts)
// tp4                      : (series float) |  NOT PLOTTED  (Use it for alerts)
// tp5                      : (series float) |  NOT PLOTTED  (Use it for alerts)
// tp6                      : (series float) |  NOT PLOTTED  (Use it for alerts)
// sl                       : (series float) |  NOT PLOTTED  (Use it for alerts)
// official_buy             : (series bool)  |  NOT PLOTTED  (PLOT IT YOUR BUY CONDITION THEY WAY YOU WANT)
// official_sell            : (series bool)  |  NOT PLOTTED  (PLOT IT YOUR SEEL CONDITION THEY WAY YOU WANT)
// buyTP1_touched           : (series bool)  |  PLOTTED      (USE IT TO ACT ON TP ACHIEVMENT) 
// buyTP2_touched           : (series bool)  |  PLOTTED      (USE IT TO ACT ON TP ACHIEVMENT) 
// buyTP3_touched           : (series bool)  |  PLOTTED      (USE IT TO ACT ON TP ACHIEVMENT) 
// buyTP4_touched           : (series bool)  |  PLOTTED      (USE IT TO ACT ON TP ACHIEVMENT) 
// buyTP5_touched           : (series bool)  |  PLOTTED      (USE IT TO ACT ON TP ACHIEVMENT) 
// buyTP6_touched           : (series bool)  |  PLOTTED      (USE IT TO ACT ON TP ACHIEVMENT) 
// buySL_touched            : (series bool)  |  PLOTTED      (USE IT TO ACT ON TP ACHIEVMENT) 
// sellTP1_touched          : (series bool)  |  PLOTTED      (USE IT TO ACT ON TP ACHIEVMENT) 
// sellTP2_touched          : (series bool)  |  PLOTTED      (USE IT TO ACT ON TP ACHIEVMENT) 
// sellTP3_touched          : (series bool)  |  PLOTTED      (USE IT TO ACT ON TP ACHIEVMENT) 
// sellTP4_touched          : (series bool)  |  PLOTTED      (USE IT TO ACT ON TP ACHIEVMENT) 
// sellTP5_touched          : (series bool)  |  PLOTTED      (USE IT TO ACT ON TP ACHIEVMENT) 
// sellTP6_touched          : (series bool)  |  PLOTTED      (USE IT TO ACT ON TP ACHIEVMENT) 
// sellSL_touched           : (series bool)  |  PLOTTED      (USE IT TO ACT ON TP ACHIEVMENT) 
// ******************=========================== Function @manageTrade END ==============================************************** \\

// ******************=========================== Function @manageFilterredTrade  ==============================************************** \\
// -------- PARAMS ---------|----- TYPE -----|------------------------------- DESCRIPTION && DETAILS -----------------------------|----------- TIPS ------------|
// @param useSignal         : (series bool)  |  TO ACTIVATE OR DEACTIVATE Trade Management                                        |           [INPUT]           |
// @param b_gameOVer        : (series bool)  |  BUY CONDITION                                                                     |       Pinesript logic       |
// @param longCancel        : (series bool)  |  CONDITION TO RESTART LOOKING FOR A BUY TRADE                                      |       Pinesript logic       |
// @param s_gameOver        : (series bool)  |  SELL CONDITION                                                                    |       Pinesript logic       |
// @param shortCancel       : (series bool)  |  CONDITION TO RESTART LOOKING FOR A SELL TRADE                                     |       Pinesript logic       |
// @param bName             : (series string)|  BUY CONDITION string ID (Make it small 3 characters max or dont listen to me lol) | Hardcode it on funtion call |
// @param sName             : (series string)|  SELL CONDITION string ID (Make it small 3 characters max or dont listen to me lol)| Hardcode it on funtion call |
// @param buyEntrySource    : (series float) |  ENTRY LEVEL FOR BUY CONDITION                                                     |[INPUT OR NOT IT'S UP TO YOU]|
// @param sellEntrySource   : (series float) |  ENTRY LEVEL FOR SELL CONDITION                                                    |[INPUT OR NOT IT'S UP TO YOU]|
// @param useTp1            : (series bool)  |  USE THE TP LEVEL OR NOT                                                           |            [INPUT]          |
// @param useTp2            : (series bool)  |  USE THE TP LEVEL OR NOT                                                           |            [INPUT]          |
// @param useTp3            : (series bool)  |  USE THE TP LEVEL OR NOT                                                           |            [INPUT]          |
// @param useTp4            : (series bool)  |  USE THE TP LEVEL OR NOT                                                           |            [INPUT]          |
// @param useTp5            : (series bool)  |  USE THE TP LEVEL OR NOT                                                           |            [INPUT]          |
// @param useTp6            : (series bool)  |  USE THE TP LEVEL OR NOT                                                           |            [INPUT]          |
// @param tp1x              : (series float) |  PERCENTAGE FOR THIS TP LEVEL ACHIEVMENT                                           |            [INPUT]          |
// @param tp2x              : (series float) |  PERCENTAGE FOR THIS TP LEVEL ACHIEVMENT                                           |            [INPUT]          |
// @param tp3x              : (series float) |  PERCENTAGE FOR THIS TP LEVEL ACHIEVMENT                                           |            [INPUT]          |
// @param tp4x              : (series float) |  PERCENTAGE FOR THIS TP LEVEL ACHIEVMENT                                           |            [INPUT]          |
// @param tp5x              : (series float) |  PERCENTAGE FOR THIS TP LEVEL ACHIEVMENT                                           |            [INPUT]          |
// @param tp6x              : (series float) |  PERCENTAGE FOR THIS TP LEVEL ACHIEVMENT                                           |            [INPUT]          |
// @param slx               : (series float) |  PERCENTAGE FOR STOPLOSS LEVEL ACHIEVMENT                                          |            [INPUT]          |


// -------- RETURN ---------|----- TYPE -----|------------------------------- BEHAVIOR -----------------------------|
// entry_touched            : (series bool)  |  PLOTTED      (Role: Showing if entry is hit)
// entry1                   : (series float) |  NOT PLOTTED  (Use it for alerts)
// tp1                      : (series float) |  NOT PLOTTED  (Use it for alerts)
// tp2                      : (series float) |  NOT PLOTTED  (Use it for alerts)
// tp3                      : (series float) |  NOT PLOTTED  (Use it for alerts)
// tp4                      : (series float) |  NOT PLOTTED  (Use it for alerts)
// tp5                      : (series float) |  NOT PLOTTED  (Use it for alerts)
// tp6                      : (series float) |  NOT PLOTTED  (Use it for alerts)
// sl                       : (series float) |  NOT PLOTTED  (Use it for alerts)
// official_buy             : (series bool)  |  NOT PLOTTED  (PLOT IT YOUR BUY CONDITION THEY WAY YOU WANT)
// official_sell            : (series bool)  |  NOT PLOTTED  (PLOT IT YOUR SEEL CONDITION THEY WAY YOU WANT)
// buyTP1_touched           : (series bool)  |  PLOTTED      (USE IT TO ACT ON TP ACHIEVMENT) 
// buyTP2_touched           : (series bool)  |  PLOTTED      (USE IT TO ACT ON TP ACHIEVMENT) 
// buyTP3_touched           : (series bool)  |  PLOTTED      (USE IT TO ACT ON TP ACHIEVMENT) 
// buyTP4_touched           : (series bool)  |  PLOTTED      (USE IT TO ACT ON TP ACHIEVMENT) 
// buyTP5_touched           : (series bool)  |  PLOTTED      (USE IT TO ACT ON TP ACHIEVMENT) 
// buyTP6_touched           : (series bool)  |  PLOTTED      (USE IT TO ACT ON TP ACHIEVMENT) 
// buySL_touched            : (series bool)  |  PLOTTED      (USE IT TO ACT ON TP ACHIEVMENT) 
// sellTP1_touched          : (series bool)  |  PLOTTED      (USE IT TO ACT ON TP ACHIEVMENT) 
// sellTP2_touched          : (series bool)  |  PLOTTED      (USE IT TO ACT ON TP ACHIEVMENT) 
// sellTP3_touched          : (series bool)  |  PLOTTED      (USE IT TO ACT ON TP ACHIEVMENT) 
// sellTP4_touched          : (series bool)  |  PLOTTED      (USE IT TO ACT ON TP ACHIEVMENT) 
// sellTP5_touched          : (series bool)  |  PLOTTED      (USE IT TO ACT ON TP ACHIEVMENT) 
// sellTP6_touched          : (series bool)  |  PLOTTED      (USE IT TO ACT ON TP ACHIEVMENT) 
// sellSL_touched           : (series bool)  |  PLOTTED      (USE IT TO ACT ON TP ACHIEVMENT) 
// ******************=========================== Function @manageFilterredTrade END ==============================************************** \\

// ******************=========================== Function @manageLevel  ==============================************************** \\
// -------- PARAMS ---------|----- TYPE -----|------------------------------- DESCRIPTION && DETAILS -----------------------------|----------- TIPS ------------|
// @param useSignal         : (series bool)  |  TO ACTIVATE OR DEACTIVATE Trade Management                                        |           [INPUT]           |
// @param b_gameOVer        : (series bool)  |  BUY CONDITION                                                                     |       Pinesript logic       |
// @param s_gameOver        : (series bool)  |  SELL CONDITION                                                                    |       Pinesript logic       |
// @param bName             : (series string)|  BUY CONDITION string ID (Make it small 3 characters max or dont listen to me lol) | Hardcode it on funtion call |
// @param sName             : (series string)|  SELL CONDITION string ID (Make it small 3 characters max or dont listen to me lol)| Hardcode it on funtion call |
// @param buyEntrySource    : (series float) |  ENTRY LEVEL FOR BUY CONDITION                                                     |[INPUT OR NOT IT'S UP TO YOU]|
// @param sellEntrySource   : (series float) |  ENTRY LEVEL FOR SELL CONDITION                                                    |[INPUT OR NOT IT'S UP TO YOU]|
// @param tp1x              : (series float) |  PERCENTAGE FOR THIS TP LEVEL ACHIEVMENT                                           |            [INPUT]          |
// @param slx               : (series float) |  PERCENTAGE FOR STOPLOSS LEVEL ACHIEVMENT                                          |            [INPUT]          |


// -------- RETURN ---------|----- TYPE -----|------------------------------- BEHAVIOR -----------------------------|
// entry_touched            : (series bool)  |  PLOTTED      (Role: Showing if entry is hit)
// entry1                   : (series float) |  NOT PLOTTED  (Use it for alerts)
// tp1                      : (series float) |  NOT PLOTTED  (Use it for alerts)
// sl                       : (series float) |  NOT PLOTTED  (Use it for alerts)
// official_buy             : (series bool)  |  NOT PLOTTED  (PLOT IT YOUR BUY CONDITION THEY WAY YOU WANT)
// official_sell            : (series bool)  |  NOT PLOTTED  (PLOT IT YOUR SEEL CONDITION THEY WAY YOU WANT)
// buyTP1_touched           : (series bool)  |  PLOTTED      (USE IT TO ACT ON TP ACHIEVMENT) 
// buySL_touched            : (series bool)  |  PLOTTED      (USE IT TO ACT ON TP ACHIEVMENT) 
// sellTP1_touched          : (series bool)  |  PLOTTED      (USE IT TO ACT ON TP ACHIEVMENT) 
// sellSL_touched           : (series bool)  |  PLOTTED      (USE IT TO ACT ON TP ACHIEVMENT) 
// ******************=========================== Function @manageLevel END ==============================************************** \\

// ******************=========================== Function @manageFilterredLevel  ==============================************************** \\
// -------- PARAMS ---------|----- TYPE -----|------------------------------- DESCRIPTION && DETAILS -----------------------------|----------- TIPS ------------|
// @param useSignal         : (series bool)  |  TO ACTIVATE OR DEACTIVATE Trade Management                                        |           [INPUT]           |
// @param b_gameOVer        : (series bool)  |  BUY CONDITION                                                                     |       Pinesript logic       |
// @param longCancel        : (series bool)  |  CONDITION TO RESTART LOOKING FOR A BUY TRADE                                      |       Pinesript logic       |
// @param s_gameOver        : (series bool)  |  SELL CONDITION                                                                    |       Pinesript logic       |
// @param shortCancel       : (series bool)  |  CONDITION TO RESTART LOOKING FOR A SELL TRADE                                     |       Pinesript logic       |
// @param bName             : (series string)|  BUY CONDITION string ID (Make it small 3 characters max or dont listen to me lol) | Hardcode it on funtion call |
// @param sName             : (series string)|  SELL CONDITION string ID (Make it small 3 characters max or dont listen to me lol)| Hardcode it on funtion call |
// @param buyEntrySource    : (series float) |  ENTRY LEVEL FOR BUY CONDITION                                                     |[INPUT OR NOT IT'S UP TO YOU]|
// @param sellEntrySource   : (series float) |  ENTRY LEVEL FOR SELL CONDITION                                                    |[INPUT OR NOT IT'S UP TO YOU]|
// @param tp1x              : (series float) |  PERCENTAGE FOR THIS TP LEVEL ACHIEVMENT                                           |            [INPUT]          |
// @param slx               : (series float) |  PERCENTAGE FOR STOPLOSS LEVEL ACHIEVMENT                                          |            [INPUT]          |


// -------- RETURN ---------|----- TYPE -----|------------------------------- BEHAVIOR -----------------------------|
// entry_touched            : (series bool)  |  PLOTTED      (Role: Showing if entry is hit)
// entry1                   : (series float) |  NOT PLOTTED  (Use it for alerts)
// tp1                      : (series float) |  NOT PLOTTED  (Use it for alerts)
// sl                       : (series float) |  NOT PLOTTED  (Use it for alerts)
// official_buy             : (series bool)  |  NOT PLOTTED  (PLOT IT YOUR BUY CONDITION THEY WAY YOU WANT)
// official_sell            : (series bool)  |  NOT PLOTTED  (PLOT IT YOUR SEEL CONDITION THEY WAY YOU WANT)
// buyTP1_touched           : (series bool)  |  PLOTTED      (USE IT TO ACT ON TP ACHIEVMENT) 
// buySL_touched            : (series bool)  |  PLOTTED      (USE IT TO ACT ON TP ACHIEVMENT) 
// sellTP1_touched          : (series bool)  |  PLOTTED      (USE IT TO ACT ON TP ACHIEVMENT) 
// sellSL_touched           : (series bool)  |  PLOTTED      (USE IT TO ACT ON TP ACHIEVMENT) 
// ******************=========================== Function @manageFilterredLevel END ==============================************************** \\


// ******************=========================== Function @tpLevels  ==============================************************** \\
// MAIN DIFFERENCE : LEVELS WILL STAY ON THE CHART
// -------- PARAMS ---------|----- TYPE -----|------------------------------- DESCRIPTION && DETAILS -----------------------------|----------- TIPS ------------|
// @param useSignal         : (series bool)  |  TO ACTIVATE OR DEACTIVATE Trade Management                                        |           [INPUT]           |
// @param b_gameOVer        : (series bool)  |  BUY CONDITION                                                                     |       Pinesript logic       |
// @param s_gameOver        : (series bool)  |  SELL CONDITION                                                                    |       Pinesript logic       |
// @param bName             : (series string)|  BUY CONDITION string ID (Make it small 3 characters max or dont listen to me lol) | Hardcode it on funtion call |
// @param sName             : (series string)|  SELL CONDITION string ID (Make it small 3 characters max or dont listen to me lol)| Hardcode it on funtion call |
// @param buyEntrySource    : (series float) |  ENTRY LEVEL FOR BUY CONDITION                                                     |[INPUT OR NOT IT'S UP TO YOU]|
// @param sellEntrySource   : (series float) |  ENTRY LEVEL FOR SELL CONDITION                                                    |[INPUT OR NOT IT'S UP TO YOU]|
// @param useTp1            : (series bool)  |  USE THE TP LEVEL OR NOT                                                           |            [INPUT]          |
// @param useTp2            : (series bool)  |  USE THE TP LEVEL OR NOT                                                           |            [INPUT]          |
// @param useTp3            : (series bool)  |  USE THE TP LEVEL OR NOT                                                           |            [INPUT]          |
// @param useTp4            : (series bool)  |  USE THE TP LEVEL OR NOT                                                           |            [INPUT]          |
// @param useTp5            : (series bool)  |  USE THE TP LEVEL OR NOT                                                           |            [INPUT]          |
// @param useTp6            : (series bool)  |  USE THE TP LEVEL OR NOT                                                           |            [INPUT]          |
// @param tp1x              : (series float) |  PERCENTAGE FOR THIS TP LEVEL ACHIEVMENT                                           |            [INPUT]          |
// @param tp2x              : (series float) |  PERCENTAGE FOR THIS TP LEVEL ACHIEVMENT                                           |            [INPUT]          |
// @param tp3x              : (series float) |  PERCENTAGE FOR THIS TP LEVEL ACHIEVMENT                                           |            [INPUT]          |
// @param tp4x              : (series float) |  PERCENTAGE FOR THIS TP LEVEL ACHIEVMENT                                           |            [INPUT]          |
// @param tp5x              : (series float) |  PERCENTAGE FOR THIS TP LEVEL ACHIEVMENT                                           |            [INPUT]          |
// @param tp6x              : (series float) |  PERCENTAGE FOR THIS TP LEVEL ACHIEVMENT                                           |            [INPUT]          |
// @param slx               : (series float) |  PERCENTAGE FOR STOPLOSS LEVEL ACHIEVMENT                                          |            [INPUT]          |


// -------- RETURN ---------|----- TYPE -----|------------------------------- BEHAVIOR -----------------------------|
// entry_touched            : (series bool)  |  PLOTTED      (Role: Showing if entry is hit)
// entry1                   : (series float) |  NOT PLOTTED  (Use it for alerts)
// tp1                      : (series float) |  NOT PLOTTED  (Use it for alerts)
// tp2                      : (series float) |  NOT PLOTTED  (Use it for alerts)
// tp3                      : (series float) |  NOT PLOTTED  (Use it for alerts)
// tp4                      : (series float) |  NOT PLOTTED  (Use it for alerts)
// tp5                      : (series float) |  NOT PLOTTED  (Use it for alerts)
// tp6                      : (series float) |  NOT PLOTTED  (Use it for alerts)
// sl                       : (series float) |  NOT PLOTTED  (Use it for alerts)
// official_buy             : (series bool)  |  NOT PLOTTED  (PLOT IT YOUR BUY CONDITION THEY WAY YOU WANT)
// official_sell            : (series bool)  |  NOT PLOTTED  (PLOT IT YOUR SEEL CONDITION THEY WAY YOU WANT)
// buyTP1_touched           : (series bool)  |  PLOTTED      (USE IT TO ACT ON TP ACHIEVMENT) 
// buyTP2_touched           : (series bool)  |  PLOTTED      (USE IT TO ACT ON TP ACHIEVMENT) 
// buyTP3_touched           : (series bool)  |  PLOTTED      (USE IT TO ACT ON TP ACHIEVMENT) 
// buyTP4_touched           : (series bool)  |  PLOTTED      (USE IT TO ACT ON TP ACHIEVMENT) 
// buyTP5_touched           : (series bool)  |  PLOTTED      (USE IT TO ACT ON TP ACHIEVMENT) 
// buyTP6_touched           : (series bool)  |  PLOTTED      (USE IT TO ACT ON TP ACHIEVMENT) 
// buySL_touched            : (series bool)  |  PLOTTED      (USE IT TO ACT ON TP ACHIEVMENT) 
// sellTP1_touched          : (series bool)  |  PLOTTED      (USE IT TO ACT ON TP ACHIEVMENT) 
// sellTP2_touched          : (series bool)  |  PLOTTED      (USE IT TO ACT ON TP ACHIEVMENT) 
// sellTP3_touched          : (series bool)  |  PLOTTED      (USE IT TO ACT ON TP ACHIEVMENT) 
// sellTP4_touched          : (series bool)  |  PLOTTED      (USE IT TO ACT ON TP ACHIEVMENT) 
// sellTP5_touched          : (series bool)  |  PLOTTED      (USE IT TO ACT ON TP ACHIEVMENT) 
// sellTP6_touched          : (series bool)  |  PLOTTED      (USE IT TO ACT ON TP ACHIEVMENT) 
// sellSL_touched           : (series bool)  |  PLOTTED      (USE IT TO ACT ON TP ACHIEVMENT) 
// ******************=========================== Function @tpLevels END ==============================************************** \\


//  CALLING EXEMPLE \\
// HOW THE INDICATOR IN THE IMAGE CALLS @manageTrade function
// import sosso_bott/TradeManager/1 as tm
// [L1_S1entry_touched, L1_S1entry, L1_S1_tp1, L1_S1_tp2, L1_S1_tp3, L1_S1_tp4, L1_S1_tp5, L1_S1_tp6, L1_S1_sl, OL1, OS1, L1_buyTP1_touched, L1_buyTP2_touched, L1_buyTP3_touched, L1_buyTP4_touched, L1_buyTP5_touched, L1_buyTP6_touched, L1_buySL_Touched, S1_sellTP1_touched, S1_sellTP2_touched, S1_sellTP3_touched, S1_sellTP4_touched, S1_sellTP5_touched, S1_sellTP6_touched, S1_sellSL_touched] = tm.manageTrade(use_TrndSignals, L_1, S_1, "L_1", "S_1",  buyEntrySource, sellEntrySource,   useTp1, useTp2, useTp3, useTp4, useTp5, useTp6, tp1x, tp2x, tp3x, tp4x, tp5x, tp6x, slx)
// [L2_S2entry_touched, L2_S2entry, L2_S2_tp1, L2_S2_tp2, L2_S2_tp3, L2_S2_tp4, L2_S2_tp5, L2_S2_tp6, L2_S2_sl, OL2, OS2, L2_buyTP1_touched, L2_buyTP2_touched, L2_buyTP3_touched, L2_buyTP4_touched, L2_buyTP5_touched, L2_buyTP6_touched, L2_buySL_Touched, S2_sellTP1_touched, S2_sellTP2_touched, S2_sellTP3_touched, S2_sellTP4_touched, S2_sellTP5_touched, S2_sellTP6_touched, S2_sellSL_touched] = tm.manageTrade(use_MidSignals,  L_2, S_2, "L_2", "S_2",  buyEntrySource2, sellEntrySource2, useTp1, useTp2, useTp3, useTp4, useTp5, useTp6, tp1x, tp2x, tp3x, tp4x, tp5x, tp6x, slx)
// [L3_S3entry_touched, L3_S3entry, L3_S3_tp1, L3_S3_tp2, L3_S3_tp3, L3_S3_tp4, L3_S3_tp5, L3_S3_tp6, L3_S3_sl, OL3, OS3, L3_buyTP1_touched, L3_buyTP2_touched, L3_buyTP3_touched, L3_buyTP4_touched, L3_buyTP5_touched, L3_buyTP6_touched, L3_buySL_Touched, S3_sellTP1_touched, S3_sellTP2_touched, S3_sellTP3_touched, S3_sellTP4_touched, S3_sellTP5_touched, S3_sellTP6_touched, S3_sellSL_touched] = tm.manageTrade(use_scalppers,   L_3, S_3, "L_3", "S_3",  buyEntrySource3, sellEntrySource3, useTp1, useTp2, useTp3, useTp4, useTp5, useTp6, tp1x, tp2x, tp3x, tp4x, tp5x, tp6x, slx)
// [L4_S4entry_touched, L4_S4entry, L4_S4_tp1, L4_S4_tp2, L4_S4_tp3, L4_S4_tp4, L4_S4_tp5, L4_S4_tp6, L4_S4_sl, OL4, OS4, L4_buyTP1_touched, L4_buyTP2_touched, L4_buyTP3_touched, L4_buyTP4_touched, L4_buyTP5_touched, L4_buyTP6_touched, L4_buySL_Touched, S4_sellTP1_touched, S4_sellTP2_touched, S4_sellTP3_touched, S4_sellTP4_touched, S4_sellTP5_touched, S4_sellTP6_touched, S4_sellSL_touched] = tm.manageTrade(use_scalppers2,  L_4, S_4, "L_4", "S_4",  buyEntrySource4, sellEntrySource4, useTp1, useTp2, useTp3, useTp4, useTp5, useTp6, tp1x, tp2x, tp3x, tp4x, tp5x, tp6x, slx)


// Function @round_price is used by manageTrade function

// Function @getLevel is just un example of method i use to switch between mulitple
    // EXAMPLE OF CALL WITH GET LEVEL : 
    // buyEntrySource  = input(defval = "RENKOMID2",           title = "Buy entry source (S1_L1)",                  options=["CLOSE", "LOW",  "HL2", "RENKOMID1", "RENKOMID2", "RENKODN", "DOWNLEVEL1", "EXTRADN", "RENKODN2", "DOWNLEVEL2", "EXTRADN2"],     type = input.string,         group="Signals Entry")
    // sellEntrySource = input(defval = "RENKOMID2",           title = "Sell entry source (S1_L1)",                 options=["CLOSE", "HIGH", "HL2", "RENKOMID1", "RENKOMID2", "RENKOUP", "UPLEVEL1", "EXTRAUP", "RENKOUP2", "UPLEVEL2", "EXTRAUP2"],         type = input.string,         group="Signals Entry")

    //  [L1_S1entry_touched, L1_S1entry, L1_S1_tp1, L1_S1_tp2, L1_S1_tp3, L1_S1_tp4, L1_S1_tp5, L1_S1_tp6, L1_S1_sl, OL1, OS1, L1_buyTP1_touched, L1_buyTP2_touched, L1_buyTP3_touched, L1_buyTP4_touched, L1_buyTP5_touched, L1_buyTP6_touched, L1_buySL_touched, S1_sellTP1_touched, S1_sellTP2_touched, S1_sellTP3_touched, S1_sellTP4_touched, S1_sellTP5_touched, S1_sellTP6_touched, S1_sellSL_touched] = manageTrade(use_TrndSignals, L_1, S_1, "L_1", "S_1",  getLevel(buyEntrySource), getLevelsellEntrySource),  useTp1, useTp2, useTp3, useTp4, useTp5, useTp6, tp1x, tp2x, tp3x, tp4x, tp5x, tp6x, slx)
 
// getLevel(EntrySource) =>
//     level = EntrySource   == "LOW"  ? low : EntrySource    == "CLOSE" ? close : EntrySource  == "HIGH" ? high : EntrySource  == "HL2" ? hl2 : EntrySource  == "RENKODN" ? RENKODN1 : EntrySource  == "RENKOUP" ? RENKOUP1: EntrySource  == "EXTRADN" ? EXTRADN1: EntrySource  == "EXTRAUP" ? EXTRAUP1: EntrySource  == "UPLEVEL1" ? UPLEVEL1: EntrySource  == "DOWNLEVEL1" ? DOWNLEVEL1: EntrySource  == "RENKODN2" ? RENKODN2: EntrySource  == "RENKOUP2" ? RENKOUP2: EntrySource  == "DOWNLEVEL2" ? DOWNLEVEL2: EntrySource  == "UPLEVEL2" ? UPLEVEL2: EntrySource  == "EXTRAUP2" ? EXTRAUP2: EntrySource  == "EXTRADN2" ? EXTRADN2 : EntrySource  == "RENKOMID1" ? RENKOMID: EntrySource  == "RENKOMID2" ? RENKOMID2 :hl2
    
//     level

round_price(x) =>
    xx = int(x / syminfo.mintick)
    xx * syminfo.mintick
    

// @function Track TakeProfits and StopLoss achievement for one or many of your buy/sell conditions. CHECK the commented section:  "Function @manageTrade" (lines: 14 - 64) for Description
// @param bool useSignal.
// @param bool b_gameOVer.
// @param bool b_gameOVer.
// @param string bName.
// @param string sName.
// @param float buyEntrySource.
// @param float sellEntrySource.
// @param bool useTp1.
// @param bool useTp2.
// @param bool useTp3.
// @param bool useTp4.
// @param bool useTp5.
// @param bool useTp6.
// @param float tp1x.
// @param float tp2x.
// @param float tp3x.
// @param float tp4x.
// @param float tp5x.
// @param float tp6x.
// @param float slx.
// @returns check commented section:  "Function @manageTrade" (lines: 14 - 64).
export manageTrade(bool useSignal, bool b_gameOVer, bool s_gameOver , string bName, string sName, float buyEntrySource, float sellEntrySource, bool useTp1, bool useTp2, bool useTp3, bool useTp4, bool useTp5,  bool useTp6, float tp1x, float tp2x, float tp3x, float tp4x, float tp5x, float tp6x, float slx) =>
    long        = b_gameOVer
    short       = s_gameOver
    
    BentryPrice  =   buyEntrySource
    SentryPrice  =   sellEntrySource

    
    // Position Management Tools
    pos         = 0.0
    pos         := long? 1 : short? -1 : pos[1]
    
    longCond1   = long and pos[1]!= 1
    shortCond1  = short and pos[1]!=-1
    
    buySignal   = long and longCond1
    sellSignal  = short and shortCond1
    
    var int trade_state = 0
    var float tp1       = na
    var float tp2       = na
    var float tp3       = na
    var float tp4       = na
    var float tp5       = na
    var float tp6       = na
    var float sl        = na
    var float entry1    = na
    var int et          = 0
    var entry_hit       = false
    var tp1_hit         = false
    var tp2_hit         = false
    var tp3_hit         = false
    var tp4_hit         = false
    var tp5_hit         = false
    var tp6_hit         = false
    
    var sl_hit          = false
    
    line l11    = na
    line l2     = na
    line l3     = na
    line l4     = na
    line l5     = na
    line l6     = na
    line l7     = na
    line l8     = na
    
    label lb11  = na
    label lb2   = na
    label lb3   = na
    label lb4   = na
    label lb5   = na
    label lb6   = na
    label lb7   = na
    label lb8   = na
    
    label lb_entryHit  = na
    label lb_buyTP1  = na
    label lb_buyTP2  = na
    label lb_buyTP3  = na
    label lb_buyTP4  = na
    label lb_buyTP5  = na
    label lb_buyTP6  = na
    label lb_buySL   = na
    
    label lb_sellTP1 = na
    label lb_sellTP2 = na
    label lb_sellTP3 = na
    label lb_sellTP4 = na
    label lb_sellTP5 = na
    label lb_sellTP6 = na
    label lb_sellSL  = na
    
    
    dt          = time - time[1]
    
    
    
    if trade_state == 1 and useSignal 
    
        if sellSignal
            trade_state := 0
        
        if entry_hit == false and ta.cross(low ,entry1) or ta.cross(high, entry1)
            entry_hit   := true
        
        if entry_hit == true and tp1_hit == false and high >= tp1
            tp1_hit     := true
        if entry_hit == true and tp2_hit == false and high >= tp2
            tp2_hit     := true   
        if entry_hit == true and tp3_hit == false and high >= tp3
            tp3_hit     := true         
        if entry_hit == true and tp4_hit == false and high >= tp4
            tp4_hit     := true    
        if entry_hit == true and tp5_hit == false and high >= tp5
            tp5_hit     := true 
        if entry_hit == true and tp6_hit == false and high >= tp6
            tp6_hit     := true 
    
        if entry_hit == true and low <= sl
            trade_state := 0
            sl_hit      := low <= sl

    if trade_state == -1 and useSignal 
        if buySignal
            trade_state := 0
            
        if  entry_hit == false and ta.cross(low ,entry1) or ta.cross(high, entry1)
            entry_hit   := true
        
        if entry_hit == true and tp1_hit == false and low <= tp1
            tp1_hit     := true
        if entry_hit == true and tp2_hit == false and low <= tp2
            tp2_hit     := true
        if entry_hit == true and tp3_hit == false and low <= tp3
            tp3_hit     := true      
        if entry_hit == true and tp4_hit == false and low <= tp4
            tp4_hit     := true    
    	if entry_hit == true and tp5_hit == false and low <= tp5
            tp5_hit     := true
        if entry_hit == true and tp6_hit == false and low <= tp6
            tp6_hit     := true 
    
        if entry_hit == true and high >= sl
            trade_state := 0
            sl_hit      := high >= sl

            
      
    if trade_state == 0 and useSignal 
        if buySignal  
            trade_state := 1
            
            entry_hit   := false
            tp1_hit     := false
            tp2_hit     := false
            tp3_hit     := false
            tp4_hit     := false
            tp5_hit     := false
            tp6_hit     := false
            sl_hit      := false
            
            entry1      := round_price(BentryPrice)
            et          := time
            tp1         := round_price(entry1  * (1 + (tp1x / 100)))
            tp2         := round_price(entry1  * (1 + (tp2x / 100)))
            tp3         := round_price(entry1  * (1 + (tp3x / 100)))
            tp4         := round_price(entry1  * (1 + (tp4x / 100)))
            tp5         := round_price(entry1  * (1 + (tp5x / 100)))
            tp6         := round_price(entry1  * (1 + (tp6x / 100)))
            sl          := round_price(entry1  * (1 - (slx  / 100)))
    
        if sellSignal 
            trade_state := -1
            
            entry_hit   := false
            tp1_hit     := false
            tp2_hit     := false
            tp3_hit     := false
            tp4_hit     := false
            tp5_hit     := false
            tp6_hit     := false
            sl_hit      := false
            
            entry1      := round_price(SentryPrice)
            et          := time
            tp1         := round_price(entry1  * (1 - (tp1x / 100)))
            tp2         := round_price(entry1  * (1 - (tp2x / 100)))
            tp3         := round_price(entry1  * (1 - (tp3x / 100)))
            tp4         := round_price(entry1  * (1 - (tp4x / 100)))
            tp5         := round_price(entry1  * (1 - (tp5x / 100)))
            tp6         := round_price(entry1  * (1 - (tp6x / 100)))
            sl          := round_price(entry1  * (1 + (slx  / 100))) 
    
    if trade_state[1] == -1 and useSignal  
        if barstate.islast
            l11     := line.new(et, entry1, time + dt * 2, entry1,  color=color.purple, style=line.style_solid,xloc = xloc.bar_time)
            l2      := line.new(et, sl,     time + dt * 2,  sl,     color=color.red,    style=line.style_solid,xloc = xloc.bar_time)
            
            l3      := line.new(useTp1 ? et : na, useTp1 ? tp1 : na,useTp1 ?time + dt * 2:na,useTp1 ? tp1 : na,color=color.green,style=line.style_solid,xloc = xloc.bar_time)
            l4      := line.new(useTp2 ? et : na, useTp2 ? tp2 : na,useTp2 ?time + dt * 2:na,useTp2 ? tp2 : na,color=color.green,style=line.style_solid,xloc = xloc.bar_time)
            l5      := line.new(useTp3 ? et : na, useTp3 ? tp3 : na,useTp3 ?time + dt * 2:na,useTp3 ? tp3 : na,color=color.green,style=line.style_solid,xloc = xloc.bar_time)
            l6      := line.new(useTp4 ? et : na, useTp4 ? tp4 : na,useTp4 ?time + dt * 2:na,useTp4 ? tp4 : na,color=color.green,style=line.style_solid,xloc = xloc.bar_time)
            l7      := line.new(useTp5 ? et : na, useTp5 ? tp5 : na,useTp5 ?time + dt * 2:na,useTp5 ? tp5 : na,color=color.green,style=line.style_solid,xloc = xloc.bar_time)
            l8      := line.new(useTp6 ? et : na, useTp6 ? tp6 : na,useTp6 ?time + dt * 2:na,useTp6 ? tp6 : na,color=color.green,style=line.style_solid,xloc = xloc.bar_time)
    
            lb11    := label.new(time + dt * 4, entry1, text=str.tostring(sName) +"Entry:" + str.tostring(entry1),color=color.blue,textcolor=color.black,style=label.style_label_left,xloc = xloc.bar_time,textalign=text.align_left,size=size.normal)
            lb2     := label.new(time + dt * 4, sl,     text=str.tostring(sName) +"Stop:" + str.tostring(sl),color=color.red,textcolor=color.black,style=label.style_label_left,xloc = xloc.bar_time,textalign=text.align_left,size=size.normal)

            lb3     := label.new(useTp1 ? time + dt * 4 : na, tp1,text=str.tostring(sName) +"TP1:" + str.tostring(tp1),color=color.green,textcolor=color.black,style=label.style_label_left,xloc = xloc.bar_time,textalign=text.align_left,size=size.normal)
            lb4     := label.new(useTp2 ? time + dt * 4 : na, tp2,text=str.tostring(sName) +"TP2:" + str.tostring(tp2),color=color.green,textcolor=color.black,style=label.style_label_left,xloc = xloc.bar_time,textalign=text.align_left,size=size.normal)
            lb5     := label.new(useTp3 ? time + dt * 4 : na, tp3,text=str.tostring(sName) +"TP3:" + str.tostring(tp3),color=color.green,textcolor=color.black,style=label.style_label_left,xloc = xloc.bar_time,textalign=text.align_left,size=size.normal)
    		lb6     := label.new(useTp4 ? time + dt * 4 : na, tp4,text=str.tostring(sName) +"TP4:" + str.tostring(tp4),color=color.green,textcolor=color.black,style=label.style_label_left,xloc = xloc.bar_time,textalign=text.align_left,size=size.normal)
    		lb7     := label.new(useTp5 ? time + dt * 4 : na, tp5,text=str.tostring(sName) +"TP5:" + str.tostring(tp5),color=color.green,textcolor=color.black,style=label.style_label_left,xloc = xloc.bar_time,textalign=text.align_left,size=size.normal)
    		lb8     := label.new(useTp6 ? time + dt * 4 : na, tp6,text=str.tostring(sName) +"TP6:" + str.tostring(tp6),color=color.green,textcolor=color.black,style=label.style_label_left,xloc = xloc.bar_time,textalign=text.align_left,size=size.normal)
    
    if trade_state[1] == 1 and useSignal 
        if barstate.islast
            l11     := line.new(et, entry1, time + dt * 2,  entry1, color=color.purple, style=line.style_solid,xloc = xloc.bar_time)
            l2      := line.new(et, sl,     time + dt * 2,  sl,     color=color.red,    style=line.style_solid,xloc = xloc.bar_time)
            
            //TPS
            l3      := line.new(useTp1 ? et : na, useTp1 ? tp1 : na,useTp1 ?time + dt * 2:na,useTp1 ? tp1 : na,color=color.green,style=line.style_solid,xloc = xloc.bar_time)
            l4      := line.new(useTp2 ? et : na, useTp2 ? tp2 : na,useTp2 ?time + dt * 2:na,useTp2 ? tp2 : na,color=color.green,style=line.style_solid,xloc = xloc.bar_time)
            l5      := line.new(useTp3 ? et : na, useTp3 ? tp3 : na,useTp3 ?time + dt * 2:na,useTp3 ? tp3 : na,color=color.green,style=line.style_solid,xloc = xloc.bar_time)
            l6      := line.new(useTp4 ? et : na, useTp4 ? tp4 : na,useTp4 ?time + dt * 2:na,useTp4 ? tp4 : na,color=color.green,style=line.style_solid,xloc = xloc.bar_time)
            l7      := line.new(useTp5 ? et : na, useTp5 ? tp5 : na,useTp5 ?time + dt * 2:na,useTp5 ? tp5 : na,color=color.green,style=line.style_solid,xloc = xloc.bar_time)
            l8      := line.new(useTp6 ? et : na, useTp6 ? tp6 : na,useTp6 ?time + dt * 2:na,useTp6 ? tp6 : na,color=color.green,style=line.style_solid,xloc = xloc.bar_time)
    
            lb11    := label.new(time + dt * 4, entry1,text=str.tostring(bName) +"Entry:" + str.tostring(entry1),color=color.blue,textcolor=color.black,style=label.style_label_left,xloc = xloc.bar_time,textalign=text.align_left,size=size.normal)
            lb2     := label.new(time + dt * 4, sl,text=str.tostring(bName) +"Stop:" + str.tostring(sl),color=color.red,textcolor=color.black,style=label.style_label_left,xloc = xloc.bar_time,textalign=text.align_left,size=size.normal)
            //TPS
            lb3     := label.new(useTp1 ? time + dt * 4 : na, tp1,text=str.tostring(bName) +"TP1:" + str.tostring(tp1),color=color.green,textcolor=color.black,style=label.style_label_left,xloc = xloc.bar_time,textalign=text.align_left,size=size.normal)
            lb4     := label.new(useTp2 ? time + dt * 4 : na, tp2,text=str.tostring(bName) +"TP2:" + str.tostring(tp2),color=color.green,textcolor=color.black,style=label.style_label_left,xloc = xloc.bar_time,textalign=text.align_left,size=size.normal)
            lb5     := label.new(useTp3 ? time + dt * 4 : na, tp3,text=str.tostring(bName) +"TP3:" + str.tostring(tp3),color=color.green,textcolor=color.black,style=label.style_label_left,xloc = xloc.bar_time,textalign=text.align_left,size=size.normal)
            lb6     := label.new(useTp4 ? time + dt * 4 : na, tp4,text=str.tostring(bName) +"TP4:" + str.tostring(tp4),color=color.green,textcolor=color.black,style=label.style_label_left,xloc = xloc.bar_time,textalign=text.align_left,size=size.normal)
    		lb7     := label.new(useTp5 ? time + dt * 4 : na, tp5,text=str.tostring(bName) +"TP5:" + str.tostring(tp5),color=color.green,textcolor=color.black,style=label.style_label_left,xloc = xloc.bar_time,textalign=text.align_left,size=size.normal)
    		lb8     := label.new(useTp6 ? time + dt * 4 : na, tp6,text=str.tostring(bName) +"TP6:" + str.tostring(tp6),color=color.green,textcolor=color.black,style=label.style_label_left,xloc = xloc.bar_time,textalign=text.align_left,size=size.normal)
    
    line.delete(l11[1])
    label.delete(lb11[1])
    line.delete(l2[1])
    label.delete(lb2[1])
    line.delete(l3[1])
    label.delete(lb3[1])
    line.delete(l4[1])
    label.delete(lb4[1])
    line.delete(l5[1])
    label.delete(lb5[1])
    line.delete(l6[1])
    label.delete(lb6[1])
    line.delete(l7[1])
    label.delete(lb7[1])
    line.delete(l8[1])
    label.delete(lb8[1])
    //--------------------------------------------------------------------
    //                     ENTRY && EXIT
    //--------------------------------------------------------------------
    official_buy    = trade_state == 1  and trade_state != trade_state[1]
    official_sell   = trade_state == -1 and trade_state != trade_state[1]
    
    entry_touched   = not entry_hit[1] and  entry_hit
    
    buyTP1_touched  = trade_state[1] == 1 and tp1_hit and tp1_hit[1]==false
    buyTP2_touched  = useTp2 and trade_state[1] == 1 and tp2_hit and tp2_hit[1]==false
    buyTP3_touched  = useTp3 and trade_state[1] == 1 and tp3_hit and tp3_hit[1]==false
    buyTP4_touched  = useTp4 and trade_state[1] == 1 and tp4_hit and tp4_hit[1]==false
    buyTP5_touched  = useTp5 and trade_state[1] == 1 and tp5_hit and tp5_hit[1]==false
    buyTP6_touched  = useTp6 and trade_state[1] == 1 and tp6_hit and tp6_hit[1]==false
    buySL_touched   = trade_state[1] == 1 and sl_hit and tp1_hit==false
    
    sellTP1_touched = trade_state[1] == -1 and tp1_hit and tp1_hit[1]==false
    sellTP2_touched = useTp2 and trade_state[1] == -1 and tp2_hit and tp2_hit[1]==false
    sellTP3_touched = useTp3 and trade_state[1] == -1 and tp3_hit and tp3_hit[1]==false
    sellTP4_touched = useTp4 and trade_state[1] == -1 and tp4_hit and tp4_hit[1]==false
    sellTP5_touched = useTp5 and trade_state[1] == -1 and tp5_hit and tp5_hit[1]==false
    sellTP6_touched = useTp6 and trade_state[1] == -1 and tp6_hit and tp6_hit[1]==false
    sellSL_touched  = trade_state[1] == -1 and sl_hit and tp1_hit==false
    
    if trade_state == 1 and entry_touched and useSignal
        lb_entryHit := label.new(bar_index, na, text=str.tostring(bName) +"entry",color=color.purple,  textcolor=color.black,  style=label.style_cross,xloc = xloc.bar_index,  yloc=yloc.belowbar, textalign=text.align_left,size=size.normal)
    
    if trade_state == -1 and entry_touched and useSignal
        lb_entryHit := label.new(bar_index, na, text=str.tostring(sName) +"entry",color=color.purple,  textcolor=color.black,  style=label.style_cross,xloc = xloc.bar_index,  yloc=yloc.abovebar, textalign=text.align_left,size=size.normal)
    
   
    if buyTP1_touched and useSignal 
        lb_buyTP1   := label.new(bar_index, na, text=str.tostring(bName) +"TP1",color=color.green,  textcolor=color.black,  style=label.style_cross,xloc = xloc.bar_index,  yloc=yloc.abovebar, textalign=text.align_left,size=size.normal)
    
    if buyTP2_touched and useSignal 
        lb_buyTP2   := label.new(bar_index, na, text=str.tostring(bName) +"TP2",color=color.yellow, textcolor=color.black,  style=label.style_cross,xloc = xloc.bar_index,  yloc=yloc.abovebar, textalign=text.align_left,size=size.normal)
    
    if buyTP3_touched and useSignal 
        lb_buyTP3   := label.new(bar_index, na, text=str.tostring(bName) +"TP3",color=color.orange, textcolor=color.black,  style=label.style_cross,xloc = xloc.bar_index,  yloc=yloc.abovebar, textalign=text.align_left,size=size.normal)
    
    if buyTP4_touched and useSignal 
        lb_buyTP4   := label.new(bar_index, na, text=str.tostring(bName) +"TP4",color=color.gray,   textcolor=color.black,  style=label.style_cross,xloc = xloc.bar_index,  yloc=yloc.abovebar, textalign=text.align_left,size=size.normal)

    if buyTP5_touched and useSignal 
        lb_buyTP5   := label.new(bar_index, na, text=str.tostring(bName) +"TP5",color=color.lime,   textcolor=color.black,  style=label.style_cross,xloc = xloc.bar_index,  yloc=yloc.abovebar, textalign=text.align_left,size=size.normal)

    if buyTP6_touched and useSignal 
        lb_buyTP6   := label.new(bar_index, na, text=str.tostring(bName) +"TP6",color=color.black,  textcolor=color.black,  style=label.style_cross,xloc = xloc.bar_index,  yloc=yloc.abovebar, textalign=text.align_left,size=size.normal)

    if buySL_touched and useSignal 
        lb_buySL   := label.new(bar_index, na,  text=str.tostring(bName) + "SL",color=color.red,    textcolor=color.black,  style=label.style_cross,xloc = xloc.bar_index,  yloc=yloc.abovebar, textalign=text.align_left,size=size.normal)



    if sellTP1_touched and useSignal 
        lb_sellTP1 := label.new(bar_index, na, text=str.tostring(sName) +"TP1",color=color.green,   textcolor=color.black,  style=label.style_cross,xloc = xloc.bar_index,  yloc=yloc.belowbar, textalign=text.align_left,size=size.normal)
    
    if sellTP2_touched and useSignal 
        lb_sellTP2 := label.new(bar_index, na, text=str.tostring(sName) +"TP2",color=color.yellow,  textcolor=color.black,  style=label.style_cross,xloc = xloc.bar_index,  yloc=yloc.belowbar, textalign=text.align_left,size=size.normal)

    if sellTP3_touched and useSignal 
        lb_sellTP3 := label.new(bar_index, na, text=str.tostring(sName) +"TP3",color=color.orange,  textcolor=color.black,  style=label.style_cross,xloc = xloc.bar_index,  yloc=yloc.belowbar, textalign=text.align_left,size=size.normal)

    if sellTP4_touched and useSignal 
        lb_sellTP4 := label.new(bar_index, na, text=str.tostring(sName) +"TP4",color=color.gray,    textcolor=color.black,  style=label.style_cross,xloc = xloc.bar_index,  yloc=yloc.belowbar, textalign=text.align_left,size=size.normal)

    if sellTP5_touched and useSignal 
        lb_sellTP5 := label.new(bar_index, na, text=str.tostring(sName) +"TP5",color=color.lime,    textcolor=color.black,  style=label.style_cross,xloc = xloc.bar_index,  yloc=yloc.belowbar, textalign=text.align_left,size=size.normal)

    if sellTP6_touched and useSignal 
        lb_sellTP6 := label.new(bar_index, na, text=str.tostring(sName) +"TP6",color=color.black,   textcolor=color.black,  style=label.style_cross,xloc = xloc.bar_index,  yloc=yloc.belowbar, textalign=text.align_left,size=size.normal)

    if sellSL_touched and useSignal 
        lb_sellSL := label.new(bar_index, na,  text=str.tostring(sName) + "SL",color=color.red,     textcolor=color.black,  style=label.style_cross,xloc = xloc.bar_index,  yloc=yloc.belowbar, textalign=text.align_left,size=size.normal)

    
    [entry_touched, entry1, tp1, tp2, tp3, tp4, tp5, tp6, sl, official_buy, official_sell, buyTP1_touched, buyTP2_touched, buyTP3_touched, buyTP4_touched, buyTP5_touched, buyTP6_touched, buySL_touched , sellTP1_touched, sellTP2_touched, sellTP3_touched, sellTP4_touched, sellTP5_touched, sellTP6_touched, sellSL_touched]

// ======================================================================================================================================================================================================================================================================= \\

// @function Track TakeProfits and StopLoss achievement for one or many of your buy/sell conditions. CHECK the commented section:  "Function @manageFilterredTrade" (lines: 66 - 118) for Description
// @param bool useSignal.
// @param bool b_gameOVer.
// @param bool longCancel.
// @param bool s_gameOVer.
// @param bool shortCancel.
// @param string bName.
// @param string sName.
// @param float buyEntrySource.
// @param float sellEntrySource.
// @param bool useTp1.
// @param bool useTp2.
// @param bool useTp3.
// @param bool useTp4.
// @param bool useTp5.
// @param bool useTp6.
// @param float tp1x.
// @param float tp2x.
// @param float tp3x.
// @param float tp4x.
// @param float tp5x.
// @param float tp6x.
// @param float slx.
// @returns check commented section:  "Function @manageFilterredTrade" (lines: 66 - 118).
export manageFilteredTrade(bool useSignal, bool b_gameOVer, bool longCancel, bool s_gameOver, bool shortCancel, string bName, string sName, float buyEntrySource, float sellEntrySource, bool useTp1, bool useTp2, bool useTp3, bool useTp4, bool useTp5,  bool useTp6, float tp1x, float tp2x, float tp3x, float tp4x, float tp5x, float tp6x, float slx) =>
    // long        = b_gameOVer
    // short       = s_gameOver
    
    BentryPrice  =   buyEntrySource
    SentryPrice  =   sellEntrySource

    // // Position Management Tools
    // pos         = 0.0
    // pos         := long? 1 : short? -1 : pos[1]
    
    // longCond1   = b_gameOVer //and pos[1]!= 1
    // shortCond1  = s_gameOver// and pos[1]!=-1
    
    buySignal   = b_gameOVer //and longCond1
    sellSignal  = s_gameOver // shortCond1
    
    var int trade_state = 0
    var float tp1       = na
    var float tp2       = na
    var float tp3       = na
    var float tp4       = na
    var float tp5       = na
    var float tp6       = na
    var float sl        = na
    var float entry1    = na
    var int et          = 0
    var entry_hit       = false
    var tp1_hit         = false
    var tp2_hit         = false
    var tp3_hit         = false
    var tp4_hit         = false
    var tp5_hit         = false
    var tp6_hit         = false
    
    var sl_hit          = false
    
    line l11            = na
    line l2             = na
    line l3             = na
    line l4             = na
    line l5             = na
    line l6             = na
    line l7             = na
    line l8             = na
    
    label lb11          = na
    label lb2           = na
    label lb3           = na
    label lb4           = na
    label lb5           = na
    label lb6           = na
    label lb7           = na
    label lb8           = na
    
    label lb_entryHit   = na
    label lb_buyTP1     = na
    label lb_buyTP2     = na
    label lb_buyTP3     = na
    label lb_buyTP4     = na
    label lb_buyTP5     = na
    label lb_buyTP6     = na
    label lb_buySL      = na
    
    label lb_sellTP1    = na
    label lb_sellTP2    = na
    label lb_sellTP3    = na
    label lb_sellTP4    = na
    label lb_sellTP5    = na
    label lb_sellTP6    = na
    label lb_sellSL     = na
    
    
    dt                  = time - time[1]
    
    if trade_state != 0
        if longCancel
            trade_state := 0
            
        if shortCancel
            trade_state := 0
    
    if trade_state == 1 and useSignal 
    
        if sellSignal
            trade_state := 0
        
        if entry_hit == false and ta.cross(low ,entry1) or ta.cross(high, entry1)
            entry_hit   := true
        
        if entry_hit == true and tp1_hit == false and high >= tp1
            tp1_hit     := true
        if entry_hit == true and tp2_hit == false and high >= tp2
            tp2_hit     := true   
        if entry_hit == true and tp3_hit == false and high >= tp3
            tp3_hit     := true         
        if entry_hit == true and tp4_hit == false and high >= tp4
            tp4_hit     := true    
        if entry_hit == true and tp5_hit == false and high >= tp5
            tp5_hit     := true 
        if entry_hit == true and tp6_hit == false and high >= tp6
            tp6_hit     := true 
    
        if entry_hit == true and low <= sl
            trade_state := 0
            sl_hit      := low <= sl

    if trade_state == -1 and useSignal 
        if buySignal
            trade_state := 0
            
        if  entry_hit == false and ta.cross(low ,entry1) or ta.cross(high, entry1)
            entry_hit   := true
        
        if entry_hit == true and tp1_hit == false and low <= tp1
            tp1_hit     := true
        if entry_hit == true and tp2_hit == false and low <= tp2
            tp2_hit     := true
        if entry_hit == true and tp3_hit == false and low <= tp3
            tp3_hit     := true      
        if entry_hit == true and tp4_hit == false and low <= tp4
            tp4_hit     := true    
    	if entry_hit == true and tp5_hit == false and low <= tp5
            tp5_hit     := true
        if entry_hit == true and tp6_hit == false and low <= tp6
            tp6_hit     := true 
    
        if entry_hit == true and high >= sl
            trade_state := 0
            sl_hit      := high >= sl

            
      
    if trade_state == 0 and useSignal 
        if buySignal  
            trade_state := 1
            
            entry_hit   := false
            tp1_hit     := false
            tp2_hit     := false
            tp3_hit     := false
            tp4_hit     := false
            tp5_hit     := false
            tp6_hit     := false
            sl_hit      := false
            
            entry1      := round_price(BentryPrice)
            et          := time
            tp1         := round_price(entry1  * (1 + (tp1x / 100)))
            tp2         := round_price(entry1  * (1 + (tp2x / 100)))
            tp3         := round_price(entry1  * (1 + (tp3x / 100)))
            tp4         := round_price(entry1  * (1 + (tp4x / 100)))
            tp5         := round_price(entry1  * (1 + (tp5x / 100)))
            tp6         := round_price(entry1  * (1 + (tp6x / 100)))
            sl          := round_price(entry1  * (1 - (slx  / 100)))
    
        if sellSignal 
            trade_state := -1
            
            entry_hit   := false
            tp1_hit     := false
            tp2_hit     := false
            tp3_hit     := false
            tp4_hit     := false
            tp5_hit     := false
            tp6_hit     := false
            sl_hit      := false
            
            entry1      := round_price(SentryPrice)
            et          := time
            tp1         := round_price(entry1  * (1 - (tp1x / 100)))
            tp2         := round_price(entry1  * (1 - (tp2x / 100)))
            tp3         := round_price(entry1  * (1 - (tp3x / 100)))
            tp4         := round_price(entry1  * (1 - (tp4x / 100)))
            tp5         := round_price(entry1  * (1 - (tp5x / 100)))
            tp6         := round_price(entry1  * (1 - (tp6x / 100)))
            sl          := round_price(entry1  * (1 + (slx  / 100))) 
    
    if trade_state[1] == -1 and useSignal  
        if barstate.islast
            l11     := line.new(et, entry1, time + dt * 2, entry1,  color=color.purple, style=line.style_solid,xloc = xloc.bar_time)
            l2      := line.new(et, sl,     time + dt * 2,  sl,     color=color.red,    style=line.style_solid,xloc = xloc.bar_time)
            
            l3      := line.new(useTp1 ? et : na, useTp1 ? tp1 : na,useTp1 ?time + dt * 2:na,useTp1 ? tp1 : na,color=color.green,style=line.style_solid,xloc = xloc.bar_time)
            l4      := line.new(useTp2 ? et : na, useTp2 ? tp2 : na,useTp2 ?time + dt * 2:na,useTp2 ? tp2 : na,color=color.green,style=line.style_solid,xloc = xloc.bar_time)
            l5      := line.new(useTp3 ? et : na, useTp3 ? tp3 : na,useTp3 ?time + dt * 2:na,useTp3 ? tp3 : na,color=color.green,style=line.style_solid,xloc = xloc.bar_time)
            l6      := line.new(useTp4 ? et : na, useTp4 ? tp4 : na,useTp4 ?time + dt * 2:na,useTp4 ? tp4 : na,color=color.green,style=line.style_solid,xloc = xloc.bar_time)
            l7      := line.new(useTp5 ? et : na, useTp5 ? tp5 : na,useTp5 ?time + dt * 2:na,useTp5 ? tp5 : na,color=color.green,style=line.style_solid,xloc = xloc.bar_time)
            l8      := line.new(useTp6 ? et : na, useTp6 ? tp6 : na,useTp6 ?time + dt * 2:na,useTp6 ? tp6 : na,color=color.green,style=line.style_solid,xloc = xloc.bar_time)
    
            lb11    := label.new(time + dt * 4, entry1, text=str.tostring(sName) +"Entry:" + str.tostring(entry1),color=color.blue,textcolor=color.black,style=label.style_label_left,xloc = xloc.bar_time,textalign=text.align_left,size=size.normal)
            lb2     := label.new(time + dt * 4, sl,     text=str.tostring(sName) +"Stop:" + str.tostring(sl),color=color.red,textcolor=color.black,style=label.style_label_left,xloc = xloc.bar_time,textalign=text.align_left,size=size.normal)

            lb3     := label.new(useTp1 ? time + dt * 4 : na, tp1,text=str.tostring(sName) +"TP1:" + str.tostring(tp1),color=color.green,textcolor=color.black,style=label.style_label_left,xloc = xloc.bar_time,textalign=text.align_left,size=size.normal)
            lb4     := label.new(useTp2 ? time + dt * 4 : na, tp2,text=str.tostring(sName) +"TP2:" + str.tostring(tp2),color=color.green,textcolor=color.black,style=label.style_label_left,xloc = xloc.bar_time,textalign=text.align_left,size=size.normal)
            lb5     := label.new(useTp3 ? time + dt * 4 : na, tp3,text=str.tostring(sName) +"TP3:" + str.tostring(tp3),color=color.green,textcolor=color.black,style=label.style_label_left,xloc = xloc.bar_time,textalign=text.align_left,size=size.normal)
    		lb6     := label.new(useTp4 ? time + dt * 4 : na, tp4,text=str.tostring(sName) +"TP4:" + str.tostring(tp4),color=color.green,textcolor=color.black,style=label.style_label_left,xloc = xloc.bar_time,textalign=text.align_left,size=size.normal)
    		lb7     := label.new(useTp5 ? time + dt * 4 : na, tp5,text=str.tostring(sName) +"TP5:" + str.tostring(tp5),color=color.green,textcolor=color.black,style=label.style_label_left,xloc = xloc.bar_time,textalign=text.align_left,size=size.normal)
    		lb8     := label.new(useTp6 ? time + dt * 4 : na, tp6,text=str.tostring(sName) +"TP6:" + str.tostring(tp6),color=color.green,textcolor=color.black,style=label.style_label_left,xloc = xloc.bar_time,textalign=text.align_left,size=size.normal)
    
    if trade_state[1] == 1 and useSignal 
        if barstate.islast
            l11     := line.new(et, entry1, time + dt * 2,  entry1, color=color.purple, style=line.style_solid,xloc = xloc.bar_time)
            l2      := line.new(et, sl,     time + dt * 2,  sl,     color=color.red,    style=line.style_solid,xloc = xloc.bar_time)
            
            //TPS
            l3      := line.new(useTp1 ? et : na, useTp1 ? tp1 : na,useTp1 ?time + dt * 2:na,useTp1 ? tp1 : na,color=color.green,style=line.style_solid,xloc = xloc.bar_time)
            l4      := line.new(useTp2 ? et : na, useTp2 ? tp2 : na,useTp2 ?time + dt * 2:na,useTp2 ? tp2 : na,color=color.green,style=line.style_solid,xloc = xloc.bar_time)
            l5      := line.new(useTp3 ? et : na, useTp3 ? tp3 : na,useTp3 ?time + dt * 2:na,useTp3 ? tp3 : na,color=color.green,style=line.style_solid,xloc = xloc.bar_time)
            l6      := line.new(useTp4 ? et : na, useTp4 ? tp4 : na,useTp4 ?time + dt * 2:na,useTp4 ? tp4 : na,color=color.green,style=line.style_solid,xloc = xloc.bar_time)
            l7      := line.new(useTp5 ? et : na, useTp5 ? tp5 : na,useTp5 ?time + dt * 2:na,useTp5 ? tp5 : na,color=color.green,style=line.style_solid,xloc = xloc.bar_time)
            l8      := line.new(useTp6 ? et : na, useTp6 ? tp6 : na,useTp6 ?time + dt * 2:na,useTp6 ? tp6 : na,color=color.green,style=line.style_solid,xloc = xloc.bar_time)
    
            lb11    := label.new(time + dt * 4, entry1,text=str.tostring(bName) +"Entry:" + str.tostring(entry1),color=color.blue,textcolor=color.black,style=label.style_label_left,xloc = xloc.bar_time,textalign=text.align_left,size=size.normal)
            lb2     := label.new(time + dt * 4, sl,text=str.tostring(bName) +"Stop:" + str.tostring(sl),color=color.red,textcolor=color.black,style=label.style_label_left,xloc = xloc.bar_time,textalign=text.align_left,size=size.normal)
            //TPS
            lb3     := label.new(useTp1 ? time + dt * 4 : na, tp1,text=str.tostring(bName) +"TP1:" + str.tostring(tp1),color=color.green,textcolor=color.black,style=label.style_label_left,xloc = xloc.bar_time,textalign=text.align_left,size=size.normal)
            lb4     := label.new(useTp2 ? time + dt * 4 : na, tp2,text=str.tostring(bName) +"TP2:" + str.tostring(tp2),color=color.green,textcolor=color.black,style=label.style_label_left,xloc = xloc.bar_time,textalign=text.align_left,size=size.normal)
            lb5     := label.new(useTp3 ? time + dt * 4 : na, tp3,text=str.tostring(bName) +"TP3:" + str.tostring(tp3),color=color.green,textcolor=color.black,style=label.style_label_left,xloc = xloc.bar_time,textalign=text.align_left,size=size.normal)
            lb6     := label.new(useTp4 ? time + dt * 4 : na, tp4,text=str.tostring(bName) +"TP4:" + str.tostring(tp4),color=color.green,textcolor=color.black,style=label.style_label_left,xloc = xloc.bar_time,textalign=text.align_left,size=size.normal)
    		lb7     := label.new(useTp5 ? time + dt * 4 : na, tp5,text=str.tostring(bName) +"TP5:" + str.tostring(tp5),color=color.green,textcolor=color.black,style=label.style_label_left,xloc = xloc.bar_time,textalign=text.align_left,size=size.normal)
    		lb8     := label.new(useTp6 ? time + dt * 4 : na, tp6,text=str.tostring(bName) +"TP6:" + str.tostring(tp6),color=color.green,textcolor=color.black,style=label.style_label_left,xloc = xloc.bar_time,textalign=text.align_left,size=size.normal)
    
    line.delete(l11[1])
    label.delete(lb11[1])
    line.delete(l2[1])
    label.delete(lb2[1])
    line.delete(l3[1])
    label.delete(lb3[1])
    line.delete(l4[1])
    label.delete(lb4[1])
    line.delete(l5[1])
    label.delete(lb5[1])
    line.delete(l6[1])
    label.delete(lb6[1])
    line.delete(l7[1])
    label.delete(lb7[1])
    line.delete(l8[1])
    label.delete(lb8[1])
    //--------------------------------------------------------------------
    //                     ENTRY && EXIT
    //--------------------------------------------------------------------
    official_buy    = trade_state == 1  and trade_state != trade_state[1]
    official_sell   = trade_state == -1 and trade_state != trade_state[1]
    
    entry_touched   = not entry_hit[1] and  entry_hit
    
    buyTP1_touched  = trade_state[1] == 1 and tp1_hit and tp1_hit[1]==false
    buyTP2_touched  = useTp2 and trade_state[1] == 1 and tp2_hit and tp2_hit[1]==false
    buyTP3_touched  = useTp3 and trade_state[1] == 1 and tp3_hit and tp3_hit[1]==false
    buyTP4_touched  = useTp4 and trade_state[1] == 1 and tp4_hit and tp4_hit[1]==false
    buyTP5_touched  = useTp5 and trade_state[1] == 1 and tp5_hit and tp5_hit[1]==false
    buyTP6_touched  = useTp6 and trade_state[1] == 1 and tp6_hit and tp6_hit[1]==false
    buySL_touched   = trade_state[1] == 1 and sl_hit and tp1_hit==false
    
    sellTP1_touched = trade_state[1] == -1 and tp1_hit and tp1_hit[1]==false
    sellTP2_touched = useTp2 and trade_state[1] == -1 and tp2_hit and tp2_hit[1]==false
    sellTP3_touched = useTp3 and trade_state[1] == -1 and tp3_hit and tp3_hit[1]==false
    sellTP4_touched = useTp4 and trade_state[1] == -1 and tp4_hit and tp4_hit[1]==false
    sellTP5_touched = useTp5 and trade_state[1] == -1 and tp5_hit and tp5_hit[1]==false
    sellTP6_touched = useTp6 and trade_state[1] == -1 and tp6_hit and tp6_hit[1]==false
    sellSL_touched  = trade_state[1] == -1 and sl_hit and tp1_hit==false
    
    if trade_state == 1 and entry_touched and useSignal
        lb_entryHit := label.new(bar_index, na, text=str.tostring(bName) +"entry",color=color.purple,  textcolor=color.black,  style=label.style_cross,xloc = xloc.bar_index,  yloc=yloc.belowbar, textalign=text.align_left,size=size.normal)
    
    if trade_state == -1 and entry_touched and useSignal
        lb_entryHit := label.new(bar_index, na, text=str.tostring(sName) +"entry",color=color.purple,  textcolor=color.black,  style=label.style_cross,xloc = xloc.bar_index,  yloc=yloc.abovebar, textalign=text.align_left,size=size.normal)
    
    
    if buyTP1_touched and useSignal 
        lb_buyTP1   := label.new(bar_index, na, text=str.tostring(bName) +"TP1",color=color.green,  textcolor=color.black,  style=label.style_cross,xloc = xloc.bar_index,  yloc=yloc.abovebar, textalign=text.align_left,size=size.normal)
    
    if buyTP2_touched and useSignal 
        lb_buyTP2   := label.new(bar_index, na, text=str.tostring(bName) +"TP2",color=color.yellow, textcolor=color.black,  style=label.style_cross,xloc = xloc.bar_index,  yloc=yloc.abovebar, textalign=text.align_left,size=size.normal)
    
    if buyTP3_touched and useSignal 
        lb_buyTP3   := label.new(bar_index, na, text=str.tostring(bName) +"TP3",color=color.orange, textcolor=color.black,  style=label.style_cross,xloc = xloc.bar_index,  yloc=yloc.abovebar, textalign=text.align_left,size=size.normal)
    
    if buyTP4_touched and useSignal 
        lb_buyTP4   := label.new(bar_index, na, text=str.tostring(bName) +"TP4",color=color.gray,   textcolor=color.black,  style=label.style_cross,xloc = xloc.bar_index,  yloc=yloc.abovebar, textalign=text.align_left,size=size.normal)

    if buyTP5_touched and useSignal 
        lb_buyTP5   := label.new(bar_index, na, text=str.tostring(bName) +"TP5",color=color.lime,   textcolor=color.black,  style=label.style_cross,xloc = xloc.bar_index,  yloc=yloc.abovebar, textalign=text.align_left,size=size.normal)

    if buyTP6_touched and useSignal 
        lb_buyTP6   := label.new(bar_index, na, text=str.tostring(bName) +"TP6",color=color.black,  textcolor=color.black,  style=label.style_cross,xloc = xloc.bar_index,  yloc=yloc.abovebar, textalign=text.align_left,size=size.normal)

    if buySL_touched and useSignal 
        lb_buySL   := label.new(bar_index, na,  text=str.tostring(bName) + "SL",color=color.red,    textcolor=color.black,  style=label.style_cross,xloc = xloc.bar_index,  yloc=yloc.abovebar, textalign=text.align_left,size=size.normal)



    if sellTP1_touched and useSignal 
        lb_sellTP1 := label.new(bar_index, na, text=str.tostring(sName) +"TP1",color=color.green,   textcolor=color.black,  style=label.style_cross,xloc = xloc.bar_index,  yloc=yloc.belowbar, textalign=text.align_left,size=size.normal)
    
    if sellTP2_touched and useSignal 
        lb_sellTP2 := label.new(bar_index, na, text=str.tostring(sName) +"TP2",color=color.yellow,  textcolor=color.black,  style=label.style_cross,xloc = xloc.bar_index,  yloc=yloc.belowbar, textalign=text.align_left,size=size.normal)

    if sellTP3_touched and useSignal 
        lb_sellTP3 := label.new(bar_index, na, text=str.tostring(sName) +"TP3",color=color.orange,  textcolor=color.black,  style=label.style_cross,xloc = xloc.bar_index,  yloc=yloc.belowbar, textalign=text.align_left,size=size.normal)

    if sellTP4_touched and useSignal 
        lb_sellTP4 := label.new(bar_index, na, text=str.tostring(sName) +"TP4",color=color.gray,    textcolor=color.black,  style=label.style_cross,xloc = xloc.bar_index,  yloc=yloc.belowbar, textalign=text.align_left,size=size.normal)

    if sellTP5_touched and useSignal 
        lb_sellTP5 := label.new(bar_index, na, text=str.tostring(sName) +"TP5",color=color.lime,    textcolor=color.black,  style=label.style_cross,xloc = xloc.bar_index,  yloc=yloc.belowbar, textalign=text.align_left,size=size.normal)

    if sellTP6_touched and useSignal 
        lb_sellTP6 := label.new(bar_index, na, text=str.tostring(sName) +"TP6",color=color.black,   textcolor=color.black,  style=label.style_cross,xloc = xloc.bar_index,  yloc=yloc.belowbar, textalign=text.align_left,size=size.normal)

    if sellSL_touched and useSignal 
        lb_sellSL := label.new(bar_index, na,  text=str.tostring(sName) + "SL",color=color.red,     textcolor=color.black,  style=label.style_cross,xloc = xloc.bar_index,  yloc=yloc.belowbar, textalign=text.align_left,size=size.normal)

    
    [entry_touched, entry1, tp1, tp2, tp3, tp4, tp5, tp6, sl, official_buy, official_sell, buyTP1_touched, buyTP2_touched, buyTP3_touched, buyTP4_touched, buyTP5_touched, buyTP6_touched, buySL_touched , sellTP1_touched, sellTP2_touched, sellTP3_touched, sellTP4_touched, sellTP5_touched, sellTP6_touched, sellSL_touched]

// ======================================================================================================================================================================================================================================================================= \\


// @function Track 1 TakeProfit Level and  StopLoss  achievement for one or many of your buy/sell conditions. CHECK the commented section:  "Function @manageTrade" (lines: 120 - 144) for Description
// @param bool useSignal.
// @param bool b_gameOVer.
// @param bool s_gameOVer.
// @param string bName.
// @param string sName.
// @param float buyEntrySource.
// @param float sellEntrySource.
// @param float tp1x.
// @param float slx.
// @returns check commented section:  "Function @manageLevel" (lines: 120 - 144).
export manageLevel(bool useSignal, bool b_gameOVer, bool s_gameOver , string bName, string sName, float buyEntrySource, float sellEntrySource, float tp1x, float slx) =>
    long        = b_gameOVer
    short       = s_gameOver
    
    BentryPrice  =   buyEntrySource
    SentryPrice  =   sellEntrySource

    
    // Position Management Tools
    pos         = 0.0
    pos         := long? 1 : short? -1 : pos[1]
    
    longCond1   = long and pos[1]!= 1
    shortCond1  = short and pos[1]!=-1
    
    buySignal   = long and longCond1
    sellSignal  = short and shortCond1
    
    var int trade_state = 0
    var float tp1       = na
    var float sl        = na
    var float entry1    = na
    var int et          = 0
    var entry_hit       = false
    var tp1_hit         = false
    var sl_hit          = false
    
    line l11            = na
    line l2             = na
    line l3             = na
    line l4             = na

    
    label lb11          = na
    label lb2           = na
    label lb3           = na

    
    label lb_entryHit   = na
    label lb_buyTP1     = na
    label lb_buySL      = na
    label lb_sellTP1    = na
    label lb_sellSL     = na
    
    
    dt                  = time - time[1]
    
    
    
    if trade_state == 1 and useSignal 
    
        if sellSignal
            trade_state := 0
        
        if entry_hit == false and ta.cross(low ,entry1) or ta.cross(high, entry1)
            entry_hit   := true
        
        if entry_hit == true and tp1_hit == false and high >= tp1
            tp1_hit     := true
    
        if entry_hit == true and low <= sl
            trade_state := 0
            sl_hit      := low <= sl

    if trade_state == -1 and useSignal 
        if buySignal
            trade_state := 0
            
        if  entry_hit == false and ta.cross(low ,entry1) or ta.cross(high, entry1)
            entry_hit   := true
        
        if entry_hit == true and tp1_hit == false and low <= tp1
            tp1_hit     := true
    
        if entry_hit == true and high >= sl
            trade_state := 0
            sl_hit      := high >= sl

      
    if trade_state == 0 and useSignal 
        if buySignal  
            trade_state := 1
            
            entry_hit   := false
            tp1_hit     := false
            sl_hit      := false
            
            entry1      := round_price(BentryPrice)
            et          := time
            tp1         := round_price(entry1  * (1 + (tp1x / 100)))
            sl          := round_price(entry1  * (1 - (slx  / 100)))
    
        if sellSignal 
            trade_state := -1
            
            entry_hit   := false
            tp1_hit     := false
            sl_hit      := false
            
            entry1      := round_price(SentryPrice)
            et          := time
            tp1         := round_price(entry1  * (1 - (tp1x / 100)))
            sl          := round_price(entry1  * (1 + (slx  / 100))) 
    
    if trade_state[1] == -1 and useSignal  
        if barstate.islast
            l11     := line.new(et, entry1, time + dt * 2, entry1,  color=color.purple, style=line.style_solid,xloc = xloc.bar_time)
            l2      := line.new(et, sl,     time + dt * 2,  sl,     color=color.red,    style=line.style_solid,xloc = xloc.bar_time)
            l3      := line.new(et, tp1,    time + dt * 2,  tp1,    color=color.green,  style=line.style_solid,xloc = xloc.bar_time)
            
            lb11    := label.new(time + dt * 4, entry1, text=str.tostring(sName) +"Entry:" + str.tostring(entry1),  color=color.blue,textcolor=color.black,style=label.style_label_left,xloc = xloc.bar_time,textalign=text.align_left,size=size.normal)
            lb2     := label.new(time + dt * 4, sl,     text=str.tostring(sName) +"Stop:" + str.tostring(sl),       color=color.red,textcolor=color.black,style=label.style_label_left,xloc = xloc.bar_time,textalign=text.align_left,size=size.normal)
            lb3     := label.new(time + dt * 4, tp1,    text=str.tostring(sName) +"TP1:" + str.tostring(tp1),       color=color.green,textcolor=color.black,style=label.style_label_left,xloc = xloc.bar_time,textalign=text.align_left,size=size.normal)
            
    if trade_state[1] == 1 and useSignal 
        if barstate.islast
            l11     := line.new(et, entry1, time + dt * 2,  entry1, color=color.purple, style=line.style_solid,xloc = xloc.bar_time)
            l2      := line.new(et, sl,     time + dt * 2,  sl,     color=color.red,    style=line.style_solid,xloc = xloc.bar_time)
            l3      := line.new(et, tp1,    time + dt * 2,  tp1,    color=color.green,  style=line.style_solid,xloc = xloc.bar_time)
            
            lb11    := label.new(time + dt * 4, entry1, text=str.tostring(bName) +"Entry:" + str.tostring(entry1),  color=color.blue,textcolor=color.black,style=label.style_label_left,xloc = xloc.bar_time,textalign=text.align_left,size=size.normal)
            lb2     := label.new(time + dt * 4, sl,     text=str.tostring(bName) +"Stop:" + str.tostring(sl),       color=color.red,textcolor=color.black,style=label.style_label_left,xloc = xloc.bar_time,textalign=text.align_left,size=size.normal)
            lb3     := label.new(time + dt * 4, tp1,    text=str.tostring(bName) +"TP1:" + str.tostring(tp1),       color=color.green,textcolor=color.black,style=label.style_label_left,xloc = xloc.bar_time,textalign=text.align_left,size=size.normal)

    line.delete(l11[1])
    label.delete(lb11[1])
    line.delete(l2[1])
    label.delete(lb2[1])
    line.delete(l3[1])
    label.delete(lb3[1])
    //--------------------------------------------------------------------
    //                     ENTRY && EXIT
    //--------------------------------------------------------------------
    official_buy    = trade_state == 1  and trade_state != trade_state[1]
    official_sell   = trade_state == -1 and trade_state != trade_state[1]
    
    entry_touched   = not entry_hit[1] and  entry_hit
    
    buyTP1_touched  = trade_state[1] == 1 and tp1_hit and tp1_hit[1]==false
    buySL_touched   = trade_state[1] == 1 and sl_hit  and tp1_hit==false
    
    sellTP1_touched = trade_state[1] == -1 and tp1_hit and tp1_hit[1]==false
    sellSL_touched  = trade_state[1] == -1 and sl_hit  and tp1_hit==false
    
    if trade_state == 1 and entry_touched and useSignal
        lb_entryHit := label.new(bar_index, na, text=str.tostring(bName) +"entry",color=color.purple,  textcolor=color.black,  style=label.style_cross,xloc = xloc.bar_index,  yloc=yloc.belowbar, textalign=text.align_left,size=size.normal)
    
    if trade_state == -1 and entry_touched and useSignal
        lb_entryHit := label.new(bar_index, na, text=str.tostring(sName) +"entry",color=color.purple,  textcolor=color.black,  style=label.style_cross,xloc = xloc.bar_index,  yloc=yloc.abovebar, textalign=text.align_left,size=size.normal)
    
    
    if buyTP1_touched and useSignal 
        lb_buyTP1   := label.new(bar_index, na, text=str.tostring(bName) +"TP1",color=color.green,  textcolor=color.black,  style=label.style_cross,xloc = xloc.bar_index,  yloc=yloc.abovebar, textalign=text.align_left,size=size.normal)
    
   
    if buySL_touched and useSignal 
        lb_buySL   := label.new(bar_index, na,  text=str.tostring(bName) + "SL",color=color.red,    textcolor=color.black,  style=label.style_cross,xloc = xloc.bar_index,  yloc=yloc.abovebar, textalign=text.align_left,size=size.normal)



    if sellTP1_touched and useSignal 
        lb_sellTP1 := label.new(bar_index, na, text=str.tostring(sName) +"TP1",color=color.green,   textcolor=color.black,  style=label.style_cross,xloc = xloc.bar_index,  yloc=yloc.belowbar, textalign=text.align_left,size=size.normal)
    
    if sellSL_touched and useSignal 
        lb_sellSL := label.new(bar_index, na,  text=str.tostring(sName) + "SL",color=color.red,     textcolor=color.black,  style=label.style_cross,xloc = xloc.bar_index,  yloc=yloc.belowbar, textalign=text.align_left,size=size.normal)

    
    [entry_touched, entry1, tp1, sl, official_buy, official_sell, buyTP1_touched, buySL_touched , sellTP1_touched, sellSL_touched]

// ======================================================================================================================================================================================================================================================================= \\

// @function Track 1 TakeProfit Level and  StopLoss  achievement for one or many of your buy/sell conditions. CHECK the commented section:  "Function @manageTrade" (lines: 146 - 172) for Description
// @param bool useSignal.
// @param bool b_gameOVer.
// @param bool longCancel.
// @param bool s_gameOVer.
// @param bool shortCancel.
// @param string bName.
// @param string sName.
// @param float buyEntrySource.
// @param float sellEntrySource.
// @param float tp1x.
// @param float slx.
// @returns check commented section:  "Function @manageFilterredLevel" (lines: 146 - 172) .
export manageFilterredLevel(bool useSignal, bool b_gameOVer, bool longCancel, bool s_gameOver, bool shortCancel, string bName, string sName, float buyEntrySource, float sellEntrySource, float tp1x, float slx) =>
    long        = b_gameOVer
    short       = s_gameOver
    
    BentryPrice  =   buyEntrySource
    SentryPrice  =   sellEntrySource

    
    // Position Management Tools
    pos         = 0.0
    pos         := long? 1 : short? -1 : pos[1]
    
    longCond1   = long and pos[1]!= 1
    shortCond1  = short and pos[1]!=-1
    
    buySignal   = long and longCond1
    sellSignal  = short and shortCond1
    
    var int trade_state = 0
    var float tp1       = na
    var float sl        = na
    var float entry1    = na
    var int et          = 0
    var entry_hit       = false
    var tp1_hit         = false
    var sl_hit          = false
    
    line l11            = na
    line l2             = na
    line l3             = na
    line l4             = na

    
    label lb11          = na
    label lb2           = na
    label lb3           = na

    
    label lb_entryHit   = na
    label lb_buyTP1     = na
    label lb_buySL      = na
    label lb_sellTP1    = na
    label lb_sellSL     = na
    
    
    dt                  = time - time[1]
    
    if trade_state != 0
        if longCancel
            trade_state := 0
            
        if shortCancel
            trade_state := 0
    
    if trade_state == 1 and useSignal 
    
        if sellSignal
            trade_state := 0
        
        if entry_hit == false and ta.cross(low ,entry1) or ta.cross(high, entry1)
            entry_hit   := true
        
        if entry_hit == true and tp1_hit == false and high >= tp1
            tp1_hit     := true
    
        if entry_hit == true and low <= sl
            trade_state := 0
            sl_hit      := low <= sl

    if trade_state == -1 and useSignal 
        if buySignal
            trade_state := 0
            
        if  entry_hit == false and ta.cross(low ,entry1) or ta.cross(high, entry1)
            entry_hit   := true
        
        if entry_hit == true and tp1_hit == false and low <= tp1
            tp1_hit     := true
    
        if entry_hit == true and high >= sl
            trade_state := 0
            sl_hit      := high >= sl

      
    if trade_state == 0 and useSignal 
        if buySignal  
            trade_state := 1
            
            entry_hit   := false
            tp1_hit     := false
            sl_hit      := false
            
            entry1      := round_price(BentryPrice)
            et          := time
            tp1         := round_price(entry1  * (1 + (tp1x / 100)))
            sl          := round_price(entry1  * (1 - (slx  / 100)))
    
        if sellSignal 
            trade_state := -1
            
            entry_hit   := false
            tp1_hit     := false
            sl_hit      := false
            
            entry1      := round_price(SentryPrice)
            et          := time
            tp1         := round_price(entry1  * (1 - (tp1x / 100)))
            sl          := round_price(entry1  * (1 + (slx  / 100))) 
    
    if trade_state[1] == -1 and useSignal  
        if barstate.islast
            l11     := line.new(et, entry1, time + dt * 2, entry1,  color=color.purple, style=line.style_solid,xloc = xloc.bar_time)
            l2      := line.new(et, sl,     time + dt * 2,  sl,     color=color.red,    style=line.style_solid,xloc = xloc.bar_time)
            l3      := line.new(et, tp1,    time + dt * 2,  tp1,    color=color.green,  style=line.style_solid,xloc = xloc.bar_time)
            
            lb11    := label.new(time + dt * 4, entry1, text=str.tostring(sName) +"Entry:" + str.tostring(entry1),  color=color.blue,textcolor=color.black,style=label.style_label_left,xloc = xloc.bar_time,textalign=text.align_left,size=size.normal)
            lb2     := label.new(time + dt * 4, sl,     text=str.tostring(sName) +"Stop:" + str.tostring(sl),       color=color.red,textcolor=color.black,style=label.style_label_left,xloc = xloc.bar_time,textalign=text.align_left,size=size.normal)
            lb3     := label.new(time + dt * 4, tp1,    text=str.tostring(sName) +"TP1:" + str.tostring(tp1),       color=color.green,textcolor=color.black,style=label.style_label_left,xloc = xloc.bar_time,textalign=text.align_left,size=size.normal)
            
    if trade_state[1] == 1 and useSignal 
        if barstate.islast
            l11     := line.new(et, entry1, time + dt * 2,  entry1, color=color.purple, style=line.style_solid,xloc = xloc.bar_time)
            l2      := line.new(et, sl,     time + dt * 2,  sl,     color=color.red,    style=line.style_solid,xloc = xloc.bar_time)
            l3      := line.new(et, tp1,    time + dt * 2,  tp1,    color=color.green,  style=line.style_solid,xloc = xloc.bar_time)
            
            lb11    := label.new(time + dt * 4, entry1, text=str.tostring(bName) +"Entry:" + str.tostring(entry1),  color=color.blue,textcolor=color.black,style=label.style_label_left,xloc = xloc.bar_time,textalign=text.align_left,size=size.normal)
            lb2     := label.new(time + dt * 4, sl,     text=str.tostring(bName) +"Stop:" + str.tostring(sl),       color=color.red,textcolor=color.black,style=label.style_label_left,xloc = xloc.bar_time,textalign=text.align_left,size=size.normal)
            lb3     := label.new(time + dt * 4, tp1,    text=str.tostring(bName) +"TP1:" + str.tostring(tp1),       color=color.green,textcolor=color.black,style=label.style_label_left,xloc = xloc.bar_time,textalign=text.align_left,size=size.normal)

    line.delete(l11[1])
    label.delete(lb11[1])
    line.delete(l2[1])
    label.delete(lb2[1])
    line.delete(l3[1])
    label.delete(lb3[1])
    //--------------------------------------------------------------------
    //                     ENTRY && EXIT
    //--------------------------------------------------------------------
    official_buy    = trade_state == 1  and trade_state != trade_state[1]
    official_sell   = trade_state == -1 and trade_state != trade_state[1]
    
    entry_touched   = not entry_hit[1] and  entry_hit
    
    buyTP1_touched  = trade_state[1] == 1 and tp1_hit and tp1_hit[1]==false
    buySL_touched   = trade_state[1] == 1 and sl_hit  and tp1_hit==false
    
    sellTP1_touched = trade_state[1] == -1 and tp1_hit and tp1_hit[1]==false
    sellSL_touched  = trade_state[1] == -1 and sl_hit  and tp1_hit==false
    
    if trade_state == 1 and entry_touched and useSignal
        lb_entryHit := label.new(bar_index, na, text=str.tostring(bName) +"entry",color=color.purple,  textcolor=color.black,  style=label.style_cross,xloc = xloc.bar_index,  yloc=yloc.belowbar, textalign=text.align_left,size=size.normal)
    
    if trade_state == -1 and entry_touched and useSignal
        lb_entryHit := label.new(bar_index, na, text=str.tostring(sName) +"entry",color=color.purple,  textcolor=color.black,  style=label.style_cross,xloc = xloc.bar_index,  yloc=yloc.abovebar, textalign=text.align_left,size=size.normal)
    
    
    if buyTP1_touched and useSignal 
        lb_buyTP1   := label.new(bar_index, na, text=str.tostring(bName) +"TP1",color=color.green,  textcolor=color.black,  style=label.style_cross,xloc = xloc.bar_index,  yloc=yloc.abovebar, textalign=text.align_left,size=size.normal)
    
   
    if buySL_touched and useSignal 
        lb_buySL   := label.new(bar_index, na,  text=str.tostring(bName) + "SL",color=color.red,    textcolor=color.black,  style=label.style_cross,xloc = xloc.bar_index,  yloc=yloc.abovebar, textalign=text.align_left,size=size.normal)



    if sellTP1_touched and useSignal 
        lb_sellTP1 := label.new(bar_index, na, text=str.tostring(sName) +"TP1",color=color.green,   textcolor=color.black,  style=label.style_cross,xloc = xloc.bar_index,  yloc=yloc.belowbar, textalign=text.align_left,size=size.normal)
    
    if sellSL_touched and useSignal 
        lb_sellSL := label.new(bar_index, na,  text=str.tostring(sName) + "SL",color=color.red,     textcolor=color.black,  style=label.style_cross,xloc = xloc.bar_index,  yloc=yloc.belowbar, textalign=text.align_left,size=size.normal)

    
    [entry_touched, entry1, tp1, sl, official_buy, official_sell, buyTP1_touched, buySL_touched , sellTP1_touched, sellSL_touched]

// ======================================================================================================================================================================================================================================================================= \\
// @function Track TakeProfits and StopLoss achievement for one or many of your buy/sell conditions. CHECK the commented section:  "Function @tpLevels" (lines: 66 - 118) for Description
// @param bool useSignal.
// @param bool b_gameOVer.
// @param bool s_gameOVer.
// @param string bName.
// @param string sName.
// @param float buyEntrySource.
// @param float sellEntrySource.
// @param bool useTp1.
// @param bool useTp2.
// @param bool useTp3.
// @param bool useTp4.
// @param bool useTp5.
// @param bool useTp6.
// @param float tp1x.
// @param float tp2x.
// @param float tp3x.
// @param float tp4x.
// @param float tp5x.
// @param float tp6x.
// @param float slx.
// @returns check commented section:  "Function @tpLevels" (lines: 175 - 226).
export tpLevels(bool useSignal, bool b_gameOVer,bool s_gameOver, string bName, string sName, float buyEntrySource, float sellEntrySource, bool useTp1, bool useTp2, bool useTp3, bool useTp4, bool useTp5,  bool useTp6, float tp1x, float tp2x, float tp3x, float tp4x, float tp5x, float tp6x, float slx) =>
 
    BentryPrice         = buyEntrySource
    SentryPrice         = sellEntrySource

    buySignal           = b_gameOVer
    sellSignal          = s_gameOver
    
    var int trade_state = 0
    var float tp1       = na
    var float tp2       = na
    var float tp3       = na
    var float tp4       = na
    var float tp5       = na
    var float tp6       = na
    var float sl        = na
    var float entry1    = na
    var int et          = 0
    var entry_hit       = false
    var tp1_hit         = false
    var tp2_hit         = false
    var tp3_hit         = false
    var tp4_hit         = false
    var tp5_hit         = false
    var tp6_hit         = false
    
    var sl_hit          = false
    
    line l11            = na
    line l2             = na
    line l3             = na
    line l4             = na
    line l5             = na
    line l6             = na
    line l7             = na
    line l8             = na
    
    label lb11          = na
    label lb2           = na
    label lb3           = na
    label lb4           = na
    label lb5           = na
    label lb6           = na
    label lb7           = na
    label lb8           = na
    
    label lb_entryHit   = na
    label lb_buyTP1     = na
    label lb_buyTP2     = na
    label lb_buyTP3     = na
    label lb_buyTP4     = na
    label lb_buyTP5     = na
    label lb_buyTP6     = na
    label lb_buySL      = na
    
    label lb_sellTP1    = na
    label lb_sellTP2    = na
    label lb_sellTP3    = na
    label lb_sellTP4    = na
    label lb_sellTP5    = na
    label lb_sellTP6    = na
    label lb_sellSL     = na
    
    
    dt                  = time - time[1]
    
    
    if trade_state == 1 and useSignal 
    
        if sellSignal
            trade_state := 0
        
        if entry_hit == false and ta.cross(low ,entry1) or ta.cross(high, entry1)
            entry_hit   := true
        
        if entry_hit == true and tp1_hit == false and high >= tp1
            tp1_hit     := true
        if entry_hit == true and tp2_hit == false and high >= tp2
            tp2_hit     := true   
        if entry_hit == true and tp3_hit == false and high >= tp3
            tp3_hit     := true         
        if entry_hit == true and tp4_hit == false and high >= tp4
            tp4_hit     := true    
        if entry_hit == true and tp5_hit == false and high >= tp5
            tp5_hit     := true 
        if entry_hit == true and tp6_hit == false and high >= tp6
            tp6_hit     := true 
    
        if entry_hit == true and low <= sl
            trade_state := 0
            sl_hit      := low <= sl

    if trade_state == -1 and useSignal 
        if buySignal
            trade_state := 0
            
        if  entry_hit == false and ta.cross(low ,entry1) or ta.cross(high, entry1)
            entry_hit   := true
        
        if entry_hit == true and tp1_hit == false and low <= tp1
            tp1_hit     := true
        if entry_hit == true and tp2_hit == false and low <= tp2
            tp2_hit     := true
        if entry_hit == true and tp3_hit == false and low <= tp3
            tp3_hit     := true      
        if entry_hit == true and tp4_hit == false and low <= tp4
            tp4_hit     := true    
    	if entry_hit == true and tp5_hit == false and low <= tp5
            tp5_hit     := true
        if entry_hit == true and tp6_hit == false and low <= tp6
            tp6_hit     := true 
    
        if entry_hit == true and high >= sl
            trade_state := 0
            sl_hit      := high >= sl

            
      
    if trade_state == 0 and useSignal 
        if buySignal  
            trade_state := 1
            
            entry_hit   := false
            tp1_hit     := false
            tp2_hit     := false
            tp3_hit     := false
            tp4_hit     := false
            tp5_hit     := false
            tp6_hit     := false
            sl_hit      := false
            
            entry1      := round_price(BentryPrice)
            et          := time
            tp1         := round_price(entry1  * (1 + (tp1x / 100)))
            tp2         := round_price(entry1  * (1 + (tp2x / 100)))
            tp3         := round_price(entry1  * (1 + (tp3x / 100)))
            tp4         := round_price(entry1  * (1 + (tp4x / 100)))
            tp5         := round_price(entry1  * (1 + (tp5x / 100)))
            tp6         := round_price(entry1  * (1 + (tp6x / 100)))
            sl          := round_price(entry1  * (1 - (slx  / 100)))
    
        if sellSignal 
            trade_state := -1
            
            entry_hit   := false
            tp1_hit     := false
            tp2_hit     := false
            tp3_hit     := false
            tp4_hit     := false
            tp5_hit     := false
            tp6_hit     := false
            sl_hit      := false
            
            entry1      := round_price(SentryPrice)
            et          := time
            tp1         := round_price(entry1  * (1 - (tp1x / 100)))
            tp2         := round_price(entry1  * (1 - (tp2x / 100)))
            tp3         := round_price(entry1  * (1 - (tp3x / 100)))
            tp4         := round_price(entry1  * (1 - (tp4x / 100)))
            tp5         := round_price(entry1  * (1 - (tp5x / 100)))
            tp6         := round_price(entry1  * (1 - (tp6x / 100)))
            sl          := round_price(entry1  * (1 + (slx  / 100))) 
    
    if trade_state == -1 and useSignal  
        l11     := line.new(et, entry1, time + dt * 2, entry1,  color=color.purple, style=line.style_solid,xloc = xloc.bar_time)
        l2      := line.new(et, sl,     time + dt * 2,  sl,     color=color.red,    style=line.style_solid,xloc = xloc.bar_time)
        
        l3      := line.new(useTp1 ? et : na, useTp1 ? tp1 : na,useTp1 ?time + dt * 2:na,useTp1 ? tp1 : na,color=color.green,   style=line.style_solid,    xloc = xloc.bar_time)
        l4      := line.new(useTp2 ? et : na, useTp2 ? tp2 : na,useTp2 ?time + dt * 2:na,useTp2 ? tp2 : na,color=color.green,   style=line.style_solid,    xloc = xloc.bar_time)
        l5      := line.new(useTp3 ? et : na, useTp3 ? tp3 : na,useTp3 ?time + dt * 2:na,useTp3 ? tp3 : na,color=color.green,   style=line.style_solid,    xloc = xloc.bar_time)
        l6      := line.new(useTp4 ? et : na, useTp4 ? tp4 : na,useTp4 ?time + dt * 2:na,useTp4 ? tp4 : na,color=color.green,   style=line.style_solid,    xloc = xloc.bar_time)
        l7      := line.new(useTp5 ? et : na, useTp5 ? tp5 : na,useTp5 ?time + dt * 2:na,useTp5 ? tp5 : na,color=color.green,   style=line.style_solid,    xloc = xloc.bar_time)
        l8      := line.new(useTp6 ? et : na, useTp6 ? tp6 : na,useTp6 ?time + dt * 2:na,useTp6 ? tp6 : na,color=color.green,   style=line.style_solid,    xloc = xloc.bar_time)

        // lb11    := label.new(time + dt * 4, entry1, text=str.tostring(sName) +"Entry:" + str.tostring(entry1),color=color.blue,textcolor=color.black,style=label.style_label_left,xloc = xloc.bar_time,textalign=text.align_left,size=size.normal)
        // lb2     := label.new(time + dt * 4, sl,     text=str.tostring(sName) +"Stop:" + str.tostring(sl),color=color.red,textcolor=color.black,style=label.style_label_left,xloc = xloc.bar_time,textalign=text.align_left,size=size.normal)

        // lb3     := label.new(useTp1 ? time + dt * 4 : na, tp1,text=str.tostring(sName) +"TP1:" + str.tostring(tp1),color=color.green,textcolor=color.black,style=label.style_label_left,xloc = xloc.bar_time,textalign=text.align_left,size=size.normal)
        // lb4     := label.new(useTp2 ? time + dt * 4 : na, tp2,text=str.tostring(sName) +"TP2:" + str.tostring(tp2),color=color.green,textcolor=color.black,style=label.style_label_left,xloc = xloc.bar_time,textalign=text.align_left,size=size.normal)
        // lb5     := label.new(useTp3 ? time + dt * 4 : na, tp3,text=str.tostring(sName) +"TP3:" + str.tostring(tp3),color=color.green,textcolor=color.black,style=label.style_label_left,xloc = xloc.bar_time,textalign=text.align_left,size=size.normal)
        // lb6     := label.new(useTp4 ? time + dt * 4 : na, tp4,text=str.tostring(sName) +"TP4:" + str.tostring(tp4),color=color.green,textcolor=color.black,style=label.style_label_left,xloc = xloc.bar_time,textalign=text.align_left,size=size.normal)
        // lb7     := label.new(useTp5 ? time + dt * 4 : na, tp5,text=str.tostring(sName) +"TP5:" + str.tostring(tp5),color=color.green,textcolor=color.black,style=label.style_label_left,xloc = xloc.bar_time,textalign=text.align_left,size=size.normal)
        // lb8     := label.new(useTp6 ? time + dt * 4 : na, tp6,text=str.tostring(sName) +"TP6:" + str.tostring(tp6),color=color.green,textcolor=color.black,style=label.style_label_left,xloc = xloc.bar_time,textalign=text.align_left,size=size.normal)
    
    if trade_state == 1 and useSignal 
        l11     := line.new(et, entry1, time + dt * 2,  entry1, color=color.purple, style=line.style_solid,xloc = xloc.bar_time)
        l2      := line.new(et, sl,     time + dt * 2,  sl,     color=color.red,    style=line.style_solid,xloc = xloc.bar_time)
        
        //TPS
        l3      := line.new(useTp1 ? et : na, useTp1 ? tp1 : na,useTp1 ?time + dt * 2:na,useTp1 ? tp1 : na,color=color.green,style=line.style_solid,xloc = xloc.bar_time)
        l4      := line.new(useTp2 ? et : na, useTp2 ? tp2 : na,useTp2 ?time + dt * 2:na,useTp2 ? tp2 : na,color=color.green,style=line.style_solid,xloc = xloc.bar_time)
        l5      := line.new(useTp3 ? et : na, useTp3 ? tp3 : na,useTp3 ?time + dt * 2:na,useTp3 ? tp3 : na,color=color.green,style=line.style_solid,xloc = xloc.bar_time)
        l6      := line.new(useTp4 ? et : na, useTp4 ? tp4 : na,useTp4 ?time + dt * 2:na,useTp4 ? tp4 : na,color=color.green,style=line.style_solid,xloc = xloc.bar_time)
        l7      := line.new(useTp5 ? et : na, useTp5 ? tp5 : na,useTp5 ?time + dt * 2:na,useTp5 ? tp5 : na,color=color.green,style=line.style_solid,xloc = xloc.bar_time)
        l8      := line.new(useTp6 ? et : na, useTp6 ? tp6 : na,useTp6 ?time + dt * 2:na,useTp6 ? tp6 : na,color=color.green,style=line.style_solid,xloc = xloc.bar_time)

        // lb11    := label.new(time + dt * 4, entry1,text=str.tostring(bName) +"Entry:" + str.tostring(entry1),color=color.blue,textcolor=color.black,style=label.style_label_left,xloc = xloc.bar_time,textalign=text.align_left,size=size.normal)
        // lb2     := label.new(time + dt * 4, sl,text=str.tostring(bName) +"Stop:" + str.tostring(sl),color=color.red,textcolor=color.black,style=label.style_label_left,xloc = xloc.bar_time,textalign=text.align_left,size=size.normal)
        // //TPS
        // lb3     := label.new(useTp1 ? time + dt * 4 : na, tp1,text=str.tostring(bName) +"TP1:" + str.tostring(tp1),color=color.green,textcolor=color.black,style=label.style_label_left,xloc = xloc.bar_time,textalign=text.align_left,size=size.normal)
        // lb4     := label.new(useTp2 ? time + dt * 4 : na, tp2,text=str.tostring(bName) +"TP2:" + str.tostring(tp2),color=color.green,textcolor=color.black,style=label.style_label_left,xloc = xloc.bar_time,textalign=text.align_left,size=size.normal)
        // lb5     := label.new(useTp3 ? time + dt * 4 : na, tp3,text=str.tostring(bName) +"TP3:" + str.tostring(tp3),color=color.green,textcolor=color.black,style=label.style_label_left,xloc = xloc.bar_time,textalign=text.align_left,size=size.normal)
        // lb6     := label.new(useTp4 ? time + dt * 4 : na, tp4,text=str.tostring(bName) +"TP4:" + str.tostring(tp4),color=color.green,textcolor=color.black,style=label.style_label_left,xloc = xloc.bar_time,textalign=text.align_left,size=size.normal)
        // lb7     := label.new(useTp5 ? time + dt * 4 : na, tp5,text=str.tostring(bName) +"TP5:" + str.tostring(tp5),color=color.green,textcolor=color.black,style=label.style_label_left,xloc = xloc.bar_time,textalign=text.align_left,size=size.normal)
        // lb8     := label.new(useTp6 ? time + dt * 4 : na, tp6,text=str.tostring(bName) +"TP6:" + str.tostring(tp6),color=color.green,textcolor=color.black,style=label.style_label_left,xloc = xloc.bar_time,textalign=text.align_left,size=size.normal)

    //--------------------------------------------------------------------
    //                     ENTRY && EXIT
    //--------------------------------------------------------------------
    official_buy    = trade_state == 1  and trade_state != trade_state[1]
    official_sell   = trade_state == -1 and trade_state != trade_state[1]
    
    entry_touched   = not entry_hit[1] and  entry_hit
    
    buyTP1_touched  = trade_state[1] == 1 and tp1_hit and tp1_hit[1]==false
    buyTP2_touched  = useTp2 and trade_state[1] == 1 and tp2_hit and tp2_hit[1]==false
    buyTP3_touched  = useTp3 and trade_state[1] == 1 and tp3_hit and tp3_hit[1]==false
    buyTP4_touched  = useTp4 and trade_state[1] == 1 and tp4_hit and tp4_hit[1]==false
    buyTP5_touched  = useTp5 and trade_state[1] == 1 and tp5_hit and tp5_hit[1]==false
    buyTP6_touched  = useTp6 and trade_state[1] == 1 and tp6_hit and tp6_hit[1]==false
    buySL_touched   = trade_state[1] == 1 and sl_hit and tp1_hit==false
    
    sellTP1_touched = trade_state[1] == -1 and tp1_hit and tp1_hit[1]==false
    sellTP2_touched = useTp2 and trade_state[1] == -1 and tp2_hit and tp2_hit[1]==false
    sellTP3_touched = useTp3 and trade_state[1] == -1 and tp3_hit and tp3_hit[1]==false
    sellTP4_touched = useTp4 and trade_state[1] == -1 and tp4_hit and tp4_hit[1]==false
    sellTP5_touched = useTp5 and trade_state[1] == -1 and tp5_hit and tp5_hit[1]==false
    sellTP6_touched = useTp6 and trade_state[1] == -1 and tp6_hit and tp6_hit[1]==false
    sellSL_touched  = trade_state[1] == -1 and sl_hit and tp1_hit==false
    
    if trade_state == 1 and entry_touched and useSignal
        lb_entryHit := label.new(bar_index, na, text=str.tostring(bName) +"entry",color=color.purple,  textcolor=color.black,  style=label.style_cross,xloc = xloc.bar_index,  yloc=yloc.belowbar, textalign=text.align_left,size=size.normal)
    
    if trade_state == -1 and entry_touched and useSignal
        lb_entryHit := label.new(bar_index, na, text=str.tostring(sName) +"entry",color=color.purple,  textcolor=color.black,  style=label.style_cross,xloc = xloc.bar_index,  yloc=yloc.abovebar, textalign=text.align_left,size=size.normal)
    
    
    if buyTP1_touched and useSignal 
        lb_buyTP1   := label.new(bar_index, na, text=str.tostring(bName) +"TP1",color=color.green,  textcolor=color.black,  style=label.style_cross,xloc = xloc.bar_index,  yloc=yloc.abovebar, textalign=text.align_left,size=size.normal)
    
    if buyTP2_touched and useSignal 
        lb_buyTP2   := label.new(bar_index, na, text=str.tostring(bName) +"TP2",color=color.yellow, textcolor=color.black,  style=label.style_cross,xloc = xloc.bar_index,  yloc=yloc.abovebar, textalign=text.align_left,size=size.normal)
    
    if buyTP3_touched and useSignal 
        lb_buyTP3   := label.new(bar_index, na, text=str.tostring(bName) +"TP3",color=color.orange, textcolor=color.black,  style=label.style_cross,xloc = xloc.bar_index,  yloc=yloc.abovebar, textalign=text.align_left,size=size.normal)
    
    if buyTP4_touched and useSignal 
        lb_buyTP4   := label.new(bar_index, na, text=str.tostring(bName) +"TP4",color=color.gray,   textcolor=color.black,  style=label.style_cross,xloc = xloc.bar_index,  yloc=yloc.abovebar, textalign=text.align_left,size=size.normal)

    if buyTP5_touched and useSignal 
        lb_buyTP5   := label.new(bar_index, na, text=str.tostring(bName) +"TP5",color=color.lime,   textcolor=color.black,  style=label.style_cross,xloc = xloc.bar_index,  yloc=yloc.abovebar, textalign=text.align_left,size=size.normal)

    if buyTP6_touched and useSignal 
        lb_buyTP6   := label.new(bar_index, na, text=str.tostring(bName) +"TP6",color=color.black,  textcolor=color.black,  style=label.style_cross,xloc = xloc.bar_index,  yloc=yloc.abovebar, textalign=text.align_left,size=size.normal)

    if buySL_touched and useSignal 
        lb_buySL   := label.new(bar_index, na,  text=str.tostring(bName) + "SL",color=color.red,    textcolor=color.black,  style=label.style_cross,xloc = xloc.bar_index,  yloc=yloc.abovebar, textalign=text.align_left,size=size.normal)



    if sellTP1_touched and useSignal 
        lb_sellTP1 := label.new(bar_index, na, text=str.tostring(sName) +"TP1",color=color.green,   textcolor=color.black,  style=label.style_cross,xloc = xloc.bar_index,  yloc=yloc.belowbar, textalign=text.align_left,size=size.normal)
    
    if sellTP2_touched and useSignal 
        lb_sellTP2 := label.new(bar_index, na, text=str.tostring(sName) +"TP2",color=color.yellow,  textcolor=color.black,  style=label.style_cross,xloc = xloc.bar_index,  yloc=yloc.belowbar, textalign=text.align_left,size=size.normal)

    if sellTP3_touched and useSignal 
        lb_sellTP3 := label.new(bar_index, na, text=str.tostring(sName) +"TP3",color=color.orange,  textcolor=color.black,  style=label.style_cross,xloc = xloc.bar_index,  yloc=yloc.belowbar, textalign=text.align_left,size=size.normal)

    if sellTP4_touched and useSignal 
        lb_sellTP4 := label.new(bar_index, na, text=str.tostring(sName) +"TP4",color=color.gray,    textcolor=color.black,  style=label.style_cross,xloc = xloc.bar_index,  yloc=yloc.belowbar, textalign=text.align_left,size=size.normal)

    if sellTP5_touched and useSignal 
        lb_sellTP5 := label.new(bar_index, na, text=str.tostring(sName) +"TP5",color=color.lime,    textcolor=color.black,  style=label.style_cross,xloc = xloc.bar_index,  yloc=yloc.belowbar, textalign=text.align_left,size=size.normal)

    if sellTP6_touched and useSignal 
        lb_sellTP6 := label.new(bar_index, na, text=str.tostring(sName) +"TP6",color=color.black,   textcolor=color.black,  style=label.style_cross,xloc = xloc.bar_index,  yloc=yloc.belowbar, textalign=text.align_left,size=size.normal)

    if sellSL_touched and useSignal 
        lb_sellSL := label.new(bar_index, na,  text=str.tostring(sName) + "SL",color=color.red,     textcolor=color.black,  style=label.style_cross,xloc = xloc.bar_index,  yloc=yloc.belowbar, textalign=text.align_left,size=size.normal)

    
    [entry_touched, entry1, tp1, tp2, tp3, tp4, tp5, tp6, sl, official_buy, official_sell, buyTP1_touched, buyTP2_touched, buyTP3_touched, buyTP4_touched, buyTP5_touched, buyTP6_touched, buySL_touched , sellTP1_touched, sellTP2_touched, sellTP3_touched, sellTP4_touched, sellTP5_touched, sellTP6_touched, sellSL_touched]

// ======================================================================================================================================================================================================================================================================= \\
