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

//@version=5

// @description
library("WHAlertCommand", overlay = true)
export f_WH_Risk(string risk_Type_) =>
    switch risk_Type_
        "Very Low" => "VERY_LOW"
        "Low" => str.upper(risk_Type_)
        "Medium" => str.upper(risk_Type_)
        "High" => str.upper(risk_Type_)
        "Very High" => "VERY_HIGH"

export f_WH_Open_Position(string uuid_, bool enable_Buy_, bool enable_Sell, bool enable_All_Group_Members_, bool enable_Close_Opposite_Side_, bool enable_Risk_, string risk_Type_, string signal_Type_Buy_Or_Sell) =>
    string WICK_HUNTER_START_COMMAND = "{"
    string WICK_HUNTER_END_COMMAND = "}"
    string WICK_HUNTER_OPEN = "\"cmd\":\"OPEN\""
    string WICK_HUNTER_UUID = ",\"uuid\":\"" + uuid_ + "\""
    string WICK_HUNTER_SYMBOL = ",\"symbol\":\"" + syminfo.ticker + "\""
    string WICK_HUNTER_SIDE_BUY = ",\"side\":\"BUY\""
    string WICK_HUNTER_SIDE_SELL = ",\"side\":\"SELL\""
    string WICK_HUNTER_RISK = enable_Risk_ ? ",\"risk\":\"" + f_WH_Risk(risk_Type_ = risk_Type_) + "\"" : ""
    string WICK_HUNTER_ALL_GROUP_MEMBERS = enable_All_Group_Members_ ? ",\"group\":true" : ""
    string WICK_HUNTER_CLOSE_OPPOSITE_SIDE = enable_Close_Opposite_Side_ ? ",\"closePrevious\": true" : ""
    string WICK_HUNTER_BUY = enable_Buy_ ? WICK_HUNTER_START_COMMAND + WICK_HUNTER_OPEN + WICK_HUNTER_UUID + WICK_HUNTER_SYMBOL + WICK_HUNTER_SIDE_BUY + WICK_HUNTER_RISK + WICK_HUNTER_ALL_GROUP_MEMBERS + WICK_HUNTER_CLOSE_OPPOSITE_SIDE + WICK_HUNTER_END_COMMAND : na
    string WICK_HUNTER_SELL = enable_Sell ? WICK_HUNTER_START_COMMAND + WICK_HUNTER_OPEN + WICK_HUNTER_UUID + WICK_HUNTER_SYMBOL + WICK_HUNTER_SIDE_SELL + WICK_HUNTER_RISK + WICK_HUNTER_ALL_GROUP_MEMBERS + WICK_HUNTER_CLOSE_OPPOSITE_SIDE + WICK_HUNTER_END_COMMAND : na

    if str.upper(signal_Type_Buy_Or_Sell) == "BUY"
        WICK_HUNTER_BUY
    else if str.upper(signal_Type_Buy_Or_Sell) == "SELL"
        WICK_HUNTER_SELL

export f_WH_TP(string uuid_, float position_Size_Percent_, string side_) =>
    string WICK_HUNTER_START_COMMAND = "{"
    string WICK_HUNTER_END_COMMAND = "}"
    string WICK_HUNTER_MARKET_TP = "\"cmd\":\"MARKET_TAKE_PROFIT\""
    string WICK_HUNTER_UUID = ",\"uuid\":\"" + uuid_ + "\""
    string WICK_HUNTER_SYMBOL = ",\"symbol\":\"" + syminfo.ticker + "\""
    string WICK_HUNTER_SIDE_BUY = ",\"side\":\"BUY\""
    string WICK_HUNTER_SIDE_SELL = ",\"side\":\"SELL\""
    string WICK_HUNTER_PERCENT_POSITION_SIZE = ",\"percentageOfPositionSize\":" + str.tostring(position_Size_Percent_)
    string WICK_HUNTER_TP_LONG = WICK_HUNTER_START_COMMAND + WICK_HUNTER_MARKET_TP + WICK_HUNTER_UUID + WICK_HUNTER_SYMBOL + WICK_HUNTER_SIDE_BUY + WICK_HUNTER_PERCENT_POSITION_SIZE + WICK_HUNTER_END_COMMAND
    string WICK_HUNTER_TP_SHORT = WICK_HUNTER_START_COMMAND + WICK_HUNTER_MARKET_TP + WICK_HUNTER_UUID + WICK_HUNTER_SYMBOL + WICK_HUNTER_SIDE_SELL + WICK_HUNTER_PERCENT_POSITION_SIZE + WICK_HUNTER_END_COMMAND

    if str.upper(side_) == "BUY"
        WICK_HUNTER_TP_LONG
    else if str.upper(side_) == "SELL"
        WICK_HUNTER_TP_SHORT

export f_WH_MARKET_CLOSE(string uuid_, string side_) =>
    string WICK_HUNTER_START_COMMAND = "{"
    string WICK_HUNTER_END_COMMAND = "}"
    string WICK_HUNTER_MARKET_TP = "\"cmd\":\"MARKET_CLOSE\""
    string WICK_HUNTER_UUID = ",\"uuid\":\"" + uuid_ + "\""
    string WICK_HUNTER_SYMBOL = ",\"symbol\":\"" + syminfo.ticker + "\""
    string WICK_HUNTER_SIDE_BUY = ",\"side\":\"BUY\""
    string WICK_HUNTER_SIDE_SELL = ",\"side\":\"SELL\""
    string WICK_HUNTER_TP_LONG = WICK_HUNTER_START_COMMAND + WICK_HUNTER_MARKET_TP + WICK_HUNTER_UUID + WICK_HUNTER_SYMBOL + WICK_HUNTER_SIDE_BUY + WICK_HUNTER_END_COMMAND
    string WICK_HUNTER_TP_SHORT = WICK_HUNTER_START_COMMAND + WICK_HUNTER_MARKET_TP + WICK_HUNTER_UUID + WICK_HUNTER_SYMBOL + WICK_HUNTER_SIDE_SELL + WICK_HUNTER_END_COMMAND

    if str.upper(side_) == "BUY"
        WICK_HUNTER_TP_LONG
    else if str.upper(side_) == "SELL"
        WICK_HUNTER_TP_SHORT