设为首页收藏本站

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

求助,不同条件下如何平仓! [复制链接]

Rank: 4

精华
0
UID
2282
积分
265
帖子
51
主题
17
阅读权限
50
注册时间
2008-9-5
最后登录
2012-2-27
跳转到指定楼层
1#
发表于 2009-9-20 15:51:17 |只看该作者 |倒序浏览
在不同均线排列下,根据条件建仓,建仓后当条件满足平仓所设定条件平仓
程序代码:
Params
        Numeric Length(5);

         Numeric Xb1(-4);
         Numeric Xs1(2);

         Numeric Xb2(-1);
         Numeric Xs2(1);

         Numeric Xb3(-1);
         Numeric Xs3(1);
  
Vars
         Numeric ma1;
         Numeric ma2;
         Numeric ma3;
         Numeric hh;
         Numeric ll;
         Numeric ROCValue;
         Numeric win1;            

         Numeric exitBar1;
         Numeric win2;              

         Numeric exitBar2;
         Numeric win3;     

         Numeric exitBar3;
         Numeric myEntryPrice;  //记录开仓情况


Begin
         ma1=AverageFC(C,8);
         ma2=AverageFC(C,13);
         ma3=AverageFC(C,21);
  
ROCValue = (Close - Close[Length])/Close[Length]*100;


//不同均线排列的建仓如下:

if (ma1>ma2 and ma2>ma3)
{

myEntryPrice=1;

If(rocvalue<0 and rocvalue>Xb1 and MarketPosition<>1)
buy(1,close);

if(rocvalue>0 and rocvalue<XS1 and MarketPosition<>-1)
SellShort(1,close);
   }

hh=max(HighestFC(open,(length+1)),HighestFC(close,(length+1)));
ll=min(LowestFC(open,(length+1)),LowestFC(close,(length+1)));
Win1=abs(hh-ll);
exitBar1=5;// 持仓天数

if (ma1>ma3 and ma3>ma2)

{

myEntryPrice=2;

If(rocvalue<0 and rocvalue>Xb2 and MarketPosition<>1)
buy(1,close);

    if(rocvalue>0 and rocvalue<XS2 and MarketPosition<>-1)
SellShort(1,close);
    }

hh=max(HighestFC(open,(length+1)),HighestFC(close,(length+1)));
ll=min(LowestFC(open,(length+1)),LowestFC(close,(length+1)));
Win2=abs(hh-ll);
exitBar2=3;

if (ma2>ma1 and ma1>ma3)

{

myEntryPrice=3;
If(rocvalue<0 and rocvalue>Xb3 and MarketPosition<>1)
buy(1,close);
  
    if(rocvalue>0 and rocvalue<XS3 and MarketPosition<>-1)
SellShort(1,close);
    }

hh=max(HighestFC(open,(length+1)),HighestFC(close,(length+1)));
ll=min(LowestFC(open,(length+1)),LowestFC(close,(length+1)));
Win3=abs(hh-ll);
exitBar3=2;

//平仓条件如下:
If(myEntryPrice==1)
{
if( BarsSinceEntry==exitBar1 )
{
Sell( 0,Close );
BuyToCover( 0,Close );
}
//SetProfitTarget(1,win1*0.3,False);
}

If(myEntryPrice==2)
{
if( BarsSinceEntry==exitbar2 )
{
Sell( 0,Close );
BuyToCover( 0,Close );
}
//SetProfitTarget(1,win2*0.2,False);
}


If(myEntryPrice==3)
{
if( BarsSinceEntry==exitbar3 )
{
Sell( 0,Close );
BuyToCover( 0,Close );
}
//SetProfitTarget(1,win3*0.25,False);
}

End
求助,程序这样写对吗,为何平仓无法按指定持仓日期平仓,谢谢!


[ 本帖最后由 qqboy1978 于 2009-9-20 15:53 编辑 ]

Rank: 4

精华
0
UID
2282
积分
265
帖子
51
主题
17
阅读权限
50
注册时间
2008-9-5
最后登录
2012-2-27
2#
发表于 2009-9-21 10:16:08 |只看该作者
求助啊。。。。。。。。。各位老大!。。。。。快晕了!

使用道具 举报

Rank: 4

精华
0
UID
2282
积分
265
帖子
51
主题
17
阅读权限
50
注册时间
2008-9-5
最后登录
2012-2-27
3#
发表于 2009-9-21 13:27:00 |只看该作者

求助,程序这样写对吗

求助,不同条件下如何平仓!在不同均线排列下,根据条件建仓,建仓后当条件满足平仓所设定条件平仓
程序代码:
Params
        Numeric Length(5);

         Numeric Xb1(-4);
         Numeric Xs1(2);

         Numeric Xb2(-1);
         Numeric Xs2(1);

         Numeric Xb3(-1);
         Numeric Xs3(1);
  
Vars
         Numeric ma1;
         Numeric ma2;
         Numeric ma3;
         Numeric hh;
         Numeric ll;
         Numeric ROCValue;
         Numeric win1;            

         Numeric exitBar1;
         Numeric win2;              

         Numeric exitBar2;
         Numeric win3;     

         Numeric exitBar3;
         Numeric myEntryPrice;  //记录开仓情况


Begin
         ma1=AverageFC(C,8);
         ma2=AverageFC(C,13);
         ma3=AverageFC(C,21);
  
ROCValue = (Close - Close[Length])/Close[Length]*100;


//不同均线排列的建仓如下:

if (ma1>ma2 and ma2>ma3)
{

myEntryPrice=1;

If(rocvalue<0 and rocvalue>Xb1 and MarketPosition<>1)
buy(1,close);

if(rocvalue>0 and rocvalue<XS1 and MarketPosition<>-1)
SellShort(1,close);
   }

hh=max(HighestFC(open,(length+1)),HighestFC(close,(length+1)));
ll=min(LowestFC(open,(length+1)),LowestFC(close,(length+1)));
Win1=abs(hh-ll);
exitBar1=5;// 持仓天数

if (ma1>ma3 and ma3>ma2)

{

myEntryPrice=2;

If(rocvalue<0 and rocvalue>Xb2 and MarketPosition<>1)
buy(1,close);

    if(rocvalue>0 and rocvalue<XS2 and MarketPosition<>-1)
SellShort(1,close);
    }

hh=max(HighestFC(open,(length+1)),HighestFC(close,(length+1)));
ll=min(LowestFC(open,(length+1)),LowestFC(close,(length+1)));
Win2=abs(hh-ll);
exitBar2=3;

if (ma2>ma1 and ma1>ma3)

{

myEntryPrice=3;
If(rocvalue<0 and rocvalue>Xb3 and MarketPosition<>1)
buy(1,close);
  
    if(rocvalue>0 and rocvalue<XS3 and MarketPosition<>-1)
SellShort(1,close);
    }

hh=max(HighestFC(open,(length+1)),HighestFC(close,(length+1)));
ll=min(LowestFC(open,(length+1)),LowestFC(close,(length+1)));
Win3=abs(hh-ll);
exitBar3=2;

//平仓条件如下:
If(myEntryPrice==1)
{
if( BarsSinceEntry==exitBar1 )
{
Sell( 0,Close );
BuyToCover( 0,Close );
}
//SetProfitTarget(1,win1*0.3,False);
}

If(myEntryPrice==2)
{
if( BarsSinceEntry==exitbar2 )
{
Sell( 0,Close );
BuyToCover( 0,Close );
}
//SetProfitTarget(1,win2*0.2,False);
}


If(myEntryPrice==3)
{
if( BarsSinceEntry==exitbar3 )
{
Sell( 0,Close );
BuyToCover( 0,Close );
}
//SetProfitTarget(1,win3*0.25,False);
}

End
求助,程序这样写对吗,为何平仓无法按指定持仓日期平仓,谢谢!

使用道具 举报

Rank: 10Rank: 10Rank: 10

精华
20
UID
4
积分
22709
帖子
4802
主题
64
阅读权限
255
注册时间
2007-7-20
最后登录
2024-1-15
4#
发表于 2009-9-21 13:56:02 |只看该作者
myEntryPrice要用序列变量来记录

Vars
    NumericSeries myEntryPrice;
Begin
If(CurrentBar >0)
{
myEntryPrice = myEntryPrice[1];
}
...

使用道具 举报

Rank: 4

精华
0
UID
2282
积分
265
帖子
51
主题
17
阅读权限
50
注册时间
2008-9-5
最后登录
2012-2-27
5#
发表于 2009-9-22 09:07:27 |只看该作者
寓问:接下来程序按原来的写对吗?谢谢!
Vars
    NumericSeries myEntryPrice;
Begin
If(CurrentBar >0)
{
myEntryPrice = myEntryPrice[1];
}

//不同均线排列的建仓如下:

if (ma1>ma2 and ma2>ma3)
{
myEntryPrice=1;
If(rocvalue<0 and rocvalue>Xb1 and MarketPosition<>1)
buy(1,close);
if(rocvalue>0 and rocvalue<XS1 and MarketPosition<>-1)
SellShort(1,close);
   }
hh=max(HighestFC(open,(length+1)),HighestFC(close,(length+1)));
ll=min(LowestFC(open,(length+1)),LowestFC(close,(length+1)));
Win1=abs(hh-ll);
exitBar1=5;// 持仓天数

if (ma1>ma3 and ma3>ma2)
{
myEntryPrice=2;
......
//平仓条件如下:
If(myEntryPrice==1)
{
if( BarsSinceEntry==exitBar1 )
{
Sell( 0,Close );
BuyToCover( 0,Close );
}
//SetProfitTarget(1,win1*0.3,False);
}

If(myEntryPrice==2)
{
if( BarsSinceEntry==exitbar2 )
{
Sell( 0,Close );
BuyToCover( 0,Close );
}
//SetProfitTarget(1,win2*0.2,False);
}
...

使用道具 举报

Rank: 10Rank: 10Rank: 10

精华
20
UID
4
积分
22709
帖子
4802
主题
64
阅读权限
255
注册时间
2007-7-20
最后登录
2024-1-15
6#
发表于 2009-9-22 10:07:08 |只看该作者
是啊,这样序列变量才能保存住

使用道具 举报

Rank: 4

精华
0
UID
2282
积分
265
帖子
51
主题
17
阅读权限
50
注册时间
2008-9-5
最后登录
2012-2-27
7#
发表于 2009-9-22 11:41:52 |只看该作者
谢谢老大,回头俺试一下,有啥不懂还需麻烦老大。。。。。。。。。。。。

使用道具 举报

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

bottom

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

GMT+8, 2024-5-23 21:51

Powered by Discuz! X2 LicensedChrome插件扩展

© 2011-2012 交易开拓者 Inc.

回顶部