论坛全局菜单下方 -  icmarkets285X70论坛全局菜单下方 - 荔枝返现285X70论坛全局菜单下方 - ThinkMarkets285X70论坛全局菜单下方 - TICKMILL 285X70
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 18
前往
共 344 条
帖子
作者
回复/查看
最后发表
2025-12-02 08:18
17
230
2025-12-06 11:47
2025-12-06 02:46
2025-11-21 06:19
19
426
2025-11-29 13:43

#include <Trade\Trade.mqh>


//--- 输入参数

input int BreakEvenPoints = 20;    // 启动平保的点数

input int LockPoints = 0;          // 平保锁定利润点数


CTrade trade;


//+------------------------------------------------------------------+

//| Script program start function                                    |

//+------------------------------------------------------------------+

void OnStart()

 {

//---

  // 检查交易权限

  if(!TerminalInfoInteger(TERMINAL_TRADE_ALLOWED))

    {

     Alert("脚本检测到你没有允许自动交易,请先设置允许自动交易,再重新加载脚本");

     return;

    }


  int total_positions = PositionsTotal();

  if(total_positions == 0)

    {

     Print("没有持仓订单");

     return;

    }


  // 遍历所有持仓

  for(int i = total_positions - 1; i >= 0; i--)

    {

     ulong ticket = PositionGetTicket(i);

     if(ticket > 0)

       {

        string symbol = PositionGetString(POSITION_SYMBOL);

        long type = PositionGetInteger(POSITION_TYPE);

        double current_sl = PositionGetDouble(POSITION_SL);

        double open_price = PositionGetDouble(POSITION_PRICE_OPEN);


        // 获取当前价格

        double bid = SymbolInfoDouble(symbol, SYMBOL_BID);

        double ask = SymbolInfoDouble(symbol, SYMBOL_ASK);

        double point = SymbolInfoDouble(symbol, SYMBOL_POINT);

        int digits = (int)SymbolInfoInteger(symbol, SYMBOL_DIGITS);


        double new_sl = current_sl;

        double profit_points = 0;


        if(type == POSITION_TYPE_BUY)

          {

           profit_points = (bid - open_price) / point;

           // 平保逻辑:当盈利达到指定点数且当前无止损时,设置止损到开仓价+锁定利润

           if(current_sl == 0 && profit_points >= BreakEvenPoints)

             {

              new_sl = open_price + (LockPoints * point);

              new_sl = NormalizeDouble(new_sl, digits);

             }

          }

        else if(type == POSITION_TYPE_SELL)

          {

           profit_points = (open_price - ask) / point;

           // 平保逻辑:当盈利达到指定点数且当前无止损时,设置止损到开仓价-锁定利润

           if(current_sl == 0 && profit_points >= BreakEvenPoints)

             {

              new_sl = open_price - (LockPoints * point);

              new_sl = NormalizeDouble(new_sl, digits);

             }

          }


        // 如果需要修改止损

        if(new_sl != current_sl)

          {

           double current_tp = PositionGetDouble(POSITION_TP);

           if(trade.PositionModify(ticket, new_sl, current_tp))

             {

              Print("平保设置成功: ", symbol,

                    " 新止损: ", DoubleToString(new_sl, digits),

                    " 利润点数: ", DoubleToString(profit_points, 1));

             }

           else

             {

              Print("平保设置失败: ", symbol, " 错误代码: ", GetLastError());

             }

          }

       }

    }


  Print("自动平保脚本执行完成");

 }

//+------------------------------------------------------------------+

2025-12-03 15:00

#include <Trade\Trade.mqh>


//--- 输入参数

input int BreakEvenPoints = 20;    // 启动平保的点数

input int LockPoints = 0;          // 平保锁定利润点数


CTrade trade;


//+------------------------------------------------------------------+

//| Script program start function                                    |

//+------------------------------------------------------------------+

void OnStart()

 {

//---

  // 检查交易权限

  if(!TerminalInfoInteger(TERMINAL_TRADE_ALLOWED))

    {

     Alert("脚本检测到你没有允许自动交易,请先设置允许自动交易,再重新加载脚本");

     return;

    }


  int total_positions = PositionsTotal();

  if(total_positions == 0)

    {

     Print("没有持仓订单");

     return;

    }


  // 遍历所有持仓

  for(int i = total_positions - 1; i >= 0; i--)

    {

     ulong ticket = PositionGetTicket(i);

     if(ticket > 0)

       {

        string symbol = PositionGetString(POSITION_SYMBOL);

        long type = PositionGetInteger(POSITION_TYPE);

        double current_sl = PositionGetDouble(POSITION_SL);

        double open_price = PositionGetDouble(POSITION_PRICE_OPEN);


        // 获取当前价格

        double bid = SymbolInfoDouble(symbol, SYMBOL_BID);

        double ask = SymbolInfoDouble(symbol, SYMBOL_ASK);

        double point = SymbolInfoDouble(symbol, SYMBOL_POINT);

        int digits = (int)SymbolInfoInteger(symbol, SYMBOL_DIGITS);


        double new_sl = current_sl;

        double profit_points = 0;


        if(type == POSITION_TYPE_BUY)

          {

           profit_points = (bid - open_price) / point;

           // 平保逻辑:当盈利达到指定点数且当前无止损时,设置止损到开仓价+锁定利润

           if(current_sl == 0 && profit_points >= BreakEvenPoints)

             {

              new_sl = open_price + (LockPoints * point);

              new_sl = NormalizeDouble(new_sl, digits);

             }

          }

        else if(type == POSITION_TYPE_SELL)

          {

           profit_points = (open_price - ask) / point;

           // 平保逻辑:当盈利达到指定点数且当前无止损时,设置止损到开仓价-锁定利润

           if(current_sl == 0 && profit_points >= BreakEvenPoints)

             {

              new_sl = open_price - (LockPoints * point);

              new_sl = NormalizeDouble(new_sl, digits);

             }

          }


        // 如果需要修改止损

        if(new_sl != current_sl)

          {

           double current_tp = PositionGetDouble(POSITION_TP);

           if(trade.PositionModify(ticket, new_sl, current_tp))

             {

              Print("平保设置成功: ", symbol,

                    " 新止损: ", DoubleToString(new_sl, digits),

                    " 利润点数: ", DoubleToString(profit_points, 1));

             }

           else

             {

              Print("平保设置失败: ", symbol, " 错误代码: ", GetLastError());

             }

          }

       }

    }


  Print("自动平保脚本执行完成");

 }

//+------------------------------------------------------------------+

2025-12-03 14:59
2025-11-29 01:59
1神无月1 发表于 2025-11-22 04: 44

不用那么麻烦,直接调用系统自带的#include <Trade\Trade.mqh>模块,再自定义个名称CTrade trade;,然后用trade.PositionModify就能进行修改了,也就人工zhizhang会用这么古老且复杂的方案,还搞错

这是AI 写的,我不会,兄台能否帮忙写一个?

2025-11-29 01:48
2025-11-29 01:52
19
176
2025-12-01 00:56

正经话题,严肃点.......

2025-11-29 02:01
braun 发表于 2025-09-16 16: 48

这个人可能也是靠运气吧。因为他的回撤达到了50%。所有他不是有了一个很好的系统才翻了300倍的。只是运气。而本论坛就有一位高人,一个月把100刀做到一万刀。今年一月份以后就再也没有看到他上论坛了。

哪个帖子,想学习下呢。

2025-09-19 16:12
2025-07-19 13:33
31
894
2025-07-23 04:52
2025-06-26 05:36
13
702
2025-07-16 13:53
2025-07-16 09:38
2025-07-16 01:37
22
863
2025-08-05 00:48
2025-07-16 09:35
2025-07-15 01:21
12
421
2025-07-17 03:05
2025-07-15 04:42
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 18
前往
共 344 条

本站免责声明:

1、本站所有广告及宣传信息均与韬客无关,如需投资请依法自行决定是否投资、斟酌资金安全及交易亏损风险;

2、韬客是独立的、仅为投资者提供交流的平台,网友发布信息不代表韬客的观点与意思表示,所有因网友发布的信息而造成的任何法律后果、风险与责任,均与韬客无关;

3、金融交易存在极高法律风险,未必适合所有投资者,请不要轻信任何高额投资收益的诱导而贸然投资;投资保证金交易导致的损失可能超过您投入的资金和预期。请您考虑自身的投资经验及风险承担能力,进行合法、理性投资;

4、所有投资者的交易帐户应仅限本人使用,不应交由第三方操作,对于任何接受第三方喊单、操盘、理财等操作的投资和交易,由此导致的任何风险、亏损及责任由投资者个人自行承担;

5、韬客不隶属于任何券商平台,亦不受任何第三方控制,韬客不邀约客户投资任何保证金交易,不接触亦不涉及投资者的任何资金及账户信息,不代理任何交易操盘行为,不向客户推荐任何券商平台,亦不存在其他任何推荐行为。投资者应自行选择券商平台,券商平台的任何行为均与韬客无关。投资者注册及使用韬客即表示其接受和认可上述声明,并自行承担法律风险。

版权所有:韬客外汇论坛 www.talkfx.com 联络我们:[email protected]