myAlerts
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © incryptowetrust100k
//@version=5

// @description My Alerts Functions - To use with autoview
library("myAlerts")

//==================================================-----------EXTERNAL-----------==================================================//
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//              - 1      - INTERNAL        {
//              - 1.0    - Header          {
// @function             - Set token on Messages
// @param typeMsg        - Used to define type of writing
// @param i_token        - User token
// @returns              - Returns the header message
f_header(bool typeMsg, string i_token) => typeMsg ? i_token+"," : "{ \n \"token\": \""+i_token+"\", \n \"commands\": \" " // }
//              -                          } End 1.0 - Header
//              -                          } End INTERNAL
//              - 2      - EXTERNAL        {
//              - 2.1    - Order           {
// @function             - Write the entry order message
// @param _price         - The order price
// @param _qty           - The order quantity
// @param _position      - The order side
// @param _account       - The user account
// @param _exchange      - The user exchange
// @param _i             - Used for multi-accounts, this represents the index of accounts
// @param i_qtyTypeOrder - String used to set Thether or Bitcoin Type Orders
// @param typeMsg        - True = Autoview; False = Metatrader
// @param syminfoticker  - Ticker
// @returns              - Returns the open order message
export f_order(float _price,float _qty, int _position, string _account, string _exchange, int _i, string i_qtyTypeOrder, int i_delayOrders, bool typeMsg, string msg_syminfoticker) =>
    _msg                =           ""
    _xQty               =           _qty
    _currency           =           i_qtyTypeOrder == "TETHER" ? " u=currency" : ""
    
    if i_qtyTypeOrder == "FIAT"
        _xQty           :=          math.round(math.round(_qty*close) / 100) * 100
    else if i_qtyTypeOrder == "TETHER"
        _xQty           :=          _qty * close / 100
    
    _op                 =           _position == 1 ? "long" : "short"
    
    _txtDelay           =           _i == 0 ? " delay=" + str.tostring(i_delayOrders) + " " : " "

    if not typeMsg
        _msg            :=          " a="+_account+" e="+_exchange+" s="+msg_syminfoticker + _txtDelay + " b="+_op+" q="+str.tostring(_xQty)+ _currency + " fp="+str.tostring(_price)+" | "
    else
        _op             :=          _op == "long" ? "buylimit" : "selllimit"
        _msg            :=          _op+","+msg_syminfoticker+",risk="+str.tostring(math.round(_xQty/100000,2))+",price="+str.format("{0,number,#.#####}",_price)+""
    _msg
//              -                          } End 2.1 - Order
//              - 2.2    - Stop            {
// @function             - Write the stop order message
// @param _stop_price    - The order stop price
// @param _slLimit_price - The order stop limit price
// @param _account       - The user account
// @param _exchange      - The user exchange
// @param _i             - Used for multi-accounts, this represents the index of accounts
// @param i_delayOrders  - Time in seconds to delay command on autoview
// @param typeMsg        - True = Autoview; False = Metatrader
// @param syminfoticker  - Ticker
// @returns              - Returns the open order message
export f_stop(float _stop_price, float _slLimit_price, string _account, string _exchange, int _i, int i_delayOrders, bool typeMsg, string msg_syminfoticker) =>
    _msg                =           ""
    _txtDelay           =           _i == 0 ? " delay=" + str.tostring(i_delayOrders) + " " : " "
    
    if not typeMsg
        _msg            :=          " a="+_account+" e="+_exchange+" s="+msg_syminfoticker + _txtDelay + " q=100% c=position fsl="+str.tostring(_stop_price)+" fp="+str.tostring(_slLimit_price)+" ro=1 | "
    else
        _msg            :=          ",sl="+str.tostring(_stop_price)+""
    _msg
//              -                          } End 2.2 - Order
//              - 2.3    - Take            {
// @function             - Write the stop order message
// @param _take_price    - The order stop price
// @param _account       - The user account
// @param _exchange      - The user exchange
// @param _i             - Used for multi-accounts, this represents the index of accounts
// @param i_delayOrders  - Time in seconds to delay command on autoview
// @param typeMsg        - True = Autoview; False = Metatrader
// @param syminfoticker  - Ticker
// @returns              - Returns the open order message
export f_take(float _take_price, string _account, string _exchange, int _i, int i_delayOrders, bool typeMsg, string msg_syminfoticker) =>
    _msg                =           ""
    _txtDelay           =           _i == 0 ? " delay=" + str.tostring(i_delayOrders) + " " : " "
    
    if not typeMsg
        _msg            :=          " a="+_account+" e="+_exchange+" s="+msg_syminfoticker + _txtDelay + " q=100% c=position fp="+str.tostring(_take_price)+" ro=1 | "
    else
        _msg            :=          ",tp="+str.tostring(_take_price)+""
    _msg
//              -                          } End 2.3 - Take
//              - 2.4    - Update          {
// @function             - Write the update order message
// @param _account       - The user account
// @param _exchange      - The user exchange
// @param _i             - Used for multi-accounts, this represents the index of accounts
// @param i_delayOrders  - Time in seconds to delay command on autoview
// @param typeMsg        - True = Autoview; False = Metatrader
// @param syminfoticker  - Ticker
// @returns              - Returns the open order message
export f_update(string _account, string _exchange, int _i, int i_delayOrders, bool typeMsg, string msg_syminfoticker) =>
    _msg                =           ""
    _txtDelay           =           _i == 0 ? " delay=" + str.tostring(i_delayOrders + 1) + " " : " "
    
    if not typeMsg
        _msg            :=          " a="+_account+" e="+_exchange+" s="+msg_syminfoticker + _txtDelay +" c=order | "
    else
        _msg            :=          ""
    _msg
//              -                          } End 2.4 - Update
//              - 2.5    - Exit            {
// @function             - Write the exit order message
// @param _account       - The user account
// @param _exchange      - The user exchange
// @param _i             - Used for multi-accounts, this represents the index of accounts
// @param i_delayOrders  - Time in seconds to delay command on autoview
// @param typeMsg        - True = Autoview; False = Metatrader
// @param syminfoticker  - Ticker
// @returns              - Returns the open order message
export f_exit(string _account, string _exchange, int _i, int i_delayOrders, bool typeMsg, string msg_syminfoticker)=>
    _msg                =           ""
    _txtDelay           =           _i == 0 ? " delay=" + str.tostring(i_delayOrders) + " " : " "
    
    if not typeMsg
        _msg            :=          " a="+_account+" e="+_exchange+" s="+msg_syminfoticker + _txtDelay + " c=position t=market ro=1 | "
    else
        _msg            :=          ""
    _msg
//              -                          } End 2.5 - Exit
//              - 2.6    - Hedge           {
// @function             - Write the exit order message
// @param _account       - The user account
// @param _exchange      - The user exchange
// @param _i             - Used for multi-accounts, this represents the index of accounts
// @param i_delayOrders  - Time in seconds to delay command on autoview
// @param typeMsg        - True = Autoview; False = Metatrader
// @param syminfoticker  - Ticker
// @returns              - Returns the open order message
export f_hedge(string _account, string _exchange, int _i, int i_delayOrders, bool typeMsg, string msg_syminfoticker)=>
    _msg                =           ""
    _txtDelay           =           _i == 0 ? " delay=" + str.tostring(i_delayOrders) + " " : " "
    
    if not typeMsg
        _msg            :=          _msg + " a="+_account+" e="+_exchange+" s="+msg_syminfoticker + _txtDelay + " b=short q=100% t=limit | "
    else
        _msg            :=          ""
    _msg
//              -                          } End 2.6 - Hedge
//              -                          } End EXTERNAL



































