// Filter Name :   HF-514 FREE
// User: Mostafa Ejarestaghi
// UPDATE: 1402/09/21
// 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---------------
/*
فیلتر نوسان گیری با ایچیموکو


*/
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);
  }
  var i;
  var buy_ratio = Math.round(((((ct).Buy_I_Volume / (ct).Buy_CountI) * (pc)) / 10000000) * 10) / 10;
  var sell_ratio = Math.round(((((ct).Sell_I_Volume / (ct).Sell_CountI) * (pc)) / 10000000) * 10) / 10;
  var buy_power = Math.round((((ct).Buy_I_Volume / (ct).Buy_CountI) / ((ct).Sell_I_Volume / (ct).Sell_CountI)) * 100) / 100;
  var moneyVal = ((ct).Buy_I_Volume - (ct).Sell_I_Volume) * (pc);
  moneyVal = ((moneyVal / 10) / 1000000).toFixed(2);

  if (isNaN(buy_ratio)) {
    buy_ratio = 0;
  }
  if (isNaN(sell_ratio)) {
    sell_ratio = 0;
  }
  if (isNaN(buy_power)) {
    buy_power = 0;
  }
  if (isNaN(moneyVal)) {
    moneyVal = 0;
  }

  var MoneyColor = "";
  if (moneyVal > 0) {
    MoneyColor = "green";
  }
  if (moneyVal < 0) {
    MoneyColor = "red";
  }


  function SaraneKharid_Haqiqi_avg(start, day) {
    var sum = 0;
    for (var i = start; i < day; i++) {
      sum += (([ic][i].Buy_I_Volume / [ic][i].Buy_CountI) * ([ih][i].QTotCap / [ih][i].QTotTran5J));
    }
    var avg = sum / day;
    return avg;
  }
  function FindMax(start, day) {
    var max = 0;
    for (var i = start; i < start + day; i++) {
      if ([ih][i].PriceMax > max) {
        max = [ih][i].PriceMax;
      }
    }
    return max;
  }
  function FindMin(start, day) {
    var min = 9999999;
    for (var i = start; i < start + day; i++) {
      if ([ih][i].PriceMin < min) {
        min = [ih][i].PriceMin;
      }
    }
    return min;
  }



  function Tenkan_sen(start) {
    var Tenkan_sen = (FindMax(start, 9) + FindMin(start, 9)) / 2;
    return Tenkan_sen;
  }
  function Kijun_sen(start) {
    var Kijun_sen = (FindMax(start, 26) + FindMin(start, 26)) / 2;
    return Kijun_sen;
  }
  function Senkou_Span_A(start) {
    var Senkou_Span_A = (Tenkan_sen(start + 26) + Kijun_sen(start + 26)) / 2;
    return Senkou_Span_A;
  }
  function Senkou_Span_B(start) {
    var Senkou_Span_B = (FindMax(start + 26, 52) + FindMin(start + 26, 52)) / 2;
    return Senkou_Span_B;
  }

  function Senkou_Span_A(start) {
    var Senkou_Span_A = (Tenkan_sen(start + 26) + Kijun_sen(start + 26)) / 2;
    return Senkou_Span_A;
  }
  function Senkou_Span_B(start) {
    var Senkou_Span_B = (FindMax(start + 26, 52) + FindMin(start + 26, 52)) / 2;
    return Senkou_Span_B;
  }
  function Senkou_Span_AA(start) {
    var Senkou_Span_AA = (Tenkan_sen(start + 0) + Kijun_sen(start + 0)) / 2;
    return Senkou_Span_AA;
  }
  function Senkou_Span_BA(start) {
    var Senkou_Span_BA = (FindMax(start + 0, 52) + FindMin(start + 0, 52)) / 2;
    return Senkou_Span_BA;
  }

  var statusBG = "";
  var statusCOLOR = "";
  var Tenk_Kij = "";
  if (Tenkan_sen(0) > Kijun_sen(0) && Tenkan_sen(1) <= Kijun_sen(1)) {
    Tenk_Kij += " کراس تنکاستن با کیجونسن";
    statusBG = "Black";
    statusCOLOR = "#02fa1b";
  } else if (Tenkan_sen(0) > Kijun_sen(0)) {
    Tenk_Kij += "تنکاستن بالای کیجونسن ";
    statusCOLOR = "Green";
  }
  if (Tenkan_sen(0) == Kijun_sen(0)) {
    Tenk_Kij += "تنکاستن مساوی کیجونسن ";
  }
  if (Tenkan_sen(0) < Kijun_sen(0) && Tenkan_sen(1) >= Kijun_sen(1)) {
    Tenk_Kij += "  کراس کیجونسن با تنکاستن  ";
    statusBG = "Yellow";
    statusCOLOR = "Black";
  } else if (Tenkan_sen(0) < Kijun_sen(0)) {
    Tenk_Kij += " تنکاستن زیر کیجونسن";
    statusCOLOR = "Red";
  }

  var color1BG = "";
  var CanTK = "";
  if ([ih][0].PriceMin > Tenkan_sen(0)) {
    CanTK += "کندل بالای تنکاستن";
    color1BG = "#5ffab2";
  }
  if ([ih][0].PriceMax < Tenkan_sen(0)) {
    CanTK += "کندل پایین تنکاستن";
    color1BG = "#ee96fa";
  }
  if ([ih][0].PriceMax >= Tenkan_sen(0) && [ih][0].PriceMin <= Tenkan_sen(0)) {
    CanTK += "کندل درگیر تنکاستن";
    color1BG = "#42f6fc";
  }
  var color2BG = "";
  var CanKij = "";
  if ([ih][0].PriceMin > Kijun_sen(0)) {
    CanKij += "کندل بالای کیجونسن";
    color2BG = "#5ffab2";
  }
  if ([ih][0].PriceMax < Kijun_sen(0)) {
    CanKij += "کندل پایین کیجونسن";
    color2BG = "#ee96fa";
  }
  if ([ih][0].PriceMax >= Kijun_sen(0) && [ih][0].PriceMin <= Kijun_sen(0)) {
    CanKij += "کندل درگیر کیجونسن";
    color2BG = "#42f6fc";
  }




  (cfield0) = buy_power;
  (cfield1) = "<span style='opacity: 0.8;border-top: 1px solid #C0C0C0;border-left: 1px solid #000000;width:100%;display:inline-block;background:#ffffff;text-align: center;color:" + MoneyColor + ";font-weight: bold;' title='ورود و خروج پول'>&nbsp" + moneyVal + "</span>";;
  var strResult = "<span style='opacity: 0.8;border-top: 1px solid #C0C0C0;border-left: 1px solid #000000;width:160px;display:inline-block;background:" + color1BG + ";text-align: center;color:;font-weight: bold;' title=' وضعیت ابر'>&nbsp" + CanTK + "</span>";;
  strResult += "<span style='opacity: 0.8;border-top: 1px solid #C0C0C0;border-left: 1px solid #000000;width:160px;display:inline-block;background:" + color2BG + ";text-align: center;color:;font-weight: bold;' title=' وضعیت ابر جدید'>&nbsp" + CanKij + "</span>";;
  strResult += "<span style='opacity: 0.8;border-top: 1px solid #C0C0C0;border-left: 1px solid #000000;width:200px;display:inline-block;background:" + statusBG + ";text-align: center;color:" + statusCOLOR + ";font-weight: bold;' title='وضعیت تنکانسن و کیجون سن'>&nbsp" + Tenk_Kij + "</span>";;

  (cfield2) = strResult;
  return true;

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

  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="دانلود رایگان فیلتر های بورسی" 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";
    }
  }

}

