文华的SUPERTREND指标,请求转为MC指标
N:=10;M:=2.5;TR1:=MAX(MAX((HIGH-LOW),ABS(REF(CLOSE,1)-HIGH)),ABS(REF(CLOSE,1)-LOW));
UP:=(H+L)/2+MA(TR1,N)*M;
DN:=(H+L)/2-MA(TR1,N)*M;
L1:=REF(UP,BARSLAST(UP<=REF(UP,1)));
L2:=LLV(UP,N*1.5);
LL:=IF(L2<>REF(L2,1) AND L1<REF(L1,1),L1,IF(L1=L2,L1,L2));
S1:=BARSLAST(CROSS(0.5,UP=LL))+1;
S2:=CROSS(COUNT((CROSS(C,LL) OR CROSS(C,REF(LL,2))) AND UP>LL,S1),0.5);
A6:=BARSLAST(S2);
B6:=BARSLAST(CROSS(HHV(DN,A6+1),C));
BY:=CROSS(B6,A6);
SL:=CROSS(A6,B6);
SUPERTREN:IF(B6>A6,HHV(DN,BARSLAST(BY)+1),LLV(UP,BARSLAST(SL)+1)),COLORWHITE;
M1:IFELSE(B6>A6,SUPERTREN,NULL),COLORRED;
M2:IFELSE(B6<A6,SUPERTREN,NULL),COLORGREEN; 我试试。应该问题不大。 谢谢老师 MT4的版本有二个,一个是SuperLadder,代码是
#property indicator_chart_window
#property indicator_buffers 3
enum ChineseBoolean
{
A=0, // 开
B=1, // 关
};
//+------------------------------------------------------------------+
input ChineseBoolean 窗口提示 = B;
input ChineseBoolean 声音提示 = B;
input ChineseBoolean 电邮通知 = B;
input ChineseBoolean 手机MT4通知 = B;
input color 上涨颜色 = Blue;
input color 下跌颜色 = Red;
input color 阶梯颜色 = Aqua;
input double ATR_Factor = 1.5;
input int MA_Period = 20;
int ATR = 14;
string IndicatorName = "SuperLadder";
//+------------------------------------------------------------------+
double bufferLadder[], bufferUp[], bufferDn[];
double bufferDirection[];
//+------------------------------------------------------------------+
int init()
{
IndicatorBuffers(4);
SetIndexStyle(0, DRAW_LINE,STYLE_SOLID,3,阶梯颜色);
SetIndexBuffer(0, bufferLadder);
SetIndexStyle(1, DRAW_LINE,STYLE_SOLID,2,上涨颜色);
SetIndexBuffer(1, bufferUp);
SetIndexStyle(2, DRAW_LINE,STYLE_SOLID,2,下跌颜色);
SetIndexBuffer(2, bufferDn);
SetIndexBuffer(3, bufferDirection);
return(0);
}
//+------------------------------------------------------------------+
int deinit()
{
return(0);
}
//+------------------------------------------------------------------+
datetime dtLastTime = 0;
int start()
{
double thisCCI;
double dAtr=0.0;
int limit, shift;
int counted_bars=IndicatorCounted();
//---- last counted bar will be recounted
if(counted_bars>0) counted_bars--;
limit=Bars-counted_bars;
for (shift=limit-1; shift >= 0; shift--)
{
thisCCI = iCCI(NULL, 0, MA_Period, PRICE_TYPICAL, shift);
dAtr = iATR(NULL, 0, ATR, shift);
bufferDirection[shift]=0.0;
if (thisCCI >= 0)
{
bufferLadder[shift] = Low[shift] - dAtr * ATR_Factor;
if (bufferLadder[shift] < bufferLadder[shift + 1])
bufferLadder[shift] = bufferLadder[shift + 1];
}
else
{
bufferLadder[shift] = High[shift] + dAtr * ATR_Factor;
if (bufferLadder[shift] > bufferLadder[shift + 1])
bufferLadder[shift] = bufferLadder[shift + 1];
}
if (bufferLadder[shift]>bufferLadder[shift+1]) bufferDirection[shift] = 1.0;
if (bufferLadder[shift]<bufferLadder[shift+1]) bufferDirection[shift] = -1.0;
if (bufferLadder[shift]==bufferLadder[shift+1]) bufferDirection[shift] = bufferDirection[shift+1];
if (bufferDirection[shift]>0.0) bufferUp[shift]=bufferLadder[shift]-Point*2;
if (bufferDirection[shift]<0.0) bufferDn[shift]=bufferLadder[shift]+Point*2;
}
/// Alert Process
if (bufferDirection[1]!=bufferDirection[2] && dtLastTime!=Time[0])
{
dtLastTime = Time[0];
double dLastDayClose = iClose(Symbol(),PERIOD_D1,1);
double dUpDnPercent = NormalizeDouble( (Close[0] - dLastDayClose)/dLastDayClose * 100.0, 2);
string strAlertMessage;
if (bufferDirection[1] > 0.0)
{
strAlertMessage = StringConcatenate(IndicatorName," Alert: ",Symbol(),"_",PeriodToString(Period())," UP");
if (窗口提示==A)
Alert(strAlertMessage);
if (声音提示==A)
PlaySound("alert.wav");
if (电邮通知==A)
SendMail(strAlertMessage,
"Current Price "+DoubleToStr(Close[0],Digits)+
"\nTime: " + TimeToStr(TimeCurrent(),TIME_DATE|TIME_SECONDS)
+ "\nLast Day Close: " + DoubleToStr(dLastDayClose,Digits)
+ "\nChange: " + DoubleToStr(dUpDnPercent,2) + "%");
if (手机MT4通知==A)
SendNotification(strAlertMessage);
}
if (bufferDirection[1] < 0.0)
{
strAlertMessage = StringConcatenate(IndicatorName," Alert: ",Symbol(),"_",PeriodToString(Period())," DOWN");
if (窗口提示==A)
Alert(strAlertMessage);
if (声音提示==A)
PlaySound("alert.wav");
if (电邮通知==A)
SendMail(strAlertMessage,
"Current Price "+DoubleToStr(Close[0],Digits)+
"\nTime: " + TimeToStr(TimeCurrent(),TIME_DATE|TIME_SECONDS)
+ "\nLast Day Close: " + DoubleToStr(dLastDayClose,Digits)
+ "\nChange: " + DoubleToStr(dUpDnPercent,2) + "%");
if (手机MT4通知==A)
SendNotification(strAlertMessage);
}
}
return(0);
}
string PeriodToString (int imin)
{
string strprd;
switch (imin)
{
case (1):
strprd="M1";
break;
case (2):
strprd="M2";
break;
case (3):
strprd="M3";
break;
case (5):
strprd="M5";
break;
case (15):
strprd="M15";
break;
case (30):
strprd="M30";
break;
case (60):
strprd="H1";
break;
case (60*4):
strprd="H4";
break;
case (60*24):
strprd="D1";
break;
case (60*24*7):
strprd="W1";
break;
}
return (strprd);
} 另一个是TrendMagic
#property indicator_chart_window
#property indicator_buffers 4
#property indicator_color1 Blue
#property indicator_color2 Red
#property indicator_color3 Black
#property indicator_color4 Black
extern int CCPeriod = 50;
extern int ATRPeriod = 5;
double g_ibuf_76[];
double g_ibuf_80[];
int gi_84 = 0;
int init() {
{ SetIndexStyle(0, DRAW_LINE, STYLE_SOLID, 4);
SetIndexBuffer(0, g_ibuf_76);
SetIndexStyle(1, DRAW_LINE, STYLE_SOLID, 4);
SetIndexBuffer(1, g_ibuf_80);}
return (0);
}
int deinit() {
return (0);
}
int start() {
{int li_8;
double ld_12;
double ld_20;
double l_icci_28;
double l_icci_36;
int li_52 = IndicatorCounted();
if (li_52 < 0) return (-1);
if (li_52 > 0) li_52--;
int li_0 = Bars - li_52;
for (int li_4 = li_0; li_4 >= 0; li_4--) {
l_icci_28 = iCCI(NULL, 0, CCPeriod, PRICE_TYPICAL, li_4);
l_icci_36 = iCCI(NULL, 0, CCPeriod, PRICE_TYPICAL, li_4 + 1);
li_8 = li_4;
ld_12 = 0;
ld_20 = 0;
for (li_8 = li_4; li_8 >= li_4 - 9; li_8--) ld_20 += MathAbs(High[li_8] - Low[li_8]);
ld_12 = ld_20 / 10.0;
if (l_icci_28 >= gi_84 && l_icci_36 < gi_84) g_ibuf_76[li_4 + 1] = g_ibuf_80[li_4 + 1];
if (l_icci_28 <= gi_84 && l_icci_36 > gi_84) g_ibuf_80[li_4 + 1] = g_ibuf_76[li_4 + 1];
if (l_icci_28 >= gi_84) {
g_ibuf_76[li_4] = Low[li_4] - iATR(NULL, 0, ATRPeriod, li_4);
if (g_ibuf_76[li_4] < g_ibuf_76[li_4 + 1]) g_ibuf_76[li_4] = g_ibuf_76[li_4 + 1];
} else {
if (l_icci_28 <= gi_84) {
g_ibuf_80[li_4] = High[li_4] + iATR(NULL, 0, ATRPeriod, li_4);
if (g_ibuf_80[li_4] > g_ibuf_80[li_4 + 1]) g_ibuf_80[li_4] = g_ibuf_80[li_4 + 1];
}
}
}
}
return (0); 超级趋势指标及使用(What is Supertrend Indicator and How it is Used)[url=http://www.qhlt.cn/thread-116559-1-1.html]http://www.qhlt.cn/thread-116559-1-1.html[/url] 谢谢老师
页:
[1]