设为首页收藏本站

 找回密码
 注册
查看: 989|回复: 1

一个简单的程序 [复制链接]

Rank: 3Rank: 3

精华
0
UID
213396
积分
187
帖子
140
主题
26
阅读权限
40
注册时间
2015-7-10
最后登录
2023-4-14
发表于 2019-7-7 21:23:49 |显示全部楼层
Params
Numeric offset(6)        ;
Numeric n(3);
Numeric m(3);
Vars

Numeric totalequity;
Numeric turtleunits;
Numeric hh;
Numeric ll;
Numeric hhh;
Numeric lll;
NumericSeries count;

Begin


TotalEquity = A_FreeMargin + A_TotalMargin;   //账户最新资产 = 按当前Bar开盘价计算的可用资金 + 持仓保证金
TurtleUnits=(TotalEquity/(MarginRatio*ContractUnit()*BigPointValue()*Close)*1/5);
TurtleUnits = IntPart(TurtleUnits); // 对小数取整
if(GetGlobalVar(13)!=8 && BarStatus==2 && time==0.0900 || GetGlobalVar(13)!=8 && BarStatus==2 && time==0.2100)
{
SetGlobalVar(1,4);
SetGlobalVar(2,4);
SetGlobalVar(0,1);
SetGlobalVar(4,1);
SetGlobalVar(20,1);
SetGlobalVar(21,1);
SetGlobalVar(13,8);
}
Else If(Time!=0.0900 && Time!=0.2100)
SetGlobalVar(13,1);


if(GetGlobalVar(14)!=8 && BarStatus==2 )
{
SetGlobalVar(1,4);
SetGlobalVar(2,4);
SetGlobalVar(0,1);
SetGlobalVar(4,1);
SetGlobalVar(20,1);
SetGlobalVar(21,1);
SetGlobalVar(14,8);
}
hh=ting;
ll=di;
hhh=hhigh;
lll=llow;
if(time!=time[1]+0.0001 && time==0.0900 or time!=time[1]+0.0001 && time==0.2100)
count=1;
Else
count=count+1;

if(currenttime>0.090 && currenttime<0.1458 or currenttime>0.2100 && currenttime<0.2258)
{

if(A_BuyPosition==0 && A_SellPosition==0 && BarStatus==2 && vol>0)

{
if(GetGlobalVar(0)==1  && hh>=4 && hh>ll && hhh>=4 && hhh>lll && count>=4)
{
A_SendOrder(Enum_Buy,Enum_Entry,TurtleUnits,Q_AskPrice+offset*MinMove*PriceScale);
SetGlobalVar(0,2);
SetGlobalVar(4,2);
SetGlobalVar(2,4);

}
Else if(GetGlobalVar(4)==1 && ll>=4 && ll>hh && lll>=4 && lll>hhh && count>=4)
{

A_SendOrder(Enum_Sell,Enum_Entry,TurtleUnits,Q_BidPrice-offset*MinMove*PriceScale);
SetGlobalVar(4,2);
SetGlobalVar(0,2);
SetGlobalVar(1,4);

}
}

if(A_SellPosition>0 && BarStatus==2  && vol>0)
{

if(GetGlobalVar(1)==4 && hh>=4 && hh>ll && hhh>=4 && hhh>lll)
{
if(a_todaysellposition>0)
A_SendOrder(Enum_Buy,Enum_ExitToday,A_TodaySellPosition,Q_AskPrice+offset*MinMove*PriceScale);
Else
A_SendOrder(Enum_Buy,Enum_Exit,A_SellPosition,Q_AskPrice+offset*MinMove*PriceScale);
A_SendOrder(Enum_Buy,Enum_Entry,TurtleUnits,Q_AskPrice+offset*MinMove*PriceScale);
SetGlobalVar(1,5);
SetGlobalVar(2,4);

}
}


if(A_BuyPosition>0 && BarStatus==2 && vol>0)
{

if(GetGlobalVar(2)==4 && ll>=4 && ll>hh && lll>=4 && lll>hhh)
{
if(A_TodayBuyPosition>0)
A_SendOrder(Enum_Sell,Enum_ExitToday,A_TodayBuyPosition,Q_BidPrice-offset*MinMove*PriceScale);
Else
A_SendOrder(Enum_Sell,Enum_Exit,A_BuyPosition,Q_BidPrice-offset*MinMove*PriceScale);
A_SendOrder(Enum_Sell,Enum_Entry,TurtleUnits,Q_BidPrice-offset*MinMove*PriceScale);

SetGlobalVar(1,4);
SetGlobalVar(2,6);
}
}


}
if(A_GetOpenOrderCount==0)
SetGlobalVar(20,0);
Else
SetGlobalVar(20,1);
if(currenttime>0.1458 && currenttime<0.1500 && A_BuyPosition>0 or currenttime>0.1458 && currenttime<0.1500 && A_SellPosition>0 or currenttime>0.2258 && currenttime<0.2300 && A_BuyPosition>0 or currenttime>0.2258 && time<0.2300 && A_SellPosition>0)
{
if(A_TodayBuyPosition>0)
{
A_SendOrder(Enum_Sell,Enum_ExitToday,A_TodayBuyPosition,Q_BidPrice-offset*MinMove*PriceScale);
SetGlobalVar(20,1);
}
Else
{
A_SendOrder(Enum_Sell,Enum_Exit,A_BuyPosition,Q_BidPrice-offset*MinMove*PriceScale);
SetGlobalVar(20,1);
}
if(a_todaysellposition>0)
{
A_SendOrder(Enum_Buy,Enum_ExitToday,A_TodaySellPosition,Q_AskPrice+offset*MinMove*PriceScale);
SetGlobalVar(20,1);
}
Else
{
A_SendOrder(Enum_Buy,Enum_Exit,A_SellPosition,Q_AskPrice+offset*MinMove*PriceScale);
SetGlobalVar(20,1);
}
}
Commentary("GetGlobalVar(0)"+text(GetGlobalVar(0)));
Commentary("GetGlobalVar(4)"+text(GetGlobalVar(4)));
Commentary("GetGlobalVar(1)"+text(GetGlobalVar(1)));
Commentary("GetGlobalVar(2)"+text(GetGlobalVar(2)));
Commentary("GetGlobalVar(13)"+text(GetGlobalVar(13)));
Commentary("GetGlobalVar(14)"+text(GetGlobalVar(14)));
Commentary("GetGlobalVar(20)"+text(GetGlobalVar(20)));
Commentary("A_BuyPosition"+text(A_BuyPosition));
Commentary("A_SellPosition"+text(A_SellPosition));
Commentary("CurrentBar"+text(CurrentBar));
Commentary("A_OrderStatus(0)"+text(A_OrderStatus(0)));
Commentary("hh"+text(hh));
Commentary("ll"+text(ll));
Commentary("hhh"+text(hhh));
Commentary("lll"+text(lll));
Commentary("count"+text(count));
End

Rank: 3Rank: 3

精华
0
UID
213396
积分
187
帖子
140
主题
26
阅读权限
40
注册时间
2015-7-10
最后登录
2023-4-14
发表于 2019-7-7 21:28:33 |显示全部楼层
用到的函数
ting
Params
       
        Numeric Length(5);
Vars
        Numeric h1;
        Numeric h2;
        Numeric i;
       
Begin
        if (Length >0 && BarStatus==2)
        {
               
                for i = 0 To Length
                {
                       
                 if(High[i]>=High[i+1])
                 h1=h1+1;
                 Else
                 h2=h2+1;
                 

                 

                }
                Return h1;
        }Else
        {
                Return -1;
        }       
End
di
Params
       
        Numeric Length(5);
Vars
        Numeric h1;
        Numeric h2;
        Numeric i;
       
Begin
        if (Length >0 && BarStatus==2)
        {
               
                for i = 0 To Length
                {
                       
                 if(Low[i]<=Low[i+1])
                 h1=h1+1;
                 Else
                 h2=h2+1;

                 

                }
                Return h1;
        }Else
        {
                Return -1;
        }       
End
hhigh
Params
       
        Numeric Length(5);
Vars
        Numeric h1;
        Numeric h2;
        Numeric i;
       
Begin
        if (Length >0 && BarStatus==2)
        {
               
                for i = 0 To Length
                {
                       
                 if(high[i]-Close[i]<=Close[i]-Low[i])
                 h1=h1+1;
                 Else
                 h2=h2+1;
                 

                 

                }
                Return h1;
        }Else
        {
                Return -1;
        }       
End
llow
Params
       
        Numeric Length(5);
Vars
        Numeric h1;
        Numeric h2;
        Numeric i;
       
Begin
        if (Length >0 && BarStatus==2)
        {
               
                for i = 0 To Length
                {
                       
                 if(high[i]-Close[i]>=Close[i]-Low[i])
                 h1=h1+1;
                 Else
                 h2=h2+1;
                 

                 

                }
                Return h1;
        }Else
        {
                Return -1;
        }       
End

使用道具 举报

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

bottom

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

GMT+8, 2024-3-29 16:03

Powered by Discuz! X2 LicensedChrome插件扩展

© 2011-2012 交易开拓者 Inc.

回顶部