金字塔决策交易系统

 找回密码
 

微信登录

微信扫一扫,快速登录

搜索
查看: 234|回复: 1

麻烦老师帮看一下!

[复制链接]

12

主题

18

帖子

18

积分

Rank: 1

等级: 新手上路

注册:
2023-12-11
曾用名:
发表于 2025-2-4 07:33 | 显示全部楼层 |阅读模式
麻烦老师帮我编译下列代码能到决策系统里正常运行  麻烦了

// 定义参数
Input: FastLength(5);      // 快速均线周期
Input: SlowLength(20);     // 慢速均线周期
Input: ATRLength(14);      // ATR周期
Input: ATRMultiplier(2);   // ATR倍数(用于止损和止盈)
Input: TradeStart(0900);   // 交易开始时间(9:00)
Input: TradeEnd(1500);     // 交易结束时间(15:00)

Vars: FastMA(0), SlowMA(0), ATRValue(0);
Vars: CurrentTime(0), EntryPrice(0);
Vars: StopLossPrice(0), TakeProfitPrice(0);

// 计算均线和ATR
FastMA = Average(Close, FastLength);
SlowMA = Average(Close, SlowLength);
ATRValue = ATR(ATRLength);

// 获取当前时间
CurrentTime = Time;

// 开仓条件
If CurrentTime >= TradeStart And CurrentTime <= TradeEnd Then Begin
    // 开多仓条件:快速均线上穿慢速均线,且波动性足够
    If FastMA > SlowMA And ATRValue > Average(ATRValue, 10) And MarketPosition = 0 Then Begin
        Buy 1 Contract;
        EntryPrice = Close;
        StopLossPrice = EntryPrice - ATRMultiplier * ATRValue; // 动态止损
        TakeProfitPrice = EntryPrice + ATRMultiplier * ATRValue; // 动态止盈
    End;

    // 开空仓条件:快速均线下穿慢速均线,且波动性足够
    If FastMA < SlowMA And ATRValue > Average(ATRValue, 10) And MarketPosition = 0 Then Begin
        SellShort 1 Contract;
        EntryPrice = Close;
        StopLossPrice = EntryPrice + ATRMultiplier * ATRValue; // 动态止损
        TakeProfitPrice = EntryPrice - ATRMultiplier * ATRValue; // 动态止盈
    End;
End;

// 止损条件
If MarketPosition > 0 And Close <= StopLossPrice Then Begin // 多仓止损
    Sell All Contracts;
End;
If MarketPosition < 0 And Close >= StopLossPrice Then Begin // 空仓止损
    BuyToCover All Contracts;
End;

// 止盈条件
If MarketPosition > 0 And Close >= TakeProfitPrice Then Begin // 多仓止盈
    Sell All Contracts;
End;
If MarketPosition < 0 And Close <= TakeProfitPrice Then Begin // 空仓止盈
    BuyToCover All Contracts;
End;

// 收盘前平仓
If CurrentTime >= TradeEnd And MarketPosition <> 0 Then Begin
    If MarketPosition > 0 Then Sell All Contracts; // 平多仓
    If MarketPosition < 0 Then BuyToCover All Contracts; // 平空仓
End;

回复

使用道具 举报

37

主题

9741

帖子

5万

积分

Rank: 8Rank: 8

等级: 超级版主

注册:
2021-5-18
曾用名:
wenarm
发表于 2025-2-4 10:24 | 显示全部楼层
这些都不是金字塔的语法结构。自然无法在金字塔中使用。建议你学习pel语法后从新编写
https://www.weistock.com/docs/PE ... %E5%85%A5%E9%97%A8/
金字塔提供一对一VIP专业技术指导服务,技术团队实时响应您的日常使用问题与策略编写。联系电话:021-20339086
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 微信登录

本版积分规则

手机版|小黑屋|上海金之塔信息技术有限公司 ( 沪ICP备13035422号 )

GMT+8, 2025-3-14 14:59 , Processed in 0.215693 second(s), 22 queries .

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

快速回复 返回顶部 返回列表