0
Views
0
Downloads
0
Favorites
Net_Trend_Lines_v01
//+------------------------------------------------------------------+
//| Net_Trend_Lines_v01.mq4 |
//+------------------------------------------------------------------+
#property copyright "Inkov Evgeni"
#property link "ew123@mail.ru"
//+------------------------------------------------------------------+
#property version "1.00"
#property strict
//----
#property indicator_chart_window
extern int nPeriod=20;
extern int n_lines=20;
//+------------------------------------------------------------------+
datetime time_0;
//+------------------------------------------------------------------+
int OnInit()
{
time_0=0;
return(INIT_SUCCEEDED);
}
//+------------------------------------------------------------------+
void OnDeinit(const int reason)
{
ObjectsDeleteAll(0,"Trend ");
}
//+------------------------------------------------------------------+
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 (time_0==Time[0])return(0);
//......................................
time_0=Time[0];
int n_lo_1_pred=0,n_lo_2_pred=0;
int n_hi_1_pred=0,n_hi_2_pred=0;
ObjectsDeleteAll(0,"Trend ");
for(int j=1;j<=n_lines;j++)
{
double lo_1=0,lo_2=0;
int n_lo_1=0,n_lo_2=0;
double hi_1=0,hi_2=0;
int n_hi_1=0,n_hi_2=0;
int Limit=nPeriod*j*5;
if (Limit+(nPeriod*j-1)/2>=Bars)break;
for(int i=Limit; i>0; i--)
{
if(Low[i+(nPeriod*j-1)/2]==Low[iLowest(NULL,0,MODE_LOW,nPeriod*j,i)])
{
hi_2=hi_1;
hi_1=Low[i+(nPeriod*j-1)/2];
n_hi_2=n_hi_1;
n_hi_1=i+(nPeriod*j-1)/2;
}
if(High[i+(nPeriod*j-1)/2]==High[iHighest(NULL,0,MODE_HIGH,nPeriod*j,i)])
{
lo_2=lo_1;
lo_1=High[i+(nPeriod*j-1)/2];
n_lo_2=n_lo_1;
n_lo_1=i+(nPeriod*j-1)/2;
}
}
if (n_hi_2>n_hi_1+5 && (n_hi_1_pred!=n_hi_1 || n_hi_2_pred!=n_hi_2))
{
n_hi_1_pred=n_hi_1;
n_hi_2_pred=n_hi_2;
string name="Trend lo"+IntegerToString(j)+"-"+IntegerToString(nPeriod*j);
ObjectCreate(name,OBJ_TREND,0,0,0,0,0);
ObjectSet(name,OBJPROP_WIDTH,2);
ObjectSet(name,OBJPROP_COLOR,clrMagenta);
ObjectSet(name,OBJPROP_SELECTED,true);
ObjectMove(name,1,Time[n_hi_1],hi_1);
ObjectMove(name,0,Time[n_hi_2],hi_2);
}
if (n_lo_2>n_lo_1+5 && (n_lo_1_pred!=n_lo_1 || n_lo_2_pred!=n_lo_2))
{
n_lo_1_pred=n_lo_1;
n_lo_2_pred=n_lo_2;
string name="Trend hi"+IntegerToString(j)+"-"+IntegerToString(nPeriod*j);
ObjectCreate(name,OBJ_TREND,0,0,0,0,0);
ObjectSet(name,OBJPROP_COLOR,clrBlue);
ObjectSet(name,OBJPROP_WIDTH,2);
ObjectSet(name,OBJPROP_SELECTED,true);
ObjectMove(name,1,Time[n_lo_1],lo_1);
ObjectMove(name,0,Time[n_lo_2],lo_2);
}
}
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
---