
/*
Filter Name : HF-600 vip
User        : Mostafa Ejarestaghi
UPDATE      : 1405/07/25
Version     : 1.0.0

Website     : www.hooshefaal.ir
Email       : hooshefaal@gmail.com
Telegram    : @hooshefaal_indicator

فیلتر شکاف قیمتی مثبت
*/

//------------------ COMMAND START -----------------------

true == function () {

    Hooshefaal();

    (cfield0) = "";
    (cfield1) = "";
    (cfield2) = "";

    // Check valid previous closing price
    if ((py) <= 0 || (pf) <= 0) {
        return false;
    }

    // Calculate positive price gap
    var gapValue = (pf) - (py);
    var gapPercent = (gapValue / (py)) * 100;

    // Positive gap condition
    if (gapValue <= 0) {
        return false;
    }

    // Format values
    gapValue = Math.round(gapValue * 100) / 100;
    gapPercent = Math.round(gapPercent * 100) / 100;

    // Calculate trading value in million Rials
    var tradeValue = ((tval) / 1000000);

    if (isNaN(tradeValue)) {
        tradeValue = 0;
    }

    tradeValue = Math.round(tradeValue * 100) / 100;

    // Set display colors
    var gapColor = "#008000";
    var gapBG = "#D9F7D9";

    if (gapPercent >= 2) {
        gapBG = "#A8E6A3";
    }

    // Display gap percentage
    (cfield0) =
        "<span style='display:inline-block;width:100%;"
        + "background:" + gapBG + ";color:" + gapColor + ";"
        + "text-align:center;font-weight:bold;padding:3px 0;'>"
        + gapPercent + "%</span>";

    // Display price gap
    (cfield1) =
        "<span style='display:inline-block;width:100%;"
        + "background:#E8F4FD;color:#154360;"
        + "text-align:center;font-weight:bold;padding:3px 0;'>"
        + gapValue + "</span>";

    // Display trading value
    (cfield2) =
        "<span style='display:inline-block;width:100%;"
        + "background:#FFF2CC;color:#7D6608;"
        + "text-align:center;font-weight:bold;padding:3px 0;'>"
        + tradeValue + "</span>";

    return true;

}();

//========================= END FUNCTION =========================


function Hooshefaal() {

    var HelpLink = "https://www.hooshefaal.ir/tse-filter-hf-600/";
    var FilterName = "HF-600";

    var column1 = "شکاف مثبت (%)";
    var column2 = "میزان شکاف";
    var column3 = "ارزش معاملات (میلیون ریال)";

    var my_data_title0 =
        "<div style='direction:rtl;'>";

    my_data_title0 +=
        "<span style='border:1px solid gray;width:100%;"
        + "display:inline-block;text-align:center;color:#000;"
        + "background:#A8E6A3;font-weight:normal;'>"
        + column1 + "</span>";

    my_data_title0 +=
        "<span style='left:10px;direction:rtl;display:inline-block;"
        + "background:#FFD700;text-align:center;border-radius:6px;"
        + "padding:3px;top:42%;position:fixed;font-family:Tahoma;"
        + "font-size:12px;color:Blue;width:150px;'>"
        + "<a href='https://www.hooshefaal.ir/category/vip-filter/gold/' "
        + "target='_blank'><b>فیلترهای پریمیوم</b></a></span>";

    my_data_title0 +=
        "<span style='left:10px;direction:rtl;display:inline-block;"
        + "background:#06FF00;text-align:center;border-radius:6px;"
        + "padding:3px;top:45%;position:fixed;font-family:Tahoma;"
        + "font-size:12px;color:Blue;width:150px;'>"
        + "<a href='https://www.hooshefaal.ir/category/stock-market/free-filter/' "
        + "target='_blank'>فیلترهای ویژه</a></span>";

    my_data_title0 +=
        "<span style='left:10px;direction:rtl;display:inline-block;"
        + "background:#A4EBF3;text-align:center;border-radius:6px;"
        + "padding:3px;top:48%;position:fixed;font-family:Tahoma;"
        + "font-size:12px;color:Blue;width:150px;'>"
        + "سفارش <a href='https://www.hooshefaal.ir/tsetmc-filter-order/' "
        + "target='_blank'>فیلتر</a></span>";

    my_data_title0 +=
        "<span style='left:10px;direction:rtl;display:inline-block;"
        + "background:#FFFF00;text-align:center;border-radius:6px;"
        + "padding:3px;top:51%;position:fixed;font-family:Tahoma;"
        + "font-size:12px;color:Blue;width:150px;'>"
        + "<a href='" + HelpLink + "' target='_blank'>"
        + "راهنمای این فیلتر</a></span>";

    my_data_title0 +=
        "<span style='left:10px;direction:rtl;display:inline-block;"
        + "background:#FFFF55;text-align:center;border-radius:6px;"
        + "padding:3px;top:54%;position:fixed;font-family:Tahoma;"
        + "font-size:20px;color:Blue;width:150px;'>"
        + "<a href='https://www.hooshefaal.ir/' target='_blank'>"
        + "<b>هوش فعال</b><br><b>" + FilterName + "</b></a></span>";

    my_data_title0 += "</div>";

    var my_data_title1 =
        "<span style='border:1px solid gray;width:100%;"
        + "display:inline-block;text-align:center;color:#000;"
        + "background:#BDE0FE;font-weight:normal;'>"
        + column2 + "</span>";

    var my_data_title2 =
        "<span style='border:1px solid gray;width:100%;"
        + "display:inline-block;text-align:center;color:#000;"
        + "background:#FFF2CC;font-weight:normal;'>"
        + column3 + "</span>";

    var cfield0_title = my_data_title0;
    var cfield1_title = my_data_title1;
    var cfield2_title = my_data_title2;

    var title = document.getElementsByClassName("t0head");

    for (var i = 0; i < title.length; i++) {

        if (title[i].outerHTML.includes("cfield0")) {
            title[i].innerHTML = cfield0_title;
            title[i].style.fontWeight = "normal";
        }
        else if (title[i].outerHTML.includes("cfield1")) {
            title[i].innerHTML = cfield1_title;
            title[i].style.fontWeight = "normal";
        }
        else if (title[i].outerHTML.includes("cfield2")) {
            title[i].innerHTML = cfield2_title;
            title[i].style.fontWeight = "normal";
        }

    }

}
