Miscellaneous
0
Views
0
Downloads
0
Favorites
Tendency_Estimate
//+------------------------------------------------------------------+
//| Tendency_Estimate.mq4 |
//| Hs |
//| http://www.mql5.com |
//+------------------------------------------------------------------+
#property copyright "Hs"
#property link "http://www.mql5.com"
#property version "1.00"
#property strict
#property indicator_separate_window
#property indicator_minimum -1
#property indicator_maximum 1
#property indicator_buffers 1
#property indicator_plots 1
//--- plot Label1
#property indicator_label1 "Label1"
#property indicator_type1 DRAW_LINE
#property indicator_color1 clrForestGreen
#property indicator_style1 STYLE_SOLID
#property indicator_width1 1
//--- input parameters
input int points=100; // Target Points
//--- indicator buffers
double Label1Buffer[];
//+------------------------------------------------------------------+
//| Custom indicator initialization function |
//+------------------------------------------------------------------+
int OnInit()
{
//--- indicator buffers mapping
SetIndexBuffer(0,Label1Buffer);
//---
return(INIT_SUCCEEDED);
}
//+------------------------------------------------------------------+
//| 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[])
{
//---
double cprice,dev; //
double cmax,cmin;
double rmax,rmin;
int i,j;
bool break_up;
bool break_down;
dev=points*Point;
if(ArraySetAsSeries(open,true) && ArraySetAsSeries(close,true) && ArraySetAsSeries(high,true) && ArraySetAsSeries(low,true))
{
for(i=prev_calculated;i<rates_total;i++)
{
cprice=open[i]; // starting price
cmax=cprice+dev;
cmin=cprice-dev;
rmax=cprice;
rmin=cprice;
break_up=false;
break_down=false;
for(j=i;j>=0;j--)
{
rmax=MathMax(rmax,high[j]);
rmin=MathMin(rmin,low[j]);
if((open[j]+high[j]+close[j])>=cmax*3) break_up=true; else break_up=false;
if((open[j]+low[j]+close[j])<=cmin*3) break_down=true; else break_down=false;
if(break_up || break_down) break;
}
if(break_up && !break_down)
{
rmin=(rmin-cprice)/dev;
if(rmin<=-1) Label1Buffer[i]=0; else Label1Buffer[i]=rmin+1;
}
else if(!break_up && break_down)
{
rmax=(rmax-cprice)/dev;
if(rmax>1) Label1Buffer[i]=0; else Label1Buffer[i]=rmax-1;
}
else
{
Label1Buffer[i]=NULL;
// result in unknown
}
}
}
else
{
Alert("Fail");
return(0);
}
//--- return value of prev_calculated for next call
return(rates_total);
}
//+------------------------------------------------------------------+
Comments
Markdown Formatting Guide
# H1
## H2
### H3
**bold text**
*italicized text*
[title](https://www.example.com)

`code`
```
code block
```
> blockquote
- Item 1
- Item 2
1. First item
2. Second item
---