Indicators Used
Miscellaneous
0
Views
0
Downloads
0
Favorites
T3 crosses
//+------------------------------------------------------------------+
//| T3 crosses.mq4 |
//| mladen |
//| |
//| |
//| original T3 developed by Tim Tilson (TASC January 1998) |
//| period lag modification by Bob Fulks and Alex Matulich 4/2003 |
//+------------------------------------------------------------------+
#property copyright "copyleft mladen"
#property link "mladenfx@gmail.com"
#property indicator_chart_window
#property indicator_buffers 2
#property indicator_color1 Green
#property indicator_color2 Red
#property indicator_width1 1
#property indicator_width2 1
//
//
//
//
//
extern int T3FastPeriod = 9;
extern int T3FastPrice = PRICE_CLOSE;
extern double T3FastHot = 1.0;
extern bool T3FastOriginal = true;
extern int T3SlowPeriod = 27;
extern int T3SlowPrice = PRICE_CLOSE;
extern double T3SlowHot = 0.5;
extern bool T3SlowOriginal = true;
//
//
//
//
//
double t3fast[];
double t3slow[];
double t3gCross[];
double t3rCross[];
double emas[][12];
double alphaFast,alphaSlow;
double c1fast,c1slow;
double c2fast,c2slow;
double c3fast,c3slow;
double c4fast,c4slow;
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
//
//
//
//
//
int init()
{
IndicatorBuffers(4);
SetIndexBuffer(0,t3gCross); SetIndexStyle(0,DRAW_ARROW); SetIndexArrow(0,217);
SetIndexBuffer(1,t3rCross); SetIndexStyle(1,DRAW_ARROW); SetIndexArrow(1,218);
SetIndexBuffer(2,t3fast);
SetIndexBuffer(3,t3slow);
//
//
//
//
//
T3FastPeriod = MathMax(1,T3FastPeriod);
if (T3FastOriginal)
alphaFast = 2.0/(1.0 + T3FastPeriod);
else alphaFast = 2.0/(2.0 + (T3FastPeriod-1.0)/2.0);
double a = T3FastHot;
c1fast = -a*a*a;
c2fast = 3*a*a+3*a*a*a;
c3fast = -6*a*a-3*a-3*a*a*a;
c4fast = 1+3*a+a*a*a+3*a*a;
//
//
//
//
//
T3SlowPeriod = MathMax(1,T3SlowPeriod);
if (T3SlowOriginal)
alphaSlow = 2.0/(1.0 + T3SlowPeriod);
else alphaSlow = 2.0/(2.0 + (T3SlowPeriod-1.0)/2.0);
a = T3SlowHot;
c1slow = -a*a*a;
c2slow = 3*a*a+3*a*a*a;
c3slow = -6*a*a-3*a-3*a*a*a;
c4slow = 1+3*a+a*a*a+3*a*a;
//
//
//
//
//
IndicatorShortName("T3 crosses ("+T3FastPeriod+","+T3SlowPeriod+")");
return(0);
}
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
//
//
//
//
//
int start()
{
int counted_bars=IndicatorCounted();
int i,limit;
if(counted_bars<0) return(-1);
if(counted_bars>0) counted_bars--;
limit=Bars-counted_bars;
if (ArrayRange(emas,0) != Bars) ArrayResize(emas,Bars);
//
//
//
//
//
for(i=limit; i>=0; i--)
{
t3fast[i] = iT3(iMA(NULL,0,1,0,MODE_SMA,T3FastPrice,i),i,0,alphaFast,c1fast,c2fast,c3fast,c4fast);
t3slow[i] = iT3(iMA(NULL,0,1,0,MODE_SMA,T3SlowPrice,i),i,6,alphaSlow,c1slow,c2slow,c3slow,c4slow);
t3gCross[i] = EMPTY_VALUE;
t3rCross[i] = EMPTY_VALUE;
//
//
//
//
//
if (t3fast[i] > t3slow[i] && t3fast[i+1] < t3slow[i+1]) t3gCross[i] = Low[i] -iATR(NULL,0,20,i);
if (t3fast[i] < t3slow[i] && t3fast[i+1] > t3slow[i+1]) t3rCross[i] = High[i]+iATR(NULL,0,20,i);
}
return(0);
}
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
//
//
//
//
//
double iT3(double price,int shift,int startBuff,double alpha,double c1,double c2,double c3,double c4)
{
int i = Bars-shift-1;
if (i < 1)
{
emas[i][startBuff+0] = price;
emas[i][startBuff+1] = price;
emas[i][startBuff+2] = price;
emas[i][startBuff+3] = price;
emas[i][startBuff+4] = price;
emas[i][startBuff+5] = price;
}
else
{
emas[i][startBuff+0] = emas[i-1][startBuff+0]+alpha*(price -emas[i-1][startBuff+0]);
emas[i][startBuff+1] = emas[i-1][startBuff+1]+alpha*(emas[i][startBuff+0]-emas[i-1][startBuff+1]);
emas[i][startBuff+2] = emas[i-1][startBuff+2]+alpha*(emas[i][startBuff+1]-emas[i-1][startBuff+2]);
emas[i][startBuff+3] = emas[i-1][startBuff+3]+alpha*(emas[i][startBuff+2]-emas[i-1][startBuff+3]);
emas[i][startBuff+4] = emas[i-1][startBuff+4]+alpha*(emas[i][startBuff+3]-emas[i-1][startBuff+4]);
emas[i][startBuff+5] = emas[i-1][startBuff+5]+alpha*(emas[i][startBuff+4]-emas[i-1][startBuff+5]);
}
return(c1*emas[i][startBuff+5] + c2*emas[i][startBuff+4] + c3*emas[i][startBuff+3] + c4*emas[i][startBuff+2]);
}
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
---