#property copyright "Extreme TMA System"
#property link "_http://www.forexfactory.com/showthread.php?t=343533m"
#property indicator_chart_window
extern color NeutralColor = LightGray; extern color BullColor = SeaGreen; extern color ExtremeBullColor = Lime; extern color BearColor = Orange; extern color ExtremeBearColor = Red;
extern int TmaPeriod = 56; extern int TmaAtrPeriod = 100; extern double TmaBandSize = 2; extern double TmaSlopeThreshold = 0.5; extern double TmaBandSizeH1 = 3; extern double TmaBandSizeH4 = 3; extern int PivotHoursShift = 0; extern double PivotThreshold = 10;
extern int MaPeriod = 10;
//This is the same as 4 in the original TMA MACross
extern int MaShift = 1;
extern int Size = 13; extern string Font = "Arial";
extern bool ShowPrice = false; extern bool ShowDailyAtr = false; extern bool ShowSpread = false;
extern bool ShowTmaSize = false; extern bool ShowTmaSizeH1 = false; extern bool ShowTmaSizeH4 = false;
// ???
extern bool ShowSlope = true;
extern bool ShowSlopeH1 = true;
extern bool ShowSlopeH4 = true;
extern bool ShowExtremeTMA = true;
extern bool ShowSlopeChange = true;
extern bool ShowPivotDistance = true;
extern bool ShowHeikenAshi = false; extern bool ShowMACrossover = false;
extern bool AlertOn = false; extern bool AlertMessage = false; extern bool AlertEmail = false; extern bool AlertSound = false; extern string AlertSoundFile = "alert2.wav";
int LinearRegressionPeriod = 7;
bool ShowLinearPriceChange = false;
int Bottom = 25;
double Tick = 0;
bool AdditionalDigit;
double Pivots[];
int LastPivotDay= 0;
bool AlertHappened = false;
//+------------------------------------------------------------------+
// expert initialization function |
//+------------------------------------------------------------------+
int init()
{
ArrayResize(Pivots,11);
Tick = MarketInfo(Symbol(), MODE_TICKSIZE);
AdditionalDigit = MarketInfo(Symbol(), MODE_MARGINCALCMODE) == 0 && MarketInfo(Symbol(), MODE_PROFITCALCMODE) == 0 && Digits % 2 == 1;
if (AdditionalDigit) {
Tick *= 10;
}
initGraph();
return(0);
}
int deinit()
{
deinitGraph();
Print("shutdown error - ",GetLastError());
return(0);
}
int start()
{
main();
return(0);
}
void main()
{
RefreshRates();
//General Info
double spread=NormalizeDouble(((Ask-Bid)/Point)/10,1);
int dayShift = iBarShift(Symbol(),PERIOD_D1,Time[0]);
double atr = iATR(Symbol(),PERIOD_D1, 14,dayShift);
double price = NormalizeDouble(Close[0],4);
atr = NormalizeDouble((atr/Point)/10,1);
if (ShowSpread) paintGeneral("SpreadValue", spread, NeutralColor, 1);
if (ShowDailyAtr) paintGeneral("AtrValue", atr, NeutralColor);
// if (ShowPrice) paintPrice(price);
double tmaH1,tmaH1Prev,tmaH4,tmaH4Prev;
//Tma Info
GetPivots(Symbol());
int shiftH1 = iBarShift(NULL,60,Time[0]);
int shiftH4 = iBarShift(Symbol(),240,Time[0]);
if (ShowSlopeH1)
{
tmaH1 = CalcTma(60, shiftH1);
tmaH1Prev = CalcTma(60, shiftH1+1);
}
if (ShowSlopeH4)
{
tmaH4 = CalcTma(240, shiftH4);
tmaH4Prev = CalcTma(240, shiftH4+1);
}
//if (Symbol() == "EURUSDm") Print (" tmaH1 ",tmaH1," tmaH1Prev ",tmaH1Prev, " shiftH1 ", shiftH1, " Time[0] ", TimeToStr(Time[0])
//, "iClose(Symbol(),60,shiftH1);", iClose(Symbol(),60,shiftH1), "iTime(Symbol(),60,shiftH1);", TimeToStr(iTime(Symbol(),60,shiftH1)));
double tma = getTma(Symbol(),0, 0);
double tmaPrev = getTma(Symbol(),0, 1);
double tmaPrev2 = getTma(Symbol(),0, 2);
double tmaPrev3 = getTma(Symbol(),0, 3);
double priceSlope = getPriceSlope(Symbol(),0,LinearRegressionPeriod);
double pivotDist = GetNearestPivotDistance()/Tick;
double tmaAtr = iATR( Symbol(), 0, TmaAtrPeriod, 10);
double tmaAtrH1 = iATR( Symbol(), 60, TmaAtrPeriod,shiftH1 + 10);
double tmaAtrH4 = iATR( Symbol(), 240, TmaAtrPeriod, shiftH4 + 10);
double diff = Close[0] - tma;
double extremeTma = (diff/tmaAtr) / TmaBandSize;
double n = tmaAtr * 0.1;
double tmaSlope = ((tma- tmaPrev) / n) ;
double tmaSlopeH1 = ((tmaH1- tmaH1Prev) / (tmaAtrH1 * 0.1)) ;
double tmaSlopeH4 = ((tmaH4- tmaH4Prev) / (tmaAtrH4 * 0.1)) ;
double tmaSlope1 = ((tmaPrev- tmaPrev2) / n) ;
double tmaSlope2 = ((tmaPrev2- tmaPrev3) / n) ;
double tmaSlopeChange = ((tmaSlope - tmaSlope1) + (tmaSlope1 - tmaSlope2)) / 2.0;
if (ShowTmaSize) paintGeneral("TmaSizeValue", (tmaAtr/Tick) * 2 * TmaBandSize , NeutralColor);
if (ShowTmaSizeH1) paintGeneral("TmaSizeH1Value", (tmaAtrH1/Tick) * 2 * TmaBandSizeH1 , NeutralColor);
if (ShowTmaSizeH4) paintGeneral("TmaSizeH4Value", (tmaAtrH4/Tick) * 2 * TmaBandSizeH4 , NeutralColor);
color c = NeutralColor;
if (ShowExtremeTMA)
{
if(extremeTma<=-1){c = ExtremeBullColor; }
else if(extremeTma>=1){c = ExtremeBearColor; }
else if(extremeTma>0){c = BearColor; }
else if(extremeTma<0){c = BullColor; }
else {c = NeutralColor; }
paintGeneral("ExtremeTMA", extremeTma, c);
}
if (ShowSlope)
{
if(tmaSlope<-1 * TmaSlopeThreshold){c = ExtremeBearColor; }
else if(tmaSlope>TmaSlopeThreshold){c = ExtremeBullColor; }
//else {c = NeutralColor; }
paintGeneral("TmaSlope", tmaSlope, c,2);
}
if (ShowSlopeH1)
{
if(tmaSlopeH1 <-1 * TmaSlopeThreshold){c = ExtremeBearColor; }
else if(tmaSlopeH1 >TmaSlopeThreshold){c = ExtremeBullColor; }
else if(tmaSlopeH1 > 0){c = BullColor; }
else if(tmaSlopeH1 < 0 ){c = BearColor; }
else {c = NeutralColor; }
paintGeneral("TmaSlopeH1", tmaSlopeH1, c,2);
}
if (ShowSlopeH4)
{
if(tmaSlopeH4 <-1 * TmaSlopeThreshold){c = ExtremeBearColor; }
else if(tmaSlopeH4 >TmaSlopeThreshold){c = ExtremeBullColor; }
else if(tmaSlopeH4 > 0){c = BullColor; }
else if(tmaSlopeH4 < 0 ){c = BearColor; }
else {c = NeutralColor; }
paintGeneral("TmaSlopeH4", tmaSlopeH4, c,2);
}
if (ShowSlopeChange)
{
if(tmaSlopeChange<0 && extremeTma>= 1){c = ExtremeBearColor; }
else if(tmaSlopeChange<0){c = BearColor; }
else if(tmaSlopeChange>0 && extremeTma<= -1){c = ExtremeBullColor; }
else if(tmaSlopeChange>0){c = BullColor; }
else {c = NeutralColor; }
paintGeneral("TmaSlopeChange", tmaSlopeChange* 100, c);
}