设为首页收藏本站

 找回密码
 注册
查看: 7902|回复: 10

TS源码(据说很好) [复制链接]

Rank: 2

精华
0
UID
15271
积分
86
帖子
29
主题
2
阅读权限
30
注册时间
2010-8-18
最后登录
2019-3-30
发表于 2010-10-8 17:14:43 |显示全部楼层
Input:  c1       (0),          { Coefficient of indicator 1 }
         c2       (0),          { Coefficient of indicator 2 }
         c3       (0),          { Coefficient of indicator 3 }
         c4       (0),          { Coefficient of indicator 4 }
         c5       (0),          { Coefficient of indicator 5 }
         c6       (0),          { Coefficient of indicator 6 }
         NMA1     (10),         { Length of moving average 1 }
         NMA2     (50),         { Length of moving average 2 }
         NMA3     (135),        { Length of moving average 3 }
         NATR     (27),        { Period for average true range }
         NRnge    (30),         { Period for computing average daily range }
         RngeFr   (0.6);        { Fraction of daily range }

Var:    SessLen  (0),          { Length in minutes of trading session }
         Time1Thrd(0),          { Time of end of 1st third of session }
         Time2Thrd(0),          { Time of end of 2nd third of session }
         NBarsDay (0),          { Number of bars per day }
         minTrend (0),          { minimum required daily change for "trend" }
         AveCO    (0),          { Average close - open }
         ACOPrior (0),          { Value of AveCO on prior day }
         DayRnge  (0),          { Most recent day's close - open }
         DRPrior  (0),          { Prior day's DayRnge }
         MovAve1  (0),          { Value of moving average 1 }
         MA1Prior (0),          { Value of moving average 1 on prior day }
         MovAve2  (0),          { Value of moving average 2 }
         MA2Prior (0),          { Value of moving average 2 on prior day }
         MovAve3  (0),          { Value of moving average 3 }
         MA3Prior (0),          { Value of moving average 3 on prior day }
         ATR      (0),          { Average true range }
         ATRPrior (0),          { Value of ATR on prior day }
         TRPrior  (0),          { Prior day's true range }
         PatVal   (0),          { Pattern number }
         PatCount (0),          { Number of occurances of pattern PatID }
         DayCount (0),          { Number of days examined }
         Cond1L   (False),      { Condition 1, up trend }
         Cond1S   (False),      { Condition 1, down trend }
         Cond2L   (False),      { Condition 2, up trend }
         Cond2S   (False),      { Condition 2, down trend }
         Cond3L   (False),      { Condition 3, up trend }
         Cond3S   (False),      { Condition 3, down trend }
         Cond4L   (False),      { Condition 4, up trend }
         Cond4S   (False),      { Condition 4, down trend }
         Cond5L   (False),      { Condition 5, up trend }
         Cond5S   (False),      { Condition 5, down trend }
         Cond6L   (False),      { Condition 6, up trend }
         Cond6S   (False),      { Condition 6, down trend }
         SumCondL (False),      { Summary of conditions for up trend }
         SumCondS (False),      { Summary of conditions for down trend }
         Score    (0),          { Accuracy of neural network prediction }
         FalsePos (0),          { Number of false positives: predicted pattern when not present }
         FalseNeg (0);          { Number of false negatives: didn't predict pattern when present }

Array: OThird[3](0),                   { Open prices for each third of day }
        HThird[3](0),                   { High prices for each third of day }
        LThird[3](99999999),            { Low prices for each third of day }
        CThird[3](0);                   { Close prices for each third of day }

{ Calculate indicator values }
ATR = Average(TrueRange, NATR);
MovAve1 = Average(C, NMA1);
MovAve2 = Average(C, NMA2);
MovAve3 = Average(C, NMA3);

{ Initialize some variables on 1st bar }
If BarNumber = 1 then Begin
    SessLen = AbsValue(TimeToMinutes(SessionEndTime(0,1)) - TimeToMinutes(SessionStartTime(0,1)));
    Time1Thrd = CalcTime(SessionStartTime(0,1), SessLen/3.);
    Time2Thrd = CalcTime(SessionStartTime(0,1), (2. * SessLen/3.));

    If BarInterval > 0 then
       NBarsDay = SessLen/BarInterval;
End;

{ Calculations on first bar of new day }
If date <> date[1] or BarNumber = 1 then Begin
       
    DayRnge = AbsValue(CloseD(1) - OpenD(1));   { range of prior day }

    { Calculate the minimum required move for a trend based on average daily range }
    AveCO = GetAveDayRange(NRnge);
    minTrend = RngeFr * AveCO;
    {Print("AveCO = ", AveCO, " minTrend = ", minTrend);}

    { Obtain O, H, L, C of each third of day }
    Value1 = GetDayThirds(Time1Thrd, Time2Thrd, NBarsDay, OThird, HThird, LThird, CThird);

End;

{ Initialize prior values of indicators }
If BarNumber = 1 then Begin
    MA1Prior = MovAve1;
    MA2Prior = MovAve2;
    MA3Prior = MovAve3;
    DRPrior = DayRnge;
    ACOPrior = AveCO;
    ATRPrior = ATR;
    TRPrior = TrueRange;
End;

{ Evaluate indicators to obtain prediction on prior day }
If date <> date[1] then Begin
       
    { Use indicator values from day prior to one we're trying to predict }
    MovAve1 = MA1Prior;
    MovAve2 = MA2Prior;
    MovAve3 = MA3Prior;
    ATR = ATRPrior;
       
    { Pattern on prior day; we want to predict this }
    PatVal = GetTrendPattern(OThird, HThird, LThird, CThird, minTrend);

    { See if we can predict pattern or absence of pattern }               
    DayCount = DayCount + 1;

    If AbsValue(PatVal) > 0 then
       PatCount = PatCount + 1;

    { Construct indicators and evaluate }
    Cond1L = TRUE;
    Cond1S = TRUE;
    If AbsValue(c1) > 0 then Begin
       Cond1L = c1 * (CloseD(2) - MovAve1) > 0;
       Cond1S = -c1 * (CloseD(2) - MovAve1) > 0;
    End;

    Cond2L = TRUE;
    Cond2S = TRUE;
    If AbsValue(c2) > 0 then Begin
       Cond2L = c2 * (CloseD(2) - MovAve2) > 0;
       Cond2S = -c2 * (CloseD(2) - MovAve2) > 0;
    End;

    Cond3L = TRUE;
    Cond3S = TRUE;
    If AbsValue(c3) > 0 then Begin
       Cond3L = c3 * (CloseD(2) - MovAve3) > 0;
       Cond3S = -c3 * (CloseD(2) - MovAve3) > 0;
    End;

    Cond4L = TRUE;
    Cond4S = TRUE;
    If AbsValue(c4) > 0 then Begin
       Cond4L = c4 * (DRPrior - ACOPrior) > 0;
           Cond4S = -c4 * (DRPrior - ACOPrior) > 0;
    End;

    Cond5L = TRUE;
    Cond5S = TRUE;
    If AbsValue(c5) > 0 then Begin
       Cond5L = c5 * (CloseD(2) - CloseD(3)) > 0;
       Cond5S = -c5 * (CloseD(2) - CloseD(3)) > 0;
    End;

        Cond6L = TRUE;
        Cond6S = TRUE;
    If AbsValue(c6) > 0 then Begin
      { Cond6L = c6 * (TRPrior - ATR) > 0;
           Cond6S = -c6 * (TRPrior - ATR) > 0; }
       Cond6L = c6 * (CloseD(2) - OpenD(2)) > 0;
       Cond6S = -c6 * (CloseD(2) - OpenD(2)) > 0;
    End;

    SumCondL = Cond1L and Cond2L and Cond3L and Cond4L and Cond5L and Cond6L;
    SumCondS = Cond1S and Cond2S and Cond3S and Cond4S and Cond5S and Cond6S;

    If PatVal > 0 then Begin              { Long pattern present so see if we predict its presence }
       If SumCondL then
          Score = Score + 1          { Correct prediction }
       Else
          FalseNeg = FalseNeg + 1;   { False negative }
        End
    Else If PatVal < 0 then Begin         { Short pattern present so see if we predict its presence }
       If SumCondS then
          Score = Score + 1          { Correct prediction }
       Else
          FalseNeg = FalseNeg + 1;   { False negative }
        End
    Else Begin                                 { Pattern not present, so see if we don't predict it }
           If SumCondL = False and SumCondS = False then
          Score = Score + 1          { Correct prediction }
       Else
          FalsePos = FalsePos + 1;   { False positive }
    End;
    {Print("Date: ", Date[1]:0:0, " Pattern: ", PatVal:0:0); }

    { Calculate indicator values at end of prior day }
    MA1Prior = MovAve1[1];
    MA2Prior = MovAve2[1];
    MA3Prior = MovAve3[1];
    ACOPrior = AveCO;
        DRPrior = DayRnge;
    TRPrior = TrueRange[1];
    ATRPrior = ATR[1];
End;

If LastBarOnChart then Begin
    If DayCount > 0 then
       Score = 100 * Score/DayCount;
    If PatCount > 0 then
       FalseNeg = 100 * FalseNeg/PatCount;
    If (DayCount - PatCount) > 0 then
       FalsePos = 100 * FalsePos/(DayCount - PatCount);
    Print("FindPrediction (c1 c2 c3 c4 c5 c6 Score FNeg FPos DayCount PatCount):,", c1:0:0, ",", c2:0:0, ",", c3:0:0,
              ",", c4:0:0, ",", c5:0:0, ",", c6:0:0, ",", Score:0:2, ",", FalseNeg:0:1, ",", FalsePos:0:1, ",", DayCount:0:0, ",",
              PatCount:0:0);
End;

请高手会改成TB的

Rank: 3Rank: 3

精华
0
UID
111289
积分
122
帖子
98
主题
0
阅读权限
40
注册时间
2012-6-30
最后登录
2012-7-2
发表于 2012-7-1 11:41:06 |显示全部楼层
支持下。。。

使用道具 举报

Rank: 2

精华
0
UID
110162
积分
103
帖子
75
主题
4
阅读权限
30
注册时间
2012-4-23
最后登录
2013-2-13
发表于 2012-7-7 18:15:57 |显示全部楼层
我是 没看明白, 高手 是不是 改成了TB 的 在 自己用哦

使用道具 举报

Rank: 1

精华
0
UID
111019
积分
42
帖子
22
主题
1
阅读权限
10
注册时间
2012-6-18
最后登录
2013-5-28
发表于 2012-8-19 08:52:12 |显示全部楼层
等牛了,现在还不太明白

使用道具 举报

Rank: 1

精华
0
UID
112104
积分
0
帖子
6
主题
1
阅读权限
10
注册时间
2012-8-19
最后登录
1970-1-1
发表于 2012-8-19 18:14:37 |显示全部楼层

使用道具 举报

Rank: 2

精华
0
UID
26451
积分
70
帖子
18
主题
5
阅读权限
30
注册时间
2011-2-22
最后登录
2020-11-16
发表于 2012-9-2 09:21:13 |显示全部楼层
多谢分享

使用道具 举报

Rank: 1

精华
0
UID
112450
积分
43
帖子
20
主题
3
阅读权限
10
注册时间
2012-9-11
最后登录
2012-10-12
发表于 2012-9-22 09:14:20 |显示全部楼层
有人转成TB源码吗?

使用道具 举报

Rank: 5Rank: 5

精华
0
UID
15203
积分
1411
帖子
397
主题
35
阅读权限
60
注册时间
2010-8-14
最后登录
2017-12-29
发表于 2012-9-23 18:51:48 来自手机 |显示全部楼层
明天研究一下

使用道具 举报

Rank: 5Rank: 5

精华
0
UID
15203
积分
1411
帖子
397
主题
35
阅读权限
60
注册时间
2010-8-14
最后登录
2017-12-29
发表于 2012-9-25 11:12:04 |显示全部楼层
放弃了,好多看不懂的地方

使用道具 举报

Rank: 1

精华
0
UID
112200
积分
48
帖子
28
主题
0
阅读权限
10
注册时间
2012-8-29
最后登录
2013-7-22
发表于 2012-10-8 15:01:12 |显示全部楼层
比较复杂

使用道具 举报

您需要登录后才可以回帖 登录 | 注册

bottom

静态版|手机版|联系我们|交易开拓者 ( 粤ICP备07044698   

GMT+8, 2024-4-17 01:30

Powered by Discuz! X2 LicensedChrome插件扩展

© 2011-2012 交易开拓者 Inc.

回顶部