设为首页收藏本站

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

关于止盈问题 [复制链接]

Rank: 1

精华
0
UID
264292
积分
27
帖子
16
主题
8
阅读权限
10
注册时间
2018-4-10
最后登录
2020-11-2
跳转到指定楼层
1#
发表于 2018-10-24 14:58:37 |只看该作者 |倒序浏览
本帖最后由 a4585574 于 2018-10-24 15:05 编辑

请大神帮忙看看这段代码有什么问题,为何开空之后没有止盈,一直到开多反转时才平仓。

Params
Numeric jxz(60); //均线
Numeric zs(30);  //止损点
Numeric bs(3);   //止盈与止损倍数
Numeric kcb(0.1); //开仓比例

vars
Numeric TotalEquity; //总资金
Numeric Lots;        
Numeric bl;
Numeric zy;  
begin
zy=bs*zs;
bl=Average(C,jxz);
PlotNumeric("jx",bl);
TotalEquity = Portfolio_CurrentCapital()+Portfolio_UsedMargin;
Lots=Round((TotalEquity*kcb)/(Close*ContractUnit()*BigPointValue()*MarginRatio()),0);
If(c>bl)
{ buy(lots,c);
  If(MarketPosition==1)
  {If(c-AvgEntryPrice>=zy) Sell(CurrentContracts,c);
   If(AvgEntryPrice-c>=zs) Sell(CurrentContracts,c);}
  
          }
If(c<bl)
{ SellShort(lots,c);
  If(MarketPosition==-1)
  {If(AvgEntryPrice-c>=zy) BuyToCover(CurrentContracts,c);
   If(c-AvgEntryPrice>=zs) BuyToCover(CurrentContracts,c);}
   }
                  
end

Rank: 10Rank: 10Rank: 10

精华
3
UID
5
积分
26584
帖子
12686
主题
49
阅读权限
200
注册时间
2007-7-20
最后登录
2021-11-3
2#
发表于 2018-10-24 15:08:02 |只看该作者
本帖最后由 小米 于 2018-10-24 15:09 编辑
  1. If(c<bl)
  2. { SellShort(lots,c);
  3.   If(MarketPosition==-1)
  4.   {If(AvgEntryPrice-c>=zy) BuyToCover( abs(CurrentContracts),c);
  5.    If(c-AvgEntryPrice>=zs) BuyToCover(abs(CurrentContracts),c);}
  6.    }
复制代码
空头持仓时,currentcontracts的值是负数,而在buytocover的交易手数是不可为负的。

使用道具 举报

Rank: 1

精华
0
UID
264292
积分
27
帖子
16
主题
8
阅读权限
10
注册时间
2018-4-10
最后登录
2020-11-2
3#
发表于 2018-10-24 15:25:05 |只看该作者
小米 发表于 2018-10-24 15:08
空头持仓时,currentcontracts的值是负数,而在buytocover的交易手数是不可为负的。 ...

谢谢版主

使用道具 举报

Rank: 1

精华
0
UID
264292
积分
27
帖子
16
主题
8
阅读权限
10
注册时间
2018-4-10
最后登录
2020-11-2
4#
发表于 2018-10-26 13:59:43 |只看该作者
本帖最后由 a4585574 于 2018-10-26 14:16 编辑
小米 发表于 2018-10-24 15:08
空头持仓时,currentcontracts的值是负数,而在buytocover的交易手数是不可为负的。 ...


版主,能否麻烦您再帮忙看看这段代码为何开多仓后亏50点不止损
If(MarketPosition == 0 And exitdate!=Truedate(0))
        {       
                        If(High>= BuyPosition)
                        {        SellShort(Lots,Max(Open,BuyPosition)+i_offset);
                        Return;
                        }
                       
                        If(Low<= SellPosition)
                        {        Buy(Lots,Min(Open,SellPosition)-i_offset);
                        Return;
                        }
                               
        }
        If(MarketPosition == -1)
        {
                If(Low<= SellPosition)
                {       
                Buy(Lots,Min(Open,sellPosition)-i_offset);
                Return;}
       
        }
       
        If(MarketPosition == 1)
        {
                If(High>= BuyPosition )
                SellShort(Lots,Max(Open, BuyPosition)+i_offset);
                Return;}
        }
           
        If(MarketPosition == 1)
        {
          If( Low<=AvgEntryPrice-50)
          Sell(Lots,AvgEntryPrice-50);
         }
        If(MarketPosition == -1)
        {
          If(high>=avgentryprice+50)
          BuyToCover(Lots,avgentryprice+50);
          }
       

使用道具 举报

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

bottom

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

GMT+8, 2024-5-21 06:46

Powered by Discuz! X2 LicensedChrome插件扩展

© 2011-2012 交易开拓者 Inc.

回顶部