
// Filter Name :   HF-602 VIP
// User: Mostafa Ejarestaghi
// UPDATE: 1401/01/15
// version : 1.1.1
// ------------ site inormation -------------
// website : www.hooshefaal.ir
// Email : hooshefaal@gmail.com
//Telegram Channel : @hooshefaal
//Telegram Support : @hooshefaal_support
// Instagram Page :  @hooshefaal.ir
//whatsapp number :  09364549266
// --------------END---------------
/*
فیلتر شناسایی نمادهای آماده حرکت صعودی - نسخه HF-602
منطق: فشردگی قیمت + افزایش حجم + برتری خریدار حقیقی + قدرت پایانی + شروع روند
*/
true == function () {
    //------------------COMMAND START-----------------------
    Hooshefaal();
    (cfield0) = "";
    (cfield1) = "";
    (cfield2) = "";

    // ذخیره تاریخچه کندل‌ها
    if ([ih][0].PClosing != (pc) && [ih][0].ZTotTran != (tno) && [ih][0].QTotCap != (tval)) {
        var len = [ih].length;
        if (typeof [ih][0].fixed == 'undefined') {
            for (var i = len; i > 0; i--) {
                if (typeof [ih][i] == 'undefined') {
                    [ih][i] = {};
                }
                [ih][i].PriceFirst = [ih][i - 1].PriceFirst;
                [ih][i].PClosing = [ih][i - 1].PClosing;
                [ih][i].PDrCotVal = [ih][i - 1].PDrCotVal;
                [ih][i].ZTotTran = [ih][i - 1].PriceFirst;
                [ih][i].QTotTran5J = [ih][i - 1].QTotTran5J;
                [ih][i].QTotCap = [ih][i - 1].QTotCap;
                [ih][i].PriceChange = [ih][i - 1].PriceChange;
                [ih][i].PriceMin = [ih][i - 1].PriceMin;
                [ih][i].PriceMax = [ih][i - 1].PriceMax;
                [ih][i].PriceYesterday = [ih][i - 1].PriceYesterday;
            }
            [ih][0].fixed = 1;
        }
        [ih][0].PriceFirst = (pf);
        [ih][0].PClosing = (pc);
        [ih][0].PDrCotVal = (pl);
        [ih][0].ZTotTran = (tno);
        [ih][0].QTotTran5J = (tvol);
        [ih][0].QTotCap = (tval);
        [ih][0].PriceChange = (pcc);
        [ih][0].PriceMin = (pmin);
        [ih][0].PriceMax = (pmax);
        [ih][0].PriceYesterday = (py);
    }

    //------------------ منطق فیلتر HF-602 ------------------

    // میانگین حجم ۵ روز اخیر
    var avgVol =
    (
        [ih][0].QTotTran5J +
        [ih][1].QTotTran5J +
        [ih][2].QTotTran5J +
        [ih][3].QTotTran5J +
        [ih][4].QTotTran5J
    ) / 5;

    // نسبت حجم امروز به میانگین ۵ روزه
    var volumeRatio = (tvol) / avgVol;

    // قدرت خریدار حقیقی
    var buyPower =
        ((ct).Buy_I_Volume / (ct).Buy_CountI) /
        ((ct).Sell_I_Volume / (ct).Sell_CountI);

    // درصد تغییر قیمت آخرین معامله
    var priceChange = (plp);

    // فشردگی قیمت: دامنه امروز به قیمت پایانی
    var priceRange = ((pmax) - (pmin)) / (pc) * 100;

    // قدرت پایانی: چه سهمی از دامنه روز در قیمت پایانی پر شده
    var closeStrength = ((pmax) - (pmin)) > 0
        ? ((pc) - (pmin)) / ((pmax) - (pmin)) * 100
        : 0;

    // شیب شروع روند: قیمت پایانی نسبت به قیمت اول و دیروز
    var trendUp = ((pc) >= (pf)) && ((pc) > (py));

    // مقداردهی امن در برابر NaN
    if (isNaN(avgVol)) avgVol = 0;
    if (isNaN(volumeRatio)) volumeRatio = 0;
    if (isNaN(buyPower)) buyPower = 0;
    if (isNaN(priceChange)) priceChange = 0;
    if (isNaN(priceRange)) priceRange = 0;
    if (isNaN(closeStrength)) closeStrength = 0;

    // ستون‌ها
    (cfield0) = AdvRoundColor(priceRange, 2);     // دامنه نوسان (فشردگی)
    (cfield1) = AdvRoundColor(buyPower, 2);       // قدرت خریدار حقیقی
    (cfield2) = AdvRoundColor(closeStrength, 1);  // قدرت پایانی (%)

    return (
        avgVol > 0 &&
        (ct).Buy_CountI > 0 &&
        (ct).Sell_CountI > 0 &&
        (ct).Buy_I_Volume > 0 &&
        (ct).Sell_I_Volume > 0 &&
        // ۱) فشردگی قیمت: دامنه امروز کمتر از ۳٪ قیمت پایانی
        priceRange > 0 && priceRange <= 3 &&
        // ۲) افزایش نسبی حجم: بین ۱ تا ۲.۵ برابر میانگین
        volumeRatio >= 1 && volumeRatio <= 2.5 &&
        // ۳) برتری خریدار حقیقی: بین ۱ تا ۳
        buyPower >= 1 && buyPower <= 3 &&
        // ۴) قدرت پایانی: حداقل ۷۰٪ دامنه روز در قیمت پایانی
        closeStrength >= 70 &&
        // ۵) شروع روند صعودی
        trendUp &&
        (pcp) > 0
    );
}()
//=========================END FUNCTION =========================

function Hooshefaal() {
    var HelpLink = "https://www.hooshefaal.ir/tse-filter-hf-602/";
    var FilterName = "HF-602";

    var column1 = "دامنه نوسان %", column2 = "قدرت خریدار", column3 = "قدرت پایانی %", column4 = "", column5 = "";

    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: #FFAB73;font-weight: normal;"> ' + column1 + '</span>';
    my_data_title0 += '<span style="left: 10px;direction: rtl; display: inline-block; background: #F6F7BF;font-weight: normal; text-align: center;border: 0 solid red;border-radius: 6px; padding: 3px;top: 42%;position: fixed;font-family: Tahoma; font-size: 12px; background-color: #FFD700 !important;  box-shadow: 0 2px 5px rgb(0 0 0 / 50%);color: Blue; width: 150px;animation: NotificationAnim 2s infinite linear;"><a href="https://www.hooshefaal.ir/category/vip-filter/gold/" title="فیلتر های طلایی سایت هوش فعال" target="_blank"><b>💎فیلتر های پریمیوم</b></a> </span>';
    my_data_title0 += '<span style="left: 10px;direction: rtl;display: inline-block;background: #F6F7BF;font-weight: normal;text-align: center;border: 0 solid red;border-radius: 6px;padding: 3px;top: 45%;position: fixed;font-family: Tahoma;font-size: 12px;background-color: #06FF00 !important;box-shadow: 0 2px 5px rgb(0 0 0 / 50%);color: Blue;width: 150px;animation: NotificationAnim 2s infinite linear;"><a href="https://www.hooshefaal.ir/category/%d9%81%db%8c%d9%84%d8%aa%d8%b1-%d9%86%d9%88%db%8c%d8%b3%db%8c-%d8%a8%d9%88%d8%b1%d8%b3/free-filter/"title="دانلود فیلتر های vip بورسی" target="_blank">دانلود فیلترهای vip</a></span>';
    my_data_title0 += '<span style="left: 10px;direction: rtl; display: inline-block; background: #F6F7BF;font-weight: normal; text-align: center;border: 0 solid red;border-radius: 6px; padding: 3px;top: 48%;position: fixed;font-family: Tahoma; font-size: 12px; background-color: #06FF00 !important;  box-shadow: 0 2px 5px rgb(0 0 0 / 50%);color: Blue; width: 150px;animation: NotificationAnim 2s infinite linear;"><a href="https://www.hooshefaal.ir/category/indicator-download/" title=" دانلود رایگان اندیکاتور" target="_blank">دانلود رایگان اندیکاتور </a> </span>';
    my_data_title0 += '<span style="left: 10px;direction: rtl; display: inline-block; background: #F6F7BF;font-weight: normal; text-align: center;border: 0 solid red;border-radius: 6px; padding: 3px;top: 51%;position: fixed;font-family: Tahoma; font-size: 12px; background-color: #A4EBF3 !important;  box-shadow: 0 2px 5px rgb(0 0 0 / 50%);color: Blue; width: 150px;animation: NotificationAnim 2s infinite linear;">سفارش <a href="https://www.hooshefaal.ir/expert-order/" title="سفارش اکسپرت" target="_blank">اکسپرت</a> و <a href="https://www.hooshefaal.ir/tsetmc-filter-order/" title="سفارش فیلتر" target="_blank">فیلتر </a> </span>';
    my_data_title0 += '<span style="left: 10px;direction: rtl; display: inline-block; background: #F6F7BF;font-weight: normal; text-align: center;border: 0 solid red;border-radius: 6px; padding: 3px;top: 54%;position: fixed;font-family: Tahoma; font-size: 12px; background-color: #A4EBF3 !important;  box-shadow: 0 2px 5px rgb(0 0 0 / 50%);color: Blue; width: 150px;animation: NotificationAnim 2s infinite linear;"><a href="https://t.me/hooshefaal_indicator" title="کانال تلگرام هوش فعال" target="_blank">کانال تلگرام هوش فعال</a> </span>';
    my_data_title0 += '<span style="left: 10px;direction: rtl; display: inline-block; background: #F6F7BF;font-weight: normal; text-align: center;border: 0 solid red;border-radius: 6px; padding: 3px;top: 57%;position: fixed;font-family: Tahoma; font-size: 12px; background-color: #ffad00 !important;  box-shadow: 0 2px 5px rgb(0 0 0 / 50%);color: Blue; width: 150px;animation: NotificationAnim 2s infinite linear;"><a href="https://www.youtube.com/@hooshefaal" title="کانال یوتیوب هوش فعال" target="_blank">یوتیوب هوش فعال </a> </span>';
    my_data_title0 += '<span style="left: 10px;direction: rtl; display: inline-block; background: #F6F7BF;font-weight: normal; text-align: center;border: 0 solid red;border-radius: 6px; padding: 3px;top: 60%;position: fixed;font-family: Tahoma; font-size: 12px; background-color: #ffcc00 !important;  box-shadow: 0 2px 5px rgb(0 0 0 / 50%);color: Blue; width: 150px;animation: NotificationAnim 2s infinite linear;"><a href="https://www.aparat.com/hooshefaal.ir" title="کانال آپارات  هوش فعال" target="_blank">آپارات هوش فعال </a> </span>';
    my_data_title0 += '<span style="left: 10px;direction: rtl; display: inline-block; background: #F6F7BF;font-weight: normal; text-align: center;border: 0 solid red;border-radius: 6px; padding: 3px;top: 63%;position: fixed;font-family: Tahoma; font-size: 12px; background-color: #ffff00 !important;  box-shadow: 0 2px 5px rgb(0 0 0 / 50%);color: Blue; width: 150px;animation: NotificationAnim 2s infinite linear;"><b><a href="' + HelpLink + '" title="لینک آموزش شیوه استفاده از این فیلتر" target="_blank">راهنمای این فیلتر</a> </b></span>';
    my_data_title0 += '<span style="left: 10px;direction: rtl; display: inline-block; background: #F6F7BF;font-weight: normal; text-align: center;border: 0 solid red;border-radius: 6px; padding: 3px;top: 66%;position: fixed;font-family: Tahoma; font-size: 25px; background-color: #ff5;  box-shadow: 0 2px 5px rgb(0 0 0 / 50%);color: Blue !important; width: 150px;animation: NotificationAnim 2s infinite linear;"><a href="' + HelpLink + '" title=" سایت  هوش فعال" target="_blank"><b>هوش فعال</b><br><b>' + FilterName + '</b></a> </span></div>';

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

    var cfield0_title = my_data_title0, cfield1_title = my_data_title1, cfield2_title = my_data_title2;
    var wc0 = "100px", wc1 = "100px", wc2 = "1200px";

    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";
        }
    }

    // ------------------ تابع کمکی رنگ‌دهی ------------------
    window.AdvRoundColor = function (value, decimals) {
        var v = parseFloat(value);
        var d = (typeof decimals === 'number') ? decimals : 2;
        if (isNaN(v)) v = 0;
        var color;
        if (v > 0) color = "green";
        else if (v < 0) color = "red";
        else color = "#555";
        return "<span style='font-weight:bold;color:" + color + ";'>" + v.toFixed(d) + "</span>";
    };
}