开拓者期货期权程序化系统交易论坛

标题: 恳请fish0451出手 移植个mt4的好公式--qqe [打印本页]

作者: bluefox    时间: 2009-2-26 09:56:14     标题: 恳请fish0451出手 移植个mt4的好公式--qqe

您移植的stepma感觉很棒 偶然看到qqe这个指标 脱胎于rsi 感觉不错 但很多mt4代码看不懂 能否移植一下 谢谢
//+------------------------------------------------------------------+
//|            Qualitative Quantitative Estimation Indicator for Metatrader 4 |
//|            Copyright © 2006Roman Ignatov |
//|             mailto:roman.ignatov@gmail.com |
//+------------------------------------------------------------------+
#property copyright "Copyright © 200 Roman Ignatov"
#property link      "mailto:roman.ignatov@gmail.com  "

#property indicator_separate_window

#property indicator_buffers 2

#property indicator_color1 Navy
#property indicator_style1 STYLE_SOLID
#property indicator_width1 2

#property indicator_color2 Navy
#property indicator_style2 STYLE_DOT


extern int SF = 5;

int RSI_Period = 14;
int Wilders_Period;
int StartBar;

double TrLevelSlow[];
double AtrRsi[];
double MaAtrRsi[];
double Rsi[];
double RsiMa[];

int init()
{
    Wilders_Period = RSI_Period * 2 - 1;
    if (Wilders_Period < SF)
        StartBar = SF;
    else
        StartBar = Wilders_Period;
        
    IndicatorBuffers(6);
    SetIndexBuffer(0, RsiMa);
    SetIndexStyle(0, DRAW_LINE, STYLE_SOLID, 2);
    SetIndexLabel(0, "Value 1");
    SetIndexDrawBegin(0, StartBar);
    SetIndexStyle(1, DRAW_LINE, STYLE_DOT);
    SetIndexBuffer(1, TrLevelSlow);
    SetIndexLabel(1, "Value 2");
    SetIndexDrawBegin(1, StartBar);
    SetIndexBuffer(2, AtrRsi);
    SetIndexBuffer(3, MaAtrRsi);
    SetIndexBuffer(4, Rsi);
    IndicatorShortName(StringConcatenat  e("QQE(", SF, ")"));
    return(0);
}


int start()
{
    int counted, i;
    double rsi0, rsi1, dar, tr, dv;
   
    if(Bars <= StartBar)
        return (0);

    counted = IndicatorCounted();
    if(counted < 1)
        for(i = Bars - StartBar; i < Bars; i++)
        {
            TrLevelSlow = 0.0;
            AtrRsi = 0.0;
            MaAtrRsi = 0.0;
            Rsi = 0.0;
            RsiMa = 0.0;
        }
   
    counted = Bars - counted - 1;
        
    for (i = counted; i >= 0; i--)
        Rsi = iRSI(NULL, 0, RSI_Period, PRICE_CLOSE, i);

    for (i = counted; i >= 0; i--)
    {
        RsiMa = iMAOnArray(Rsi, 0, SF, 0, MODE_EMA, i);
        AtrRsi = MathAbs(RsiMa[i + 1] - RsiMa);
    }

    for (i = counted; i >= 0; i--)
        MaAtrRsi = iMAOnArray(AtrRsi, 0, Wilders_Period, 0, MODE_EMA, i);

    i = counted + 1;
    tr = TrLevelSlow;
    rsi1 = iMAOnArray(Rsi, 0, SF, 0, MODE_EMA, i);
    while (i > 0)
    {
        i--;
        rsi0 = iMAOnArray(Rsi, 0, SF, 0, MODE_EMA, i);
        dar = iMAOnArray(MaAtrRsi, 0, Wilders_Period, 0, MODE_EMA, i) * 4.236;

        dv = tr;
        if (rsi0 < tr)
        {
            tr = rsi0 + dar;
            if (rsi1 < dv)
                if (tr > dv)
                    tr = dv;
        }
        else if (rsi0 > tr)
        {
            tr = rsi0 - dar;
            if (rsi1 > dv)
                if (tr < dv)
                    tr = dv;
        }
        TrLevelSlow = tr;
        rsi1 = rsi0;
    }
   
    return(0);
}
作者: bluefox    时间: 2009-2-26 12:17:38

上个效果图 最下面的指标就是qqe
[attach]1382[/attach]
作者: funnyhaah    时间: 2009-2-26 13:37:06

这个图怎么看着这么诡异呢?
作者: cfmx2007    时间: 2009-2-26 13:41:36

都不上传上来,谁能帮你改啊。。。
作者: fish0451    时间: 2009-2-26 16:32:06

好!先收藏了,周末看看。
作者: wk668668    时间: 2009-2-26 22:25:46

这个看起很高超样,帮你顶! 期待高手出招!!!
作者: hedgehog    时间: 2009-2-27 22:28:32

mt4如此有名,果然不是盖的啊,看画面确实不错
作者: bluefox    时间: 2009-2-28 10:15:32     标题: 期待 fish0451 根据tb的rsi指标改了个rsi函数 以方便引用

//------------------------------------------------------------------------
// 简称: rsi
// 名称: rsi
// 类别: 用户函数
// 类型: 内建函数
// 输出: 数值型
//------------------------------------------------------------------------

Params
        Numeric Length(14) ;

Vars
        NumericSeries NetChgAvg( 0 );
        NumericSeries TotChgAvg( 0 );
        Numeric Change( 0 );
        Numeric SF( 0 );
        Numeric ChgRatio( 0 ) ;
        Numeric RSIValue;
Begin
        SF = 1/Length;
        If(CurrentBar < Length)
        {
                RSIValue = InvalidNumeric;
        }Else
        {
                If(CurrentBar == Length)
                {
                        NetChgAvg = ( Close - Close[Length] ) / Length ;
                        TotChgAvg = AverageFC( Abs( Close - Close[1] ), Length ) ;
                }
               
                If(CurrentBar>length)
                {
                        Change = Close - Close[1] ;
                        NetChgAvg = NetChgAvg[1] + SF * ( Change - NetChgAvg[1] ) ;
                        TotChgAvg = TotChgAvg[1] + SF * ( Abs( Change ) - TotChgAvg[1] ) ;
                }
               
                If( TotChgAvg <> 0 )
                {
                        ChgRatio = NetChgAvg / TotChgAvg ;
                }else
                {
                        ChgRatio = 0 ;
                }
               
                RSIValue = 50 * ( ChgRatio + 1 ) ;
        }

        Return rsivalue;
End

//------------------------------------------------------------------------
// 编译版本        GS2004.06.12
// 用户版本        2009/02/28 10:04
// 版权所有         
// 更改声明        TradeBlazer Software保留对TradeBlazer平台
//                        每一版本的TrabeBlazer公式修改和重写的权利
//------------------------------------------------------------------------
作者: bluefox    时间: 2009-2-28 10:26:13

另 在tb中 ema对应函数XAverage
作者: fish0451    时间: 2009-2-28 22:31:50

//------------------------------------------------------------------------
// 简称: qqe
// 名称:
// 类别: 技术指标
// 类型: 其它类
// 输出:
//------------------------------------------------------------------------
Params
        Numeric SF(5);                       
        Numeric RSI_Period(14);       
        Numeric rat(4.236);
Vars
        NumericSeries TrLevelSlow(0);       
        NumericSeries AtrRsi(0);       
        NumericSeries MaAtrRsi(0);       
        NumericSeries Rsi(0);
        NumericSeries RsiMa(0);
        Numeric Wilders_Period(0);       
        Numeric dar(0);       
        NumericSeries  smin(0);
    NumericSeries  smax(0);
        NumericSeries p;
       
Begin
        Wilders_Period=RSI_Period * 2 - 1;
        If(BarStatus==0)
        {
                 TrLevelSlow=0;
         AtrRsi=0;
         MaAtrRsi=0;
         Rsi=0;
         RsiMa=0;
                 p=0;
        }
        if(CurrentBar>RSI_Period)
        {
                Rsi=iRSI(Close,RSI_Period);
                RsiMa=XAverage(Rsi,SF);
                AtrRsi=Abs(RsiMa[1] - RsiMa);
                MaAtrRsi=XAverage(AtrRsi,Wilders_Period);
                dar=XAverage(MaAtrRsi,Wilders_Period) * rat;       
                smax=RsiMa+dar;
                smin=RsiMa-dar;

                p=p[1];

                if (RsiMa>smax[1]) {p=1; }         
                if (RsiMa<smin[1]) {p=-1;}

                if(p>0)
          {
                if(smin<smin[1])
                        smin=smin[1];
                TrLevelSlow=smin;
                if(TrLevelSlow<TrLevelSlow[1])
                        TrLevelSlow=TrLevelSlow[1];
          }
          Else
          {
                if(smax>smax[1])
                        smax=smax[1];
                TrLevelSlow=smax;
                if(TrLevelSlow>TrLevelSlow[1])
                        TrLevelSlow=TrLevelSlow[1];
          }
                PlotNumeric("RsiMa",RsiMa);
                PlotNumeric("TrLevelSlow",TrLevelSlow);
        }

End


//------------------------------------------------------------------------
// 编译版本        GS2004.06.12
// 用户版本        2009/02/28 20:14
// 版权所有        fish0451
// 更改声明        TradeBlazer Software保留对TradeBlazer平台
//                        每一版本的TrabeBlazer公式修改和重写的权利
//------------------------------------------------------------------------
作者: fish0451    时间: 2009-2-28 22:35:11

把Rsi=iRSI(Close,RSI_Period);改成你的Rsi=rsi(RSI_Period);
没法完全转换,竟似模拟吧。
作者: bluefox    时间: 2009-2-28 22:54:54

非常感谢fish0451 的帮助 高人就是高人
作者: wk668668    时间: 2009-3-1 20:20:43

先收下,看看。多谢高手出招!!!
作者: 九九归一    时间: 2009-4-19 02:21:05

--------------------------
作者: 捕快    时间: 2009-5-10 15:11:51

顶                                      !
作者: cfmx2007    时间: 2009-8-23 00:20:09

这是非常好的指标,可惜和MT4上的显示,有点差别啊。。。
作者: chengjun1201    时间: 2009-11-7 15:21:11     标题: 内建函数要修改为

//------------------------------------------------------------------------
// 简称: iRSI
// 名称: iRSI
// 类别: 用户函数
// 类型: 内建函数
// 输出: 数值型
//------------------------------------------------------------------------

Params
        Numeric Length(14) ;

Vars
        NumericSeries NetChgAvg( 0 );
        NumericSeries TotChgAvg( 0 );
        Numeric Change( 0 );
        Numeric SF( 0 );
        Numeric ChgRatio( 0 ) ;
        Numeric iRSIValue;
Begin
        SF = 1/Length;
        If(CurrentBar < Length)
        {
                iRSIValue = InvalidNumeric;
        }Else
        {
                If(CurrentBar == Length)
                {
                        NetChgAvg = ( Close - Close[Length] ) / Length ;
                        TotChgAvg = AverageFC( Abs( Close - Close[1] ), Length ) ;
                }
               
                If(CurrentBar>length)
                {
                        Change = Close - Close[1] ;
                        NetChgAvg = NetChgAvg[1] + SF * ( Change - NetChgAvg[1] ) ;
                        TotChgAvg = TotChgAvg[1] + SF * ( Abs( Change ) - TotChgAvg[1] ) ;
                }
               
                If( TotChgAvg <> 0 )
                {
                        ChgRatio = NetChgAvg / TotChgAvg ;
                }else
                {
                        ChgRatio = 0 ;
                }
               
                iRSIValue = 50 * ( ChgRatio + 1 ) ;
        }

        Return iRSIvalue;
End

//------------------------------------------------------------------------
// 编译版本        GS2004.06.12
// 用户版本        2009/11/07 14:59
// 版权所有        chengjun1201
// 更改声明        TradeBlazer Software保留对TradeBlazer平台
//                        每一版本的TrabeBlazer公式修改和重写的权利
//------------------------------------------------------------------------
作者: chengjun1201    时间: 2009-11-7 15:45:30

//------------------------------------------------------------------------
// 简称: qqe
// 名称: qqe
// 类别: 技术指标
// 类型: 其它类
// 输出:
//------------------------------------------------------------------------
Params
        Numeric SF(5);                        
        Numeric RSI_Period(14);        
        Numeric rat(4.236);
Vars
        NumericSeries TrLevelSlow(0);        
        NumericSeries AtrRsi(0);        
        NumericSeries MaAtrRsi(0);        
        NumericSeries Rsi(0);
        NumericSeries RsiMa(0);
        Numeric Wilders_Period(0);        
        Numeric dar(0);        
        NumericSeries  smin(0);
    NumericSeries  smax(0);
        NumericSeries p;
        
Begin
        Wilders_Period=RSI_Period * 2 - 1;//   14*2-1
        If(BarStatus==0)
        {
                 TrLevelSlow=0;
         AtrRsi=0;
         MaAtrRsi=0;
         Rsi=0;
         RsiMa=0;
                 p=0;
        }
        if(CurrentBar>RSI_Period)
        {
                Rsi=iRSI(RSI_Period);
                RsiMa=XAverage(Rsi,SF);//将RSI 5周期平均
                AtrRsi=Abs(RsiMa[1] - RsiMa);//前一周期--今周期
                MaAtrRsi=XAverage(AtrRsi,Wilders_Period);
                dar=XAverage(MaAtrRsi,Wilders_Period) * rat;        
                smax=RsiMa+dar;
                smin=RsiMa-dar;

                p=p[1];

                if (RsiMa>smax[1]) {p=1; }         
                if (RsiMa<smin[1]) {p=-1;}

                if(p>0)
          {
                if(smin<smin[1])
                        smin=smin[1];
                TrLevelSlow=smin; //
                if(TrLevelSlow<TrLevelSlow[1])
                        TrLevelSlow=TrLevelSlow[1];//当 TrLevelSlow 慢速线向下运动时  就把昨天的 慢速线 向后传递 。。目的只向上升 不向下走
          }
          Else
          {
                if(smax>smax[1])
                        smax=smax[1];
                TrLevelSlow=smax;
                if(TrLevelSlow>TrLevelSlow[1])
                        TrLevelSlow=TrLevelSlow[1];
          }
                PlotNumeric("RsiMa",RsiMa);
                PlotNumeric("TrLevelSlow",TrLevelSlow);
        }
               

End



//------------------------------------------------------------------------
// 编译版本        GS2004.06.12
// 用户版本        2009/11/07 15:01
// 版权所有        chengjun1201
// 更改声明        TradeBlazer Software保留对TradeBlazer平台
//                        每一版本的TrabeBlazer公式修改和重写的权利
//------------------------------------------------------------------------
作者: telescope    时间: 2009-11-7 18:08:19

原帖由 chengjun1201 于 2009-11-7 15:21 发表
//------------------------------------------------------------------------
// 简称: iRSI
// 名称: iRSI
// 类别: 用户函数
// 类型: 内建函数
// 输出: 数值型
//------------------------------------------- ...


???RETURN语句的返回值类型与公式定义的返回值类型不符,错误号为C0122。




欢迎光临 开拓者期货期权程序化系统交易论坛 (http://bbs.tb18.net/) Powered by Discuz! X2