Indicators Used
Miscellaneous
0
Views
0
Downloads
0
Favorites
iK_trend_v01_2
//+------------------------------------------------------------------+
//| iK_trend_v01.mq4 |
//| Ivan Katsko |
//| ICQ:372739628 |
//+------------------------------------------------------------------+
#property copyright "Ivan Katsko"
#property link "ICQ:372739628"
//---- indicator settings
#property indicator_separate_window
#property indicator_buffers 3
#property indicator_color2 Blue
#property indicator_width1 2
#property indicator_color1 Red
#property indicator_color3 Green
#property indicator_width2 2
#property indicator_width3 2
//---- indicator parameters
extern int PeriodMA=3;
extern int History=200;
extern int VerExtr=10;
//---- indicator buffers
double up;
double BuySell;
double Trend[];
double Trade[];
double SL[];
double Delta[];
double DeltaMA[];
//+------------------------------------------------------------------+
int init()
{
//----
IndicatorBuffers(5);
//----
SetIndexStyle(1,DRAW_HISTOGRAM);
SetIndexDrawBegin(0,VerExtr);
SetIndexStyle(0,DRAW_LINE);
SetIndexStyle(2,DRAW_LINE);
IndicatorDigits(Digits+5);
//----
SetIndexBuffer(1,Trend);
SetIndexBuffer(0,SL);
SetIndexBuffer(2,Trade);
SetIndexBuffer(3,Delta);
SetIndexBuffer(4,DeltaMA);
//----
IndicatorShortName("iK_trend("+PeriodMA+","+History+","+VerExtr+")");
//----
return(0);
}
//+------------------------------------------------------------------+
int start()
{
int limit;
// int counted_bars=IndicatorCounted();
//---- last counted bar will be recounted
// if(counted_bars>0) counted_bars--;
// limit=Bars-counted_bars;
limit=History;
//---- Ðàçíèöà äâóõ ÌÀ-øåê
for(int i=0; i<limit; i++)
Delta[i]=iMA(NULL,0,PeriodMA,0,MODE_EMA,PRICE_MEDIAN,i)-iMA(NULL,0,PeriodMA,0,MODE_EMA,PRICE_MEDIAN,i+1);
//---- Ñðåäíåå çíà÷åíèå ðàçíèöû äâóõ ÌÀ-øåê çà PeriodMA áàð
int j=0;
for(i=0; i<limit; i++)
{
DeltaMA[i]=0;
for (j=i; j<i+PeriodMA; j++) DeltaMA[i]+=MathAbs(Delta[j]);
DeltaMA[i]=DeltaMA[i]/PeriodMA;
}
//---- Ñòðîèì áóôåð òðåíäà
up=1;
double min=0;
double minmin=0;
while(up==1)
{
for(i=History; i>=0; i--)
{
if (MathAbs(Delta[i])>min && Delta[i]>0)
{
Trend[i]=MathRound(Open[1]);
BuySell=1;
}
else
if (MathAbs(Delta[i])>min && Delta[i]<0)
{
Trend[i]=-MathRound(Open[1]);
BuySell=-1;
}
else
{
Trend[i]=0;
}
if ((BuySell==1 && Delta[i]<0 && MathAbs(Delta[i])>0.33*min)
|| (BuySell==-1 && Delta[i]>0 && MathAbs(Delta[i])>0.33*min))
{
BuySell=0;
}
if (BuySell==1) Trade[i]=MathRound(Open[1])/2;
else
if (BuySell==-1) Trade[i]=-MathRound(Open[1])/2;
else Trade[i]=0;
}
up=0;
for(i=0; i<History; i++)
if ((Trade[i]>=0 && Trade[i+1]<0 && Trade[i+2]>=0)
|| (Trade[i]<=0 && Trade[i+1]>0 && Trade[i+2]<=0)
)
{
up=1;
minmin=min;
min=DeltaMA[1]*100;
for(i=0; i<History; i++)
{if (min>DeltaMA[i]
&& minmin<DeltaMA[i]) min=DeltaMA[i];
}
}
if (min/Point<MarketInfo(Symbol(),MODE_SPREAD)) min=MarketInfo(Symbol(),MODE_SPREAD)*Point;
if (up==0) break;
}
//---- Èùåì è ñòðîèì ÑòîðËîññ
SL[0]=Open[0];
for(i=1; i<VerExtr; i++)
{
if (Trade[0]>0 && Low[i]<SL[0])
SL[0]=Low[i];
if (Trade[0]<0 && High[i]>SL[0])
SL[0]=High[i];
if (Trade[0]==0)
SL[0]=0;
}
if (Trade[0]>0)SL[0]=-(SL[0] - MarketInfo(Symbol(), MODE_SPREAD)*Point);
if (Trade[0]<0)SL[0]= SL[0] + MarketInfo(Symbol(), MODE_SPREAD)*Point;
for(i=0; i<3; i++)
SL[i]=SL[0];
//---- done
return(0);
}
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
---