kiosotto_lines

Download script
Author: Kilian19@FF, remix by Scriptong

This script is a specialized technical analysis tool designed to help traders visualize the relationship between market momentum and price extremes. Rather than simply showing a standard trend line, it calculates a unique ratio to identify potential imbalances between "bullish" and "bearish" forces over a specific period of time.

Core Logic and Behavior

1. Data Input and Customization The tool allows the user to define two primary parameters:

  • The Analysis Period: This determines how many previous price bars the script looks back at to perform its calculations.
  • The Display Limit: This controls how much historical data is shown on your chart at once, ensuring the platform remains responsive by not loading unnecessary information.

2. Calculation Methodology The heart of this script lies in how it evaluates "Power." To do this, it looks at a specific period of time and scans every bar to find two key landmarks:

  • The highest price point reached during that window.
  • The lowest price point reached during that window.

While identifying these points, the script also calculates a "Power Value" for each individual bar by multiplying a standard Relative Strength Index (RSI) value by the closing price of that bar.

3. The Momentum Ratio The script then accumulates these Power Values into two separate categories:

  • Bullish Power: The sum of values associated with the highest price points found in the period.
  • Bearish Power: The sum of values associated with the lowest price points found in the period.

Finally, it produces a ratio by dividing one power total by the other. This results in two distinct visual lines on your chart:

  • One line represents the ratio of Bearish Power relative to Bullish Power (traditionally associated with sell signals).
  • The other line represents the ratio of Bullish Power relative to Bearish Power (traditionally associated with buy signals).

Visual Representation

The script renders these calculations as two continuous lines in a separate window below your main price chart.

  • Red Line: Represents the Bearish-to-Bullish ratio.
  • Green Line: Represents the Bullish-to-Bearish ratio.

By watching how these lines move and cross, traders can attempt to identify moments where momentum is shifting significantly from one direction to another, providing a visual representation of which "side" of the market currently holds more weighted strength based on the chosen period.

Price Data Components
Series array that contains the highest prices of each barSeries array that contains the lowest prices of each barSeries array that contains close prices for each bar
Indicators Used
Relative strength index
Miscellaneous
It issuies visual alerts to the screenImplements a curve of type %1
11 Views
0 Downloads
0 Favorites
kiosotto_lines
//+------------------------------------------------------------------+
//|                                               kiosotto_lines.mq4 |
//|                  Copyright 2016, Kilian19@FF, remix by Scriptong |
//|                                          http://advancetools.net |
//+------------------------------------------------------------------+
#property copyright "Kilian19@FF, remix by Scriptong"
#property link      "http://advancetools.net"
#property version "1.00"
#property strict

#property indicator_separate_window
#property indicator_buffers 2 
#property indicator_color1 clrRed 
#property indicator_color2 clrGreen 
#property indicator_width1 2 
#property indicator_width2 2 

// Input parameters of indicator
input int                      i_dev_period          = 5;                                          // RSI period / Ïåðèîä RSI
input int                      i_indBarsCount        = 10000;                                      // The number of bars to display / Êîëè÷åñòâî áàðîâ îòîáðàæåíèÿ

                                                                                                   // The indicator's buffers
double            g_sellBuffer[];
double            g_buyBuffer[];

// Other global variables of indicator
bool              g_activate;                                                                      // Sign of successful initialization of indicator
//+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
//| Custom indicator initialization function                                                                                                                                                          |
//+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
int OnInit()
  {
   g_activate=false;

   if(!IsTuningParametersCorrect())
      return INIT_FAILED;

   iTime(NULL,PERIOD_D1,0);

   if(!BuffersBind())
      return (INIT_FAILED);

   g_activate=true;
   return INIT_SUCCEEDED;
  }
//+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
//| Checking the correctness of input parameters                                                                                                                                                      |
//+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
bool IsTuningParametersCorrect()
  {
   string name=WindowExpertName();

   bool isRussianLang=(TerminalInfoString(TERMINAL_LANGUAGE)=="Russian");

   if(i_dev_period<1)
     {
      Alert(name,(isRussianLang)? ": ïåðèîä RSI äîëæåí áûòü 1 è áîëåå. Èíäèêàòîð îòêëþ÷åí." :
            ": the RSI period must be 1 or more. The indicator is turned off.");
      return false;
     }

   return true;
  }
//+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
//| Custom indicator deinitialization function                                                                                                                                                        |
//+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
void OnDeinit(const int reason)
  {
  }
//+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
//| Determination of bar index which needed to recalculate                                                                                                                                            |
//+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
int GetRecalcIndex(int &total,const int ratesTotal,const int prevCalculated)
  {
   total=ratesTotal-1;

   if(i_indBarsCount>0 && i_indBarsCount<total)
      total=MathMin(i_indBarsCount,total);

   if(prevCalculated<ratesTotal-1)
     {
      InitializeBuffers();
      return (total);
     }

   return (MathMin(ratesTotal - prevCalculated, total));
  }
//+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
//| Initialize of all indicator buffers                                                                                                                                                               |
//+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
void InitializeBuffers()
  {
   ArrayInitialize(g_sellBuffer,EMPTY_VALUE);
   ArrayInitialize(g_buyBuffer,EMPTY_VALUE);
  }
//+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
//| Binding the indicator buffers with arrays                                                                                                                                                         |
//+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
bool BuffersBind()
  {
   string name=WindowExpertName();
   bool isRussianLang=(TerminalInfoString(TERMINAL_LANGUAGE)=="Russian");

   if(!SetIndexBuffer(0,g_sellBuffer) || 
      !SetIndexBuffer(1,g_buyBuffer))
     {
      Alert(name,(isRussianLang)? ": îøèáêà ñâÿçûâàíèÿ ìàññèâîâ ñ áóôåðàìè èíäèêàòîðà. Îøèáêà ¹"+IntegerToString(GetLastError()) :
            ": error of binding of the arrays and the indicator buffers. Error N"+IntegerToString(GetLastError()));
      return false;
     }

   for(int i=0; i<2; i++)
      SetIndexStyle(i,DRAW_LINE);

   return true;
  }
//+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
//| Process the specified bar                                                                                                                                                                         |
//+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
void ProcessBar(int barIndex,int total)
  {
   double curHigh=0.0,curLow=0.0;
   double bullPower=0.0,bearPower=0.0;
   for(int i=0; i<i_dev_period; i++)
     {
      int shift=i+barIndex;
      double rsi=iRSI(NULL,0,i_dev_period,PRICE_CLOSE,shift);
      double high= iHigh(NULL,0,shift);
      double low = iLow(NULL,0,shift);
      double power=rsi*iClose(NULL,0,shift);

      if(high>curHigh)
        {
         curHigh=high;
         bullPower+=power;
        }

      if(low<curLow || curLow==0.0)
        {
         curLow=low;
         bearPower+=power;
        }
     }

   if(bullPower!=0.0)
      g_sellBuffer[barIndex]=bearPower/bullPower;

   if(bearPower!=0.0)
      g_buyBuffer[barIndex]=bullPower/bearPower;
  }
//+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
//| Displaying of indicators values                                                                                                                                                                   |
//+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
void ShowIndicatorData(int limit,int total)
  {
   for(int i=limit; i>0; i--)
      ProcessBar(i,total);
  }
//+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
//| Custom indicator iteration function                                                                                                                                                               |
//+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
int OnCalculate(const int rates_total,
                const int prev_calculated,
                const datetime &time[],
                const double &open[],
                const double &high[],
                const double &low[],
                const double &close[],
                const long &tick_volume[],
                const long &volume[],
                const int &spread[])
  {
   if(!g_activate)
      return prev_calculated;

   int total;
   int limit=GetRecalcIndex(total,rates_total,prev_calculated);

   ShowIndicatorData(limit,total);

   return rates_total;
  }
//+------------------------------------------------------------------+

Comments