设为首页收藏本站

 找回密码
 注册
查看: 5070|回复: 3
打印 上一主题 下一主题

哪位好心人把这段TradeStation code变成TB,谢谢啦! [复制链接]

Rank: 5Rank: 5

精华
0
UID
38411
积分
669
帖子
160
主题
17
阅读权限
60
注册时间
2011-5-8
最后登录
2023-10-4
跳转到指定楼层
1#
发表于 2012-3-31 11:09:28 |只看该作者 |倒序浏览
input:trials(500),entrymethod(1);

var: LongShort(0);
Var: BarstoNext(0);
Var:ATRexitL(-99999.),ATRexitS(99999.),ATRx(0);


if entrymethod=1 then begin  //random entry

//Entry logic
Longshort=random(1);  //chose a random number between 0 and 1
BarstoNext=intportion(random(15))+1; //entry should occur at BarsToNext bars after previous exit

if (totaltrades=0 or BarsSinceExit(1)>=BarsToNext) and marketposition=0 then begin
    if LongShort<.5 then buy next bar at market;
    if LongShort>.5 then sellshort next bar at market;
end;

end; //exit method 1


if entrymethod=2 and marketposition=0 then begin  //Bollinger Band entry
inputs: Length( 20 ), NumDevsDn( 2 ) ;
variables: LowerBand( 0 ),UpperBand( 0 ) ;

LowerBand = BollingerBand( Close, Length, -NumDevsDn ) ;
UpperBand = BollingerBand( Close, Length, NumDevsDn ) ;

if CurrentBar > 1 and Low crosses over LowerBand then
{ CB > 1 check used to avoid spurious cross confirmation at CB = 1 }
    If close>=LowerBand then buy next bar at market;

if CurrentBar > 1 and High crosses under UpperBand then
{ CB > 1 check used to avoid spurious cross confirmation at CB = 1 }
    If Close<=Upperband then sellshort next bar at market;
    //SellShort ( "BBandSE" ) next bar at UpperBand stop ;

end;//entry method 2

if entrymethod=3 and marketposition=0 then begin
    inputs:  FastLength( 12 ) ;
variables:  MyMACD( 0 ), MACDAvg( 0 ), MACDDiff( 0 ),slowLength(0),MACDLength(0) ;
variables:  MyMACD2( 0 ), MACDAvg2( 0 ), MACDDiff2( 0 ) ;

SlowLength=2.*FastLength;
MACDLength=FastLength;

MyMACD = MACD( Close, FastLength, SlowLength ) ;
MACDAvg = XAverage( MyMACD, MACDLength ) ;
MACDDiff = MyMACD - MACDAvg ;

if CurrentBar > 2 and MACDDiff crosses over 0 then { CB > 2 check used to
avoid spurious cross confirmation at CB = 2 (at CB = 1, MyMACD and MACDAvg will be
the same) }
    Buy ( "MacdLE" ) next bar at market ;

MyMACD2 = MACD( Close, FastLength, SlowLength ) ;
MACDAvg2 = XAverage( MyMACD2, MACDLength ) ;
MACDDiff2 = MyMACD2 - MACDAvg2 ;

if CurrentBar > 2 and MACDDiff2 crosses under 0 then { CB > 2 check used to
avoid spurious cross confirmation at CB = 2 (at CB = 1, MyMACD and MACDAvg will be
the same) }
    Sell Short ( "MacdSE" ) next bar at market ;
end; //entry method 3 (MACD)

if entrymethod=4 and marketposition=0 then begin //(momentum)
    inputs:  Price( Close ), MomeLength( 12 ) ; ;
variables:  Mom( 0 ), Accel( 0 ) ;

Mom = Momentum( Price, MomeLength ) ;
Accel = Momentum( Mom, 1 ) ; { 1 bar acceleration }

if Mom > 0 and Accel > 0  then
    If high>high[1] then buy next bar at market;

if Mom < 0 and Accel < 0  then
    If low<low[1] then sellshort next bar at market;

end; //entry 4


if entrymethod=5  and marketposition=0 then begin //2 mov avg
    inputs: xPrice( Close ), MAFastLength( 9 );
variables: MAFastAvg( 0 ), MASlowAvg( 0 ),MAslowlength(0) ;

MASlowLength=2*MAFastLength;

MAFastAvg = AverageFC( xPrice, MAFastLength ) ;
MASlowAvg = AverageFC( xPrice, MASlowLength ) ;

if CurrentBar > 1 and MAFastAvg crosses over MASlowAvg then
{ CB > 1 check used to avoid spurious cross confirmation at CB = 1 }
    Buy ( "MA2CrossLE" ) next bar at market ;

if CurrentBar > 1 and MAFastAvg crosses under MASlowAvg then
{ CB > 1 check used to avoid spurious cross confirmation at CB = 1 }
    Sell Short ( "MA2CrossSE" ) next bar at market ;
end; //dual ma entry

if entrymethod=6 and marketposition=0 then begin
    inputs: RSILength( 14 ), OverSold( 30 ),overbought(70) ;
variables:  MyRSI( 0 ) ;

MyRSI = RSI( Close, Length ) ;

if Currentbar > 1 and MyRSI crosses over OverSold then
{ CB > 1 check used to avoid spurious cross confirmation at CB = 1 }
    Buy ( "RsiLE" ) next bar at market ;
if Currentbar > 1 and MyRSI crosses under OverBought then
{ CB > 1 check used to avoid spurious cross confirmation at CB = 1 }
    Sell Short ( "RsiSE" ) next bar at market ;

    end;//RSi entry


var:ExitBar(0);
//exit method
   
ExitBar=intportion(random(20))+1;

if BarssinceEntry>=ExitBar then begin
    sell next bar market;
    Buytocover next bar market;
end;

REVERSE ENTRIES –Bollinger Bands and RSI

if entrymethod=2 and marketposition=0 then begin  //reverse Bollinger Band entry
inputs: Length( 20 ), NumDevsDn( 2 ) ;
variables: LowerBand( 0 ),UpperBand( 0 ) ;

LowerBand = BollingerBand( Close, Length, -NumDevsDn ) ;
UpperBand = BollingerBand( Close, Length, NumDevsDn ) ;

if CurrentBar > 1 and Low crosses over LowerBand then
{ CB > 1 check used to avoid spurious cross confirmation at CB = 1 }
    If close>=LowerBand then sellshort next bar at market;

if CurrentBar > 1 and High crosses under UpperBand then
{ CB > 1 check used to avoid spurious cross confirmation at CB = 1 }
    If Close<=Upperband then buy next bar at market;

end;//entry method 2r


if entrymethod=6 and marketposition=0 then begin //reverse RSI entry
    inputs: RSILength( 14 ), OverSold( 30 ),overbought(70) ;
variables:  MyRSI( 0 ) ;

MyRSI = RSI( Close, Length ) ;

if Currentbar > 1 and MyRSI crosses over OverSold then
{ CB > 1 check used to avoid spurious cross confirmation at CB = 1 }
    SellShort( "RsiSE" ) next bar at market ;
if Currentbar > 1 and MyRSI crosses under OverBought then
{ CB > 1 check used to avoid spurious cross confirmation at CB = 1 }
    Buy ( "RsiLE" ) next bar at market ;

    end;//RSi entry 6r

Rank: 5Rank: 5

精华
0
UID
12330
积分
838
帖子
254
主题
15
阅读权限
60
注册时间
2010-6-16
最后登录
2017-4-25
2#
发表于 2012-3-31 20:05:38 |只看该作者
好复杂的交易模型!

使用道具 举报

Rank: 3Rank: 3

精华
0
UID
39083
积分
219
帖子
47
主题
2
阅读权限
40
注册时间
2011-5-11
最后登录
2012-7-14
3#
发表于 2012-4-1 22:23:19 |只看该作者
不如你把思路说一下,重新写比翻译要快得多
让机器完成复杂的工作

使用道具 举报

Rank: 3Rank: 3

精华
0
UID
12849
积分
230
帖子
109
主题
13
阅读权限
40
注册时间
2010-6-23
最后登录
2024-2-2
4#
发表于 2012-10-14 23:50:21 |只看该作者
If(Close<Close[1]&&Close<high*(1-0.3))
{
     SellShort(1,Close);
}
If(Close<Close[1]&&Close>high*(1-0.3))
{
     Buy(1,CLose);
}

使用道具 举报

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

bottom

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

GMT+8, 2024-5-5 10:34

Powered by Discuz! X2 LicensedChrome插件扩展

© 2011-2012 交易开拓者 Inc.

回顶部