// ------------ site inormation -------------
// description : Finding  Items with RSI  Less than 20 and greet than 80
// return value in (cfield0)
//FILTER NAME : free filter FH-4
// User: Mostafa Ejarestaghi
// Date: 1399/12/11
// UPDATE: 1400/11/16
// version : 1.1.2
// website : www.hooshefaal.ir 
// Email : hooshefaal@gmail.com
//Telegram Channel : @hooshefaal
//Telegram Support : @hooshefaal_support
//Telegram seller : @hooshefaal_seller
// Instagram Page :  @hooshefaal.ir
//whatsapp number :  09364549266
// --------------END---------------
true == function () {
    (cfield0) = 0;
    (cfield1) = 0;
    (cfield2) = 0;

    var CalculateRSI = function (period) {
        var len = 20;
        for (var i = 0; i < len; i++) {
            var rec = [ih][len - 1 - i];
            var change = rec.PClosing - rec.PriceYesterday;
            if (change > 0) {
                rec.gain = change;
                rec.loss = 0;
            }
            else {
                rec.gain = 0;
                rec.loss = -change;
            }
        }
        // Calculate first "average gain" and "average loss"
        var gainSum = 0;
        var lossSum = 0;
        for (var i = 0; i < period; i++) {
            var rec = [ih][len - 1 - i];
            gainSum += rec.gain;
            lossSum += rec.loss;
        }
        var averageGain = gainSum / period;
        var averageLoss = lossSum / period;
        // Calculate subsequent "average gain" and "average loss" values
        for (var i = period + 1; i < len; i++) {
            var rec = [ih][len - 1 - i];
            averageGain = (averageGain * (period - 1) + rec.gain) / period;
            averageLoss = (averageLoss * (period - 1) + rec.loss) / period;
            rec.averageGain = averageGain;
            rec.averageLoss = averageLoss;
        }
        // Calculate RSI
        var RS = 0; // Relative strength
        var RSIndex = 0; // Relative strength index
        for (var i = period + 1; i < len; i++) {
            var rec = [ih][len - 1 - i];
            RS = rec.averageGain / rec.averageLoss;
            RSIndex = 100 - 100 / (1 + RS);
            rec.rsi = RSIndex;
        }
    };
    if (typeof [ih][0].rsi == "undefined") CalculateRSI(14);
    (cfield0) = Math.floor([ih][0].rsi);
    if ([ih][0].rsi > 80 || [ih][0].rsi < 20) {
        (cfield1) = 0;
        (cfield2) = 0;
        Hooshefaal();
        return true;
    }
    else {
        return false;
    }
}()
function Hooshefaal() {
    var HelpLink = "https://www.hooshefaal.ir/پیداکردن-نمادهایی-که-rsi-بالای-80-یا-زیر-20-دا/";
    var FilterName = "FH-4";
    var column1 = "A", column2 = "B", column3 = "پیام", column4 = "", column5 = "";
    var my_data_title0 = '<div style = "direction:rtl;";><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: 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="دانلود رایگان فیلتر های بورسی" 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: 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/" 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/channel/UCMWCAmtUbiZcF4d7vZVtjfg" 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/vitanet" 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>'
    //cfield Titel
    var cfield0_title = my_data_title0, cfield1_title = my_data_title1, cfield2_title = my_data_title2;
    //Columns width
    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.width = wc0;
            title[i].style.fontWeight = "normal";
        }

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

}