我要开发一个比TB,文华更牛的程序化交易软件

Discussion in 'CTP' started by marry3640, Mar 30, 2013.

  1. diy

    diy

    数据机,下单机,策略机完全分开到三台电脑。作为一个阴谋论支持者,对老外的软件总是持怀疑态度。。。
     
  2. diy

    diy

    #include "m3_header.h"


    int InpFastEMA=12; // Fast EMA Period
    int InpSlowEMA=26; // Slow EMA Period
    int InpSignalSMA=9; // Signal SMA Period

    double* ExtMacdBuffer = NULL;
    double* ExtSignalBuffer = NULL;

    //--- right input parameters flag
    bool ExtParameters=false;
    int FastMI;
    int SlowMI;

    double* pFastEMABuffer = NULL;
    double* pSlowEMABuffer = NULL;

    /*functions that must be realized*/
    void setInputs()
    {
    input(InpFastEMA);
    input(InpSlowEMA);
    input(InpSignalSMA);
    }

    void setProperties()
    {
    property_shortname(L"EMA");
    property_copyright(L"2005-2014, MetaQuotes Software Corp.");
    property_link(L"http://www.mql4.com");
    property_description(L"Exponential Moving Average");

    property_indicator_buffers(2);

    property_indicator_color(0,RGB(192,192,192));
    property_indicator_width(0,2);
    property_indicator_style(0,0);
    property_indicator_type(0,DRAW_HISTOGRAM);

    property_indicator_color(1,RGB(255,0,0));
    property_indicator_width(1,1);
    property_indicator_style(1,0);
    property_indicator_type(1,DRAW_LINE);

    property_indicator_separate_window();
    }

    void setLineBuffers()
    {
    line_buffer(ExtMacdBuffer);
    line_buffer(ExtSignalBuffer);
    }

    /*-------------------------------------------------------*/

    void onInit()
    {
    if(InpFastEMA<=1 || InpSlowEMA<=1 || InpSignalSMA<=1 || InpFastEMA>=InpSlowEMA)
    {
    ExtParameters=false;
    return;
    }
    else
    ExtParameters=true;


    FastMI = LoadIndicator(Period(), L"EMA", InpFastEMA);
    SetNestedIndicatorBuffer(FastMI, 0, pFastEMABuffer);

    SlowMI = LoadIndicator(Period(), L"EMA", InpSlowEMA);
    SetNestedIndicatorBuffer(SlowMI, 0, pSlowEMABuffer);
    }


    //+------------------------------------------------------------------+
    //| Simple moving average on price array |
    //+------------------------------------------------------------------+
    int SimpleMAOnBuffer(const int rates_total,const int prev_calculated,const int begin,
    const int period,const double* price,double* buffer)
    {
    int i,limit;
    //--- check for data
    if(period<=1 || rates_total-begin<period) return(0);

    //--- first calculation or number of bars was changed
    if(prev_calculated==0) // first calculation
    {
    limit=period+begin;
    //--- set empty value for first bars
    for(i=0;i<limit-1;i++) buffer[Bars -1 - i]=0.0;
    //--- calculate first visible value
    double firstValue=0;
    for(i=begin;i<limit;i++)
    firstValue+=price[Bars - 1 - i];
    firstValue/=period;
    buffer[Bars - limit]=firstValue;
    }
    else limit=prev_calculated-1;
    //--- main loop
    for(i=limit;i<rates_total;i++)
    buffer[Bars - 1 - i]=buffer[Bars - i]+(price[Bars -1 - i]-price[Bars - 1 - i + period])/period;
    //---
    return(rates_total);
    }


    void onCaculate()
    {
    int i,limit, counted_bars = IndicatorCounted();
    //---
    if(Bars<=InpSignalSMA || !ExtParameters)
    return;
    //--- last counted bar will be recounted
    limit=Bars-counted_bars;


    //--- macd counted in the 1-st buffer
    for(i=0; i<limit; i++)
    {
    ExtMacdBuffer= pFastEMABuffer - pSlowEMABuffer;/*iMA(NULL,0,InpFastEMA,0,MODE_EMA,PRICE_CLOSE,i)-
    iMA(NULL,0,InpSlowEMA,0,MODE_EMA,PRICE_CLOSE,i);*/
    }
    //--- signal line counted in the 2-nd buffer
    SimpleMAOnBuffer(Bars,counted_bars,0,InpSignalSMA,ExtMacdBuffer,ExtSignalBuffer);

    }

    void onDeinit()
    {
    DelIndicator(FastMI);
    DelIndicator(SlowMI);
    }
     
  3. diy

    diy

    手动交易永远不能丢,自动化交易只能慢慢玩。。。
     
  4. diy

    diy

    吹牛吹到底

    谈谈代码备份:本地git 仓库 -> 代码加密文件 -> 分割多个单独文件 -> 上传到网络多个服务器分散备份。

    阴谋论+小气吧啦的 diy
     
  5. 感觉没必要加密代码吧,现在做自动交易的开源项目挺多的。不愿意公开可以找一个免费的private repository管理代码就好了
     
  6. diy

    diy

    嗯,在 github上私有账户托管了大半年。只是觉得现在软件越来越成熟了,我承认我很小心眼。。。

    之前一直在mt4上看图表,策略都是用dll导出的,但是发现有许多不太希望继续使用的理由:
    1) 时区问题 - 主要是日K图,不同平台不同,而我的策略有基于日线分析的,转换时候很麻烦

    2)报价,以Bid报价有时候会出现很大误差,尤其是数据波动很厉害时候,这个对策略有影响,我希望使用中间价

    3) 内部效率:mt4计算效率确实很高,但是我不理解它如何进行计算的。我属于有点吹毛求疵的人,希望得到最佳效率,策略希望能以最快速度执行

    4) MT4是个好平台,但是能交易的东西太少了。Multicharts 提供自定义数据源(需要另外购买),但同样基于效率的理由,而且我实在不喜欢读文档。。。

    最后干脆决定自己做一个,因为交易这行我个人认为任何时候入行都不晚,所以大半年时间都是写写停停,不过到现在对我自己而言外汇方面的处理基本已经很好配置了。

    现在开发的东西跟mt4很像,界面几乎都是差不多的。并且数据源,策略平台,下单平台完全独立了。以后可以用这个东东交易几乎所有产品了。。。外汇,期货,股票。。。

    有点想要炫耀的意思,请包涵。
     
  7. diy

    diy

    准备再给自己半年到一年时间,把平台完善好,代码再审查一遍,到时候就可以拿自己的平台做交易了。这种感觉其实还是满爽的。
     
  8. diy

    diy

    其实这次觉得收获最大的倒不是做平台的逻辑部分,那个觉得不是很难想。而是做界面,以前做界面水平实在一般,现在大幅度提高。。。
     
  9. 老兄现在在哪个地方?多交流一下。
     
  10. for(k=0;k<meChart->kcount;k++)
    {
    if(k<nDay)
    {
    HighestValue = HighestFC(&higprice[0],k+1);
    LowestValue = LowestFC (&lowprice[0],k+1);
    }
    else
    {
    HighestValue = HighestFC(&higprice[k+1-nDay],nDay);
    LowestValue = LowestFC (&lowprice[k+1-nDay],nDay);
    }
    RSV=(closeprice[k]-LowestValue)/(HighestValue-LowestValue)*100;
    if(k==0)
    {
    a = (1 * RSV + (SlowLength - 1) * 0) / 1;


    b = (1 * a + (SmoothLength - 1) * 0) / 1;
    e = 3 * a - 2 * b;
    }
    else
    {
    a = (1 * RSV + (SlowLength - 1) * kval[k-1]) / SlowLength;
    b = (1 * a + (SmoothLength - 1) * dval[k-1]) / SmoothLength;
    e = 3 * a - 2 * b;
    }
    rsv[k]=RSV;
    kval[k]=a;
    dval[k]=b;
    jval[k]=e;
    }
     
  11. diy

    diy


    看起来大家都喜欢自己搞平台:D

    给你发邮件了。请查收。