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

标题: 哪位好心人把这段TradeStation code变成TB,谢谢啦! [打印本页]

作者: 期货进行中    时间: 2012-3-31 11:09:28     标题: 哪位好心人把这段TradeStation code变成TB,谢谢啦!

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
作者: 趋势跟踪    时间: 2012-3-31 20:05:38

好复杂的交易模型!
作者: genesisdate    时间: 2012-4-1 22:23:19

不如你把思路说一下,重新写比翻译要快得多
作者: win5ms    时间: 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);
}




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