设为首页收藏本站

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

请大咖帮忙指正这段代码的错误 [复制链接]

Rank: 1

精华
0
UID
277935
积分
2
帖子
1
主题
1
阅读权限
10
注册时间
2019-4-16
最后登录
1970-1-1
跳转到指定楼层
1#
发表于 2019-4-19 08:31:59 |只看该作者 |倒序浏览
Params
        Numeric Length1(5);
        Numeric Length2(20);
        Numeric Lots(1);
        Numeric ATRLength(20);
        Numeric TrailStop(2);
Vars
        NumericSeries MA1;
        NumericSeries MA2;
        NumericSeries ATRValue;
        NumericSeries HiAfterEntry;
        NumericSeries LoAfterEntry;
        Numeric Stopline;
        BoolSeries bLongStoped(false);
        BoolSeries bShortStoped(false);
Begin
        ATRValue = AvgTrueRange(ATRLength);
        MA1 = AverageFC(Close,Length1);
        MA2 = AverageFC(Close,Length2);
        PlotNumeric("MA1",MA1);
        PlotNumeric("MA2",MA2);
        If (!bLongStoped and MarketPosition <> 1 and MA1[1] > MA2[1])       
        {
                        Buy(Lots,Open);
                        bShortStoped = false;
        }
        If (!bShortStoped and MarketPosition <> -1 and MA1[1] < MA2[1])
        {
                        SellShort(lots,Open);
                        SellShort(lots,Open);
        }
        If (bLongStoped and MarketPosition <> 1 and High >= HiAfterEntry)
        {
                        Buy(Lots, Max(Open, HiAfterEntry));
                        bShortStoped = false;
        }
        If (MarketPosition == 1 and BarsSinceEntry == 0) HiAfterEntry = High;
        If (MarketPosition == 1 and BarsSinceEntry >= 1)
                        HiAfterEntry = Max(HiAfterEntry,High);
        If (MarketPosition == -1 and BarsSinceEntry == 0) LoAfterEntry = Low;
        If (MarketPosition == -1 and BarsSinceEntry >= 1)
                        LoAfterEntry = Min(LoAfterEntry,Low);
        if (BarssinceEntry > 0 and MarketPosition == 1)
        {
                        StopLine = HiAfterEntry[1] - TrailStop * ATRValue[1];
                        If (Low <= StopLine)
                        {
                                        Sell(0, Min(Open, Stopline));
                                        bLongStoped = true;
                        }
        } Else If(BarsSinceEntry > 0 and MarketPosition == -1)
        {
                        StopLine = LoAfterEntry[1] + TrailStop * ATRValue[1];
                        If(High >= StopLine)
                        {
                                        BuyToCover(0, Max(Open, Stopline));
                                        bShortStoped = true;
                        }
        }
        End
                       
                                       
您需要登录后才可以回帖 登录 | 注册

bottom

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

GMT+8, 2024-4-24 23:52

Powered by Discuz! X2 LicensedChrome插件扩展

© 2011-2012 交易开拓者 Inc.

回顶部