诚信为本
量力而为
当前位置:峰汇在线 > MetaTrader 4 > MT4指标 > 正文

BtTrendTrigger-T.mq4

BtTrendTrigger-T指标是BtTrendTrigger的一种优化。

图表:BtTrendTrigger-T指标

源码:

//+------------------------------------------------------------------+
//|                                             BtTrendTrigger-T.mq4 |
//+------------------------------------------------------------------+
#property copyright ""
#property link      "http://www.125808047.com/"

#property indicator_separate_window
#property indicator_buffers 2
#property indicator_color1 Gold
#property indicator_color2 Red

extern int TTFbars=15; 
extern int t3_period=5;
extern double b=0.7;
extern int ppor=50,mpor=-50;
extern int barBegin=1000; 

string IndicatorName="py.TTF";
string Version="S01";
double HighestHighRecent;
double HighestHighOlder;
double LowestLowRecent;
double LowestLowOlder;
double BuyPower;
double SellPower;
double TTF;
double t3;
double e1;
double e2;
double e3;
double e4;
double e5;
double e6;
double c1;
double c2;
double c3;
double c4;
double r;
double w1;
double w2;
double b2;
double b3;

int shift;
int count;
bool is_First=True;
int loopBegin;
int prevBars;
int PrevTime;
int tick;
int prevShift=99999;
int badPlotBars; 
int firstPlotBar;
double CheckSum;
double CheckSumPrev;
string Msg;

double ExtMapBuffer1[];
double ExtMapBuffer2[];
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
void OnInit(void)
  {
   SetIndexStyle(0,DRAW_LINE);
   SetIndexBuffer(0,ExtMapBuffer1);
   SetIndexStyle(1,DRAW_LINE);
   SetIndexBuffer(1,ExtMapBuffer2);
  Comment("www.125808047.com"); 
  }
//+------------------------------------------------------------------+
//| Custom indicator iteration function                              |
//+------------------------------------------------------------------+
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[])
  {
   b2 = b * b;
   b3 = b2 * b;
   c1 = (-b3);
   c2 = (3 * (b2 + b3));
   c3 = (-3) * (2 * b2 + b + b3);
   c4 = (1 + 3 * b + b3 + 3 * b2);

   r = t3_period;

   if(r < 1) r = 1;
   r = 1 + 0.5 * (r - 1);
   w1 = 2 / (r + 1);
   w2 = 1 - w1;

   if(Bars < prevBars || Bars - prevBars > 1)is_First = True;
   prevBars = Bars;
   
   CheckSum = TTF + barBegin;   
 
   if(CheckSum != CheckSumPrev)is_First = True;
   CheckSumPrev = CheckSum;
   //--------------------------------------------------------------------

   if(is_First){
	
	  if(0 > TTFbars || TTFbars > 299){ 
		 Msg = IndicatorName + " **Input Error** :" + " TTFbars must be between 0 and 300. Cannot=" + TTFbars;
		 Alert(Msg);
		 return(0);
	  }

	  if(barBegin > 0 && barBegin < Bars - 1)loopBegin = barBegin; else loopBegin = Bars - 1; 
	
	  loopBegin = loopBegin - TTFbars; 
	
	  is_First = False;
   } 

   loopBegin = loopBegin + 1; //Replot previous bar
   for(shift = loopBegin;shift>=0;shift--){

	  HighestHighRecent = High[Highest(NULL,0,MODE_HIGH,TTFbars,shift)];
	  HighestHighOlder = High[Highest(NULL,0,MODE_HIGH,TTFbars,shift + TTFbars)];
	  LowestLowRecent = Low [Lowest(NULL,0,MODE_LOW,TTFbars,shift)];
	  LowestLowOlder = Low [Lowest(NULL,0,MODE_LOW,TTFbars,shift+TTFbars)];
	  BuyPower = HighestHighRecent - LowestLowOlder;
	  SellPower = HighestHighOlder - LowestLowRecent;
	  TTF = (BuyPower - SellPower) / (0.5 * (BuyPower + SellPower)) * 100;

	  e1 = w1 * TTF + w2 * e1;
	  e2 = w1 * e1 + w2 * e2;
	  e3 = w1 * e2 + w2 * e3;
	  e4 = w1 * e3 + w2 * e4;
	  e5 = w1 * e4 + w2 * e5;
	  e6 = w1 * e5 + w2 * e6;

	  TTF = c1 * e6 + c2 * e5 + c3 * e4 + c4 * e3;
	  ExtMapBuffer1[shift]=TTF;
 
		if(TTF >= 0)ExtMapBuffer2[shift]=ppor; else ExtMapBuffer2[shift]=mpor;
 
		loopBegin = loopBegin - 1;
}
   return(rates_total);
  }
//+------------------------------------------------------------------+
打赏
版权所有转载请注明标题及链接:峰汇在线 » BtTrendTrigger-T.mq4
上一篇:
下一篇:
分享到: 更多 (0)

如您觉得此文不错请扫码打赏!

支付宝扫一扫打赏

微信扫一扫打赏