: | : | :期货程序化 | :期货程序化研究 | :期货量化学习 | :期货量化 |
返回列表 发帖

文华的SUPERTREND指标,请求转为MC指标

文华的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;

论坛官方微信、群(期货热点、量化探讨、开户与绑定实盘)
 
期货论坛 - 版权/免责声明   1.本站发布源码(包括函数、指标、策略等)均属开放源码,用意在于让使用者学习程序化语法撰写,使用者可以任意修改语法內容并调整参数。仅限用于个人学习使用,请勿转载、滥用,严禁私自连接实盘账户交易
  2.本站发布资讯(包括文章、视频、历史记录、教材、评论、资讯、交易方案等)均系转载自网络主流媒体,内容仅为作者当日个人观点,本网转载此文出于传递更多信息之目的,并不意味着赞同其观点或证实其描述。本网不对该类信息或数据做任何保证。不对您构成任何投资建议,不能依靠信息而取代自身独立判断,不对因使用本篇文章所诉信息或观点等导致的损失承担任何责任。
  3.本站发布资源(包括书籍、杂志、文档、软件等)均从互联网搜索而来,仅供个人免费交流学习,不可用作商业用途,本站不对显示的内容承担任何责任。请在下载后24小时内删除。如果喜欢,请购买正版,谢谢合作!
  4.龙听期货论坛原创文章属本网版权作品,转载须注明来源“龙听期货论坛”,违者本网将保留追究其相关法律责任的权力。本论坛除发布原创文章外,亦致力于优秀财经文章的交流分享,部分文章推送时若未能及时与原作者取得联系并涉及版权问题时,请及时联系删除。联系方式:http://www.qhlt.cn/thread-262-1-1.html

我试试。应该问题不大。
如何访问权限为100/255贴子:/thread-37840-1-1.html;注册后仍无法回复:/thread-23-1-1.html;微信/QQ群:/thread-262-1-1.html;网盘链接失效解决办法:/thread-93307-1-1.html

TOP

谢谢老师

TOP

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);

}

TOP

另一个是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);
立于反弱,守于静雌,才能达致刚强伟大。

TOP

超级趋势指标及使用(What is Supertrend Indicator and How it is Used)http://www.qhlt.cn/thread-116559-1-1.html
如何访问权限为100/255贴子:/thread-37840-1-1.html;注册后仍无法回复:/thread-23-1-1.html;微信/QQ群:/thread-262-1-1.html;网盘链接失效解决办法:/thread-93307-1-1.html

TOP

谢谢老师

TOP

返回列表