Indicators Used
0
Views
0
Downloads
0
Favorites
Schaff_Trend_Cycle_mtf
//+------------------------------------------------------------------+
//| Schaff Trend Cycle.mq4 |
//| mladen |
//+------------------------------------------------------------------+
//mtf2008fxtsd ki
#property copyright "mladen"
#property link "mladenfx@gmail.com"
#property indicator_separate_window
#property indicator_buffers 1
#property indicator_color1 Red
#property indicator_maximum 100
#property indicator_minimum 0
#property indicator_level1 80
#property indicator_level2 50
#property indicator_level3 20
#property indicator_levelcolor SlateGray
//
//
//
//
//
extern int STCPeriod = 10;
extern int FastMAPeriod = 23;
extern int SlowMAPeriod = 50;
extern int TimeFrame = 0;
extern string note_TimeFrames = "M1;5,15,30,60H1;240H4;1440D1;10080W1;43200MN|0-CurrentTF";
string IndicatorFileName;
//
//
//
//
//
double stcBuffer[];
double macdBuffer[];
double fastKBuffer[];
double fastDBuffer[];
double fastKKBuffer[];
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
//
//
//
//
//
int init()
{
IndicatorBuffers(5);
SetIndexBuffer(0,stcBuffer);
SetIndexBuffer(1,macdBuffer);
SetIndexBuffer(2,fastKBuffer);
SetIndexBuffer(3,fastDBuffer);
SetIndexBuffer(4,fastKKBuffer);
TimeFrame=MathMax(TimeFrame, Period());
string shortname = "Schaff TC ("+STCPeriod+","+FastMAPeriod+","+SlowMAPeriod+") ["+TimeFrame+"]";
SetIndexLabel(0, ""+shortname);
IndicatorShortName(shortname);
IndicatorFileName = WindowExpertName();
return(0);
}
int deinit()
{
return(0);
}
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
//
//
//
//
//
int start()
{
int counted_bars=IndicatorCounted();
int limit,i;
if(counted_bars < 0) return(-1);
if(counted_bars>0) counted_bars--;
limit = Bars-counted_bars;
if (TimeFrame != Period())
{
limit = MathMax(limit,TimeFrame/Period());
datetime TimeArray[];
ArrayCopySeries(TimeArray ,MODE_TIME ,NULL,TimeFrame);
for(i=0,int y=0; i<limit; i++)
{
if(Time[i]<TimeArray[y]) y++;
stcBuffer[i]=iCustom(NULL,TimeFrame,IndicatorFileName,STCPeriod,FastMAPeriod,SlowMAPeriod,0,y);
}
return(0);
}
//
//
//
//
//
for(i = limit; i >= 0; i--)
{
macdBuffer[i] = iMA(NULL,0,FastMAPeriod,0,MODE_EMA,PRICE_CLOSE,i)-
iMA(NULL,0,SlowMAPeriod,0,MODE_EMA,PRICE_CLOSE,i);
//
//
//
//
//
double lowMacd = minValue(macdBuffer,i);
double highMacd = maxValue(macdBuffer,i)-lowMacd;
if (highMacd > 0)
fastKBuffer[i] = 100*((macdBuffer[i]-lowMacd)/highMacd);
else fastKBuffer[i] = fastKBuffer[i+1];
fastDBuffer[i] = fastDBuffer[i+1]+0.5*(fastKBuffer[i]-fastDBuffer[i+1]);
//
//
//
//
//
double lowStoch = minValue(fastDBuffer,i);
double highStoch = maxValue(fastDBuffer,i)-lowStoch;
if (highStoch > 0)
fastKKBuffer[i] = 100*((fastDBuffer[i]-lowStoch)/highStoch);
else fastKKBuffer[i] = fastKKBuffer[i+1];
stcBuffer[i] = stcBuffer[i+1]+0.5*(fastKKBuffer[i]-stcBuffer[i+1]);
}
return(0);
}
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
//
//
//
//
//
double minValue(double& array[],int shift)
{
double minValue = array[shift];
for (int i=1; i<STCPeriod; i++) minValue = MathMin(minValue,array[shift+i]);
return(minValue);
}
double maxValue(double& array[],int shift)
{
double maxValue = array[shift];
for (int i=1; i<STCPeriod; i++) maxValue = MathMax(maxValue,array[shift+i]);
return(maxValue);
}
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
---