Theil_Sen Indicator Free – indicator MetaTrader 4

Β This is essentially a tool to estimate the general trajectory of a line drawn from a collection of data points. The estimated line is derived by first performing regression on the series of values and then calculating the slope of this resulting regression line. Β The data set selection can be a simple moving average, exponential moving average, close prices, high/low prices and they are automatically collected from the meta trader chart . You only need to select one type of data you want to collect. It support multiple currencies.

iTSlope(asymbol,timeframe,regperiod,adataset,rmp,rtc,slope,line_nickname,enable_text,ashift);
//This is the main function to use in your EA. Just input your own parameters. 
//Manual traders can use this or use the indicator directly. 


As usual, this supports multiple currencies at the same time and I am including the “BreakPoint” tool here but it is not needed by the indicator itself.

This is what the trend-line look like in a ranging market:

ranging market

randing market with tendency

Now this is what the trend-line looks like on a trending market:

trending

Here is a demo expert advisor:

  DF-ProfitMonitor - indicator MetaTrader 4
//+------------------------------------------------------------------+
//|Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β  demo.mq4 |
//|Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β  Copyright 2020, Everybody Software Corp. |
//|Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β  https://anywhere.com |
//+------------------------------------------------------------------+
#property copyright "Copyright 2020, Everybody Software Corp."
#property linkΒ Β Β Β Β Β "https://anywhere.com"
#property versionΒ Β  "1.00"
#property strict
#include <TheilSen_Indicator.mqh>
#include <BreakPoint.mqh>//<--- not required
//+------------------------------------------------------------------+
//| Expert initialization functionΒ Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β  |
//+------------------------------------------------------------------+
int OnInit()
Β Β {
Β Β  return(INIT_SUCCEEDED);
Β Β }
Β Β 
//+------------------------------------------------------------------+
//| Expert deinitialization functionΒ Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β  |
//+------------------------------------------------------------------+
void OnDeinit(const int reason)
Β Β { 
Β Β }
Β Β 
//+------------------------------------------------------------------+
//| Expert tick functionΒ Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β  |
//+------------------------------------------------------------------+
void OnTick()
Β Β {
Β Β  //---------these variables are created empty but they will contain data after iTSlop() is used below.------//
Β Β  double slope=0;//the slope of the regression line.
Β Β  
Β Β  ENUM_TIMEFRAMES timeframe=0;//this is the timeframe for the symbol. 0 means current chart timeframe.
Β Β  
Β Β  int 
Β Β  regperiod=20,//the regression period. how many bars do you want to perform regression on.
Β Β  ashift=1;//the shift of the bar where you want the regression line to be drawn over.
Β Β  
Β Β  string 
Β Β  asymbol="",//this is the symbol/currency pair you want to perform the calculations on. "" means current symbol.
Β Β  adataset="ema_close",//the type of data you want to perform regression on.
Β Β  line_nickname="anything_goes_here",
Β Β  rmp,//the calculated "market phase" which is a specific description of the market 
Β Β  rtc;//the calculated "market tendency" which is a general description of the market.
Β Β  
Β Β  bool enable_text=true;//when set = true, textual data is displayed on the current chart.
Β Β Β Β  
Β Β  iTSlope(asymbol,timeframe,regperiod,adataset,rmp,rtc,slope,line_nickname,enable_text,ashift);//single currency
   //if(rmp == "trending")BreakPoint("","","",true,"rmp",rmp,"rtc",rtc,"asymbol",asymbol);
Β Β }
//+------------------------------------------------------------------+

Special thanks whroeder and others who helped clarify the concept.

  InputResizer: edit indicator and EA settings comfortably - EA MetaTrader 4
    πŸ“ˆ ROBOTFX MetaTrader Expert Advisors and Indicators to maximize profits and minimize the risks