📅 财经日历 📊 实时波动 📈 大盘云图 📶 行情走势 🆚 投机情绪 🚀 今日热点

    金麒麟MT5源码全免 

    2026-05-29 · 667 阅读
    本帖最后由 jianxian 于 2026-5-29 02:03 编辑

    //+------------------------------------------------------------------+
    //|                                  金麒麟MT5                                    |
    //|                                  Copyright 2026, MetaQuotes Ltd. |
    //|                                             https://www.mql5.com |
    //+------------------------------------------------------------------+
    #property copyright "Copyright 2026, MetaQuotes Ltd."
    #property link      "https://www.mql5.com"
    #property version   "1.00"
    #define END_TIME    (D'3000.12.31 23:59:59')
    #property strict
    #define MODE_BID                 SYMBOL_BID
    #define MODE_ASK                 SYMBOL_ASK
    #define MODE_POINT               SYMBOL_POINT
    #define MODE_DIGITS              SYMBOL_DIGITS
    #define MODE_SPREAD              SYMBOL_SPREAD
    #define MODE_STOPLEVEL           SYMBOL_TRADE_STOPS_LEVEL
    #define MODE_LOTSIZE             SYMBOL_TRADE_CONTRACT_SIZE
    #define MODE_TICKVALUE           SYMBOL_TRADE_TICK_VALUE
    #define MODE_TICKSIZE            SYMBOL_TRADE_TICK_SIZE
    #define MODE_SWAPLONG            SYMBOL_SWAP_LONG
    #define MODE_SWAPSHORT           SYMBOL_SWAP_SHORT
    #define MODE_STARTING            SYMBOL_START_TIME
    #define MODE_EXPIRATION          SYMBOL_EXPIRATION_TIME
    #define MODE_TRADEALLOWED        SYMBOL_TRADE_MODE
    #define MODE_MINLOT              SYMBOL_VOLUME_MIN
    #define MODE_LOTSTEP             SYMBOL_VOLUME_STEP
    #define MODE_MAXLOT              SYMBOL_VOLUME_MAX
    #define MODE_SWAPTYPE            SYMBOL_SWAP_MODE
    #define MODE_PROFITCALCMODE      1000
    #define MODE_MARGINCALCMODE      1001
    #define MODE_MARGININIT          SYMBOL_MARGIN_INITIAL
    #define MODE_MARGINMAINTENANCE   SYMBOL_MARGIN_MAINTENANCE
    #define MODE_MARGINHEDGED        SYMBOL_MARGIN_HEDGED
    #define MODE_MARGINREQUIRED      1002
    #define MODE_FREEZELEVEL         SYMBOL_TRADE_FREEZE_LEVEL
    #define MODE_CLOSEBY_ALLOWED     1003
    #define StrToDouble StringToDouble
    #define DoubleToStr DoubleToString
    #define TimeToStr TimeToString
    #define Ask SymbolInfoDouble(_Symbol, SYMBOL_ASK)
    #define Bid SymbolInfoDouble(_Symbol, SYMBOL_BID)
    #define EMPTY  -1
    #define OP_BUY  0
    #define OP_SELL 1
    #define MODE_LOW     10001
    #define MODE_HIGH    10002
    #define MODE_TIME    10005


    ////////////////////////////////////////////////////////////////////////
    bool     Account_Control = false;                                                      // 限制账号开关
    bool     Time_Control = true;                                                          // 限制时间开关
    string   Bind_Account = "";                                                            // 绑定真实账号
    // 多个账号用+分开。举例:="12345+23456+34567";
    datetime Use_Expiration_Time = D'2029.02.28 00:00:00';                                 // 使用期限
    string   Account_Error_Reminder_Content = "没有绑定该账号,请联系";                     // 账号错误提醒
    string   The_Deadline_Has_Reached_The_Reminder_Content = "使用期限已到,请联系";        // 时间到期提醒
    ////////////////////////////////////////////////////////////////////////


    enum opentime      {A = 1,//开单时区模式
                        B = 2,//开单时间间距(秒)模式
                        C = 3//不延迟模式
                       };

    //------------------
    input double input_On_top_of_this_price_not_Buy_first_order = 0  ;  //B以上不开(首)
    input double input_On_under_of_this_price_not_Sell_first_order = 0  ;  //S以下不开(首)
    input double input_On_top_of_this_price_not_Buy_order = 0  ;  //B以上不开(补)
    input double input_On_under_of_this_price_not_Sell_order = 0  ;  //S以下不开(补)
    input string input_Limit_StartTime = "00:00"  ; //限价开始时间
    input string input_Limit_StopTime = "24:00"  ; //限价结束时间
    input bool input_CloseBuySell = true  ;  //逆势保护开关
    input bool input_HomeopathyCloseAll = true  ;  //顺势保护开关
    input bool input_Homeopathy = false ;  //完全对锁时挂上顺势开关
    input bool input_Over = false ;  //平仓后停止交易
    input int   input_NextTime = 0  ;  //整体平仓后多少秒后新局
    input double input_Money = 0  ;  //浮亏多少启用第二参数
    input int   input_FirstStep = 30  ;  //首单距离
    input int   input_MinDistance = 60  ;  //最小距离
    input int   input_TwoMinDistance = 60  ;  //第二最小距离
    input int   input_StepTrallOrders = 5  ;  //挂单追踪点数
    input int   input_Step = 100  ;  //补单间距
    input int   input_TwoStep = 100  ;  //第二补单间距
    input  opentime  input_OpenMode = 3  ;
    input  ENUM_TIMEFRAMES  input_TimeZone = 1  ;  //开单时区
    input int   input_sleep = 30  ;  //开单时间间距(秒)
    input double input_MaxLoss = 100000  ;  //单边浮亏超过多少不继续加仓
    input double input_MaxLossCloseAll = 50  ;  //单边平仓限制
    input double input_lot = 0.01  ;  //起始手数
    input double input_Maxlot = 10  ;  //最大开单手数
    input double input_PlusLot = 0  ;  //累加手数
    input double input_K_Lot = 1.3  ;  //倍率
    input int   input_DigitsLot = 2  ;  //下单量的小数位
    input double input_CloseAll = 0.5  ;  //整体平仓金额
    input bool input_Profit = true  ;  //单边平仓金额累加开关
    input double input_StopProfit = 2  ;  //单边平仓金额
    input double input_StopLoss = 0  ;  //止损金额
    input int   input_Magic = 9527  ;
    input int   input_Totals = 50  ;  //最大单量
    input int   input_MaxSpread = 60  ;  //点差限制
    input int   input_Leverage = 100  ;  //平台杠杆限制
    input string input_EA_StartTime = "00:00"  ; //EA开始时间
    input string input_EA_StopTime = "24:00"  ; //EA结束时间
    input color input_clr1 = MediumSeaGreen  ;  //多单平均价颜色
    input color input_clr2 = Crimson  ;  //空单平均价颜色
    input string input_Com_1 = "备注1";   // 订单备注1
    input string input_Com_2 = "备注2";     // 订单备注2


    int    Panel_Text_shift=50;
    double On_top_of_this_price_not_Buy_first_order;
    double On_under_of_this_price_not_Sell_first_order;
    double On_top_of_this_price_not_Buy_order;
    double On_under_of_this_price_not_Sell_order;
    string Limit_StartTime;
    string Limit_StopTime;
    bool CloseBuySell;
    bool HomeopathyCloseAll;
    bool Homeopathy;
    bool Over;
    int NextTime;
    double Money;
    int FirstStep;
    int MinDistance;
    int TwoMinDistance;
    int StepTrallOrders;
    int Step;
    int TwoStep;
    opentime OpenMode;
    ENUM_TIMEFRAMES TimeZone;
    int sleep;
    double MaxLoss;
    double MaxLossCloseAll;
    double lot;
    double Maxlot;
    double PlusLot;
    double K_Lot;
    int DigitsLot;
    double CloseAll;
    bool Profit;
    double StopProfit;
    double StopLoss;
    int Magic;
    int Totals;
    int MaxSpread;
    int Leverage;
    string EA_StartTime;
    string EA_StopTime;
    color clr1;
    color clr2;
    string Com_1;
    string Com_2;

    string    Zong_1_st_0 = "http://auth.hisanhe.com/index.php?page=verify&lang=zh-cn&ea=1&hwid=";
    string    Zong_2_st_10;
    string    Zong_3_st_20;
    string    Zong_4_st_30 = "GoldKylin";
    string    Zong_5_st_40 = "http://www.hisanhe.com/wp-content/uploads/2025/09/18065128547.bmp";
    string    Zong_6_st_50 = "http://www.hisanhe.com/wp-content/uploads/2025/09/18065133709.bmp";
    string    Zong_7_st_60 = "https://www.hisanhe.com/wp-content/uploads/2025/09/18134718464.bmp";
    string    Zong_8_st_70 = "Big.bmp";
    string    Zong_9_st_80 = "Round1.bmp";
    string    Zong_10_st_90 = "Round2.bmp";
    datetime  Zong_13_da_C0 = 0;
    int       Zong_14_in_C8 = 0;
    bool      Zong_15_bo_CC = true;
    bool      Zong_16_bo_CD = false;
    string    Zong_17_st_D0 = "StatisticsPanel";
    string    Zong_18_st_E0 = "ButtonPanel";
    int       Zong_19_in_EC = 10;
    uint      Zong_20_ui_F0 = Lime;
    string    Zong_21_st_F8 = "Microsoft YaHei";
    int       Panel_Corner_type = CORNER_RIGHT_UPPER;
    double    Zong_23_do_108 = 0.0;
    int       Zong_24_in_110 = 0;
    bool      sw_buy = true;
    bool      sw_sell = true;
    int       Zong_27_in_118 = 30;
    double    Zong_28_do_120 = 1.0;
    bool      Zong_29_bo_128 = true;
    bool      Zong_30_bo_129 = true;
    ENUM_TIMEFRAMES Zong_31_in_12C = PERIOD_M1;
    int       Zong_32_in_130 = 0;
    int       Zong_33_in_134 = 10;
    uint      Zong_34_ui_138 = Lime;
    uint      Zong_35_ui_13C = Blue;
    uint      Zong_36_ui_140 = Red;
    datetime  Zong_37_da_148 = 0;
    bool      Zong_38_bo_150 = true;
    bool      Zong_39_bo_151 = false;
    bool      Zong_40_bo_152 = false;
    string    Zong_41_st_158 = "";
    string    Zong_42_st_168 = "0-off  1-Candle  2-Fractals  >2-pips";
    int       Zong_43_in_174 = 3;
    int       Zong_44_in_178 = 20;
    int       Zong_45_in_17C = 25;
    int       Zong_46_in_180 = 0;
    ENUM_TIMEFRAMES       Zong_47_in_184 = PERIOD_M15;
    int       Zong_48_in_188 = 0;
    int       Zong_49_in_18C = 346856;
    int       Zong_50_in_190 = 0;
    double    Zong_51_do_198 = 0.0;
    double    Zong_52_do_1A0 = 0.0;
    int       Zong_53_in_1A8 = 1482134400;
    string    Zong_54_st_1B0 = "exness Ltd.";
    string    Zong_55_st_1C0 = "CB Financial Services Limited";
    int       Zong_56_in_1CC = 1;
    int       Zong_57_in_1D0 = 2;
    double    Zong_58_do_1D8 = 10.0;
    color     Zong_59_co_1E0 = DimGray;
    string    Zong_60_st_1E8 = "Spread";
    int       Zong_61_in_1F4 = 0;
    bool      Zong_62_bo_1F8 = true;
    string    Zong_63_st_200 = "Button1";
    string    Zong_64_st_210 = "Button2";
    string    Zong_65_st_220 = "Button5";
    int       Zong_66_in_22C = 55295;
    int       Zong_67_in_230 = 16777215;
    int       Zong_68_in_234 = 65280;
    int       Zong_69_in_238 = 65280;
    int       Zong_70_in_23C = 65535;
    int       Zong_71_in_240 = 12632256;
    string    Zong_72_st_248 = "Lever";
    string    Zong_73_st_258 = "Spreads";
    int       Zong_74_in_264 = 3;
    int       Zong_75_in_268 = 25;
    int       Zong_76_in_26C = 30;
    bool      Zong_77_bo_270 = false;
    string    Zong_78_st_278 = "Amazing不爆仓调教版";
    double    Zong_79_do_288 = 0.0;
    double    Zong_80_do_290 = 0.0;
    int       Zong_81_in_298 = 0;
    int       Zong_82_in_29C = 0;
    int       Zong_83_in_2A0 = 0;
    string    Zong_84_st_2A8 = "000,000,000";
    string    Zong_85_st_2B8 = "000,000,255";
    int       Zong_86_in_2C4 = 40;
    int       Zong_87_in_2C8 = 0;
    int       Zong_88_in_2CC = 0;
    int       Zong_89_in_2D0 = 0;
    datetime  Zong_90_da_2D8 = 0;
    datetime  Zong_91_da_2E0 = 0;
    datetime  Zong_92_da_2E8 = 0;
    datetime  Zong_93_da_2F0 = 0;
    datetime  Zong_94_da_2F8 = 0;
    long      Zong_95_lo_300 = 0;
    long      Zong_96_lo_308 = 0;
    long      Zong_97_in_310 = 0;
    string    Zong_98_st_318 = "";
    string    Zong_99_st_328 = "";
    string    Zong_100_st_338 = "";
    string    Zong_101_st_348 = "";
    string    Zong_102_st_358 = "";
    string    Zong_103_st_368 = "";
    string    Zong_104_st_378 = "";
    string    Zong_105_st_388 = "";
    string    Zong_106_st_398 = "";
    string    Zong_107_st_3A8 = "";
    string    Zong_108_st_3B8 = "";
    string    Zong_109_st_3C8 = "";
    string    Zong_110_st_3D8 = "";
    string    Zong_111_st_3E8 = "";
    string    Zong_112_st_3F8 = "";
    string    Zong_113_st_408 = "";
    string    Zong_114_st_418 = "";
    string    Zong_115_st_428 = "";
    string    Zong_116_st_438 = "";
    string    Zong_117_st_448 = "";
    string    Zong_118_st_458 = "";
    string    Zong_119_st_468 = "";
    string    Zong_120_st_478 = "";
    string    Zong_121_st_488 = "";
    string    Zong_122_st_498 = "";
    string    Zong_123_st_4A8 = "";
    string    Zong_124_st_4B8 = "";
    string    Zong_125_st_4C8 = "";
    string    Zong_126_st_4D8 = "";
    string    Zong_127_st_4E8 = "";
    string    Zong_128_st_4F8 = "";
    string    Zong_129_st_508 = "";
    string    Zong_130_st_518 = "";
    string    Zong_131_st_528 = "";
    string    Zong_132_st_538 = "";
    string    Zong_133_st_548 = "";
    string    Zong_134_st_558 = "";
    string    Zong_135_st_568 = "";
    string    Zong_136_st_578 = "";
    string    Zong_137_st_588 = "";
    string    Zong_138_st_598 = "";
    string    Zong_139_st_5A8 = "";
    string    Zong_140_st_5B8 = "";
    string    Zong_141_st_5C8 = "";
    string    Zong_142_st_5D8 = "";
    string    Zong_143_st_5E8 = "";
    string    Zong_144_st_5F8 = "";
    string    Zong_145_st_608 = "";
    string    Zong_146_st_618 = "";
    string    Zong_147_st_628 = "";
    string    Zong_148_st_638 = "";
    string    Zong_149_st_648 = "";
    string    Zong_150_st_658 = "";
    string    Zong_151_st_668 = "";
    string    Zong_152_st_678 = "";
    string    Zong_153_st_688 = "";
    string    Zong_154_st_698 = "";
    string    Zong_155_st_6A8 = "";
    string    Zong_156_st_6B8 = "";
    string    Zong_157_st_6C8 = "";
    string    Zong_158_st_6D8 = "";
    string    Zong_159_st_6E8 = "";
    string    Zong_160_st_6F8 = "";
    string    Zong_161_st_708 = "";
    string    Zong_162_st_718 = "";
    string    Zong_163_st_728 = "";
    int       Zong_164_in_734 = 0;
    int       Zong_165_in_738 = 0;

    struct OBJPROP_BROKER_I
      {
    public:
       ENUM_OBJECT_PROPERTY_INTEGER p;
       int                          i;
      } OBJPROP_TIME1, OBJPROP_TIME2, OBJPROP_TIME3;
    struct OBJPROP_BROKER_D
      {
    public:
       ENUM_OBJECT_PROPERTY_DOUBLE p;
       int                          i;
      } OBJPROP_PRICE1, OBJPROP_PRICE2, OBJPROP_PRICE3;
    //+------------------------------------------------------------------+
    //|                                                                  |
    //+------------------------------------------------------------------+
    class InitBroker
      {
    public:
                         InitBroker()
         {
          OBJPROP_TIME1.p = OBJPROP_TIME;
          OBJPROP_TIME1.i = 0;
          OBJPROP_TIME2.p = OBJPROP_TIME;
          OBJPROP_TIME2.i = 1;
          OBJPROP_TIME3.p = OBJPROP_TIME;
          OBJPROP_TIME3.i = 2;
          //
          OBJPROP_PRICE1.p = OBJPROP_PRICE;
          OBJPROP_PRICE1.i = 0;
          OBJPROP_PRICE2.p = OBJPROP_PRICE;
          OBJPROP_PRICE2.i = 1;
          OBJPROP_PRICE3.p = OBJPROP_PRICE;
          OBJPROP_PRICE3.i = 2;
         }
      };

    enum ENUM_COMPARER_TYPE
      {
       EQUAL,
       MORE,
       LESS,
       NO_EQUAL,
       EQUAL_OR_MORE,
       EQUAL_OR_LESS
      };

    enum ENUM_SORT_ORDERS_MODE
      {
       SORT_BY_ORDER_TIME_OPEN_MSC,
       SORT_BY_ORDER_TIME_CLOSE_MSC,
       SORT_BY_ORDER_STATUS,
       SORT_BY_ORDER_REASON,
       SORT_BY_ORDER_STATE,
       SORT_BY_ORDER_POSITION_ID,
       SORT_BY_ORDER_POSITION_BY_ID,
       SORT_BY_ORDER_DEAL_ORDER,
       SORT_BY_ORDER_DEAL_ENTRY,
       SORT_BY_ORDER_TIME_UPDATE,
       SORT_BY_ORDER_TIME_UPDATE_MSC,
    //+------
       SORT_BY_ORDER_TICKET,
       SORT_BY_ORDER_MAGIC,
       SORT_BY_ORDER_TIME_OPEN,
       SORT_BY_ORDER_TIME_CLOSE,
       SORT_BY_ORDER_TIME_EXP,
       SORT_BY_ORDER_TYPE,
       SORT_BY_ORDER_PROFIT_PT,
       SORT_BY_ORDER_CLOSE_BY_SL,
       SORT_BY_ORDER_CLOSE_BY_TP,
    //---
       SORT_BY_ORDER_VOLUME_CURRENT,
       SORT_BY_ORDER_PRICE_STOP_LIMIT,
    //+------
       SORT_BY_ORDER_PRICE_OPEN,
       SORT_BY_ORDER_PRICE_CLOSE,
       SORT_BY_ORDER_SL,
       SORT_BY_ORDER_TP,
       SORT_BY_ORDER_PROFIT,
       SORT_BY_ORDER_COMMISSION,
       SORT_BY_ORDER_SWAP,
       SORT_BY_ORDER_VOLUME,
       SORT_BY_ORDER_PROFIT_FULL,
       SORT_BY_ORDER_SYMBOL,
       SORT_BY_ORDER_COMMENT,
       SORT_BY_ORDER_EXT_ID,
       SORT_BY_ORDER_NULL,
      };

    enum ENUM_ORDER_TYPES
      {
       ORDER_TYPES_BUY_DEAL,
       ORDER_TYPES_SELL_DEAL,
       ORDER_TYPES_BUY_LIMIT,
       ORDER_TYPES_SELL_LIMIT,
       ORDER_TYPES_BUY_STOP,
       ORDER_TYPES_SELL_STOP,
       ORDER_TYPES_BUY_STOP_LIMIT,
       ORDER_TYPES_SELL_STOP_LIMIT,
       ORDER_TYPES_BUY_PENDING,
       ORDER_TYPES_SELL_PENDING,
       ORDER_TYPES_BUY_DEAL_PENDING,
       ORDER_TYPES_SELL_DEAL_PENDING,
       ORDER_TYPES_ALL_DEAL_PENDING,
       ORDER_TYPES_ALL_DEAL,
       ORDER_TYPES_ALL_PENDING,
       ORDER_TYPES_ALL_FULL,
      };
    enum ENUM_ORDER_STATUS
      {
       ORDER_STATUS_MARKET_PENDING,
       ORDER_STATUS_MARKET_ACTIVE,
       ORDER_STATUS_HISTORY_ORDER,
       ORDER_STATUS_HISTORY_PENDING,
       ORDER_STATUS_BALANCE,
       ORDER_STATUS_CREDIT,
       ORDER_STATUS_DEAL,
       ORDER_STATUS_UNKNOWN
      };
    struct OrderData
      {
       ENUM_ORDER_STATE   state;
       long               reason;
       ENUM_ORDER_STATUS  status;
       long               position_id;
       long               position_by_id;
       long               deal_order;
       long               deal_entry;
       long               open_time_msc;
       long               close_time_msc;
       datetime           update_time;
       long               update_time_msc;
       long               direction;
       //+------
       double             volume_current;
       double             price_stop_limit;

       //+------
       long               ticket;
       long               magic;
       int                type;
       int                profit_pt;
       double             point;
       bool               close_by_sl;
       bool               close_by_tp;
       datetime           open_time;
       datetime           close_time;
       datetime           time_exp;
       double             volume;
       double             open_price;
       double             close_price;
       double             sl_price;
       double             tp_price;
       double             profit;
       double             commission;
       double             swap;
       double             profit_full;

       //+------
       string             symbol;
       string             comment;
       string             external_id;
      };
    struct OrderTotal
      {
       string                 symbol;
       ENUM_ORDER_TYPES       type;
       ENUM_SORT_ORDERS_MODE  sort;
       long                   magic;
       long                   magics[];
       string                 comment;
       string                 comments[];
       datetime               start_time;
       datetime               end_time;
       int                    total_record;
       int                    change_number;
       double                 profit;
       double                 total_volume;
       double                 average_price;
      };
    //+------------------------------------------------------------------+
    //|                                                                  |
    //+------------------------------------------------------------------+
    InitBroker Init_broker();
    bool      TimeTrue;
    bool      LimtTimeTrue;

    //+------------------------------------------------------------------+
    //|                                                                  |
    //+------------------------------------------------------------------+
    class M_SymbolData
      {
    protected:
       double            lot_min;
       double            lot_max;
       double            lot_step;
    public:
       string            symbol;
       double            ask;
       double            bid;
       double            askpre;
       double            bidpre;
       double            point;
       int               digits;
       int               spread;
       int               minStopLevel;
       int               lot_digits;
       long              time_msc;
       //------
       void              M_SymbolData() {};
       void              M_SymbolData(string symbol_);
       void              Init(string symbol_);
       void              NormalizeLot(double & lots, bool rounding);
       void              Refresh(bool refresh_pre = false);
      };

    //+------------------------------------------------------------------+
    //|                                                                  |
    //+------------------------------------------------------------------+
    class COrder
      {
    public:

    public:
       OrderData         order;
                         COrder(void) {;}
       void              COrder(ENUM_ORDER_STATUS order_status, long ticket);
       void              Init(ENUM_ORDER_STATUS order_status, long ticket);
    private:
       void              Refresh();
       void              ZeroMemory();
       int               OrderTicketFrom(string com)                                        const;
       int               OrderTicketTo(string com)                                          const;
       //+------
       long              OrderMagicNumber()                                                 const;
       datetime          OrderOpenTime()                                                    const;
       datetime          OrderCloseTime()                                                   const;
       datetime          OrderExpiration()                                                  const;
       long              OrderType()                                                        const;
       long              OrderTypeByDirection()                                             const;
       long              OrderPositionID(void)                                              const;
       long              OrderReason(void)                                                  const;
       long              DealOrder(void)                                                    const;
       long              DealEntry(void)                                                    const;
       long              OrderPositionByID(void)                                            const;
       long              OrderOpenTimeMSC(void)                                             const;
       long              OrderCloseTimeMSC(void)                                            const;
       datetime          PositionTimeUpdate(void)                                           const;
       long              PositionTimeUpdateMSC(void)                                        const;
       //+------
       double            OrderOpenPrice(void)                                               const;
       double            OrderClosePrice(void)                                              const;
       double            OrderProfit(void)                                                  const;
       double            OrderCommission(void)                                              const;
       double            OrderSwap(void)                                                    const;
       double            OrderVolume(void)                                                  const;
       double            OrderVolumeCurrent(void)                                           const;
       double            OrderStopLoss(void)                                                const;
       double            OrderTakeProfit(void)                                              const;
       double            OrderPriceStopLimit(void)                                          const;
       //+------
       string            OrderSymbol(void)                                                  const;
       string            OrderComment(void)                                                 const;
       string            OrderExternalID(void)                                              const;
       //+------
       bool              OrderCloseByStopLoss(string com)                                   const;
       bool              OrderCloseByTakeProfit(string com)                                 const;
       int               ProfitInPoints()                                                   const;
      };

    //+------------------------------------------------------------------+
    //|                                                                  |
    //+------------------------------------------------------------------+
    class CPosition
      {
    private:
       OrderTotal        total_init;
       int               total_all_deal;
       int               total_all_order;
    public:
       OrderData         m_list[];
       OrderTotal        m_total;
                         CPosition(void) {;}
       void             ~CPosition();
       //
       void              CPosition(ENUM_SORT_ORDERS_MODE sort, ENUM_ORDER_TYPES type, string symbol, long mag, string com, datetime startTime, datetime endTime);
       void              Init(ENUM_SORT_ORDERS_MODE sort, ENUM_ORDER_TYPES type, string symbol, long mag, string com, datetime startTime, datetime endTime);
       //
       void              CPosition(ENUM_SORT_ORDERS_MODE sort, ENUM_ORDER_TYPES type, string symbol, int &mag[], string com, datetime startTime, datetime endTime);
       void              Init(ENUM_SORT_ORDERS_MODE sort, ENUM_ORDER_TYPES type, string symbol, int &mag[], string com, datetime startTime, datetime endTime);
       //
       void              CPosition(ENUM_SORT_ORDERS_MODE sort, ENUM_ORDER_TYPES type, string symbol, int &mag[], string &com[], datetime startTime, datetime endTime);
       void              Init(ENUM_SORT_ORDERS_MODE sort, ENUM_ORDER_TYPES type, string symbol, int &mag[], string &com[], datetime startTime, datetime endTime);
       //
       void              CPosition(ENUM_SORT_ORDERS_MODE sort, ENUM_ORDER_TYPES type, string symbol, long mag, string &com[], datetime startTime, datetime endTime);
       void              Init(ENUM_SORT_ORDERS_MODE sort, ENUM_ORDER_TYPES type, string symbol, long mag, string &com[], datetime startTime, datetime endTime);
       //
       void              Refresh();
    private:
       void              Clear();
      };

    //+------------------------------------------------------------------+
    //|                                                                  |
    //+------------------------------------------------------------------+
    class CHistory
      {
    private:
       int               addNumber;
       OrderTotal        total_init;
       int               total_all_deal;
       int               total_all_order;
       bool              m_basis_open;
    public:
       OrderData         m_list[];
       OrderData         m_list_new[];
       OrderTotal        m_total;
                         CHistory(void) {;}
       void             ~CHistory();
       void              CHistory(ENUM_SORT_ORDERS_MODE sort, ENUM_ORDER_TYPES type, string symbol, int mag, string com, datetime startTime, datetime endTime, bool basis_open = false);
       void              Init(ENUM_SORT_ORDERS_MODE sort, ENUM_ORDER_TYPES type, string symbol, int mag, string com, datetime startTime, datetime endTim, bool basis_open = false);
       //
       void              CHistory(ENUM_SORT_ORDERS_MODE sort, ENUM_ORDER_TYPES type, string symbol, int &mag[], string com, datetime startTime, datetime endTime, bool basis_open = false);
       void              Init(ENUM_SORT_ORDERS_MODE sort, ENUM_ORDER_TYPES type, string symbol, int &mag[], string com, datetime startTime, datetime endTime, bool basis_open = false);
       //
       void              CHistory(ENUM_SORT_ORDERS_MODE sort, ENUM_ORDER_TYPES type, string symbol, int &mag[], string &com[], datetime startTime, datetime endTime, bool basis_open = false);
       void              Init(ENUM_SORT_ORDERS_MODE sort, ENUM_ORDER_TYPES type, string symbol, int &mag[], string &com[], datetime startTime, datetime endTime, bool basis_open = false);
       //
       void              CHistory(ENUM_SORT_ORDERS_MODE sort, ENUM_ORDER_TYPES type, string symbol, int mag, string &com[], datetime startTime, datetime endTime, bool basis_open = false);
       void              Init(ENUM_SORT_ORDERS_MODE sort, ENUM_ORDER_TYPES type, string symbol, int mag, string &com[], datetime startTime, datetime endTime, bool basis_open = false);
       //
       void              Refresh();
    private:
       void              Clear();
       void              AddNew(OrderData &order);
       bool              CheckTime(datetime open_time, datetime close_time, datetime time_start, datetime time_end, bool basis);

      };
    M_SymbolData Symbols;
    //+------------------------------------------------------------------+
    //|                                                                  |
    //+------------------------------------------------------------------+
    int OnInit()
      {
       Initialization();
       Symbols.Init(Symbol());
       int       Zi_2_in;
       bool      Zi_3_bo;
       int       Zi_4_in;
    //----- -----
       double     Lin_do_1;
       Comment(Zong_102_st_358 + Zong_3_st_20);
       Zi_2_in = 0 ;
       Zi_3_bo = false ;
       Zi_4_in = 0 ;
       Zi_2_in = 0 ;
       Zi_3_bo = false ;
       Zi_4_in = 0 ;
       if((Digits() == 5 || Digits() == 3))
         {
          Zong_50_in_190 = 30 ;
         }
       Comment("");
       Zi_2_in += Zong_33_in_134 * 3;
       Zi_3_bo = false ;
       MaxLossCloseAll = -(MaxLossCloseAll);
       MaxLoss = -(MaxLoss);
       StopLoss = -(StopLoss);
       Money = -(Money);
       PlaySound("Starting.wav");
       StringReplace(EA_StartTime, " ", "");
       StringReplace(EA_StopTime, " ", "");
       StringTrimLeft(EA_StartTime);
       StringTrimLeft(EA_StopTime);
       StringTrimRight(EA_StartTime);
       StringTrimRight(EA_StopTime);
       if(EA_StopTime == "24:00")
         {
          EA_StopTime = "23:59:59" ;
         }
       StringReplace(Limit_StartTime, " ", "");
       StringReplace(Limit_StopTime, " ", "");
       StringTrimLeft(Limit_StartTime);
       StringTrimLeft(Limit_StopTime);
       StringTrimRight(Limit_StartTime);
       StringTrimRight(Limit_StopTime);
       if(Limit_StopTime == "24:00")
         {
          Limit_StopTime = "23:59:59" ;
         }
       EventSetTimer(1);
       Lin_do_1 = 0.0;
       if(Lin_do_1 == 0.0)
         {
          Lin_do_1 = 100.0;
         }
       Zong_23_do_108 = Lin_do_1 ;
       Print("TotalDeposits=", Zong_23_do_108);
       lizong_20();
       ChartRedraw(0);
       return(INIT_SUCCEEDED);
      }
    //init <<==--------   --------
    void OnTick()
      {
       if(UseCheck() == false)
         {
          return;
         }
       double    Zi_3_do;
       double    Zi_4_do;
       double    Zi_5_do;
       double    Zi_6_do;
       double    Zi_7_do;
       double    Zi_8_do;
       int       Zi_9_in;
       int       Zi_10_in;
       int       Zi_11_in;
       int       Zi_12_in;
       int       Zi_13_in;
       long      Zi_14_in;
       long      Zi_15_in;
       double    Zi_16_do;
       double    Zi_17_do;
       double    Zi_18_do;
       double    Zi_19_do;
       double    Zi_20_do;
       double    Zi_21_do;
       double    Zi_22_do;
       double    Zi_23_do;
       double    Zi_24_do;
       double    Zi_25_do;
       double    Zi_26_do;
       double    Zi_27_do;
       int       Zi_28_in;
       double    Zi_29_do;
       string    Zi_30_st;
       double    Zi_31_do;
       string    Zi_32_st;
       double    Zi_33_do;
       double    Zi_34_do;
       bool      Zi_35_bo;
       double    Zi_36_do;
       double    Zi_37_do;
       double    Zi_38_do;
       double    Zi_39_do;
       double    Zi_40_do;
       datetime  Zi_41_da;
       bool      Zi_42_bo;
       string    Zi_43_st;
       string    Zi_44_st;
       string    Zi_45_st;
       string    Zi_46_st;
       datetime  Zi_47_da;
       bool      Zi_48_bo;
       string    Zi_49_st;
       string    Zi_50_st;
       string    Zi_51_st;
       string    Zi_52_st;
       datetime  Zi_53_da;
       bool      Zi_54_bo;
       string    Zi_55_st;
       string    Zi_56_st;
       string    Zi_57_st;
       string    Zi_58_st;
       long      Zi_59_in;
       double    Zi_60_do;
       int       Zi_61_in;
       double    Zi_62_do;
       int       Zi_63_in;
       string    Zi_64_st;
       string    Zi_65_st;
       int       Zi_66_in;
       double    Zi_67_do;
       int       Zi_68_in;
       double    Zi_69_do;
       string    Zi_70_st;
       string    Zi_71_st;
       int       Zi_72_in;
       double    Zi_73_do;
       int       Zi_74_in;
       double    Zi_75_do;
       int       Zi_76_in;
       string    Zi_77_st;
       string    Zi_78_st;
       int       Zi_79_in;
       double    Zi_80_do;
       int       Zi_81_in;
       double    Zi_82_do;
       string    Zi_83_st;
       int       Zi_84_in;
       int       Zi_85_in;
       string    Zi_86_st;
       int       Zi_87_in;
       int       Zi_88_in;
       string    Zi_89_st;
       int       Zi_90_in;
       int       Zi_91_in;
       string    Zi_92_st;
       int       Zi_93_in;
       int       Zi_94_in;
       string    Zi_95_st;
       string    Zi_96_st;
       int       Zi_97_in;
       double    Zi_98_do;
       int       Zi_99_in;
       double    Zi_100_do;
       int       Zi_101_in;
       string    Zi_102_st;
       string    Zi_103_st;
       int       Zi_104_in;
       double    Zi_105_do;
       int       Zi_106_in;
       double    Zi_107_do;
       string    Zi_108_st;
       string    Zi_109_st;
       int       Zi_110_in;
       double    Zi_111_do;
       int       Zi_112_in;
       double    Zi_113_do;
       int       Zi_114_in;
       string    Zi_115_st;
       string    Zi_116_st;
       int       Zi_117_in;
       double    Zi_118_do;
       int       Zi_119_in;
       double    Zi_120_do;
       string    Zi_121_st;
       string    Zi_122_st;
       int       Zi_123_in;
       double    Zi_124_do;
       int       Zi_125_in;
       double    Zi_126_do;
       int       Zi_127_in;
       string    Zi_128_st;
       string    Zi_129_st;
       int       Zi_130_in;
       double    Zi_131_do;
       int       Zi_132_in;
       double    Zi_133_do;
       string    Zi_134_st;
       string    Zi_135_st;
       int       Zi_136_in;
       double    Zi_137_do;
       int       Zi_138_in;
       double    Zi_139_do;
       int       Zi_140_in;
       string    Zi_141_st;
       string    Zi_142_st;
       int       Zi_143_in;
       double    Zi_144_do;
       int       Zi_145_in;
       double    Zi_146_do;
       int       Zi_147_in;
       int       Zi_148_in;
       int       Zi_149_in;
       double    Zi_150_do;
       double    Zi_151_do;
       int       Zi_152_in;
       int       Zi_153_in;
       int       Zi_154_in;
       int       Zi_155_in;
       double    Zi_156_do;
       double    Zi_157_do;
       int       Zi_158_in;
       datetime  Zi_159_da;
       bool      Zi_160_bo;
       datetime  Zi_161_da;
       bool      Zi_162_bo;
       datetime  Zi_163_da;
       bool      Zi_164_bo;
       datetime  Zi_165_da;
       bool      Zi_166_bo;
       datetime  Zi_167_da;
       bool      Zi_168_bo;
       datetime  Zi_169_da;
       bool      Zi_170_bo;
       int       Zi_171_in;
       int       Zi_172_in;
       datetime  Zi_173_da;
       long      Zi_174_in;
       int       Zi_175_in;
       datetime  Zi_176_da;
       bool      Zi_177_bo;
       datetime  Zi_178_da;
       bool      Zi_179_bo;
       datetime  Zi_180_da;
       bool      Zi_181_bo;
       datetime  Zi_182_da;
       bool      Zi_183_bo;
       datetime  Zi_184_da;
       bool      Zi_185_bo;
       datetime  Zi_186_da;
       bool      Zi_187_bo;
       int       Zi_188_in;
       int       Zi_189_in;
       datetime  Zi_190_da;
       long      Zi_191_in;
       int       Zi_192_in;
       color     Zi_193_co;
       color     Zi_194_co;
       color     Zi_195_co;
    //----- -----
       Zi_3_do = 0.0 ;
       Zi_4_do = 0.0 ;
       Zi_5_do = 0.0 ;
       Zi_6_do = 0.0 ;
       Zi_7_do = 0.0 ;
       Zi_8_do = 0.0 ;
       Zi_9_in = 0 ;
       Zi_10_in = 0 ;
       Zi_11_in = 0 ;
       Zi_12_in = 0 ;
       Zi_13_in = 0 ;
       Zi_14_in = 0 ;
       Zi_15_in = 0 ;
       Zi_16_do = 0.0 ;
       Zi_17_do = 0.0 ;
       Zi_18_do = 0.0 ;
       Zi_19_do = 0.0 ;
       Zi_20_do = 0.0 ;
       Zi_21_do = 0.0 ;
       Zi_22_do = 0.0 ;
       Zi_23_do = 0.0 ;
       Zi_24_do = 0.0 ;
       Zi_25_do = 0.0 ;
       Zi_26_do = 0.0 ;
       Zi_27_do = 0.0 ;
       Zi_28_in = 0 ;
       Zi_29_do = 0.0 ;
       Zi_31_do = 0.0 ;
       Zi_33_do = 0.0 ;
       Zi_34_do = 0.0 ;
       Zi_35_bo = false ;
       Zi_36_do = 0.0 ;
       Zi_37_do = 0.0 ;
       Zi_38_do = 0.0 ;
       Zi_39_do = 0.0 ;
       Zi_40_do = 0.0 ;
       Zi_41_da = 0 ;
       Zi_42_bo = false ;
       Zi_47_da = 0 ;
       Zi_48_bo = false ;
       Zi_53_da = 0 ;
       Zi_54_bo = false ;
       Zi_59_in = 0 ;
       Zi_60_do = 0.0 ;
       Zi_61_in = 0 ;
       Zi_62_do = 0.0 ;
       Zi_63_in = 0 ;
       Zi_66_in = 0 ;
       Zi_67_do = 0.0 ;
       Zi_68_in = 0 ;
       Zi_69_do = 0.0 ;
       Zi_72_in = 0 ;
       Zi_73_do = 0.0 ;
       Zi_74_in = 0 ;
       Zi_75_do = 0.0 ;
       Zi_76_in = 0 ;
       Zi_79_in = 0 ;
       Zi_80_do = 0.0 ;
       Zi_81_in = 0 ;
       Zi_82_do = 0.0 ;
       Zi_84_in = 0 ;
       Zi_85_in = 0 ;
       Zi_87_in = 0 ;
       Zi_88_in = 0 ;
       Zi_90_in = 0 ;
       Zi_91_in = 0 ;
       Zi_93_in = 0 ;
       Zi_94_in = 0 ;
       Zi_97_in = 0 ;
       Zi_98_do = 0.0 ;
       Zi_99_in = 0 ;
       Zi_100_do = 0.0 ;
       Zi_101_in = 0 ;
       Zi_104_in = 0 ;
       Zi_105_do = 0.0 ;
       Zi_106_in = 0 ;
       Zi_107_do = 0.0 ;
       Zi_110_in = 0 ;
       Zi_111_do = 0.0 ;
       Zi_112_in = 0 ;
       Zi_113_do = 0.0 ;
       Zi_114_in = 0 ;
       Zi_117_in = 0 ;
       Zi_118_do = 0.0 ;
       Zi_119_in = 0 ;
       Zi_120_do = 0.0 ;
       Zi_123_in = 0 ;
       Zi_124_do = 0.0 ;
       Zi_125_in = 0 ;
       Zi_126_do = 0.0 ;
       Zi_127_in = 0 ;
       Zi_130_in = 0 ;
       Zi_131_do = 0.0 ;
       Zi_132_in = 0 ;
       Zi_133_do = 0.0 ;
       Zi_136_in = 0 ;
       Zi_137_do = 0.0 ;
       Zi_138_in = 0 ;
       Zi_139_do = 0.0 ;
       Zi_140_in = 0 ;
       Zi_143_in = 0 ;
       Zi_144_do = 0.0 ;
       Zi_145_in = 0 ;
       Zi_146_do = 0.0 ;
       Zi_147_in = 0 ;
       Zi_148_in = 0 ;
       Zi_149_in = 0 ;
       Zi_150_do = 0.0 ;
       Zi_151_do = 0.0 ;
       Zi_152_in = 0 ;
       Zi_153_in = 0 ;
       Zi_154_in = 0 ;
       Zi_155_in = 0 ;
       Zi_156_do = 0.0 ;
       Zi_157_do = 0.0 ;
       Zi_158_in = 0 ;
       Zi_159_da = 0 ;
       Zi_160_bo = false ;
       Zi_161_da = 0 ;
       Zi_162_bo = false ;
       Zi_163_da = 0 ;
       Zi_164_bo = false ;
       Zi_165_da = 0 ;
       Zi_166_bo = false ;
       Zi_167_da = 0 ;
       Zi_168_bo = false ;
       Zi_169_da = 0 ;
       Zi_170_bo = false ;
       Zi_171_in = 0 ;
       Zi_172_in = 0 ;
       Zi_173_da = 0 ;
       Zi_174_in = 0 ;
       Zi_175_in = 0 ;
       Zi_176_da = 0 ;
       Zi_177_bo = false ;
       Zi_178_da = 0 ;
       Zi_179_bo = false ;
       Zi_180_da = 0 ;
       Zi_181_bo = false ;
       Zi_182_da = 0 ;
       Zi_183_bo = false ;
       Zi_184_da = 0 ;
       Zi_185_bo = false ;
       Zi_186_da = 0 ;
       Zi_187_bo = false ;
       Zi_188_in = 0 ;
       Zi_189_in = 0 ;
       Zi_190_da = 0 ;
       Zi_191_in = 0 ;
       Zi_192_in = 0 ;
       Zi_193_co = 0 ;
       Zi_194_co = 0 ;
       Zi_195_co = 0 ;
       Symbols.Refresh();
       Zong_48_in_188 = int(MathMax(MarketInfo(Symbol(), MODE_FREEZELEVEL), MarketInfo(Symbol(), MODE_STOPLEVEL)) + 1.0) ;
       if(Step <  Zong_48_in_188)
         {
          Step = Zong_48_in_188 ;
         }
       if(FirstStep <  Zong_48_in_188)
         {
          FirstStep = Zong_48_in_188 ;
         }
       if(MinDistance <  Zong_48_in_188)
         {
          MinDistance = Zong_48_in_188 ;
         }
       TimeTrue = TimeIntradayCheck(true, EA_StartTime, EA_StopTime, TimeLocal());
       LimtTimeTrue= TimeIntradayCheck(true, Limit_StartTime, Limit_StopTime, TimeLocal());

       Zi_42_bo=LimtTimeTrue;
       if(Zi_42_bo==false)
         {
          ObjectDelete("HLINE_LONG");
          ObjectDelete("HLINE_SHORT");
          ObjectDelete("HLINE_LONGII");
          ObjectDelete("HLINE_SHORTII");
         }
       if(Zi_42_bo)
         {
          if(On_top_of_this_price_not_Buy_first_order != 0.0)
            {
             ObjectCreate(0, "HLINE_LONG", OBJ_HLINE, 0, 0, On_top_of_this_price_not_Buy_first_order);
             ObjectSet("HLINE_LONG", OBJPROP_STYLE, 0.0);
             ObjectSet("HLINE_LONG", OBJPROP_COLOR, 10025880.0);
            }
          if(On_under_of_this_price_not_Sell_first_order != 0.0)
            {
             ObjectCreate(0, "HLINE_SHORT", OBJ_HLINE, 0, 0, On_under_of_this_price_not_Sell_first_order);
             ObjectSet("HLINE_SHORT", OBJPROP_STYLE, 0.0);
             ObjectSet("HLINE_SHORT", OBJPROP_COLOR, 16711935.0);
            }
          if(On_top_of_this_price_not_Buy_order != 0.0)
            {
             ObjectCreate(0, "HLINE_LONGII", OBJ_HLINE, 0, 0, On_top_of_this_price_not_Buy_order);
             ObjectSet("HLINE_LONGII", OBJPROP_STYLE, 2.0);
             ObjectSet("HLINE_LONGII", OBJPROP_COLOR, 10025880.0);
            }
          if(On_under_of_this_price_not_Sell_order != 0.0)
            {
             ObjectCreate(0, "HLINE_SHORTII", OBJ_HLINE, 0, 0, On_under_of_this_price_not_Sell_order);
             ObjectSet("HLINE_SHORTII", OBJPROP_STYLE, 2.0);
             ObjectSet("HLINE_SHORTII", OBJPROP_COLOR, 16711935.0);
            }
         }
       Zi_3_do = 0.0 ;
       Zi_4_do = 0.0 ;
       Zi_5_do = 0.0 ;
       Zi_6_do = 0.0 ;
       Zi_7_do = 0.0 ;
       Zi_8_do = 0.0 ;
       Zi_9_in = 0 ;
       Zi_10_in = 0 ;
       Zi_11_in = 0 ;
       Zi_12_in = 0 ;
       Zi_13_in = 0 ;
       Zi_14_in = 0 ;
       Zi_15_in = 0 ;
       Zi_16_do = 0.0 ;
       Zi_17_do = 0.0 ;
       Zi_18_do = 0.0 ;
       Zi_19_do = 0.0 ;
       Zi_20_do = 0.0 ;
       Zi_21_do = 0.0 ;
       Zi_22_do = 0.0 ;
       Zi_23_do = 0.0 ;
       Zi_24_do = 0.0 ;
       Zi_25_do = 0.0 ;
       Zi_26_do = 0.0 ;
       Zi_27_do = 0.0 ;
       Zi_28_in = 0 ;
       Zi_29_do = 0.0 ;
       Zi_31_do = 0.0 ;
       Zi_33_do = 0.0 ;
       Zi_34_do = 0.0 ;
       Zi_35_bo = false ;
       CPosition order_buffer(SORT_BY_ORDER_NULL,ORDER_TYPES_ALL_DEAL_PENDING,Symbol(),Magic,NULL,0,END_TIME);

       for(int i = 0 ; i < order_buffer.m_total.total_record ; i ++)
         {
          Zi_13_in = order_buffer.m_list.type ;
          Zi_8_do = order_buffer.m_list.volume ;
          Zi_3_do = NormalizeDouble(order_buffer.m_list.open_price, Digits()) ;
          if(Zi_13_in == ORDER_TYPE_BUY_STOP)
            {
             Zi_11_in ++;
             if((Zi_16_do < Zi_3_do || Zi_16_do == 0.0))
               {
                Zi_16_do = Zi_3_do ;
               }
             Zi_14_in = order_buffer.m_list.ticket ;
             Zi_20_do = Zi_3_do ;
            }
          if(Zi_13_in == ORDER_TYPE_SELL_STOP)
            {
             Zi_12_in ++;
             if((Zi_19_do > Zi_3_do || Zi_19_do == 0.0))
               {
                Zi_19_do = Zi_3_do ;
               }
             Zi_15_in = order_buffer.m_list.ticket ;
             Zi_21_do = Zi_3_do ;
            }
          if(Zi_13_in == POSITION_TYPE_BUY)
            {
             Zi_9_in ++;
             Zi_6_do = Zi_6_do + Zi_8_do ;
             Zi_23_do = Zi_3_do * Zi_8_do + Zi_23_do ;
             if((Zi_16_do < Zi_3_do || Zi_16_do == 0.0))
               {
                Zi_16_do = Zi_3_do ;
               }
             if((Zi_17_do > Zi_3_do || Zi_17_do == 0.0))
               {
                Zi_17_do = Zi_3_do ;
               }
             Zi_5_do =order_buffer.m_list.profit_full + Zi_5_do ;
            }
          if(Zi_13_in != POSITION_TYPE_SELL)
             continue;
          Zi_10_in ++;
          Zi_7_do = Zi_7_do + Zi_8_do ;
          Zi_22_do = Zi_3_do * Zi_8_do + Zi_22_do ;
          if((Zi_19_do > Zi_3_do || Zi_19_do == 0.0))
            {
             Zi_19_do = Zi_3_do ;
            }
          if((Zi_18_do < Zi_3_do || Zi_18_do == 0.0))
            {
             Zi_18_do = Zi_3_do ;
            }
          Zi_4_do = order_buffer.m_list.profit_full+ Zi_4_do ;
         }
       if(Zi_5_do > 0.0)
         {
          ObjectSetInteger(0, Zong_63_st_200, OBJPROP_BGCOLOR, 17919);
         }
       else
         {
          ObjectSetInteger(0, Zong_63_st_200, OBJPROP_BGCOLOR, 6908265);
         }
       if(Zi_4_do > 0.0)
         {
          ObjectSetInteger(0, Zong_64_st_210, OBJPROP_BGCOLOR, 17919);
         }
       else
         {
          ObjectSetInteger(0, Zong_64_st_210, OBJPROP_BGCOLOR, 6908265);
         }
       if(Zi_5_do + Zi_4_do > 0.0)
         {
          ObjectSetInteger(0, Zong_65_st_220, OBJPROP_BGCOLOR, 17919);
         }
       else
         {
          ObjectSetInteger(0, Zong_65_st_220, OBJPROP_BGCOLOR, 6908265);
         }
       if(Zi_6_do > 0.0 && Zi_7_do / Zi_6_do > 3.0 && Zi_7_do - Zi_6_do > 0.2)
         {
          Zong_39_bo_151 = true ;
         }
       else
         {
          Zong_39_bo_151 = false ;
         }
       if(Zi_7_do > 0.0 && Zi_6_do / Zi_7_do > 3.0 && Zi_6_do - Zi_7_do > 0.2)
         {
          Zong_40_bo_152 = true ;
         }
       else
         {
          Zong_40_bo_152 = false ;
         }
       Zi_36_do = 0.0 ;
       Zi_37_do = 0.0 ;
       Zi_38_do = 0.0 ;
       Zi_39_do = 0.0 ;
       Zi_36_do = iHigh(Symbol(), Zong_31_in_12C, 0) - iLow(Symbol(), Zong_31_in_12C, 5) ;
       Zi_38_do = iLow(Symbol(), Zong_31_in_12C, 0) - iHigh(Symbol(), Zong_31_in_12C, 5) ;
       Zi_37_do = int(Zi_36_do / Point()) ;
       Zi_39_do = MathAbs(Zi_38_do / Point());

       if((AccountLeverage() < Leverage || IsTradeAllowed() == false || IsExpertEnabled() == false || IsStopped() || Zi_9_in + Zi_10_in >= Totals || MarketInfo(Symbol(), MODE_SPREAD) > MaxSpread || (Zong_32_in_130 != 0 && Zi_37_do >= Zong_32_in_130) || (Zong_32_in_130 != 0 && Zi_39_do >= Zong_32_in_130)))
         {
          Zong_29_bo_128 = false ;
          Zong_30_bo_129 = false ;
          Zi_43_st = "Arial" ;
          Zi_44_st = "不符合设定环境,EA停止运行!" ;
          if(ObjectFind("Stop") == -1)
            {
             ObjectCreate("Stop", OBJ_LABEL, 0, 0, 0.0, 0, 0.0, 0, 0.0);
             ObjectSet("Stop", OBJPROP_CORNER, Zong_74_in_264);
             ObjectSet("Stop", OBJPROP_XDISTANCE, Zong_75_in_268);
             ObjectSet("Stop", OBJPROP_YDISTANCE, Zong_76_in_26C);
            }
          ObjectSetText("Stop", Zi_44_st, Zong_33_in_134, Zi_43_st, Zong_59_co_1E0);
         }
       else
         {
          Zong_29_bo_128 = true ;
          Zong_30_bo_129 = true ;
          Zi_45_st = "Arial" ;
          Zi_46_st = "" ;
          if(ObjectFind("Stop") == -1)
            {
             ObjectCreate("Stop", OBJ_LABEL, 0, 0, 0.0, 0, 0.0, 0, 0.0);
             ObjectSet("Stop", OBJPROP_CORNER, Zong_74_in_264);
             ObjectSet("Stop", OBJPROP_XDISTANCE, Zong_75_in_268);
             ObjectSet("Stop", OBJPROP_YDISTANCE, Zong_76_in_26C);
            }
          ObjectSetText("Stop", Zi_46_st, Zong_33_in_134, Zi_45_st, Zong_59_co_1E0);
         }
       Zi_48_bo=TimeTrue;
       if(!(Zi_48_bo))
         {
          Zi_49_st = "Arial" ;
          Zi_50_st = "非开仓时间区间,停止开仓!" ;
          if(ObjectFind("Stop") == -1)
            {
             ObjectCreate("Stop", OBJ_LABEL, 0, 0, 0.0, 0, 0.0, 0, 0.0);
             ObjectSet("Stop", OBJPROP_CORNER, Zong_74_in_264);
             ObjectSet("Stop", OBJPROP_XDISTANCE, Zong_75_in_268);
             ObjectSet("Stop", OBJPROP_YDISTANCE, Zong_76_in_26C);
            }
          ObjectSetText("Stop", Zi_50_st, Zong_33_in_134, Zi_49_st, Zong_59_co_1E0);
         }
       if(TimeCurrent() <  Zong_37_da_148)
         {
          Zi_54_bo=TimeTrue;
          if(Zi_54_bo)
            {
             Zong_29_bo_128 = false ;
             Zong_30_bo_129 = false ;
             Zi_55_st = "Arial" ;
             Zi_56_st = "EA停止运行 " + string(NextTime) + "秒! " ;
             if(ObjectFind("Stop") == -1)
               {
                ObjectCreate("Stop", OBJ_LABEL, 0, 0, 0.0, 0, 0.0, 0, 0.0);
                ObjectSet("Stop", OBJPROP_CORNER, Zong_74_in_264);
                ObjectSet("Stop", OBJPROP_XDISTANCE, Zong_75_in_268);
                ObjectSet("Stop", OBJPROP_YDISTANCE, Zong_76_in_26C);
               }
             ObjectSetText("Stop", Zi_56_st, Zong_33_in_134, Zi_55_st, Zong_59_co_1E0);
            }
         }
       if(Over == 1 && Zi_9_in == 0)
         {
          Zong_29_bo_128 = false ;
         }
       if(Over == 1 && Zi_10_in == 0)
         {
          Zong_30_bo_129 = false ;
         }
       ObjectDelete("SLb");
       ObjectDelete("SLs");
       if(Zi_9_in >  0)
         {
          Zi_24_do = NormalizeDouble(Zi_23_do / Zi_6_do, Digits()) ;
          if(ObjectFind("SLb") != -1)
            {
             ObjectMove("SLb", 0, iTime(Symbol(), PERIOD_M1, 5 - 1), Zi_24_do);
             ObjectMove("SLb", 1, iTime(Symbol(), PERIOD_M1, 0), Zi_24_do);
            }
          else
            {
             ObjectCreate("SLb", OBJ_TREND, 0, iTime(Symbol(), PERIOD_M1, 5 - 1), Zi_24_do, iTime(Symbol(), PERIOD_M1, 0), Zi_24_do, 0, 0.0);
             ObjectSet("SLb", OBJPROP_COLOR, clr1);
             ObjectSet("SLb", OBJPROP_STYLE, 0.0);
             ObjectSet("SLb", OBJPROP_WIDTH, 2.0);
             ObjectSet("SLb", OBJPROP_BACK, 0.0);
             ObjectSet("SLb", 1004, 0.0);
            }
         }
       if(Zi_10_in >  0)
         {
          Zi_25_do = NormalizeDouble(Zi_22_do / Zi_7_do, Digits()) ;
          if(ObjectFind("SLs") != -1)
            {
             ObjectMove("SLs", 0, iTime(Symbol(), PERIOD_M1, 5 - 1), Zi_25_do);
             ObjectMove("SLs", 1, iTime(Symbol(), PERIOD_M1, 0), Zi_25_do);
            }
          else
            {
             ObjectCreate("SLs", OBJ_TREND, 0, iTime(Symbol(), PERIOD_M1, 5 - 1), Zi_25_do, iTime(Symbol(), PERIOD_M1, 0), Zi_25_do, 0, 0.0);
             ObjectSet("SLs", OBJPROP_COLOR, clr2);
             ObjectSet("SLs", OBJPROP_STYLE, 0.0);
             ObjectSet("SLs", OBJPROP_WIDTH, 2.0);
             ObjectSet("SLs", OBJPROP_BACK, 0.0);
             ObjectSet("SLs", 1004, 0.0);
            }
         }
       ObjectSetText("Char.op", CharToString(74), Zong_33_in_134 + 2, "Wingdings", Red);
       Zi_40_do = Zi_5_do + Zi_4_do ;
       if(Over == 1 && Zi_40_do >= CloseAll)
         {
          Zong_29_bo_128 = false ;
          Zong_30_bo_129 = false ;
          CloseOrders(0);
          if(ObjectFind(Zong_60_st_1E8) <  0)
            {
             ObjectCreate(Zong_60_st_1E8, OBJ_LABEL, 0, 0, 0.0, 0, 0.0, 0, 0.0);
             ObjectSet(Zong_60_st_1E8, OBJPROP_CORNER, Panel_Corner_type);
             ObjectSet(Zong_60_st_1E8, OBJPROP_YDISTANCE, 260.0);
             ObjectSet(Zong_60_st_1E8, OBJPROP_XDISTANCE, 10.0);
             ObjectSetText(Zong_60_st_1E8, "点差: " + DoubleToString((Ask - Bid) / Zong_58_do_1D8, 1) + " 点", 13, "Arial", Zong_59_co_1E0);
            }
          ObjectSetText(Zong_60_st_1E8, "点差: " + DoubleToString((Ask - Bid) / Zong_58_do_1D8, 1) + " 点", 0, NULL, 0xFFFFFFFF);
          WindowRedraw();
         }
       if(Over == false)
         {
          if(HomeopathyCloseAll == true)
            {
             Zi_87_in=0;
             CPosition order_buffer(SORT_BY_ORDER_NULL,ORDER_TYPES_ALL_DEAL,Symbol(),Magic,NULL,0,END_TIME);
             for(int i=0;i<order_buffer.m_total.total_record;i++)
               {
                if(order_buffer.m_list.comment=="SS")
                   Zi_87_in++;
               }
            }
          if((Zi_87_in < 1 || HomeopathyCloseAll == false) && Zi_5_do > MaxLossCloseAll && Zi_4_do > MaxLossCloseAll)
            {
             ObjectSetText("Char.op", CharToString(251), Zong_33_in_134 + 2, "Wingdings", Silver);
             if(((Profit == true && Zi_5_do > StopProfit * Zi_9_in) || (Profit == false && Zi_5_do > StopProfit)))
               {
                Print("买单盈利 ", Zi_5_do);
                CloseOrders(1);
                return;
               }
             if(((Profit == true && Zi_4_do > StopProfit * Zi_10_in) || (Profit == false && Zi_4_do > StopProfit)))
               {
                Print("卖单盈利 ", Zi_4_do);
                CloseOrders(-1);
                return;
               }
            }
          if(HomeopathyCloseAll == true)
            {
             CPosition order_buffer(SORT_BY_ORDER_NULL,ORDER_TYPES_ALL_DEAL,Symbol(),Magic,NULL,0,END_TIME);
             if(order_buffer.m_total.total_record>0)
                if(Zi_5_do + Zi_4_do >= CloseAll)
                  {
                   CloseOrders(0);
                   if(NextTime >  0)
                     {
                      Zong_37_da_148 = TimeCurrent() + NextTime;
                     }
                   return;
                  }
            }
          if(Zi_5_do + Zi_4_do >= CloseAll && (Zi_5_do <= MaxLossCloseAll || Zi_4_do <= MaxLossCloseAll))
            {
             CloseOrders(0);
             if(NextTime >  0)
               {
                Zong_37_da_148 = TimeCurrent() + NextTime;
               }
             return;
            }
         }
       if(StopLoss != 0.0 && Zi_5_do + Zi_4_do <= StopLoss)
         {
          Print("Buy Loss ", Zi_5_do);
          Print("Sell Loss ", Zi_4_do);
          CloseOrders(0);
          if(NextTime >  0)
            {
             Zong_37_da_148 = TimeCurrent() + NextTime;
            }
          return;
         }
       if(Zi_5_do <= MaxLoss)
         {
          Comment("Buy");
          ObjectSetText("Char.b", CharToString(225) + CharToString(251), Zong_33_in_134, "Wingdings", Red);
         }
       else
         {
          ObjectSetText("Char.b", CharToString(233), Zong_33_in_134, "Wingdings", Lime);
         }
       if(Zi_4_do <= MaxLoss)
         {
          Comment("Sell");
          ObjectSetText("Char.s", CharToString(226) + CharToString(251), Zong_33_in_134, "Wingdings", Red);
         }
       else
         {
          ObjectSetText("Char.s", CharToString(234), Zong_33_in_134, "Wingdings", Lime);
         }
       if(iOpen(Symbol(), PERIOD_M1, 0) > iOpen(Symbol(), PERIOD_M1, 1))
         {
          Zong_68_in_234 = Zong_66_in_22C ;
         }
       if(iOpen(Symbol(), PERIOD_M1, 0) < iOpen(Symbol(), PERIOD_M1, 1))
         {
          Zong_68_in_234 = Zong_67_in_230 ;
         }
       if(iClose(Symbol(), PERIOD_M1, 0) > iClose(Symbol(), PERIOD_M1, 1))
         {
          Zong_68_in_234 = Zong_70_in_23C ;
         }
       if(iClose(Symbol(), PERIOD_M1, 0) < iClose(Symbol(), PERIOD_M1, 1))
         {
          Zong_68_in_234 = Zong_71_in_240 ;
         }
       Zi_29_do = (Ask - Bid) / Point() ;
       Zi_30_st = Symbol() + ": " + DoubleToString(Zi_29_do, 1) + " 点" ;
       Zi_31_do = AccountLeverage() ;
       Zi_32_st = "杠杆: " + DoubleToString(Zi_31_do, 0) + " 倍" ;
       if(CloseBuySell == 1)
         {
          Zi_33_do = GetProfitLossMoney(0, Magic, 1, Zong_56_in_1CC) - GetProfitLossMoney(0, Magic, 2, Zong_57_in_1D0) ;
          if(Zong_51_do_198 < Zi_33_do)
            {
             Zong_51_do_198 = Zi_33_do ;
            }
          if(Zong_51_do_198 > 0.0 && Zi_33_do > 0.0 && Zong_51_do_198 > 0.0)
            {
             Zi_147_in = 1 ;
             Zi_148_in = Magic ;
             Zi_149_in = 0 ;
             Zi_150_do = 0.0 ;
             Zi_151_do = 0.0 ;
             CPosition order_buffer(SORT_BY_ORDER_NULL,ORDER_TYPES_ALL_DEAL_PENDING,Symbol(),Zi_148_in,NULL,0,END_TIME);
             for(int i = order_buffer.m_total.total_record - 1 ; i >= 0 ; i --)
               {
                if((order_buffer.m_list.type != Zi_149_in && Zi_149_in != -100))
                   continue;
                if(Zi_147_in == 1 && Zi_151_do < order_buffer.m_list.profit)
                  {
                   Zi_151_do = order_buffer.m_list.profit;
                   Zi_150_do = order_buffer.m_list.volume ;
                  }
                if(Zi_147_in != 2)
                   continue;
                if((!(Zi_151_do > order_buffer.m_list.profit) && !(Zi_151_do == 0.0)))
                   continue;
                Zi_151_do = order_buffer.m_list.profit ;
                Zi_150_do = order_buffer.m_list.volume ;
               }
             if(Zi_6_do > Zi_150_do * 3.0 + Zi_7_do && Zi_9_in >  3)
               {
                lizong_16(0, Magic, Zong_56_in_1CC, 1);
                lizong_16(0, Magic, Zong_57_in_1D0, 2);
                Zong_51_do_198 = 0.0 ;
                Zong_52_do_1A0 = 0.0 ;
               }
            }
          Zi_33_do = GetProfitLossMoney(1, Magic, 1, Zong_56_in_1CC) - (GetProfitLossMoney(1, Magic, 2, Zong_57_in_1D0)) ;
          if(Zong_52_do_1A0 < Zi_33_do)
            {
             Zong_52_do_1A0 = Zi_33_do ;
            }
          if(Zong_52_do_1A0 > 0.0 && Zi_33_do > 0.0)
            {
             Zi_153_in = 1 ;
             Zi_154_in = Magic ;
             Zi_155_in = 1 ;
             Zi_156_do = 0.0 ;
             Zi_157_do = 0.0 ;
             CPosition order_buffer(SORT_BY_ORDER_PROFIT,ORDER_TYPES_SELL_DEAL,Symbol(),Magic,NULL,0,END_TIME);
             Zi_157_do=order_buffer.m_list[order_buffer.m_total.total_record-1].profit;
             Zi_156_do=order_buffer.m_list[order_buffer.m_total.total_record-1].volume;
             if(Zi_7_do > Zi_156_do * 3.0 + Zi_6_do && Zi_10_in >  3)
               {
                lizong_16(1, Magic, Zong_56_in_1CC, 1);
                lizong_16(1, Magic, Zong_57_in_1D0, 2);
                Zong_51_do_198 = 0.0 ;
                Zong_52_do_1A0 = 0.0 ;
               }
            }
         }
       if(((Money != 0.0 && Zi_40_do > Money) || Money == 0.0))
         {
          Zi_35_bo = true ;
         }
       if(Money != 0.0 && Zi_40_do <= Money)
         {
          Zi_35_bo = false ;
         }
       if(((OpenMode == 1 && Zong_90_da_2D8 != iTime(NULL, TimeZone, 0)) || OpenMode == 2 || OpenMode == 3))
         {
          if(Zi_11_in == 0 && Zi_5_do > MaxLoss && Zong_29_bo_128)
            {
             if(Zi_9_in == 0)
               {
                Zi_26_do = NormalizeDouble(FirstStep * Point() + Ask, Digits()) ;
               }
             else
               {
                if(Zi_35_bo)
                  {
                   Zi_26_do = NormalizeDouble(MinDistance * Point() + Ask, Digits()) ;
                  }
                if(Zi_35_bo == false && Money != 0.0)
                  {
                   Zi_26_do = NormalizeDouble(TwoMinDistance * Point() + Ask, Digits()) ;
                  }
                if(Zi_26_do < NormalizeDouble(Zi_17_do - Step * Point(), Digits()) && Zi_35_bo)
                  {
                   Zi_26_do = NormalizeDouble(Step * Point() + Ask, Digits()) ;
                  }
                if(Zi_26_do < NormalizeDouble(Zi_17_do - TwoStep * Point(), Digits()) && Zi_35_bo == false && Money != 0.0)
                  {
                   Zi_26_do = NormalizeDouble(TwoStep * Point() + Ask, Digits()) ;
                  }
               }
             if((Zi_9_in == 0 || (Zi_16_do != 0.0 && Zi_26_do >= NormalizeDouble(Step * Point() + Zi_16_do, Digits()) && Zong_39_bo_151 && Zi_35_bo) || (Zi_16_do != 0.0 && Zi_26_do >= NormalizeDouble(TwoStep * Point() + Zi_16_do, Digits()) && Zong_39_bo_151 && Zi_35_bo == false && Money != 0.0) || (Zi_17_do != 0.0 && Zi_26_do <= NormalizeDouble(Zi_17_do - Step * Point(), Digits()) && Zi_35_bo) || (Zi_17_do != 0.0 && Zi_26_do <= NormalizeDouble(Zi_17_do - TwoStep * Point(), Digits()) && Zi_35_bo == false && Money != 0.0) || (Homeopathy && Zi_16_do != 0.0 && Zi_26_do >= NormalizeDouble(Step * Point() + Zi_16_do, Digits()) && Zi_6_do == Zi_7_do)))
               {
                if(Zi_9_in == 0)
                  {
                   Zi_27_do = lot ;
                  }
                else
                  {
                   Zi_27_do = NormalizeDouble(Zi_9_in * PlusLot + lot * (MathPow(K_Lot, Zi_9_in)), DigitsLot) ;
                  }
                if(Zi_27_do > Maxlot)
                  {
                   Zi_27_do = Maxlot ;
                  }
                double marginrequired = MarketInfo(Symbol(), MODE_MARGINREQUIRED);
                if(Zong_38_bo_150 ||
                   (Zi_9_in > 0 && (marginrequired <= 0 || Zi_27_do * 2.0 < AccountFreeMargin() / marginrequired)))
                  {
                   Zi_160_bo=TimeTrue;
                   Zi_161_da = 0 ;
                   if(Zi_160_bo)
                     {
                      Zi_162_bo=LimtTimeTrue;
                      if(Zi_162_bo==false)
                        {
                         ObjectDelete("HLINE_LONG");
                         ObjectDelete("HLINE_SHORT");
                         ObjectDelete("HLINE_LONGII");
                         ObjectDelete("HLINE_SHORTII");
                        }
                      Zi_164_bo=LimtTimeTrue;
                      if(!(Zi_164_bo))
                        {
                         Zi_166_bo=LimtTimeTrue;

                         if(Zi_166_bo==false)
                           {
                            ObjectDelete("HLINE_LONG");
                            ObjectDelete("HLINE_SHORT");
                            ObjectDelete("HLINE_LONGII");
                            ObjectDelete("HLINE_SHORTII");
                           }
                         Zi_168_bo=LimtTimeTrue;

                         Zi_170_bo=LimtTimeTrue;
                        }
                      if((On_top_of_this_price_not_Buy_order == 0.0 || (Zi_168_bo && Zi_9_in >= 1 && Zi_26_do < On_top_of_this_price_not_Buy_order) || Zi_9_in == 0 || !(Zi_170_bo)))
                        {
                         Zi_171_in = 0 ;
                         Zi_172_in = Magic ;
                         Zi_173_da = 0 ;
                         Zi_174_in = 0 ;
                         CPosition order_buffer(SORT_BY_ORDER_TICKET,ORDER_TYPES_BUY_DEAL,Symbol(),Magic,NULL,0,END_TIME);
                         if(order_buffer.m_total.total_record>0)
                           {
                            Zi_174_in=order_buffer.m_list[order_buffer.m_total.total_record-1].ticket;
                            Zi_173_da=order_buffer.m_list[order_buffer.m_total.total_record-1].open_time;
                           }
                         if(sw_buy == true)
                            if(((TimeCurrent() - Zi_173_da >= sleep && OpenMode == 2) || OpenMode == 3 || OpenMode == 1))
                              {
                               if(((Zi_16_do != 0.0 && Zi_26_do >= NormalizeDouble(Step * Point() + Zi_16_do, Digits()) && Zong_39_bo_151 && Zi_35_bo) || (Zi_16_do != 0.0 && Zi_26_do >= NormalizeDouble(TwoStep * Point() + Zi_16_do, Digits()) && Zong_39_bo_151 && Zi_35_bo == false && Money != 0.0) || (Homeopathy && Zi_16_do != 0.0 && Zi_26_do >= NormalizeDouble(Step * Point() + Zi_16_do, Digits()) && Zi_6_do == Zi_7_do)))
                                 {
                                  Zong_97_in_310 = OrderSend(Symbol(), 4, Zi_27_do, Zi_26_do, Zong_50_in_190, 0.0, 0.0, Com_2, Magic, 0, Blue) ;
                                  if(Zong_97_in_310 >  0)
                                    {
                                     Print(Symbol() + "开单成功,订单编号:" + DoubleToString(Zong_97_in_310, 0));
                                    }
                                  else
                                    {
                                     Print(Symbol() + "开单失败" + string(GetLastError()));
                                    }
                                 }
                               else
                                 {
                                  Zong_97_in_310 = OrderSend(Symbol(), 4, Zi_27_do, Zi_26_do, Zong_50_in_190, 0.0, 0.0, Com_1, Magic, 0, Blue) ;
                                  if(Zong_97_in_310 >  0)
                                    {
                                     Print(Symbol() + "开单成功,订单编号:" + DoubleToString(Zong_97_in_310, 0));
                                    }
                                  else
                                    {
                                     Print(Symbol() + "开单失败" + string(GetLastError()));
                                    }
                                 }
                              }
                        }
                     }
                  }
                else
                  {
                   Comment("Lot ", DoubleToString(Zi_27_do, 2));
                  }
               }
            }
          if(Zi_12_in == 0 && Zi_4_do > MaxLoss && Zong_30_bo_129)
            {
             if(Zi_10_in == 0)
               {
                Zi_26_do = NormalizeDouble(Bid - FirstStep * Point(), Digits()) ;
               }
             else
               {
                if(Zi_35_bo)
                  {
                   Zi_26_do = NormalizeDouble(Bid - MinDistance * Point(), Digits()) ;
                  }
                if(Zi_35_bo == false)
                  {
                   Zi_26_do = NormalizeDouble(Bid - TwoMinDistance * Point(), Digits()) ;
                  }
                if(Zi_26_do < NormalizeDouble(Step * Point() + Zi_18_do, Digits()) && Zi_35_bo)
                  {
                   Zi_26_do = NormalizeDouble(Bid - Step * Point(), Digits()) ;
                  }
                if(Zi_26_do < NormalizeDouble(TwoStep * Point() + Zi_18_do, Digits()) && Zi_35_bo == false && Money != 0.0)
                  {
                   Zi_26_do = NormalizeDouble(Bid - TwoStep * Point(), Digits()) ;
                  }
               }
             if((Zi_10_in == 0 || (Zi_19_do != 0.0 && Zi_26_do <= NormalizeDouble(Zi_19_do - Step * Point(), Digits()) && Zong_40_bo_152 && Zi_35_bo) || (Zi_19_do != 0.0 && Zi_26_do <= NormalizeDouble(Zi_19_do - TwoStep * Point(), Digits()) && Zong_40_bo_152 && Zi_35_bo == false && Money != 0.0) || (Zi_18_do != 0.0 && Zi_26_do >= NormalizeDouble(Step * Point() + Zi_18_do, Digits()) && Zi_35_bo) || (Zi_18_do != 0.0 && Zi_26_do >= NormalizeDouble(TwoStep * Point() + Zi_18_do, Digits()) && Zi_35_bo == false && Money != 0.0) || (Homeopathy && Zi_19_do != 0.0 && Zi_26_do <= NormalizeDouble(Zi_19_do - Step * Point(), Digits()) && Zi_6_do == Zi_7_do)))
               {
                if(Zi_10_in == 0)
                  {
                   Zi_27_do = lot ;
                  }
                else
                  {
                   Zi_27_do = NormalizeDouble(Zi_10_in * PlusLot + lot * (MathPow(K_Lot, Zi_10_in)), DigitsLot) ;
                  }
                if(Zi_27_do > Maxlot)
                  {
                   Zi_27_do = Maxlot ;
                  }
                double marginrequired = MarketInfo(Symbol(), MODE_MARGINREQUIRED);
                if(Zong_38_bo_150 ||
                   (Zi_10_in > 0 && (marginrequired <= 0 || Zi_27_do * 2.0 < AccountFreeMargin() / marginrequired)))
                  {
                   Zi_177_bo=TimeTrue;

                   Zi_178_da = 0 ;
                   if(Zi_177_bo)
                     {
                      Zi_179_bo=LimtTimeTrue;
                      if(Zi_179_bo==false)
                        {
                         ObjectDelete("HLINE_LONG");
                         ObjectDelete("HLINE_SHORT");
                         ObjectDelete("HLINE_LONGII");
                         ObjectDelete("HLINE_SHORTII");
                        }
                      Zi_181_bo=LimtTimeTrue;
                      if(!(Zi_181_bo))
                        {
                         Zi_183_bo=LimtTimeTrue;
                         if(Zi_183_bo==false)
                           {
                            ObjectDelete("HLINE_LONG");
                            ObjectDelete("HLINE_SHORT");
                            ObjectDelete("HLINE_LONGII");
                            ObjectDelete("HLINE_SHORTII");
                           }
                         Zi_185_bo=LimtTimeTrue;
                         Zi_187_bo=LimtTimeTrue;
                        }
                      if((On_under_of_this_price_not_Sell_order == 0.0 || (Zi_185_bo && Zi_10_in >= 1 && Zi_26_do > On_under_of_this_price_not_Sell_order) || Zi_10_in == 0 || !(Zi_187_bo)))
                        {
                         Zi_188_in = 1 ;
                         Zi_189_in = Magic ;
                         Zi_190_da = 0 ;
                         Zi_191_in = 0 ;

                         CPosition order_buffer(SORT_BY_ORDER_TICKET,ORDER_TYPES_SELL_DEAL,Symbol(),Magic,NULL,0,END_TIME);
                         if(order_buffer.m_total.total_record>0)
                           {
                            Zi_191_in=order_buffer.m_list[order_buffer.m_total.total_record-1].ticket;
                            Zi_190_da=order_buffer.m_list[order_buffer.m_total.total_record-1].open_time;
                           }

                         if(sw_sell == true)
                            if(((TimeCurrent() - Zi_190_da >= sleep && OpenMode == 2) || OpenMode == 3 || OpenMode == 1))
                              {
                               if(((Zi_19_do != 0.0 && Zi_26_do <= NormalizeDouble(Zi_19_do - Step * Point(), Digits()) && Zong_40_bo_152 && Zi_35_bo) || (Zi_19_do != 0.0 && Zi_26_do <= NormalizeDouble(Zi_19_do - TwoStep * Point(), Digits()) && Zong_40_bo_152 && Zi_35_bo == false && Money != 0.0) || (Homeopathy && Zi_19_do != 0.0 && Zi_26_do <= NormalizeDouble(Zi_19_do - Step * Point(), Digits()) && Zi_6_do == Zi_7_do)))
                                 {
                                  Zong_97_in_310 = OrderSend(Symbol(), 5, Zi_27_do, Zi_26_do, Zong_50_in_190, 0.0, 0.0, Com_2, Magic, 0, Red) ;
                                  if(Zong_97_in_310 >  0)
                                    {
                                     Print(Symbol() + "开单成功,订单编号:" + DoubleToString(Zong_97_in_310, 0));
                                    }
                                  else
                                    {
                                     Print(Symbol() + "开单失败" + string(GetLastError()));
                                    }
                                 }
                               else
                                 {
                                  Zong_97_in_310 = OrderSend(Symbol(), 5, Zi_27_do, Zi_26_do, Zong_50_in_190, 0.0, 0.0, Com_1, Magic, 0, Red) ;
                                  if(Zong_97_in_310 >  0)
                                    {
                                     Print(Symbol() + "开单成功,订单编号:" + DoubleToString(Zong_97_in_310, 0));
                                    }
                                  else
                                    {
                                     Print(Symbol() + "开单失败" + string(GetLastError()));
                                    }
                                 }
                              }
                        }
                     }
                  }
                else
                  {
                   Comment("Lot ", DoubleToString(Zi_27_do, 2));
                  }
               }
            }
          Zong_90_da_2D8 = iTime(NULL, TimeZone, 0) ;
         }
       Zi_34_do = Zi_5_do + Zi_4_do ;
       if(Zi_6_do > 0.0)
         {
          if(Zi_5_do > 0.0)
            {
             Zi_193_co = 255 ;
            }
          else
            {
             Zi_193_co = 65280 ;
            }
          string text="";
          int length=StringConcatenate(text,"Buy ", Zi_9_in, "单 , ", DoubleToString(Zi_6_do, 2), "手,  盈亏= ", DoubleToString(Zi_5_do, 2));
          ObjectSetText("ProfitB",text, Zong_33_in_134, "Arial",Zi_193_co);
         }
       else
         {
          ObjectSetText("ProfitB", "", Zong_33_in_134, "Arial", Gray);
         }
       if(Zi_7_do > 0.0)
         {
          if(Zi_4_do > 0.0)
            {
             Zi_194_co = 255 ;
            }

          else
            {
             Zi_194_co = 65280 ;
            }

          string text="";
          int length=StringConcatenate(text,"Sell ", Zi_10_in, "单 , ", DoubleToString(Zi_7_do, 2), "手,  盈亏= ", DoubleToString(Zi_4_do, 2));
          ObjectSetText("ProfitS", text, Zong_33_in_134, "Arial", Zi_194_co);
         }
       else
         {
          ObjectSetText("ProfitS", "", Zong_33_in_134, "Arial", Gray);
         }
       if(Zi_7_do + Zi_6_do > 0.0)
         {
          if(Zi_34_do > 0.0)
            {
             Zi_195_co = 255 ;
            }
          else
            {
             Zi_195_co = 65280 ;
            }
          string text="";
          int length=StringConcatenate(text,"总盈亏= ", DoubleToString(Zi_34_do, 2));
          ObjectSetText("Profit", text, Zong_33_in_134, "Arial", Zi_195_co);
         }
       else
         {
          ObjectSetText("Profit", "", Zong_33_in_134, "Arial", White);
         }
       if(Zi_20_do != 0.0 && Zong_29_bo_128)
         {
          if(Zi_9_in == 0)
            {
             Zi_26_do = NormalizeDouble(FirstStep * Point() + Ask, Digits()) ;
            }
          if(Zi_35_bo && Zi_9_in >  0)
            {
             Zi_26_do = NormalizeDouble(MinDistance * Point() + Ask, Digits()) ;
            }
          if(Zi_35_bo == false && Zi_9_in >  0 && Money != 0.0)
            {
             Zi_26_do = NormalizeDouble(TwoMinDistance * Point() + Ask, Digits()) ;
            }
          if(NormalizeDouble(Zi_20_do - StepTrallOrders * Point(), Digits()) > Zi_26_do && (((Zi_26_do <= NormalizeDouble(Zi_17_do - Step * Point(), Digits()) || Zi_17_do == 0.0 || (Zong_39_bo_151 && Zi_9_in == 0) || Zi_26_do >= NormalizeDouble(Step * Point() + Zi_16_do, Digits()) || Zi_26_do <= NormalizeDouble(Zi_17_do - Step * Point(), Digits())) && Zi_35_bo) || ((Zi_26_do <= NormalizeDouble(Zi_17_do - TwoStep * Point(), Digits()) || Zi_17_do == 0.0 || (Zong_39_bo_151 && Zi_9_in == 0) || Zi_26_do >= NormalizeDouble(TwoStep * Point() + Zi_16_do, Digits()) || Zi_26_do <= NormalizeDouble(Zi_17_do - TwoStep * Point(), Digits())) && Zi_35_bo == false && Money != 0.0)))
            {
             if(!(OrderModify(Zi_14_in, Zi_26_do, 0.0, 0.0, 0, White)))
               {
                Print("Error ", GetLastError(), "   Order Modify Buy   OOP ", Zi_20_do, "->", Zi_26_do);
               }
             else
               {
                Print("Order Buy Modify   OOP ", Zi_3_do, "->", Zi_26_do);
               }
            }
         }
       if(Zi_21_do != 0.0 && Zong_30_bo_129)
         {
          if(Zi_10_in == 0)
            {
             Zi_26_do = NormalizeDouble(Bid - FirstStep * Point(), Digits()) ;
            }
          if(Zi_35_bo && Zi_10_in >  0)
            {
             Zi_26_do = NormalizeDouble(Bid - MinDistance * Point(), Digits()) ;
            }
          if(Zi_35_bo == false && Zi_10_in >  0 && Money != 0.0)
            {
             Zi_26_do = NormalizeDouble(Bid - TwoMinDistance * Point(), Digits()) ;
            }
          if(NormalizeDouble(StepTrallOrders * Point() + Zi_21_do, Digits()) < Zi_26_do && (((Zi_26_do >= NormalizeDouble(Step * Point() + Zi_18_do, Digits()) || Zi_18_do == 0.0 || (Zong_40_bo_152 && Zi_10_in == 0) || Zi_26_do <= NormalizeDouble(Zi_19_do - Step * Point(), Digits()) || Zi_26_do >= NormalizeDouble(Step * Point() + Zi_18_do, Digits())) && Zi_35_bo) || ((Zi_26_do >= NormalizeDouble(TwoStep * Point() + Zi_18_do, Digits()) || Zi_18_do == 0.0 || (Zong_40_bo_152 && Zi_10_in == 0) || Zi_26_do <= NormalizeDouble(Zi_19_do - TwoStep * Point(), Digits()) || Zi_26_do >= NormalizeDouble(TwoStep * Point() + Zi_18_do, Digits())) && Zi_35_bo == false && Money != 0.0)))
            {
             if(!(OrderModify(Zi_15_in, Zi_26_do, 0.0, 0.0, 0, White)))
               {
                Print("Error ", GetLastError(), "   Order Modify Sell   OOP ", Zi_21_do, "->", Zi_26_do);
               }
             else
               {
                Print("Order Sell Modify   OOP ", Zi_3_do, "->", Zi_26_do);
               }
            }
         }
       lizong_20();
      }
    //start <<==--------   --------
    void OnTimer()
      {
       lizong_20();
       if(Zong_16_bo_CD != true)
          return;
       lizong_12();
      }
    //OnTimer <<==--------   --------
    void OnChartEvent(const int id, const long & lparam, const double & dparam, const string & sparam)
      {
       string     Lin_st_1;
       string     Lin_st_2;
       int        Lin_in_3;
       string     Lin_st_4;
       string     Lin_st_5;
       int        Lin_in_6;
       int        Lin_in_7;
       string     Lin_st_8;
       string     Lin_st_10;
       string     Lin_st_12;
       string     Lin_st_14;
       if(id == 1)
         {
          if((sparam == "tubiao2" || sparam == "tubiao1"))
            {
             if(Zong_15_bo_CC == true)
               {
                Zong_15_bo_CC = false ;
                ObjectDelete(0, "tubiao1");
               }
             else
               {
                Zong_15_bo_CC = true ;
                ObjectDelete(0, "tubiao2");
               }
             Lin_st_1 = Zong_17_st_D0;
             for(Lin_in_3 = ObjectsTotal(0, -1, -1) - 1 ; Lin_in_3 >= 0 ; Lin_in_3 = Lin_in_3 - 1)
               {
                Lin_st_2 = ObjectName(0, Lin_in_3, -1, -1);
                if(StringFind(Lin_st_2, Lin_st_1, 0) >= 0)
                  {
                   ObjectDelete(0, Lin_st_2);
                  }
               }
             Lin_st_4 = Zong_18_st_E0;
             for(Lin_in_6 = ObjectsTotal(0, -1, -1) - 1 ; Lin_in_6 >= 0 ; Lin_in_6 = Lin_in_6 - 1)
               {
                Lin_st_5 = ObjectName(0, Lin_in_6, -1, -1);
                if(StringFind(Lin_st_5, Lin_st_4, 0) >= 0)
                  {
                   ObjectDelete(0, Lin_st_5);
                  }
               }
             lizong_20();
             if(Zong_16_bo_CD == true)
               {
                lizong_12();
               }
            }
          else
            {
             if(sparam == Zong_17_st_D0 + "OpenBoard")
               {
                ObjectSetInteger(0, Zong_17_st_D0 + "OpenBoard", OBJPROP_STATE, 0);
                if(Zong_16_bo_CD)
                  {
                   for(Lin_in_7 = ObjectsTotal(0, -1, -1) - 1 ; Lin_in_7 >= 0 ; Lin_in_7 = Lin_in_7 - 1)
                     {
                      if(StringFind(ObjectName(0, Lin_in_7, -1, -1), Zong_18_st_E0, 0) >= 0)
                        {
                         ObjectDelete(0, ObjectName(0, Lin_in_7, -1, -1));
                        }
                     }
                  }
                else
                  {
                   lizong_12();
                  }
                Zong_16_bo_CD = !(Zong_16_bo_CD);
                ChartRedraw(0);
               }
            }
         }
       if(id == CHARTEVENT_OBJECT_CLICK)
         {
          if(sparam == Zong_18_st_E0 + "StopAll")
            {
             stop_all = ObjectGetInteger(0, sparam, OBJPROP_STATE);
            }
          if(sparam == Zong_18_st_E0 + "StopBuy")
            {
             stop_buy =  ObjectGetInteger(0, sparam, OBJPROP_STATE);
            }
          if(sparam == Zong_18_st_E0 + "StopSell")
            {
             stop_sell =  ObjectGetInteger(0, sparam, OBJPROP_STATE);
            }
          sw_buy = true;
          sw_sell = true;
          if(stop_all == true)
            {
             sw_buy = false;
             sw_sell = false;
            }
          else
            {
             if(stop_buy == true)
               {
                sw_buy = false;
               }
             if(stop_sell == true)
               {
                sw_sell = false;
               }
            }
          if(sw_buy == false)
            {
             DelOrders(1);
            }
          if(sw_sell == false)
            {
             DelOrders(-1);
            }
          lizong_20();
          if(Zong_16_bo_CD == true)
            {
             lizong_12();
            }
         }
       if(ObjectGetInteger(0, Zong_18_st_E0 + "CloseAll", OBJPROP_STATE, 0) == 1)
         {
          CloseOrders(0);
          ObjectSetInteger(0, Zong_18_st_E0 + "CloseAll", OBJPROP_STATE, 0);
         }
       if(ObjectGetInteger(0, Zong_18_st_E0 + "CloseBuy", OBJPROP_STATE, 0) == 1)
         {
          CloseOrders(1);
          ObjectSetInteger(0, Zong_18_st_E0 + "CloseBuy", OBJPROP_STATE, 0);
         }
       if(ObjectGetInteger(0, Zong_18_st_E0 + "CloseSell", OBJPROP_STATE, 0) == 1)
         {
          CloseOrders(-1);
          ObjectSetInteger(0, Zong_18_st_E0 + "CloseSell", OBJPROP_STATE, 0);
         }
       if(ObjectGetInteger(0, Zong_18_st_E0 + "CloseProfit", OBJPROP_STATE, 0) == 1)
         {
          CloseProfitLoss(-100,0,EQUAL_OR_MORE,Symbol(),Magic,ORDER_TYPES_ALL_DEAL,NULL,Zong_27_in_118);
          ObjectSetInteger(0, Zong_18_st_E0 + "CloseProfit", OBJPROP_STATE, 0);
         }
       if(ObjectGetInteger(0, Zong_18_st_E0 + "CloseLoss", OBJPROP_STATE, 0) == 1)
         {
          CloseProfitLoss(-100,0,LESS,Symbol(),Magic,ORDER_TYPES_ALL_DEAL,NULL,Zong_27_in_118);
          ObjectSetInteger(0, Zong_18_st_E0 + "CloseLoss", OBJPROP_STATE, 0);
         }
       if(ObjectGetInteger(0, Zong_18_st_E0 + "CloseSymbol", OBJPROP_STATE, 0) == 1)
         {
          Lin_st_12 = Symbol();
          CloseOrders(Lin_st_12,-1,ORDER_TYPES_ALL_DEAL,NULL,Zong_27_in_118,clrBlue);
          ObjectSetInteger(0, Zong_18_st_E0 + "CloseSymbol", OBJPROP_STATE, 0);
         }

       if(ObjectGetInteger(0, Zong_18_st_E0 + "CloseAccountAll", OBJPROP_STATE, 0) != 1)
         {
          ChartRedraw(0);
          return;
         }
       CloseOrders(NULL,-1,ORDER_TYPES_ALL_DEAL,NULL,Zong_27_in_118,clrBlue);
       ObjectSetInteger(0, Zong_18_st_E0 + "CloseAccountAll", OBJPROP_STATE, 0);
       ChartRedraw(0);
      }
    //OnChartEvent <<==--------   --------
    void OnDeinit(const int reason)
      {
       ObjectDelete("HLINE_LONGII");
       ObjectDelete("HLINE_SHORTII");
       ObjectDelete("HLINE_LONG");
       ObjectDelete("HLINE_SHORT");
       ObjectsDeleteAll(0, -1);
       ChartRedraw(0);
      }
    //deinit <<==--------   --------
    void lizong_12()
      {
       int       Zi_1_in;
       int       Zi_2_in;
       int       Zi_3_in;
    //----- -----
       uint       Lin_ui_1;
       long       Lin_lo_2;
       Zi_1_in = Zong_24_in_110 ;
       Zi_2_in = 3 ;
       Zi_3_in = 30 ;
       Lin_ui_1 = PowderBlue;
       Lin_lo_2 = 0;
       if(ObjectFind(0, Zong_18_st_E0 + "Panel") <  0)
         {
          ObjectCreate(0, Zong_18_st_E0 + "Panel", OBJ_RECTANGLE_LABEL, 0, 0, 0.0);
          ObjectSetInteger(0, Zong_18_st_E0 + "Panel", OBJPROP_XDISTANCE, 308);
          ObjectSetInteger(0, Zong_18_st_E0 + "Panel", OBJPROP_YDISTANCE, Zong_24_in_110);
          ObjectSetInteger(0, Zong_18_st_E0 + "Panel", OBJPROP_XSIZE, 300);
          ObjectSetInteger(0, Zong_18_st_E0 + "Panel", OBJPROP_YSIZE, 205);
          ObjectSetInteger(0, Zong_18_st_E0 + "Panel", OBJPROP_BORDER_TYPE, 0);
          ObjectSetInteger(0, Zong_18_st_E0 + "Panel", OBJPROP_CORNER, Panel_Corner_type);
          ObjectSetInteger(0, Zong_18_st_E0 + "Panel", OBJPROP_COLOR, 15453831);
          ObjectSetInteger(0, Zong_18_st_E0 + "Panel", OBJPROP_STYLE, 0);
          ObjectSetInteger(0, Zong_18_st_E0 + "Panel", OBJPROP_WIDTH, 1);
          ObjectSetInteger(0, Zong_18_st_E0 + "Panel", OBJPROP_BACK, 0);
          ObjectSetInteger(0, Zong_18_st_E0 + "Panel", OBJPROP_SELECTABLE, 0);
          ObjectSetInteger(0, Zong_18_st_E0 + "Panel", OBJPROP_SELECTED, 0);
          ObjectSetInteger(0, Zong_18_st_E0 + "Panel", OBJPROP_HIDDEN, 1);
          ObjectSetInteger(0, Zong_18_st_E0 + "Panel", OBJPROP_ZORDER, 0);
         }
       ObjectSetInteger(Lin_lo_2, Zong_18_st_E0 + "Panel", OBJPROP_BGCOLOR, Lin_ui_1);
       Zi_1_in += Zi_2_in;
       lizong_22(Zong_18_st_E0 + "StopAll", "停止交易", "开启交易", 298, Zi_1_in, 280, Zi_3_in, Panel_Corner_type, White, White, Brown, SteelBlue, Zong_21_st_F8, Zong_19_in_EC, true, stop_all);
       Zi_1_in = Zi_1_in + Zi_2_in + Zi_3_in;
       lizong_22(Zong_18_st_E0 + "StopBuy", "停止做多", "开启做多", 298, Zi_1_in, 135, Zi_3_in, Panel_Corner_type, White, White, Brown, SteelBlue, Zong_21_st_F8, Zong_19_in_EC, true, stop_buy);
       lizong_22(Zong_18_st_E0 + "StopSell", "停止做空", "开启做空", 154, Zi_1_in, 135, Zi_3_in, Panel_Corner_type, White, White, Brown, SteelBlue, Zong_21_st_F8, Zong_19_in_EC, true, stop_sell);
       Zi_1_in = Zi_1_in + Zi_2_in + Zi_3_in;
       lizong_22(Zong_18_st_E0 + "CloseProfit", "获利单平仓", "获利单平仓中", 298, Zi_1_in, 135, Zi_3_in, Panel_Corner_type, White, White, Teal, Teal, Zong_21_st_F8, Zong_19_in_EC);
       lizong_22(Zong_18_st_E0 + "CloseLoss", "亏损单平仓", "亏损单平仓中", 154, Zi_1_in, 135, Zi_3_in, Panel_Corner_type, White, White, Teal, Teal, Zong_21_st_F8, Zong_19_in_EC);
       Zi_1_in = Zi_1_in + Zi_2_in + Zi_3_in;
       lizong_22(Zong_18_st_E0 + "CloseBuy", "多单平仓", "多单平仓中", 298, Zi_1_in, 135, Zi_3_in, Panel_Corner_type, White, White, Teal, Teal, Zong_21_st_F8, Zong_19_in_EC);
       lizong_22(Zong_18_st_E0 + "CloseSell", "空单平仓", "空单平仓中", 154, Zi_1_in, 135, Zi_3_in, Panel_Corner_type, White, White, Teal, Teal, Zong_21_st_F8, Zong_19_in_EC);
       Zi_1_in = Zi_1_in + Zi_2_in + Zi_3_in;
       lizong_22(Zong_18_st_E0 + "CloseSymbol", Symbol() + "全部平仓", Symbol() + "全部平仓中", 298, Zi_1_in, 135, Zi_3_in, Panel_Corner_type, White, White, Teal, Teal, Zong_21_st_F8, Zong_19_in_EC);
       lizong_22(Zong_18_st_E0 + "CloseAll", "EA全部平仓", "EA全部平仓中", 154, Zi_1_in, 135, Zi_3_in, Panel_Corner_type, White, White, Teal, Teal, Zong_21_st_F8, Zong_19_in_EC);
       Zi_1_in = Zi_1_in + Zi_2_in + Zi_3_in;
       lizong_22(Zong_18_st_E0 + "CloseAccountAll", "账号全部平仓", "账号全部平仓中", 298, Zi_1_in, 280, Zi_3_in, Panel_Corner_type, White, White, SeaGreen, DodgerBlue, Zong_21_st_F8, Zong_19_in_EC);
      }
    bool stop_buy;
    bool stop_sell;
    bool stop_all;
    //lizong_12 <<==--------   --------
    //lizong_13 <<==--------   --------
    int CloseOrders(int Mu_0_in)
      {
       if(Mu_0_in==0)
         {
          return CloseOrders(Symbol(),Magic,ORDER_TYPES_ALL_DEAL_PENDING,NULL);
         }
       else
          if(Mu_0_in==1)
            {
             return CloseOrders(Symbol(),Magic,ORDER_TYPES_BUY_DEAL_PENDING,NULL);
            }
          else
             if(Mu_0_in==-1)
               {
                return CloseOrders(Symbol(),Magic,ORDER_TYPES_SELL_DEAL_PENDING,NULL);
               }
       return(0);
      }
    //CloseOrders <<==--------   --------

    //+------------------------------------------------------------------+
    //|                                                                  |
    //+------------------------------------------------------------------+
    int DelOrders(int type)
      {
       if(type==0)
         {
          return CloseOrders(Symbol(),Magic,ORDER_TYPES_ALL_PENDING,NULL);
         }
       if(type==1)
         {
          return CloseOrders(Symbol(),Magic,ORDER_TYPES_BUY_PENDING,NULL);
         }
       if(type==-1)
         {
          return CloseOrders(Symbol(),Magic,ORDER_TYPES_SELL_PENDING,NULL);
         }
       return(1);
      }

    //lizong_15 <<==--------   --------
    void lizong_16(int type, int magic, int Mu_2_in, int Mu_3_in)
      {
       if(Mu_2_in<=0)
          return;
       ENUM_ORDER_TYPES types;
       if(type==0)
         {
          types=ORDER_TYPES_BUY_DEAL;
         }
       else
          if(type==1)
            {
             types=ORDER_TYPES_SELL_DEAL;
            }
          else
             if(type==-100)
               {
                types=ORDER_TYPES_ALL_DEAL;
               }
             else
                return;

       CPosition order_buffer(SORT_BY_ORDER_PROFIT,types,Symbol(),magic,NULL,0,END_TIME);
       if(Mu_3_in == 1)
         {
          for(int i = order_buffer.m_total.total_record - 1 ; i >= 0 ; i --)
            {
             if(order_buffer.m_list.profit >= 0.0)
               {
                if(CloseTicket(order_buffer.m_list.ticket, 0, 0,true, 0xFFFFFFFF) == true)
                  {
                   Mu_2_in --;
                  }
               }
             else
                Mu_2_in --;
             if(Mu_2_in<=0)
                break;
            }
         }
       else
          if(Mu_3_in == 2)
            {
             for(int i = 0 ; i <order_buffer.m_total.total_record ; i ++)
               {
                if(order_buffer.m_list.profit < 0.0)
                  {
                   if(CloseTicket(order_buffer.m_list.ticket, 0, 0,true, 0xFFFFFFFF) == true)
                     {
                      Mu_2_in --;
                     }
                  }
                else
                   Mu_2_in --;
                if(Mu_2_in<=0)
                   break;
               }
            }

      }

    //lizong_16 <<==--------   --------
    double GetProfitLossMoney(int type, int magic, int profit_loss, int number)
      {
       if(number<=0)
          return 0;
       double    Zi_5_do = 0.0;
       CPosition order_buffer;
       ENUM_ORDER_TYPES types;
       if(type==-100)
         {
          types=ORDER_TYPES_ALL_DEAL;
         }
       else
          if(type==0)
            {
             types=ORDER_TYPES_BUY_DEAL;
            }
          else
             if(type==-1)
               {
                types=ORDER_TYPES_SELL_DEAL;
               }
             else
                return 0;
       order_buffer.Init(SORT_BY_ORDER_PROFIT,types,Symbol(),magic,NULL,0,END_TIME);
       if(profit_loss == 1)
         {
          for(int i = order_buffer.m_total.total_record-1 ; i >= 0 ; i --)
            {
             if(order_buffer.m_list.profit<0)
                break;
             Zi_5_do = Zi_5_do + order_buffer.m_list.profit;
             number--;
             if(number<=0)
                break;
            }
          return MathAbs(Zi_5_do);
         }
       else
          if(profit_loss == 2)
            {
             for(int i = 0 ; i < order_buffer.m_total.total_record ; i ++)
               {
                if(order_buffer.m_list.profit>=0)
                   break;
                Zi_5_do = Zi_5_do + order_buffer.m_list.profit;
                number--;
                if(number<=0)
                   break;
               }
             return MathAbs(Zi_5_do);
            }

       return(Zi_5_do);
      }
    //+------------------------------------------------------------------+
    //|                                                                  |
    //+------------------------------------------------------------------+
    void lizong_20()
      {
       string    Zi_1_st;
       int       Zi_2_in;
       string    Zi_3_st;
       int       Zi_4_in;
       double    Zi_5_do;
       double    Zi_6_do;
       double    Zi_7_do;
       double    Zi_8_do;
       double    Zi_9_do;
       string    Zi_10_st;
       string    Zi_11_st;
       string    Zi_12_st;
    //----- -----
       uint       Lin_ui_1;
       long       Lin_lo_2;
       uint       Lin_ui_3;
       long       Lin_lo_4;
       uint       Lin_ui_5;
       long       Lin_lo_6;
       int        Lin_in_7;
       string     Lin_st_8;
       uint       Lin_ui_9;
       string     Lin_st_10;
       int        Lin_in_11;
       string     Lin_st_12;
       uint       Lin_ui_13;
       string     Lin_st_14;
       int        Lin_in_15;
       string     Lin_st_16;
       uint       Lin_ui_17;
       string     Lin_st_18;
       int        Lin_in_19;
       string     Lin_st_20;
       uint       Lin_ui_21;
       string     Lin_st_22;
       int        Lin_in_23;
       string     Lin_st_24;
       uint       Lin_ui_25;
       string     Lin_st_26;
       int        Lin_in_27;
       string     Lin_st_28;
       uint       Lin_ui_29;
       string     Lin_st_30;
       string     Lin_st_31;
       int        Lin_in_32;
       int        Lin_in_33;
       double     Lin_do_34;
       double     Lin_do_35;
       long       Lin_lo_36;
       int        Lin_in_38;
       int        Lin_in_39;
       string     Lin_st_40;
       int        Lin_in_41;
       uint       Lin_ui_42;
       string     Lin_st_43;
       int        Lin_in_44;
       string     Lin_st_45;
       int        Lin_in_46;
       uint       Lin_ui_47;
       string     Lin_st_48;
       int        Lin_in_49;
       string     Lin_st_50;
       uint       Lin_ui_51;
       string     Lin_st_52;
       string     Lin_st_53;
       int        Lin_in_54;
       int        Lin_in_55;
       double     Lin_do_56;
       double     Lin_do_57;
       long       Lin_lo_58;
       int        Lin_in_60;
       int        Lin_in_61;
       string     Lin_st_62;
       int        Lin_in_63;
       uint       Lin_ui_64;
       string     Lin_st_65;
       int        Lin_in_66;
       string     Lin_st_67;
       int        Lin_in_68;
       uint       Lin_ui_69;
       string     Lin_st_70;
       int        Lin_in_71;
       string     Lin_st_72;
       uint       Lin_ui_73;
       string     Lin_st_74;
       string     Lin_st_75;
       int        Lin_in_76;
       int        Lin_in_77;
       double     Lin_do_78;
       double     Lin_do_79;
       long       Lin_lo_80;
       int        Lin_in_82;
       int        Lin_in_83;
       string     Lin_st_84;
       int        Lin_in_85;
       uint       Lin_ui_86;
       string     Lin_st_87;
       int        Lin_in_88;
       string     Lin_st_89;
       int        Lin_in_90;
       uint       Lin_ui_91;
       string     Lin_st_92;
       int        Lin_in_93;
       string     Lin_st_94;
       uint       Lin_ui_95;
       string     Lin_st_96;
       int        Lin_in_97;
       string     Lin_st_98;
       uint       Lin_ui_99;
       string     Lin_st_100;
       int        Lin_in_101;
       string     Lin_st_102;
       uint       Lin_ui_103;
       string     Lin_st_104;
       int        Lin_in_105;
       string     Lin_st_106;
       uint       Lin_ui_107;
       string     Lin_st_108;
       int        Lin_in_109;
       string     Lin_st_110;
       uint       Lin_ui_111;
       string     Lin_st_112;
       int        Lin_in_113;
       string     Lin_st_114;
       uint       Lin_ui_115;
       string     Lin_st_116;
       int        Lin_in_117;
       string     Lin_st_118;
       uint       Lin_ui_119;
       string     Lin_st_120;
       string     Lin_st_121;
       int        Lin_in_122;
       double     Lin_do_123;
       string     Lin_st_125;
       int        Lin_in_126;
       double     Lin_do_127;
       string     Lin_st_129;
       int        Lin_in_130;
       double     Lin_do_131;
       string     Lin_st_133;
       int        Lin_in_134;
       double     Lin_do_135;
       uint       Lin_ui_137;
       long       Lin_lo_138;
       int        Lin_in_139;
       string     Lin_st_140;
       uint       Lin_ui_141;
       string     Lin_st_142;
       int        Lin_in_143;
       string     Lin_st_144;
       uint       Lin_ui_145;
       string     Lin_st_146;
       int        Lin_in_147;
       string     Lin_st_148;
       uint       Lin_ui_149;
       string     Lin_st_150;
       uint       Lin_ui_151;
       long       Lin_lo_152;
       int        Lin_in_153;
       string     Lin_st_154;
       uint       Lin_ui_155;
       string     Lin_st_156;
       int        Lin_in_157;
       string     Lin_st_158;
       uint       Lin_ui_159;
       string     Lin_st_160;
       int        Lin_in_161;
       string     Lin_st_162;
       uint       Lin_ui_163;
       string     Lin_st_164;
       uint       Lin_ui_165;
       long       Lin_lo_166;
       int        Lin_in_167;
       string     Lin_st_168;
       uint       Lin_ui_169;
       string     Lin_st_170;
       int        Lin_in_171;
       string     Lin_st_172;
       uint       Lin_ui_173;
       string     Lin_st_174;
       int        Lin_in_175;
       string     Lin_st_176;
       uint       Lin_ui_177;
       string     Lin_st_178;
       uint       Lin_ui_179;
       long       Lin_lo_180;
       uint       Lin_ui_181;
       long       Lin_lo_182;
       uint       Lin_ui_183;
       long       Lin_lo_184;
       int        Lin_in_185;
       string     Lin_st_186;
       uint       Lin_ui_187;
       string     Lin_st_188;
       int        Lin_in_189;
       string     Lin_st_190;
       uint       Lin_ui_191;
       string     Lin_st_192;
       int        Lin_in_193;
       string     Lin_st_194;
       uint       Lin_ui_195;
       string     Lin_st_196;
       uint       Lin_ui_197;
       long       Lin_lo_198;
       int        Lin_in_199;
       string     Lin_st_200;
       uint       Lin_ui_201;
       string     Lin_st_202;
       int        Lin_in_203;
       string     Lin_st_204;
       uint       Lin_ui_205;
       string     Lin_st_206;
       int        Lin_in_207;
       string     Lin_st_208;
       uint       Lin_ui_209;
       string     Lin_st_210;
       uint       Lin_ui_211;
       long       Lin_lo_212;
       int        Lin_in_213;
       string     Lin_st_214;
       uint       Lin_ui_215;
       string     Lin_st_216;
       int        Lin_in_217;
       string     Lin_st_218;
       uint       Lin_ui_219;
       string     Lin_st_220;
       int        Lin_in_221;
       string     Lin_st_222;
       uint       Lin_ui_223;
       string     Lin_st_224;
       uint       Lin_ui_225;
       long       Lin_lo_226;
       int        Lin_in_227;
       string     Lin_st_228;
       uint       Lin_ui_229;
       string     Lin_st_230;
       int        Lin_in_231;
       string     Lin_st_232;
       uint       Lin_ui_233;
       string     Lin_st_234;
       int        Lin_in_235;
       string     Lin_st_236;
       int        Lin_in_237;
       uint       Lin_ui_238;
       string     Lin_st_239;
       int        Lin_in_240;
       string     Lin_st_241;
       uint       Lin_ui_242;
       string     Lin_st_243;
       int        Lin_in_244;
       string     Lin_st_245;
       uint       Lin_ui_246;
       string     Lin_st_247;
       int        Lin_in_248;
       string     Lin_st_249;
       int        Lin_in_250;
       uint       Lin_ui_251;
       string     Lin_st_252;
       int        Lin_in_253;
       string     Lin_st_254;
       uint       Lin_ui_255;
       string     Lin_st_256;
       int        Lin_in_257;
       string     Lin_st_258;
       uint       Lin_ui_259;
       string     Lin_st_260;
       int        Lin_in_261;
       string     Lin_st_262;
       int        Lin_in_263;
       uint       Lin_ui_264;
       string     Lin_st_265;
       uint       Lin_ui_266;
       long       Lin_lo_267;
       int        Lin_in_268;
       string     Lin_st_269;
       uint       Lin_ui_270;
       string     Lin_st_271;
       int        Lin_in_272;
       string     Lin_st_273;
       uint       Lin_ui_274;
       string     Lin_st_275;
       Zi_1_st = "  " + AccountCurrency();
       Zi_2_in = 1 ;
       Zi_4_in = 110 ;
       Zi_5_do = 0.0 ;
       if(Zong_15_bo_CC == false)
         {
         }
       else
         {
          Lin_ui_1 = Snow;
          Lin_lo_2 = 0;
          if(ObjectFind(0, Zong_17_st_D0 + "background") <  0)
            {
             ObjectCreate(0, Zong_17_st_D0 + "background", OBJ_RECTANGLE_LABEL, 0, 0, 0.0);
             ObjectSetInteger(0, Zong_17_st_D0 + "background", OBJPROP_XDISTANCE, 308);
             ObjectSetInteger(0, Zong_17_st_D0 + "background", OBJPROP_YDISTANCE, 50);
             ObjectSetInteger(0, Zong_17_st_D0 + "background", OBJPROP_XSIZE, 300);
             ObjectSetInteger(0, Zong_17_st_D0 + "background", OBJPROP_YSIZE, 440);
             ObjectSetInteger(0, Zong_17_st_D0 + "background", OBJPROP_BORDER_TYPE, 0);
             ObjectSetInteger(0, Zong_17_st_D0 + "background", OBJPROP_CORNER, Panel_Corner_type);
             ObjectSetInteger(0, Zong_17_st_D0 + "background", OBJPROP_COLOR, 8421376);
             ObjectSetInteger(0, Zong_17_st_D0 + "background", OBJPROP_STYLE, 0);
             ObjectSetInteger(0, Zong_17_st_D0 + "background", OBJPROP_WIDTH, 10);
             ObjectSetInteger(0, Zong_17_st_D0 + "background", OBJPROP_BACK, 0);
             ObjectSetInteger(0, Zong_17_st_D0 + "background", OBJPROP_SELECTABLE, 0);
             ObjectSetInteger(0, Zong_17_st_D0 + "background", OBJPROP_SELECTED, 0);
             ObjectSetInteger(0, Zong_17_st_D0 + "background", OBJPROP_HIDDEN, 1);
             ObjectSetInteger(0, Zong_17_st_D0 + "background", OBJPROP_ZORDER, 0);
            }
          ObjectSetInteger(Lin_lo_2, Zong_17_st_D0 + "background", OBJPROP_BGCOLOR, Lin_ui_1);
          Lin_ui_3 = LightCyan;
          Lin_lo_4 = 0;
          if(ObjectFind(0, Zong_17_st_D0 + "showprofit") <  0)
            {
             ObjectCreate(0, Zong_17_st_D0 + "showprofit", OBJ_RECTANGLE_LABEL, 0, 0, 0.0);
             ObjectSetInteger(0, Zong_17_st_D0 + "showprofit", OBJPROP_XDISTANCE, 298);
             ObjectSetInteger(0, Zong_17_st_D0 + "showprofit", OBJPROP_YDISTANCE, 90);
             ObjectSetInteger(0, Zong_17_st_D0 + "showprofit", OBJPROP_XSIZE, 280);
             ObjectSetInteger(0, Zong_17_st_D0 + "showprofit", OBJPROP_YSIZE, 85);
             ObjectSetInteger(0, Zong_17_st_D0 + "showprofit", OBJPROP_BORDER_TYPE, 0);
             ObjectSetInteger(0, Zong_17_st_D0 + "showprofit", OBJPROP_CORNER, Panel_Corner_type);
             ObjectSetInteger(0, Zong_17_st_D0 + "showprofit", OBJPROP_COLOR, 8421376);
             ObjectSetInteger(0, Zong_17_st_D0 + "showprofit", OBJPROP_STYLE, 0);
             ObjectSetInteger(0, Zong_17_st_D0 + "showprofit", OBJPROP_WIDTH, 1);
             ObjectSetInteger(0, Zong_17_st_D0 + "showprofit", OBJPROP_BACK, 0);
             ObjectSetInteger(0, Zong_17_st_D0 + "showprofit", OBJPROP_SELECTABLE, 0);
             ObjectSetInteger(0, Zong_17_st_D0 + "showprofit", OBJPROP_SELECTED, 0);
             ObjectSetInteger(0, Zong_17_st_D0 + "showprofit", OBJPROP_HIDDEN, 1);
             ObjectSetInteger(0, Zong_17_st_D0 + "showprofit", OBJPROP_ZORDER, 0);
            }
          ObjectSetInteger(Lin_lo_4, Zong_17_st_D0 + "showprofit", OBJPROP_BGCOLOR, Lin_ui_3);
          Lin_ui_5 = LightCyan;
          Lin_lo_6 = 0;
          if(ObjectFind(0, Zong_17_st_D0 + "showprofittitle") <  0)
            {
             ObjectCreate(0, Zong_17_st_D0 + "showprofittitle", OBJ_RECTANGLE_LABEL, 0, 0, 0.0);
             ObjectSetInteger(0, Zong_17_st_D0 + "showprofittitle", OBJPROP_XDISTANCE, 213);
             ObjectSetInteger(0, Zong_17_st_D0 + "showprofittitle", OBJPROP_YDISTANCE, 80);
             ObjectSetInteger(0, Zong_17_st_D0 + "showprofittitle", OBJPROP_XSIZE, 120);
             ObjectSetInteger(0, Zong_17_st_D0 + "showprofittitle", OBJPROP_YSIZE, 20);
             ObjectSetInteger(0, Zong_17_st_D0 + "showprofittitle", OBJPROP_BORDER_TYPE, 0);
             ObjectSetInteger(0, Zong_17_st_D0 + "showprofittitle", OBJPROP_CORNER, Panel_Corner_type);
             ObjectSetInteger(0, Zong_17_st_D0 + "showprofittitle", OBJPROP_COLOR, 8421376);
             ObjectSetInteger(0, Zong_17_st_D0 + "showprofittitle", OBJPROP_STYLE, 0);
             ObjectSetInteger(0, Zong_17_st_D0 + "showprofittitle", OBJPROP_WIDTH, 1);
             ObjectSetInteger(0, Zong_17_st_D0 + "showprofittitle", OBJPROP_BACK, 0);
             ObjectSetInteger(0, Zong_17_st_D0 + "showprofittitle", OBJPROP_SELECTABLE, 0);
             ObjectSetInteger(0, Zong_17_st_D0 + "showprofittitle", OBJPROP_SELECTED, 0);
             ObjectSetInteger(0, Zong_17_st_D0 + "showprofittitle", OBJPROP_HIDDEN, 1);
             ObjectSetInteger(0, Zong_17_st_D0 + "showprofittitle", OBJPROP_ZORDER, 0);
            }
          ObjectSetInteger(Lin_lo_6, Zong_17_st_D0 + "showprofittitle", OBJPROP_BGCOLOR, Lin_ui_5);
          Zi_3_st = Zong_17_st_D0 + string(Zi_2_in) + "B" ;
          if(sw_buy == true)
            {
             Lin_in_7 = Zong_19_in_EC;
             Lin_st_8 = Zong_21_st_F8;
             Lin_ui_9 = Green;
             Lin_st_10 = "可以多";
             if(ObjectFind(Zi_3_st) == -1)
               {
                ObjectCreate(Zi_3_st, OBJ_LABEL, 0, 0, 0.0, 0, 0.0, 0, 0.0);
                ObjectSet(Zi_3_st, OBJPROP_CORNER, Panel_Corner_type);
                ObjectSet(Zi_3_st, OBJPROP_XDISTANCE, 230+Panel_Text_shift-5);
                ObjectSet(Zi_3_st, OBJPROP_YDISTANCE, 65);
                ObjectSet(Zi_3_st, OBJPROP_BACK, 0.0);
                ObjectSetString(0, Zi_3_st, 1001, Zong_21_st_F8);
               }
             ObjectSetText(Zi_3_st, Lin_st_10, Lin_in_7, Lin_st_8, Lin_ui_9);
            }
          else
            {
             Lin_in_11 = Zong_19_in_EC;
             Lin_st_12 = Zong_21_st_F8;
             Lin_ui_13 = Tomato;
             Lin_st_14 = "禁止多";
             if(ObjectFind(Zi_3_st) == -1)
               {
                ObjectCreate(Zi_3_st, OBJ_LABEL, 0, 0, 0.0, 0, 0.0, 0, 0.0);
                ObjectSet(Zi_3_st, OBJPROP_CORNER, Panel_Corner_type);
                ObjectSet(Zi_3_st, OBJPROP_XDISTANCE, 230+Panel_Text_shift-5);
                ObjectSet(Zi_3_st, OBJPROP_YDISTANCE, 65);
                ObjectSet(Zi_3_st, OBJPROP_BACK, 0.0);
                ObjectSetString(0, Zi_3_st, 1001, Zong_21_st_F8);
               }
             ObjectSetText(Zi_3_st, Lin_st_14, Lin_in_11, Lin_st_12, Lin_ui_13);
            }
          Zi_3_st = Zong_17_st_D0 + string(Zi_2_in) + "S" ;
          if(sw_sell == true)
            {
             Lin_in_15 = Zong_19_in_EC;
             Lin_st_16 = Zong_21_st_F8;
             Lin_ui_17 = Green;
             Lin_st_18 = "可以空";
             if(ObjectFind(Zi_3_st) == -1)
               {
                ObjectCreate(Zi_3_st, OBJ_LABEL, 0, 0, 0.0, 0, 0.0, 0, 0.0);
                ObjectSet(Zi_3_st, OBJPROP_CORNER, Panel_Corner_type);
                ObjectSet(Zi_3_st, OBJPROP_XDISTANCE, 40+Panel_Text_shift-15);
                ObjectSet(Zi_3_st, OBJPROP_YDISTANCE, 65);
                ObjectSet(Zi_3_st, OBJPROP_BACK, 0.0);
                ObjectSetString(0, Zi_3_st, 1001, Zong_21_st_F8);
               }
             ObjectSetText(Zi_3_st, Lin_st_18, Lin_in_15, Lin_st_16, Lin_ui_17);
            }
          else
            {
             Lin_in_19 = Zong_19_in_EC;
             Lin_st_20 = Zong_21_st_F8;
             Lin_ui_21 = Tomato;
             Lin_st_22 = "禁止空";
             if(ObjectFind(Zi_3_st) == -1)
               {
                ObjectCreate(Zi_3_st, OBJ_LABEL, 0, 0, 0.0, 0, 0.0, 0, 0.0);
                ObjectSet(Zi_3_st, OBJPROP_CORNER, Panel_Corner_type);
                ObjectSet(Zi_3_st, OBJPROP_XDISTANCE, 40+Panel_Text_shift-15);
                ObjectSet(Zi_3_st, OBJPROP_YDISTANCE, 65);
                ObjectSet(Zi_3_st, OBJPROP_BACK, 0.0);
                ObjectSetString(0, Zi_3_st, 1001, Zong_21_st_F8);
               }
             ObjectSetText(Zi_3_st, Lin_st_22, Lin_in_19, Lin_st_20, Lin_ui_21);
            }
          Zi_3_st = Zong_17_st_D0 + string(Zi_2_in) + "N" ;
          Lin_in_23 = Zong_19_in_EC;
          Lin_st_24 = Zong_21_st_F8;
          Lin_ui_25 = 0;
          Lin_st_26 = "获利统计";
          if(ObjectFind(Zi_3_st) == -1)
            {
             ObjectCreate(Zi_3_st, OBJ_LABEL, 0, 0, 0.0, 0, 0.0, 0, 0.0);
             ObjectSet(Zi_3_st, OBJPROP_CORNER, Panel_Corner_type);
             ObjectSet(Zi_3_st, OBJPROP_XDISTANCE, 122+Panel_Text_shift);
             ObjectSet(Zi_3_st, OBJPROP_YDISTANCE, 80);
             ObjectSet(Zi_3_st, OBJPROP_BACK, 0.0);
             ObjectSetString(0, Zi_3_st, 1001, Zong_21_st_F8);
            }
          ObjectSetText(Zi_3_st, Lin_st_26, Lin_in_23, Lin_st_24, Lin_ui_25);
          Zi_2_in ++;
          Zi_3_st = Zong_17_st_D0 + string(Zi_2_in) + "N" ;
          Lin_in_27 = Zong_19_in_EC;
          Lin_st_28 = "Microsoft YaHei";
          Lin_ui_29 = 0;
          Lin_st_30 = "今日获利:";
          if(ObjectFind(Zi_3_st) == -1)
            {
             ObjectCreate(Zi_3_st, OBJ_LABEL, 0, 0, 0.0, 0, 0.0, 0, 0.0);
             ObjectSet(Zi_3_st, OBJPROP_CORNER, Panel_Corner_type);
             ObjectSet(Zi_3_st, OBJPROP_XDISTANCE, 230+Panel_Text_shift+5);
             ObjectSet(Zi_3_st, OBJPROP_YDISTANCE, Zi_4_in);
             ObjectSet(Zi_3_st, OBJPROP_BACK, 0.0);
             ObjectSetString(0, Zi_3_st, 1001, "Microsoft YaHei");
            }
          ObjectSetText(Zi_3_st, Lin_st_30, Lin_in_27, Lin_st_28, Lin_ui_29);
          Zi_3_st = Zong_17_st_D0 + string(Zi_2_in) + "V" ;
          Lin_st_31 = (string)Magic;
          Lin_in_32 = 0;
          Lin_in_33 = 0;
          switch(0)
            {
             case 0 :
                Lin_in_32 = TimeDay(TimeCurrent());
                Lin_in_33 = Lin_in_32;
                break;
             case 1 :
                Lin_in_32 = Lin_in_33 - 1;
                Lin_in_33 = Lin_in_32;
                break;
             case 2 :
                Lin_in_32 = 0;
                Lin_in_33 = 999999;
                break;
             default :
                Lin_do_34 = 0.0;
                break;
            }
          Lin_do_35 = 0.0;
          if(Lin_st_31 == "")
            {
             Lin_lo_36 = -1;
            }
          else
            {
             Lin_lo_36 = StringToInteger(Lin_st_31);
            }
          Lin_lo_36 = Lin_lo_36;
          CHistory history_buffer(SORT_BY_ORDER_NULL,ORDER_TYPES_ALL_DEAL,NULL,Magic,NULL,0,END_TIME);
          for(int i=history_buffer.m_total.total_record-1;i>=0;i--)
            {
             Lin_in_38 = TimeDay(history_buffer.m_list.close_time);
             if(Lin_in_38 < Lin_in_32 || Lin_in_38 > Lin_in_33)
                continue;
             Lin_do_35 = history_buffer.m_list.profit_full + Lin_do_35;
            }
          Lin_do_34 = NormalizeDouble(Lin_do_35, 2);
          Zi_5_do = Lin_do_34 ;
          Lin_in_39 = Zong_19_in_EC;
          Lin_st_40 = Zong_21_st_F8;
          Lin_in_41 = Panel_Corner_type;
          Lin_ui_42 = (Zi_5_do >= 0.0) ? 25600 : 3937500 ;
          Lin_st_43 = DoubleToString(Zi_5_do, 2) + Zi_1_st;
          if(ObjectFind(Zi_3_st) == -1)
            {
             ObjectCreate(Zi_3_st, OBJ_LABEL, 0, 0, 0.0, 0, 0.0, 0, 0.0);
             ObjectSet(Zi_3_st, OBJPROP_CORNER, Lin_in_41);
             ObjectSet(Zi_3_st, OBJPROP_XDISTANCE, 100+Panel_Text_shift+40);
             ObjectSet(Zi_3_st, OBJPROP_YDISTANCE, Zi_4_in);
             ObjectSet(Zi_3_st, OBJPROP_BACK, 0.0);
             ObjectSetString(0, Zi_3_st, 1001, Lin_st_40);
            }
          ObjectSetText(Zi_3_st, Lin_st_43, Lin_in_39, Lin_st_40, Lin_ui_42);
          Zi_3_st = Zong_17_st_D0 + string(Zi_2_in) + "P" ;
          Lin_in_44 = Zong_19_in_EC;
          Lin_st_45 = Zong_21_st_F8;
          Lin_in_46 = Panel_Corner_type;
          Lin_ui_47 = (Zi_5_do >= 0.0) ? 25600 : 3937500 ;
          Lin_st_48 = DoubleToString(Zi_5_do / Zong_23_do_108 * 100.0, 2) + "%";
          if(ObjectFind(Zi_3_st) == -1)
            {
             ObjectCreate(Zi_3_st, OBJ_LABEL, 0, 0, 0.0, 0, 0.0, 0, 0.0);
             ObjectSet(Zi_3_st, OBJPROP_CORNER, Lin_in_46);
             ObjectSet(Zi_3_st, OBJPROP_XDISTANCE, 25+Panel_Text_shift+5);
             ObjectSet(Zi_3_st, OBJPROP_YDISTANCE, Zi_4_in);
             ObjectSet(Zi_3_st, OBJPROP_BACK, 0.0);
             ObjectSetString(0, Zi_3_st, 1001, Lin_st_45);
            }
          ObjectSetText(Zi_3_st, Lin_st_48, Lin_in_44, Lin_st_45, Lin_ui_47);
          Zi_2_in ++;
          Zi_4_in += Zong_19_in_EC * 2;
          Zi_3_st = Zong_17_st_D0 + string(Zi_2_in) + "N" ;
          Lin_in_49 = Zong_19_in_EC;
          Lin_st_50 = Zong_21_st_F8;
          Lin_ui_51 = 0;
          Lin_st_52 = "昨日获利:";
          if(ObjectFind(Zi_3_st) == -1)
            {
             ObjectCreate(Zi_3_st, OBJ_LABEL, 0, 0, 0.0, 0, 0.0, 0, 0.0);
             ObjectSet(Zi_3_st, OBJPROP_CORNER, Panel_Corner_type);
             ObjectSet(Zi_3_st, OBJPROP_XDISTANCE, 230+Panel_Text_shift+5);
             ObjectSet(Zi_3_st, OBJPROP_YDISTANCE, Zi_4_in);
             ObjectSet(Zi_3_st, OBJPROP_BACK, 0.0);
             ObjectSetString(0, Zi_3_st, 1001, Zong_21_st_F8);
            }
          ObjectSetText(Zi_3_st, Lin_st_52, Lin_in_49, Lin_st_50, Lin_ui_51);
          Zi_3_st = Zong_17_st_D0 + string(Zi_2_in) + "V" ;
          Lin_st_53 = (string)Magic;
          Lin_in_54 = 0;
          Lin_in_55 = 0;
          switch(1)
            {
             case 0 :
                Lin_in_54 = TimeDay(TimeCurrent());
                Lin_in_55 = Lin_in_54;
                break;
             case 1 :
                Lin_in_54 = Lin_in_55 - 1;
                Lin_in_55 = Lin_in_54;
                break;
             case 2 :
                Lin_in_54 = 0;
                Lin_in_55 = 999999;
                break;
             default :
                Lin_do_56 = 0.0;
                break;
            }
          Lin_do_57 = 0.0;
          if(Lin_st_53 == "")
            {
             Lin_lo_58 = -1;
            }
          else
            {
             Lin_lo_58 = StringToInteger(Lin_st_53);
            }
          Lin_lo_58 = Lin_lo_58;

          history_buffer.Init(SORT_BY_ORDER_NULL,ORDER_TYPES_ALL_DEAL,NULL,Magic,NULL,0,END_TIME);
          for(int i=history_buffer.m_total.total_record-1;i>=0;i--)
            {
             Lin_in_60 = TimeDay(history_buffer.m_list.close_time);
             if(Lin_in_60 < Lin_in_54 || Lin_in_60 > Lin_in_55)
                continue;
             Lin_do_57 = history_buffer.m_list.profit_full + Lin_do_57;
            }
          Lin_do_56 = NormalizeDouble(Lin_do_57, 2);
          Zi_5_do = Lin_do_56 ;
          Lin_in_61 = Zong_19_in_EC;
          Lin_st_62 = Zong_21_st_F8;
          Lin_in_63 = Panel_Corner_type;
          Lin_ui_64 = (Zi_5_do >= 0.0) ? 25600 : 3937500 ;
          Lin_st_65 = DoubleToString(Zi_5_do, 2) + Zi_1_st;
          if(ObjectFind(Zi_3_st) == -1)
            {
             ObjectCreate(Zi_3_st, OBJ_LABEL, 0, 0, 0.0, 0, 0.0, 0, 0.0);
             ObjectSet(Zi_3_st, OBJPROP_CORNER, Lin_in_63);
             ObjectSet(Zi_3_st, OBJPROP_XDISTANCE, 100+Panel_Text_shift+40);
             ObjectSet(Zi_3_st, OBJPROP_YDISTANCE, Zi_4_in);
             ObjectSet(Zi_3_st, OBJPROP_BACK, 0.0);
             ObjectSetString(0, Zi_3_st, 1001, Lin_st_62);
            }
          ObjectSetText(Zi_3_st, Lin_st_65, Lin_in_61, Lin_st_62, Lin_ui_64);
          Zi_3_st = Zong_17_st_D0 + string(Zi_2_in) + "P" ;
          Lin_in_66 = Zong_19_in_EC;
          Lin_st_67 = Zong_21_st_F8;
          Lin_in_68 = Panel_Corner_type;
          Lin_ui_69 = (Zi_5_do >= 0.0) ? 25600 : 3937500 ;
          Lin_st_70 = DoubleToString(Zi_5_do / Zong_23_do_108 * 100.0, 2) + "%";
          if(ObjectFind(Zi_3_st) == -1)
            {
             ObjectCreate(Zi_3_st, OBJ_LABEL, 0, 0, 0.0, 0, 0.0, 0, 0.0);
             ObjectSet(Zi_3_st, OBJPROP_CORNER, Lin_in_68);
             ObjectSet(Zi_3_st, OBJPROP_XDISTANCE, 25+Panel_Text_shift+5);
             ObjectSet(Zi_3_st, OBJPROP_YDISTANCE, Zi_4_in);
             ObjectSet(Zi_3_st, OBJPROP_BACK, 0.0);
             ObjectSetString(0, Zi_3_st, 1001, Lin_st_67);
            }
          ObjectSetText(Zi_3_st, Lin_st_70, Lin_in_66, Lin_st_67, Lin_ui_69);
          Zi_2_in ++;
          Zi_4_in += Zong_19_in_EC * 2;
          Zi_3_st = Zong_17_st_D0 + string(Zi_2_in) + "N" ;
          Lin_in_71 = Zong_19_in_EC;
          Lin_st_72 = Zong_21_st_F8;
          Lin_ui_73 = 0;
          Lin_st_74 = "总计获利:";
          if(ObjectFind(Zi_3_st) == -1)
            {
             ObjectCreate(Zi_3_st, OBJ_LABEL, 0, 0, 0.0, 0, 0.0, 0, 0.0);
             ObjectSet(Zi_3_st, OBJPROP_CORNER, Panel_Corner_type);
             ObjectSet(Zi_3_st, OBJPROP_XDISTANCE, 230+Panel_Text_shift+5);
             ObjectSet(Zi_3_st, OBJPROP_YDISTANCE, Zi_4_in);
             ObjectSet(Zi_3_st, OBJPROP_BACK, 0.0);
             ObjectSetString(0, Zi_3_st, 1001, Zong_21_st_F8);
            }
          ObjectSetText(Zi_3_st, Lin_st_74, Lin_in_71, Lin_st_72, Lin_ui_73);
          Zi_3_st = Zong_17_st_D0 + string(Zi_2_in) + "V" ;
          Lin_st_75 = (string)Magic;
          Lin_in_76 = 0;
          Lin_in_77 = 0;
          switch(2)
            {
             case 0 :
                Lin_in_76 = TimeDay(TimeCurrent());
                Lin_in_77 = Lin_in_76;
                break;
             case 1 :
                Lin_in_76 = Lin_in_77 - 1;
                Lin_in_77 = Lin_in_76;
                break;
             case 2 :
                Lin_in_76 = 0;
                Lin_in_77 = 999999;
                break;
             default :
                Lin_do_78 = 0.0;
                break;
            }
          Lin_do_79 = 0.0;
          if(Lin_st_75 == "")
            {
             Lin_lo_80 = -1;
            }
          else
            {
             Lin_lo_80 = StringToInteger(Lin_st_75);
            }
          Lin_lo_80 = Lin_lo_80;

          history_buffer.Init(SORT_BY_ORDER_NULL,ORDER_TYPES_ALL_DEAL,NULL,Magic,NULL,0,END_TIME);
          for(int i=history_buffer.m_total.total_record-1;i>=0;i--)
            {
             Lin_in_82 = TimeDay(history_buffer.m_list.close_time);
             if(Lin_in_82 < Lin_in_76 || Lin_in_82 > Lin_in_77)
                continue;
             Lin_do_79 = history_buffer.m_list.profit_full + Lin_do_79;
            }
          Lin_do_78 = NormalizeDouble(Lin_do_79, 2);
          Zi_5_do = Lin_do_78 ;
          Lin_in_83 = Zong_19_in_EC;
          Lin_st_84 = Zong_21_st_F8;
          Lin_in_85 = Panel_Corner_type;
          Lin_ui_86 = (Zi_5_do >= 0.0) ? 25600 : 3937500 ;
          Lin_st_87 = DoubleToString(Zi_5_do, 2) + Zi_1_st;
          if(ObjectFind(Zi_3_st) == -1)
            {
             ObjectCreate(Zi_3_st, OBJ_LABEL, 0, 0, 0.0, 0, 0.0, 0, 0.0);
             ObjectSet(Zi_3_st, OBJPROP_CORNER, Lin_in_85);
             ObjectSet(Zi_3_st, OBJPROP_XDISTANCE, 100+Panel_Text_shift+40);
             ObjectSet(Zi_3_st, OBJPROP_YDISTANCE, Zi_4_in);
             ObjectSet(Zi_3_st, OBJPROP_BACK, 0.0);
             ObjectSetString(0, Zi_3_st, 1001, Lin_st_84);
            }
          ObjectSetText(Zi_3_st, Lin_st_87, Lin_in_83, Lin_st_84, Lin_ui_86);
          Zi_3_st = Zong_17_st_D0 + string(Zi_2_in) + "P" ;
          Lin_in_88 = Zong_19_in_EC;
          Lin_st_89 = Zong_21_st_F8;
          Lin_in_90 = Panel_Corner_type;
          Lin_ui_91 = (Zi_5_do >= 0.0) ? 25600 : 3937500 ;
          Lin_st_92 = DoubleToString(Zi_5_do / Zong_23_do_108 * 100.0, 2) + "%";
          if(ObjectFind(Zi_3_st) == -1)
            {
             ObjectCreate(Zi_3_st, OBJ_LABEL, 0, 0, 0.0, 0, 0.0, 0, 0.0);
             ObjectSet(Zi_3_st, OBJPROP_CORNER, Lin_in_90);
             ObjectSet(Zi_3_st, OBJPROP_XDISTANCE, 25+Panel_Text_shift+5);
             ObjectSet(Zi_3_st, OBJPROP_YDISTANCE, Zi_4_in);
             ObjectSet(Zi_3_st, OBJPROP_BACK, 0.0);
             ObjectSetString(0, Zi_3_st, 1001, Lin_st_89);
            }
          ObjectSetText(Zi_3_st, Lin_st_92, Lin_in_88, Lin_st_89, Lin_ui_91);
          Zi_4_in += Zong_19_in_EC * 3;
          Zi_3_st = Zong_17_st_D0 + "Balance" + "N" ;
          Lin_in_93 = Zong_19_in_EC;
          Lin_st_94 = Zong_21_st_F8;
          Lin_ui_95 = Teal;
          Lin_st_96 = "账户余额:";
          if(ObjectFind(Zi_3_st) == -1)
            {
             ObjectCreate(Zi_3_st, OBJ_LABEL, 0, 0, 0.0, 0, 0.0, 0, 0.0);
             ObjectSet(Zi_3_st, OBJPROP_CORNER, Panel_Corner_type);
             ObjectSet(Zi_3_st, OBJPROP_XDISTANCE, 230+Panel_Text_shift+5);
             ObjectSet(Zi_3_st, OBJPROP_YDISTANCE, Zi_4_in);
             ObjectSet(Zi_3_st, OBJPROP_BACK, 0.0);
             ObjectSetString(0, Zi_3_st, 1001, Zong_21_st_F8);
            }
          ObjectSetText(Zi_3_st, Lin_st_96, Lin_in_93, Lin_st_94, Lin_ui_95);
          Zi_3_st = Zong_17_st_D0 + "Balance" + "V" ;
          Lin_in_97 = Zong_19_in_EC;
          Lin_st_98 = Zong_21_st_F8;
          Lin_ui_99 = Teal;
          Lin_st_100 = DoubleToString(AccountBalance(), 2) + Zi_1_st;
          if(ObjectFind(Zi_3_st) == -1)
            {
             ObjectCreate(Zi_3_st, OBJ_LABEL, 0, 0, 0.0, 0, 0.0, 0, 0.0);
             ObjectSet(Zi_3_st, OBJPROP_CORNER, Panel_Corner_type);
             ObjectSet(Zi_3_st, OBJPROP_XDISTANCE, 80+Panel_Text_shift+70);
             ObjectSet(Zi_3_st, OBJPROP_YDISTANCE, Zi_4_in);
             ObjectSet(Zi_3_st, OBJPROP_BACK, 0.0);
             ObjectSetString(0, Zi_3_st, 1001, Zong_21_st_F8);
            }
          ObjectSetText(Zi_3_st, Lin_st_100, Lin_in_97, Lin_st_98, Lin_ui_99);
          Zi_2_in ++;
          Zi_4_in += Zong_19_in_EC * 2;
          Zi_3_st = Zong_17_st_D0 + "Equity" + "N" ;
          Lin_in_101 = Zong_19_in_EC;
          Lin_st_102 = Zong_21_st_F8;
          Lin_ui_103 = Teal;
          Lin_st_104 = "账户净值:";
          if(ObjectFind(Zi_3_st) == -1)
            {
             ObjectCreate(Zi_3_st, OBJ_LABEL, 0, 0, 0.0, 0, 0.0, 0, 0.0);
             ObjectSet(Zi_3_st, OBJPROP_CORNER, Panel_Corner_type);
             ObjectSet(Zi_3_st, OBJPROP_XDISTANCE, 230+Panel_Text_shift+5);
             ObjectSet(Zi_3_st, OBJPROP_YDISTANCE, Zi_4_in);
             ObjectSet(Zi_3_st, OBJPROP_BACK, 0.0);
             ObjectSetString(0, Zi_3_st, 1001, Zong_21_st_F8);
            }
          ObjectSetText(Zi_3_st, Lin_st_104, Lin_in_101, Lin_st_102, Lin_ui_103);
          Zi_3_st = Zong_17_st_D0 + "Equity" + "V" ;
          Lin_in_105 = Zong_19_in_EC;
          Lin_st_106 = Zong_21_st_F8;
          Lin_ui_107 = Green;
          Lin_st_108 = DoubleToString(AccountEquity(), 2) + Zi_1_st;
          if(ObjectFind(Zi_3_st) == -1)
            {
             ObjectCreate(Zi_3_st, OBJ_LABEL, 0, 0, 0.0, 0, 0.0, 0, 0.0);
             ObjectSet(Zi_3_st, OBJPROP_CORNER, Panel_Corner_type);
             ObjectSet(Zi_3_st, OBJPROP_XDISTANCE, 80+Panel_Text_shift+70);
             ObjectSet(Zi_3_st, OBJPROP_YDISTANCE, Zi_4_in);
             ObjectSet(Zi_3_st, OBJPROP_BACK, 0.0);
             ObjectSetString(0, Zi_3_st, 1001, Zong_21_st_F8);
            }
          ObjectSetText(Zi_3_st, Lin_st_108, Lin_in_105, Lin_st_106, Lin_ui_107);
          Zi_2_in ++;
          Zi_4_in += Zong_19_in_EC * 2;
          Zi_3_st = Zong_17_st_D0 + "MarginLevel" + "N" ;
          Lin_in_109 = Zong_19_in_EC;
          Lin_st_110 = Zong_21_st_F8;
          Lin_ui_111 = Teal;
          Lin_st_112 = "预付款比例:";
          if(ObjectFind(Zi_3_st) == -1)
            {
             ObjectCreate(Zi_3_st, OBJ_LABEL, 0, 0, 0.0, 0, 0.0, 0, 0.0);
             ObjectSet(Zi_3_st, OBJPROP_CORNER, Panel_Corner_type);
             ObjectSet(Zi_3_st, OBJPROP_XDISTANCE, 218+Panel_Text_shift+17);
             ObjectSet(Zi_3_st, OBJPROP_YDISTANCE, Zi_4_in);
             ObjectSet(Zi_3_st, OBJPROP_BACK, 0.0);
             ObjectSetString(0, Zi_3_st, 1001, Zong_21_st_F8);
            }
          ObjectSetText(Zi_3_st, Lin_st_112, Lin_in_109, Lin_st_110, Lin_ui_111);
          Zi_3_st = Zong_17_st_D0 + "MarginLevel" + "V" ;
          if(AccountMargin() == 0.0)
            {
             Lin_in_113 = Zong_19_in_EC;
             Lin_st_114 = Zong_21_st_F8;
             Lin_ui_115 = DarkBlue;
             Lin_st_116 = "0.00%";
             if(ObjectFind(Zi_3_st) == -1)
               {
                ObjectCreate(Zi_3_st, OBJ_LABEL, 0, 0, 0.0, 0, 0.0, 0, 0.0);
                ObjectSet(Zi_3_st, OBJPROP_CORNER, Panel_Corner_type);
                ObjectSet(Zi_3_st, OBJPROP_XDISTANCE, 80+Panel_Text_shift+50);
                ObjectSet(Zi_3_st, OBJPROP_YDISTANCE, Zi_4_in);
                ObjectSet(Zi_3_st, OBJPROP_BACK, 0.0);
                ObjectSetString(0, Zi_3_st, 1001, Zong_21_st_F8);
               }
             ObjectSetText(Zi_3_st, Lin_st_116, Lin_in_113, Lin_st_114, Lin_ui_115);
            }
          else
            {
             Lin_in_117 = Zong_19_in_EC;
             Lin_st_118 = Zong_21_st_F8;
             Lin_ui_119 = DarkBlue;
             Lin_st_120 = DoubleToString(AccountEquity() / AccountMargin() * 100.0, 2) + "%";
             if(ObjectFind(Zi_3_st) == -1)
               {
                ObjectCreate(Zi_3_st, OBJ_LABEL, 0, 0, 0.0, 0, 0.0, 0, 0.0);
                ObjectSet(Zi_3_st, OBJPROP_CORNER, Panel_Corner_type);
                ObjectSet(Zi_3_st, OBJPROP_XDISTANCE, 80+Panel_Text_shift+50);
                ObjectSet(Zi_3_st, OBJPROP_YDISTANCE, Zi_4_in);
                ObjectSet(Zi_3_st, OBJPROP_BACK, 0.0);
                ObjectSetString(0, Zi_3_st, 1001, Zong_21_st_F8);
               }
             ObjectSetText(Zi_3_st, Lin_st_120, Lin_in_117, Lin_st_118, Lin_ui_119);
            }
          Lin_st_121 = "Lot";
          Lin_in_122 = 0;
          Lin_do_123 = 0.0;
          CPosition buy_buffer(SORT_BY_ORDER_NULL,ORDER_TYPES_BUY_DEAL,Symbol(),Magic,NULL,0,END_TIME);
          Lin_do_123=buy_buffer.m_total.total_volume;

          Zi_6_do = Lin_do_123 ;
          Lin_st_125 = "Lot";
          Lin_in_126 = 1;
          Lin_do_127 = 0.0;

          CPosition sell_buffer(SORT_BY_ORDER_NULL,ORDER_TYPES_SELL_DEAL,Symbol(),Magic,NULL,0,END_TIME);
          Lin_do_127=sell_buffer.m_total.total_volume;

          Zi_7_do = Lin_do_127 ;
          Lin_st_129 = "Profit";
          Lin_in_130 = 0;
          Lin_do_131 = 0.0;

          Lin_do_131=buy_buffer.m_total.profit;

          Zi_8_do = Lin_do_131 ;
          Lin_st_133 = "Profit";
          Lin_in_134 = 1;
          Lin_do_135 = 0.0;
          Lin_do_135=sell_buffer.m_total.profit;

          Zi_9_do = Lin_do_135 ;
          Zi_4_in += Zong_19_in_EC * 2;
          Lin_ui_137 = MistyRose;
          Lin_lo_138 = 0;
          if(ObjectFind(0, Zong_17_st_D0 + "showtotalprofit") <  0)
            {
             ObjectCreate(0, Zong_17_st_D0 + "showtotalprofit", OBJ_RECTANGLE_LABEL, 0, 0, 0.0);
             ObjectSetInteger(0, Zong_17_st_D0 + "showtotalprofit", OBJPROP_XDISTANCE, 190);
             ObjectSetInteger(0, Zong_17_st_D0 + "showtotalprofit", OBJPROP_YDISTANCE, Zi_4_in);
             ObjectSetInteger(0, Zong_17_st_D0 + "showtotalprofit", OBJPROP_XSIZE, 171);
             ObjectSetInteger(0, Zong_17_st_D0 + "showtotalprofit", OBJPROP_YSIZE, 60);
             ObjectSetInteger(0, Zong_17_st_D0 + "showtotalprofit", OBJPROP_BORDER_TYPE, 0);
             ObjectSetInteger(0, Zong_17_st_D0 + "showtotalprofit", OBJPROP_CORNER, Panel_Corner_type);
             ObjectSetInteger(0, Zong_17_st_D0 + "showtotalprofit", OBJPROP_COLOR, 8421376);
             ObjectSetInteger(0, Zong_17_st_D0 + "showtotalprofit", OBJPROP_STYLE, 0);
             ObjectSetInteger(0, Zong_17_st_D0 + "showtotalprofit", OBJPROP_WIDTH, 1);
             ObjectSetInteger(0, Zong_17_st_D0 + "showtotalprofit", OBJPROP_BACK, 0);
             ObjectSetInteger(0, Zong_17_st_D0 + "showtotalprofit", OBJPROP_SELECTABLE, 0);
             ObjectSetInteger(0, Zong_17_st_D0 + "showtotalprofit", OBJPROP_SELECTED, 0);
             ObjectSetInteger(0, Zong_17_st_D0 + "showtotalprofit", OBJPROP_HIDDEN, 1);
             ObjectSetInteger(0, Zong_17_st_D0 + "showtotalprofit", OBJPROP_ZORDER, 0);
            }
          ObjectSetInteger(Lin_lo_138, Zong_17_st_D0 + "showtotalprofit", OBJPROP_BGCOLOR, Lin_ui_137);
          Zi_4_in += Zong_19_in_EC * 2;
          Zi_3_st = Zong_17_st_D0 + "TotalProfit" + "N" ;
          Zi_10_st = Zong_17_st_D0 + "TotalProfit" + "V" ;
          Zi_11_st = Zong_17_st_D0 + "TotalProfit" + "P" ;
          if(Zi_6_do == 0.0 && Zi_7_do == 0.0)
            {
             Lin_in_139 = int(Zong_19_in_EC * 1.5);
             Lin_st_140 = Zong_21_st_F8;
             Lin_ui_141 = Teal;
             Lin_st_142 = "账号空仓:";
             if(ObjectFind(Zi_3_st) == -1)
               {
                ObjectCreate(Zi_3_st, OBJ_LABEL, 0, 0, 0.0, 0, 0.0, 0, 0.0);
                ObjectSet(Zi_3_st, OBJPROP_CORNER, Panel_Corner_type);
                ObjectSet(Zi_3_st, OBJPROP_XDISTANCE, 188+Panel_Text_shift);
                ObjectSet(Zi_3_st, OBJPROP_YDISTANCE, Zi_4_in);
                ObjectSet(Zi_3_st, OBJPROP_BACK, 0.0);
                ObjectSetString(0, Zi_3_st, 1001, Zong_21_st_F8);
               }
             ObjectSetText(Zi_3_st, Lin_st_142, Lin_in_139, Lin_st_140, Lin_ui_141);
             Lin_in_143 = Zong_19_in_EC;
             Lin_st_144 = Zong_21_st_F8;
             Lin_ui_145 = Teal;
             Lin_st_146 = "0.00$";
             if(ObjectFind(Zi_10_st) == -1)
               {
                ObjectCreate(Zi_10_st, OBJ_LABEL, 0, 0, 0.0, 0, 0.0, 0, 0.0);
                ObjectSet(Zi_10_st, OBJPROP_CORNER, Panel_Corner_type);
                ObjectSet(Zi_10_st, OBJPROP_XDISTANCE, 35+Panel_Text_shift);
                ObjectSet(Zi_10_st, OBJPROP_YDISTANCE, Zi_4_in - Zong_19_in_EC);
                ObjectSet(Zi_10_st, OBJPROP_BACK, 0.0);
                ObjectSetString(0, Zi_10_st, 1001, Zong_21_st_F8);
               }
             ObjectSetText(Zi_10_st, Lin_st_146, Lin_in_143, Lin_st_144, Lin_ui_145);
             Lin_in_147 = Zong_19_in_EC;
             Lin_st_148 = Zong_21_st_F8;
             Lin_ui_149 = Teal;
             Lin_st_150 = "0.00%";
             if(ObjectFind(Zi_11_st) == -1)
               {
                ObjectCreate(Zi_11_st, OBJ_LABEL, 0, 0, 0.0, 0, 0.0, 0, 0.0);
                ObjectSet(Zi_11_st, OBJPROP_CORNER, Panel_Corner_type);
                ObjectSet(Zi_11_st, OBJPROP_XDISTANCE, 50+Panel_Text_shift);
                ObjectSet(Zi_11_st, OBJPROP_YDISTANCE, Zi_4_in + Zong_19_in_EC * 2);
                ObjectSet(Zi_11_st, OBJPROP_BACK, 0.0);
                ObjectSetString(0, Zi_11_st, 1001, Zong_21_st_F8);
               }
             ObjectSetText(Zi_11_st, Lin_st_150, Lin_in_147, Lin_st_148, Lin_ui_149);
             ObjectSetText(Zi_3_st, "账号空仓:", int(Zong_19_in_EC * 1.5), Zong_21_st_F8, Teal);
             ObjectSetText(Zi_10_st, "0.00$", int(Zong_19_in_EC * 1.5), Zong_21_st_F8, Teal);
             Lin_ui_151 = Snow;
             Lin_lo_152 = 0;
             if(ObjectFind(0, Zong_17_st_D0 + "showtotalprofit") <  0)
               {
                ObjectCreate(0, Zong_17_st_D0 + "showtotalprofit", OBJ_RECTANGLE_LABEL, 0, 0, 0.0);
                ObjectSetInteger(0, Zong_17_st_D0 + "showtotalprofit", OBJPROP_XDISTANCE, 190);
                ObjectSetInteger(0, Zong_17_st_D0 + "showtotalprofit", OBJPROP_YDISTANCE, Zi_4_in);
                ObjectSetInteger(0, Zong_17_st_D0 + "showtotalprofit", OBJPROP_XSIZE, 171);
                ObjectSetInteger(0, Zong_17_st_D0 + "showtotalprofit", OBJPROP_YSIZE, 60);
                ObjectSetInteger(0, Zong_17_st_D0 + "showtotalprofit", OBJPROP_BORDER_TYPE, 0);
                ObjectSetInteger(0, Zong_17_st_D0 + "showtotalprofit", OBJPROP_CORNER, Panel_Corner_type);
                ObjectSetInteger(0, Zong_17_st_D0 + "showtotalprofit", OBJPROP_COLOR, 8421376);
                ObjectSetInteger(0, Zong_17_st_D0 + "showtotalprofit", OBJPROP_STYLE, 0);
                ObjectSetInteger(0, Zong_17_st_D0 + "showtotalprofit", OBJPROP_WIDTH, 1);
                ObjectSetInteger(0, Zong_17_st_D0 + "showtotalprofit", OBJPROP_BACK, 0);
                ObjectSetInteger(0, Zong_17_st_D0 + "showtotalprofit", OBJPROP_SELECTABLE, 0);
                ObjectSetInteger(0, Zong_17_st_D0 + "showtotalprofit", OBJPROP_SELECTED, 0);
                ObjectSetInteger(0, Zong_17_st_D0 + "showtotalprofit", OBJPROP_HIDDEN, 1);
                ObjectSetInteger(0, Zong_17_st_D0 + "showtotalprofit", OBJPROP_ZORDER, 0);
               }
             ObjectSetInteger(Lin_lo_152, Zong_17_st_D0 + "showtotalprofit", OBJPROP_BGCOLOR, Lin_ui_151);
            }
          else
            {
             if(AccountProfit() > 0.0)
               {
                Lin_in_153 = int(Zong_19_in_EC * 1.5);
                Lin_st_154 = Zong_21_st_F8;
                Lin_ui_155 = DarkGreen;
                Lin_st_156 = "账号盈利:";
                if(ObjectFind(Zi_3_st) == -1)
                  {
                   ObjectCreate(Zi_3_st, OBJ_LABEL, 0, 0, 0.0, 0, 0.0, 0, 0.0);
                   ObjectSet(Zi_3_st, OBJPROP_CORNER, Panel_Corner_type);
                   ObjectSet(Zi_3_st, OBJPROP_XDISTANCE, 188+Panel_Text_shift);
                   ObjectSet(Zi_3_st, OBJPROP_YDISTANCE, Zi_4_in);
                   ObjectSet(Zi_3_st, OBJPROP_BACK, 0.0);
                   ObjectSetString(0, Zi_3_st, 1001, Zong_21_st_F8);
                  }
                ObjectSetText(Zi_3_st, Lin_st_156, Lin_in_153, Lin_st_154, Lin_ui_155);
                Lin_in_157 = Zong_19_in_EC;
                Lin_st_158 = Zong_21_st_F8;
                Lin_ui_159 = DarkGreen;
                Lin_st_160 = DoubleToString(AccountProfit(), 2) + "$";
                if(ObjectFind(Zi_10_st) == -1)
                  {
                   ObjectCreate(Zi_10_st, OBJ_LABEL, 0, 0, 0.0, 0, 0.0, 0, 0.0);
                   ObjectSet(Zi_10_st, OBJPROP_CORNER, Panel_Corner_type);
                   ObjectSet(Zi_10_st, OBJPROP_XDISTANCE, 30+Panel_Text_shift);
                   ObjectSet(Zi_10_st, OBJPROP_YDISTANCE, Zi_4_in - Zong_19_in_EC);
                   ObjectSet(Zi_10_st, OBJPROP_BACK, 0.0);
                   ObjectSetString(0, Zi_10_st, 1001, Zong_21_st_F8);
                  }
                ObjectSetText(Zi_10_st, Lin_st_160, Lin_in_157, Lin_st_158, Lin_ui_159);
                Lin_in_161 = Zong_19_in_EC;
                Lin_st_162 = Zong_21_st_F8;
                Lin_ui_163 = DarkGreen;
                Lin_st_164 = DoubleToString(AccountProfit() / Zong_23_do_108 * 100.0, 2) + "%";
                if(ObjectFind(Zi_11_st) == -1)
                  {
                   ObjectCreate(Zi_11_st, OBJ_LABEL, 0, 0, 0.0, 0, 0.0, 0, 0.0);
                   ObjectSet(Zi_11_st, OBJPROP_CORNER, Panel_Corner_type);
                   ObjectSet(Zi_11_st, OBJPROP_XDISTANCE, 50+Panel_Text_shift);
                   ObjectSet(Zi_11_st, OBJPROP_YDISTANCE, Zi_4_in + Zong_19_in_EC * 2);
                   ObjectSet(Zi_11_st, OBJPROP_BACK, 0.0);
                   ObjectSetString(0, Zi_11_st, 1001, Zong_21_st_F8);
                  }
                ObjectSetText(Zi_11_st, Lin_st_164, Lin_in_161, Lin_st_162, Lin_ui_163);
                ObjectSetText(Zi_3_st, "账号盈利:", int(Zong_19_in_EC * 1.5), Zong_21_st_F8, Brown);
                ObjectSetText(Zi_10_st, DoubleToString(AccountProfit(), 2) + "$", int(Zong_19_in_EC * 1.5), Zong_21_st_F8, Brown);
                Lin_ui_165 = Honeydew;
                Lin_lo_166 = 0;
                if(ObjectFind(0, Zong_17_st_D0 + "showtotalprofit") <  0)
                  {
                   ObjectCreate(0, Zong_17_st_D0 + "showtotalprofit", OBJ_RECTANGLE_LABEL, 0, 0, 0.0);
                   ObjectSetInteger(0, Zong_17_st_D0 + "showtotalprofit", OBJPROP_XDISTANCE, 190);
                   ObjectSetInteger(0, Zong_17_st_D0 + "showtotalprofit", OBJPROP_YDISTANCE, Zi_4_in);
                   ObjectSetInteger(0, Zong_17_st_D0 + "showtotalprofit", OBJPROP_XSIZE, 171);
                   ObjectSetInteger(0, Zong_17_st_D0 + "showtotalprofit", OBJPROP_YSIZE, 60);
                   ObjectSetInteger(0, Zong_17_st_D0 + "showtotalprofit", OBJPROP_BORDER_TYPE, 0);
                   ObjectSetInteger(0, Zong_17_st_D0 + "showtotalprofit", OBJPROP_CORNER, Panel_Corner_type);
                   ObjectSetInteger(0, Zong_17_st_D0 + "showtotalprofit", OBJPROP_COLOR, 8421376);
                   ObjectSetInteger(0, Zong_17_st_D0 + "showtotalprofit", OBJPROP_STYLE, 0);
                   ObjectSetInteger(0, Zong_17_st_D0 + "showtotalprofit", OBJPROP_WIDTH, 1);
                   ObjectSetInteger(0, Zong_17_st_D0 + "showtotalprofit", OBJPROP_BACK, 0);
                   ObjectSetInteger(0, Zong_17_st_D0 + "showtotalprofit", OBJPROP_SELECTABLE, 0);
                   ObjectSetInteger(0, Zong_17_st_D0 + "showtotalprofit", OBJPROP_SELECTED, 0);
                   ObjectSetInteger(0, Zong_17_st_D0 + "showtotalprofit", OBJPROP_HIDDEN, 1);
                   ObjectSetInteger(0, Zong_17_st_D0 + "showtotalprofit", OBJPROP_ZORDER, 0);
                  }
                ObjectSetInteger(Lin_lo_166, Zong_17_st_D0 + "showtotalprofit", OBJPROP_BGCOLOR, Lin_ui_165);
               }
             else
               {
                if(AccountProfit() < 0.0)
                  {
                   Lin_in_167 = int(Zong_19_in_EC * 1.5);
                   Lin_st_168 = Zong_21_st_F8;
                   Lin_ui_169 = Brown;
                   Lin_st_170 = "账号亏损:";
                   if(ObjectFind(Zi_3_st) == -1)
                     {
                      ObjectCreate(Zi_3_st, OBJ_LABEL, 0, 0, 0.0, 0, 0.0, 0, 0.0);
                      ObjectSet(Zi_3_st, OBJPROP_CORNER, Panel_Corner_type);
                      ObjectSet(Zi_3_st, OBJPROP_XDISTANCE, 188+Panel_Text_shift+50);
                      ObjectSet(Zi_3_st, OBJPROP_YDISTANCE, Zi_4_in);
                      ObjectSet(Zi_3_st, OBJPROP_BACK, 0.0);
                      ObjectSetString(0, Zi_3_st, 1001, Zong_21_st_F8);
                     }
                   ObjectSetText(Zi_3_st, Lin_st_170, Lin_in_167, Lin_st_168, Lin_ui_169);
                   Lin_in_171 = Zong_19_in_EC;
                   Lin_st_172 = Zong_21_st_F8;
                   Lin_ui_173 = Brown;
                   Lin_st_174 = DoubleToString(AccountProfit(), 2) + "$";
                   if(ObjectFind(Zi_10_st) == -1)
                     {
                      ObjectCreate(Zi_10_st, OBJ_LABEL, 0, 0, 0.0, 0, 0.0, 0, 0.0);
                      ObjectSet(Zi_10_st, OBJPROP_CORNER, Panel_Corner_type);
                      ObjectSet(Zi_10_st, OBJPROP_XDISTANCE, 30+Panel_Text_shift+20);
                      ObjectSet(Zi_10_st, OBJPROP_YDISTANCE, Zi_4_in - Zong_19_in_EC);
                      ObjectSet(Zi_10_st, OBJPROP_BACK, 0.0);
                      ObjectSetString(0, Zi_10_st, 1001, Zong_21_st_F8);
                     }
                   ObjectSetText(Zi_10_st, Lin_st_174, Lin_in_171, Lin_st_172, Lin_ui_173);
                   Lin_in_175 = Zong_19_in_EC;
                   Lin_st_176 = Zong_21_st_F8;
                   Lin_ui_177 = Brown;
                   Lin_st_178 = DoubleToString(AccountProfit() / Zong_23_do_108 * 100.0, 2) + "%";
                   if(ObjectFind(Zi_11_st) == -1)
                     {
                      ObjectCreate(Zi_11_st, OBJ_LABEL, 0, 0, 0.0, 0, 0.0, 0, 0.0);
                      ObjectSet(Zi_11_st, OBJPROP_CORNER, Panel_Corner_type);
                      ObjectSet(Zi_11_st, OBJPROP_XDISTANCE, 50+Panel_Text_shift);
                      ObjectSet(Zi_11_st, OBJPROP_YDISTANCE, Zi_4_in + Zong_19_in_EC * 2);
                      ObjectSet(Zi_11_st, OBJPROP_BACK, 0.0);
                      ObjectSetString(0, Zi_11_st, 1001, Zong_21_st_F8);
                     }
                   ObjectSetText(Zi_11_st, Lin_st_178, Lin_in_175, Lin_st_176, Lin_ui_177);
                   ObjectSetText(Zi_3_st, "账号亏损:", int(Zong_19_in_EC * 1.5), Zong_21_st_F8, Crimson);
                   ObjectSetText(Zi_10_st, DoubleToString(AccountProfit(), 2) + "$", int(Zong_19_in_EC * 1.5), Zong_21_st_F8, Crimson);
                   Lin_ui_179 = MistyRose;
                   Lin_lo_180 = 0;
                   if(ObjectFind(0, Zong_17_st_D0 + "showtotalprofit") <  0)
                     {
                      ObjectCreate(0, Zong_17_st_D0 + "showtotalprofit", OBJ_RECTANGLE_LABEL, 0, 0, 0.0);
                      ObjectSetInteger(0, Zong_17_st_D0 + "showtotalprofit", OBJPROP_XDISTANCE, 190);
                      ObjectSetInteger(0, Zong_17_st_D0 + "showtotalprofit", OBJPROP_YDISTANCE, Zi_4_in);
                      ObjectSetInteger(0, Zong_17_st_D0 + "showtotalprofit", OBJPROP_XSIZE, 171);
                      ObjectSetInteger(0, Zong_17_st_D0 + "showtotalprofit", OBJPROP_YSIZE, 60);
                      ObjectSetInteger(0, Zong_17_st_D0 + "showtotalprofit", OBJPROP_BORDER_TYPE, 0);
                      ObjectSetInteger(0, Zong_17_st_D0 + "showtotalprofit", OBJPROP_CORNER, Panel_Corner_type);
                      ObjectSetInteger(0, Zong_17_st_D0 + "showtotalprofit", OBJPROP_COLOR, 8421376);
                      ObjectSetInteger(0, Zong_17_st_D0 + "showtotalprofit", OBJPROP_STYLE, 0);
                      ObjectSetInteger(0, Zong_17_st_D0 + "showtotalprofit", OBJPROP_WIDTH, 1);
                      ObjectSetInteger(0, Zong_17_st_D0 + "showtotalprofit", OBJPROP_BACK, 0);
                      ObjectSetInteger(0, Zong_17_st_D0 + "showtotalprofit", OBJPROP_SELECTABLE, 0);
                      ObjectSetInteger(0, Zong_17_st_D0 + "showtotalprofit", OBJPROP_SELECTED, 0);
                      ObjectSetInteger(0, Zong_17_st_D0 + "showtotalprofit", OBJPROP_HIDDEN, 1);
                      ObjectSetInteger(0, Zong_17_st_D0 + "showtotalprofit", OBJPROP_ZORDER, 0);
                     }
                   ObjectSetInteger(Lin_lo_180, Zong_17_st_D0 + "showtotalprofit", OBJPROP_BGCOLOR, Lin_ui_179);
                  }
               }
            }
          Zi_4_in += Zong_19_in_EC * 4;
          Lin_ui_181 = LightCyan;
          Lin_lo_182 = 0;
          if(ObjectFind(0, Zong_17_st_D0 + "EAshowaccountprofit") <  0)
            {
             ObjectCreate(0, Zong_17_st_D0 + "EAshowaccountprofit", OBJ_RECTANGLE_LABEL, 0, 0, 0.0);
             ObjectSetInteger(0, Zong_17_st_D0 + "EAshowaccountprofit", OBJPROP_XDISTANCE, 298);
             ObjectSetInteger(0, Zong_17_st_D0 + "EAshowaccountprofit", OBJPROP_YDISTANCE, Zi_4_in);
             ObjectSetInteger(0, Zong_17_st_D0 + "EAshowaccountprofit", OBJPROP_XSIZE, 280);
             ObjectSetInteger(0, Zong_17_st_D0 + "EAshowaccountprofit", OBJPROP_YSIZE, 60);
             ObjectSetInteger(0, Zong_17_st_D0 + "EAshowaccountprofit", OBJPROP_BORDER_TYPE, 0);
             ObjectSetInteger(0, Zong_17_st_D0 + "EAshowaccountprofit", OBJPROP_CORNER, Panel_Corner_type);
             ObjectSetInteger(0, Zong_17_st_D0 + "EAshowaccountprofit", OBJPROP_COLOR, 8421376);
             ObjectSetInteger(0, Zong_17_st_D0 + "EAshowaccountprofit", OBJPROP_STYLE, 0);
             ObjectSetInteger(0, Zong_17_st_D0 + "EAshowaccountprofit", OBJPROP_WIDTH, 1);
             ObjectSetInteger(0, Zong_17_st_D0 + "EAshowaccountprofit", OBJPROP_BACK, 0);
             ObjectSetInteger(0, Zong_17_st_D0 + "EAshowaccountprofit", OBJPROP_SELECTABLE, 0);
             ObjectSetInteger(0, Zong_17_st_D0 + "EAshowaccountprofit", OBJPROP_SELECTED, 0);
             ObjectSetInteger(0, Zong_17_st_D0 + "EAshowaccountprofit", OBJPROP_HIDDEN, 1);
             ObjectSetInteger(0, Zong_17_st_D0 + "EAshowaccountprofit", OBJPROP_ZORDER, 0);
            }
          ObjectSetInteger(Lin_lo_182, Zong_17_st_D0 + "EAshowaccountprofit", OBJPROP_BGCOLOR, Lin_ui_181);
          Lin_ui_183 = MistyRose;
          Lin_lo_184 = 0;
          if(ObjectFind(0, Zong_17_st_D0 + "EAshowtotalprofit") <  0)
            {
             ObjectCreate(0, Zong_17_st_D0 + "EAshowtotalprofit", OBJ_RECTANGLE_LABEL, 0, 0, 0.0);
             ObjectSetInteger(0, Zong_17_st_D0 + "EAshowtotalprofit", OBJPROP_XDISTANCE, 190);
             ObjectSetInteger(0, Zong_17_st_D0 + "EAshowtotalprofit", OBJPROP_YDISTANCE, Zi_4_in);
             ObjectSetInteger(0, Zong_17_st_D0 + "EAshowtotalprofit", OBJPROP_XSIZE, 171);
             ObjectSetInteger(0, Zong_17_st_D0 + "EAshowtotalprofit", OBJPROP_YSIZE, 60);
             ObjectSetInteger(0, Zong_17_st_D0 + "EAshowtotalprofit", OBJPROP_BORDER_TYPE, 0);
             ObjectSetInteger(0, Zong_17_st_D0 + "EAshowtotalprofit", OBJPROP_CORNER, Panel_Corner_type);
             ObjectSetInteger(0, Zong_17_st_D0 + "EAshowtotalprofit", OBJPROP_COLOR, 8421376);
             ObjectSetInteger(0, Zong_17_st_D0 + "EAshowtotalprofit", OBJPROP_STYLE, 0);
             ObjectSetInteger(0, Zong_17_st_D0 + "EAshowtotalprofit", OBJPROP_WIDTH, 1);
             ObjectSetInteger(0, Zong_17_st_D0 + "EAshowtotalprofit", OBJPROP_BACK, 0);
             ObjectSetInteger(0, Zong_17_st_D0 + "EAshowtotalprofit", OBJPROP_SELECTABLE, 0);
             ObjectSetInteger(0, Zong_17_st_D0 + "EAshowtotalprofit", OBJPROP_SELECTED, 0);
             ObjectSetInteger(0, Zong_17_st_D0 + "EAshowtotalprofit", OBJPROP_HIDDEN, 1);
             ObjectSetInteger(0, Zong_17_st_D0 + "EAshowtotalprofit", OBJPROP_ZORDER, 0);
            }
          ObjectSetInteger(Lin_lo_184, Zong_17_st_D0 + "EAshowtotalprofit", OBJPROP_BGCOLOR, Lin_ui_183);
          Zi_4_in += Zong_19_in_EC * 2;
          Zi_3_st = Zong_17_st_D0 + "EATotalProfit" + "N" ;
          Zi_10_st = Zong_17_st_D0 + "EATotalProfit" + "V" ;
          Zi_11_st = Zong_17_st_D0 + "EATotalProfit" + "P" ;
          if(Zi_6_do == 0.0 && Zi_7_do == 0.0)
            {
             Lin_in_185 = int(Zong_19_in_EC * 1.5);
             Lin_st_186 = Zong_21_st_F8;
             Lin_ui_187 = LightSkyBlue;
             Lin_st_188 = "EA等开仓:";
             if(ObjectFind(Zi_3_st) == -1)
               {
                ObjectCreate(Zi_3_st, OBJ_LABEL, 0, 0, 0.0, 0, 0.0, 0, 0.0);
                ObjectSet(Zi_3_st, OBJPROP_CORNER, Panel_Corner_type);
                ObjectSet(Zi_3_st, OBJPROP_XDISTANCE, 188+Panel_Text_shift+50);
                ObjectSet(Zi_3_st, OBJPROP_YDISTANCE, Zi_4_in);
                ObjectSet(Zi_3_st, OBJPROP_BACK, 0.0);
                ObjectSetString(0, Zi_3_st, 1001, Zong_21_st_F8);
               }
             ObjectSetText(Zi_3_st, Lin_st_188, Lin_in_185, Lin_st_186, Lin_ui_187);
             Lin_in_189 = Zong_19_in_EC;
             Lin_st_190 = Zong_21_st_F8;
             Lin_ui_191 = LightSkyBlue;
             Lin_st_192 = "0.00$";
             if(ObjectFind(Zi_10_st) == -1)
               {
                ObjectCreate(Zi_10_st, OBJ_LABEL, 0, 0, 0.0, 0, 0.0, 0, 0.0);
                ObjectSet(Zi_10_st, OBJPROP_CORNER, Panel_Corner_type);
                ObjectSet(Zi_10_st, OBJPROP_XDISTANCE, 35+Panel_Text_shift+20);
                ObjectSet(Zi_10_st, OBJPROP_YDISTANCE, Zi_4_in - Zong_19_in_EC);
                ObjectSet(Zi_10_st, OBJPROP_BACK, 0.0);
                ObjectSetString(0, Zi_10_st, 1001, Zong_21_st_F8);
               }
             ObjectSetText(Zi_10_st, Lin_st_192, Lin_in_189, Lin_st_190, Lin_ui_191);
             Lin_in_193 = Zong_19_in_EC;
             Lin_st_194 = Zong_21_st_F8;
             Lin_ui_195 = LightSkyBlue;
             Lin_st_196 = "0.00%";
             if(ObjectFind(Zi_11_st) == -1)
               {
                ObjectCreate(Zi_11_st, OBJ_LABEL, 0, 0, 0.0, 0, 0.0, 0, 0.0);
                ObjectSet(Zi_11_st, OBJPROP_CORNER, Panel_Corner_type);
                ObjectSet(Zi_11_st, OBJPROP_XDISTANCE, 50+Panel_Text_shift+20);
                ObjectSet(Zi_11_st, OBJPROP_YDISTANCE, Zi_4_in + Zong_19_in_EC * 2);
                ObjectSet(Zi_11_st, OBJPROP_BACK, 0.0);
                ObjectSetString(0, Zi_11_st, 1001, Zong_21_st_F8);
               }
             ObjectSetText(Zi_11_st, Lin_st_196, Lin_in_193, Lin_st_194, Lin_ui_195);
             ObjectSetText(Zi_3_st, "EA等开仓:", int(Zong_19_in_EC * 1.5), Zong_21_st_F8, LightSkyBlue);
             ObjectSetText(Zi_10_st, "0.00$", int(Zong_19_in_EC * 1.5), Zong_21_st_F8, LightSkyBlue);
             Lin_ui_197 = Snow;
             Lin_lo_198 = 0;
             if(ObjectFind(0, Zong_17_st_D0 + "EAshowtotalprofit") <  0)
               {
                ObjectCreate(0, Zong_17_st_D0 + "EAshowtotalprofit", OBJ_RECTANGLE_LABEL, 0, 0, 0.0);
                ObjectSetInteger(0, Zong_17_st_D0 + "EAshowtotalprofit", OBJPROP_XDISTANCE, 190);
                ObjectSetInteger(0, Zong_17_st_D0 + "EAshowtotalprofit", OBJPROP_YDISTANCE, Zi_4_in);
                ObjectSetInteger(0, Zong_17_st_D0 + "EAshowtotalprofit", OBJPROP_XSIZE, 171);
                ObjectSetInteger(0, Zong_17_st_D0 + "EAshowtotalprofit", OBJPROP_YSIZE, 60);
                ObjectSetInteger(0, Zong_17_st_D0 + "EAshowtotalprofit", OBJPROP_BORDER_TYPE, 0);
                ObjectSetInteger(0, Zong_17_st_D0 + "EAshowtotalprofit", OBJPROP_CORNER, Panel_Corner_type);
                ObjectSetInteger(0, Zong_17_st_D0 + "EAshowtotalprofit", OBJPROP_COLOR, 8421376);
                ObjectSetInteger(0, Zong_17_st_D0 + "EAshowtotalprofit", OBJPROP_STYLE, 0);
                ObjectSetInteger(0, Zong_17_st_D0 + "EAshowtotalprofit", OBJPROP_WIDTH, 1);
                ObjectSetInteger(0, Zong_17_st_D0 + "EAshowtotalprofit", OBJPROP_BACK, 0);
                ObjectSetInteger(0, Zong_17_st_D0 + "EAshowtotalprofit", OBJPROP_SELECTABLE, 0);
                ObjectSetInteger(0, Zong_17_st_D0 + "EAshowtotalprofit", OBJPROP_SELECTED, 0);
                ObjectSetInteger(0, Zong_17_st_D0 + "EAshowtotalprofit", OBJPROP_HIDDEN, 1);
                ObjectSetInteger(0, Zong_17_st_D0 + "EAshowtotalprofit", OBJPROP_ZORDER, 0);
               }
             ObjectSetInteger(Lin_lo_198, Zong_17_st_D0 + "EAshowtotalprofit", OBJPROP_BGCOLOR, Lin_ui_197);
            }
          else
            {
             if(AccountProfit() > 0.0)
               {
                Lin_in_199 = int(Zong_19_in_EC * 1.5);
                Lin_st_200 = Zong_21_st_F8;
                Lin_ui_201 = DarkGreen;
                Lin_st_202 = "EA浮盈:";
                if(ObjectFind(Zi_3_st) == -1)
                  {
                   ObjectCreate(Zi_3_st, OBJ_LABEL, 0, 0, 0.0, 0, 0.0, 0, 0.0);
                   ObjectSet(Zi_3_st, OBJPROP_CORNER, Panel_Corner_type);
                   ObjectSet(Zi_3_st, OBJPROP_XDISTANCE, 188+Panel_Text_shift+50);
                   ObjectSet(Zi_3_st, OBJPROP_YDISTANCE, Zi_4_in);
                   ObjectSet(Zi_3_st, OBJPROP_BACK, 0.0);
                   ObjectSetString(0, Zi_3_st, 1001, Zong_21_st_F8);
                  }
                ObjectSetText(Zi_3_st, Lin_st_202, Lin_in_199, Lin_st_200, Lin_ui_201);
                Lin_in_203 = Zong_19_in_EC;
                Lin_st_204 = Zong_21_st_F8;
                Lin_ui_205 = DarkGreen;
                Lin_st_206 = DoubleToString(Zi_8_do + Zi_9_do, 2) + "$";
                if(ObjectFind(Zi_10_st) == -1)
                  {
                   ObjectCreate(Zi_10_st, OBJ_LABEL, 0, 0, 0.0, 0, 0.0, 0, 0.0);
                   ObjectSet(Zi_10_st, OBJPROP_CORNER, Panel_Corner_type);
                   ObjectSet(Zi_10_st, OBJPROP_XDISTANCE, 30+Panel_Text_shift+20);
                   ObjectSet(Zi_10_st, OBJPROP_YDISTANCE, Zi_4_in - Zong_19_in_EC);
                   ObjectSet(Zi_10_st, OBJPROP_BACK, 0.0);
                   ObjectSetString(0, Zi_10_st, 1001, Zong_21_st_F8);
                  }
                ObjectSetText(Zi_10_st, Lin_st_206, Lin_in_203, Lin_st_204, Lin_ui_205);
                Lin_in_207 = Zong_19_in_EC;
                Lin_st_208 = Zong_21_st_F8;
                Lin_ui_209 = DarkGreen;
                Lin_st_210 = DoubleToString((Zi_8_do + Zi_9_do) / Zong_23_do_108 * 100.0, 2) + "%";
                if(ObjectFind(Zi_11_st) == -1)
                  {
                   ObjectCreate(Zi_11_st, OBJ_LABEL, 0, 0, 0.0, 0, 0.0, 0, 0.0);
                   ObjectSet(Zi_11_st, OBJPROP_CORNER, Panel_Corner_type);
                   ObjectSet(Zi_11_st, OBJPROP_XDISTANCE, 50+Panel_Text_shift+20);
                   ObjectSet(Zi_11_st, OBJPROP_YDISTANCE, Zi_4_in + Zong_19_in_EC * 2);
                   ObjectSet(Zi_11_st, OBJPROP_BACK, 0.0);
                   ObjectSetString(0, Zi_11_st, 1001, Zong_21_st_F8);
                  }
                ObjectSetText(Zi_11_st, Lin_st_210, Lin_in_207, Lin_st_208, Lin_ui_209);
                ObjectSetText(Zi_3_st, "EA浮盈:", int(Zong_19_in_EC * 1.5), Zong_21_st_F8, Brown);
                ObjectSetText(Zi_10_st, DoubleToString(Zi_8_do + Zi_9_do, 2) + "$", int(Zong_19_in_EC * 1.5), Zong_21_st_F8, Brown);
                Lin_ui_211 = Honeydew;
                Lin_lo_212 = 0;
                if(ObjectFind(0, Zong_17_st_D0 + "EAshowtotalprofit") <  0)
                  {
                   ObjectCreate(0, Zong_17_st_D0 + "EAshowtotalprofit", OBJ_RECTANGLE_LABEL, 0, 0, 0.0);
                   ObjectSetInteger(0, Zong_17_st_D0 + "EAshowtotalprofit", OBJPROP_XDISTANCE, 190);
                   ObjectSetInteger(0, Zong_17_st_D0 + "EAshowtotalprofit", OBJPROP_YDISTANCE, Zi_4_in);
                   ObjectSetInteger(0, Zong_17_st_D0 + "EAshowtotalprofit", OBJPROP_XSIZE, 171);
                   ObjectSetInteger(0, Zong_17_st_D0 + "EAshowtotalprofit", OBJPROP_YSIZE, 60);
                   ObjectSetInteger(0, Zong_17_st_D0 + "EAshowtotalprofit", OBJPROP_BORDER_TYPE, 0);
                   ObjectSetInteger(0, Zong_17_st_D0 + "EAshowtotalprofit", OBJPROP_CORNER, Panel_Corner_type);
                   ObjectSetInteger(0, Zong_17_st_D0 + "EAshowtotalprofit", OBJPROP_COLOR, 8421376);
                   ObjectSetInteger(0, Zong_17_st_D0 + "EAshowtotalprofit", OBJPROP_STYLE, 0);
                   ObjectSetInteger(0, Zong_17_st_D0 + "EAshowtotalprofit", OBJPROP_WIDTH, 1);
                   ObjectSetInteger(0, Zong_17_st_D0 + "EAshowtotalprofit", OBJPROP_BACK, 0);
                   ObjectSetInteger(0, Zong_17_st_D0 + "EAshowtotalprofit", OBJPROP_SELECTABLE, 0);
                   ObjectSetInteger(0, Zong_17_st_D0 + "EAshowtotalprofit", OBJPROP_SELECTED, 0);
                   ObjectSetInteger(0, Zong_17_st_D0 + "EAshowtotalprofit", OBJPROP_HIDDEN, 1);
                   ObjectSetInteger(0, Zong_17_st_D0 + "EAshowtotalprofit", OBJPROP_ZORDER, 0);
                  }
                ObjectSetInteger(Lin_lo_212, Zong_17_st_D0 + "EAshowtotalprofit", OBJPROP_BGCOLOR, Lin_ui_211);
               }
             else
               {
                if(AccountProfit() < 0.0)
                  {
                   Lin_in_213 = int(Zong_19_in_EC * 1.5);
                   Lin_st_214 = Zong_21_st_F8;
                   Lin_ui_215 = Brown;
                   Lin_st_216 = "EA浮亏:";
                   if(ObjectFind(Zi_3_st) == -1)
                     {
                      ObjectCreate(Zi_3_st, OBJ_LABEL, 0, 0, 0.0, 0, 0.0, 0, 0.0);
                      ObjectSet(Zi_3_st, OBJPROP_CORNER, Panel_Corner_type);
                      ObjectSet(Zi_3_st, OBJPROP_XDISTANCE, 188+Panel_Text_shift+50);
                      ObjectSet(Zi_3_st, OBJPROP_YDISTANCE, Zi_4_in);
                      ObjectSet(Zi_3_st, OBJPROP_BACK, 0.0);
                      ObjectSetString(0, Zi_3_st, 1001, Zong_21_st_F8);
                     }
                   ObjectSetText(Zi_3_st, Lin_st_216, Lin_in_213, Lin_st_214, Lin_ui_215);
                   Lin_in_217 = Zong_19_in_EC;
                   Lin_st_218 = Zong_21_st_F8;
                   Lin_ui_219 = Brown;
                   Lin_st_220 = DoubleToString(Zi_8_do + Zi_9_do, 2) + "$";
                   if(ObjectFind(Zi_10_st) == -1)
                     {
                      ObjectCreate(Zi_10_st, OBJ_LABEL, 0, 0, 0.0, 0, 0.0, 0, 0.0);
                      ObjectSet(Zi_10_st, OBJPROP_CORNER, Panel_Corner_type);
                      ObjectSet(Zi_10_st, OBJPROP_XDISTANCE, 30+Panel_Text_shift+20);
                      ObjectSet(Zi_10_st, OBJPROP_YDISTANCE, Zi_4_in - Zong_19_in_EC);
                      ObjectSet(Zi_10_st, OBJPROP_BACK, 0.0);
                      ObjectSetString(0, Zi_10_st, 1001, Zong_21_st_F8);
                     }
                   ObjectSetText(Zi_10_st, Lin_st_220, Lin_in_217, Lin_st_218, Lin_ui_219);
                   Lin_in_221 = Zong_19_in_EC;
                   Lin_st_222 = Zong_21_st_F8;
                   Lin_ui_223 = Brown;
                   Lin_st_224 = DoubleToString((Zi_8_do + Zi_9_do) / Zong_23_do_108 * 100.0, 2) + "%";
                   if(ObjectFind(Zi_11_st) == -1)
                     {
                      ObjectCreate(Zi_11_st, OBJ_LABEL, 0, 0, 0.0, 0, 0.0, 0, 0.0);
                      ObjectSet(Zi_11_st, OBJPROP_CORNER, Panel_Corner_type);
                      ObjectSet(Zi_11_st, OBJPROP_XDISTANCE, 50+Panel_Text_shift+20);
                      ObjectSet(Zi_11_st, OBJPROP_YDISTANCE, Zi_4_in + Zong_19_in_EC * 2);
                      ObjectSet(Zi_11_st, OBJPROP_BACK, 0.0);
                      ObjectSetString(0, Zi_11_st, 1001, Zong_21_st_F8);
                     }
                   ObjectSetText(Zi_11_st, Lin_st_224, Lin_in_221, Lin_st_222, Lin_ui_223);
                   ObjectSetText(Zi_3_st, "EA浮亏:", int(Zong_19_in_EC * 1.5), Zong_21_st_F8, Crimson);
                   ObjectSetText(Zi_10_st, DoubleToString(Zi_8_do + Zi_9_do, 2) + "$", int(Zong_19_in_EC * 1.5), Zong_21_st_F8, Crimson);
                   Lin_ui_225 = MistyRose;
                   Lin_lo_226 = 0;
                   if(ObjectFind(0, Zong_17_st_D0 + "EAshowtotalprofit") <  0)
                     {
                      ObjectCreate(0, Zong_17_st_D0 + "EAshowtotalprofit", OBJ_RECTANGLE_LABEL, 0, 0, 0.0);
                      ObjectSetInteger(0, Zong_17_st_D0 + "EAshowtotalprofit", OBJPROP_XDISTANCE, 190);
                      ObjectSetInteger(0, Zong_17_st_D0 + "EAshowtotalprofit", OBJPROP_YDISTANCE, Zi_4_in);
                      ObjectSetInteger(0, Zong_17_st_D0 + "EAshowtotalprofit", OBJPROP_XSIZE, 171);
                      ObjectSetInteger(0, Zong_17_st_D0 + "EAshowtotalprofit", OBJPROP_YSIZE, 60);
                      ObjectSetInteger(0, Zong_17_st_D0 + "EAshowtotalprofit", OBJPROP_BORDER_TYPE, 0);
                      ObjectSetInteger(0, Zong_17_st_D0 + "EAshowtotalprofit", OBJPROP_CORNER, Panel_Corner_type);
                      ObjectSetInteger(0, Zong_17_st_D0 + "EAshowtotalprofit", OBJPROP_COLOR, 8421376);
                      ObjectSetInteger(0, Zong_17_st_D0 + "EAshowtotalprofit", OBJPROP_STYLE, 0);
                      ObjectSetInteger(0, Zong_17_st_D0 + "EAshowtotalprofit", OBJPROP_WIDTH, 1);
                      ObjectSetInteger(0, Zong_17_st_D0 + "EAshowtotalprofit", OBJPROP_BACK, 0);
                      ObjectSetInteger(0, Zong_17_st_D0 + "EAshowtotalprofit", OBJPROP_SELECTABLE, 0);
                      ObjectSetInteger(0, Zong_17_st_D0 + "EAshowtotalprofit", OBJPROP_SELECTED, 0);
                      ObjectSetInteger(0, Zong_17_st_D0 + "EAshowtotalprofit", OBJPROP_HIDDEN, 1);
                      ObjectSetInteger(0, Zong_17_st_D0 + "EAshowtotalprofit", OBJPROP_ZORDER, 0);
                     }
                   ObjectSetInteger(Lin_lo_226, Zong_17_st_D0 + "EAshowtotalprofit", OBJPROP_BGCOLOR, Lin_ui_225);
                  }
               }
            }
          Zi_4_in += Zong_19_in_EC * 4;
          Zi_4_in = int(Zi_4_in + Zong_19_in_EC * 0.5) ;
          Zi_3_st = Zong_17_st_D0 + "BuyOrders" + "N" ;
          Lin_in_227 = Zong_19_in_EC;
          Lin_st_228 = Zong_21_st_F8;
          Lin_ui_229 = CadetBlue;
          Lin_st_230 = "买单:";
          if(ObjectFind(Zi_3_st) == -1)
            {
             ObjectCreate(Zi_3_st, OBJ_LABEL, 0, 0, 0.0, 0, 0.0, 0, 0.0);
             ObjectSet(Zi_3_st, OBJPROP_CORNER, Panel_Corner_type);
             ObjectSet(Zi_3_st, OBJPROP_XDISTANCE, 255+Panel_Text_shift-10);
             ObjectSet(Zi_3_st, OBJPROP_YDISTANCE, Zi_4_in);
             ObjectSet(Zi_3_st, OBJPROP_BACK, 0.0);
             ObjectSetString(0, Zi_3_st, 1001, Zong_21_st_F8);
            }
          ObjectSetText(Zi_3_st, Lin_st_230, Lin_in_227, Lin_st_228, Lin_ui_229);
          Zi_3_st = Zong_17_st_D0 + "BuyOrders" + "L" ;
          Lin_in_231 = Zong_19_in_EC;
          Lin_st_232 = Zong_21_st_F8;
          Lin_ui_233 = DarkBlue;
          Lin_st_234 = DoubleToString(Zi_6_do, 2) + "手";
          if(ObjectFind(Zi_3_st) == -1)
            {
             ObjectCreate(Zi_3_st, OBJ_LABEL, 0, 0, 0.0, 0, 0.0, 0, 0.0);
             ObjectSet(Zi_3_st, OBJPROP_CORNER, Panel_Corner_type);
             ObjectSet(Zi_3_st, OBJPROP_XDISTANCE, 120+Panel_Text_shift+20);
             ObjectSet(Zi_3_st, OBJPROP_YDISTANCE, Zi_4_in);
             ObjectSet(Zi_3_st, OBJPROP_BACK, 0.0);
             ObjectSetString(0, Zi_3_st, 1001, Zong_21_st_F8);
            }
          ObjectSetText(Zi_3_st, Lin_st_234, Lin_in_231, Lin_st_232, Lin_ui_233);
          Zi_3_st = Zong_17_st_D0 + "BuyOrders" + "P" ;
          Lin_in_235 = Zong_19_in_EC;
          Lin_st_236 = Zong_21_st_F8;
          Lin_in_237 = Panel_Corner_type;
          Lin_ui_238 = (Zi_8_do >= 0.0) ? 9109504 : 3937500 ;
          Lin_st_239 = DoubleToString(Zi_8_do, 2) + Zi_1_st;
          if(ObjectFind(Zi_3_st) == -1)
            {
             ObjectCreate(Zi_3_st, OBJ_LABEL, 0, 0, 0.0, 0, 0.0, 0, 0.0);
             ObjectSet(Zi_3_st, OBJPROP_CORNER, Lin_in_237);
             ObjectSet(Zi_3_st, OBJPROP_XDISTANCE, 25+Panel_Text_shift+20);
             ObjectSet(Zi_3_st, OBJPROP_YDISTANCE, Zi_4_in);
             ObjectSet(Zi_3_st, OBJPROP_BACK, 0.0);
             ObjectSetString(0, Zi_3_st, 1001, Lin_st_236);
            }
          ObjectSetText(Zi_3_st, Lin_st_239, Lin_in_235, Lin_st_236, Lin_ui_238);
          Zi_2_in ++;
          Zi_4_in += Zong_19_in_EC * 2;
          Zi_3_st = Zong_17_st_D0 + "SellOrders" + "N" ;
          Lin_in_240 = Zong_19_in_EC;
          Lin_st_241 = Zong_21_st_F8;
          Lin_ui_242 = Tomato;
          Lin_st_243 = "卖单:";
          if(ObjectFind(Zi_3_st) == -1)
            {
             ObjectCreate(Zi_3_st, OBJ_LABEL, 0, 0, 0.0, 0, 0.0, 0, 0.0);
             ObjectSet(Zi_3_st, OBJPROP_CORNER, Panel_Corner_type);
             ObjectSet(Zi_3_st, OBJPROP_XDISTANCE, 255+Panel_Text_shift-10);
             ObjectSet(Zi_3_st, OBJPROP_YDISTANCE, Zi_4_in);
             ObjectSet(Zi_3_st, OBJPROP_BACK, 0.0);
             ObjectSetString(0, Zi_3_st, 1001, Zong_21_st_F8);
            }
          ObjectSetText(Zi_3_st, Lin_st_243, Lin_in_240, Lin_st_241, Lin_ui_242);
          Zi_3_st = Zong_17_st_D0 + "SellOrders" + "L" ;
          Lin_in_244 = Zong_19_in_EC;
          Lin_st_245 = Zong_21_st_F8;
          Lin_ui_246 = Tomato;
          Lin_st_247 = DoubleToString(Zi_7_do, 2) + "手";
          if(ObjectFind(Zi_3_st) == -1)
            {
             ObjectCreate(Zi_3_st, OBJ_LABEL, 0, 0, 0.0, 0, 0.0, 0, 0.0);
             ObjectSet(Zi_3_st, OBJPROP_CORNER, Panel_Corner_type);
             ObjectSet(Zi_3_st, OBJPROP_XDISTANCE, 120+Panel_Text_shift+20);
             ObjectSet(Zi_3_st, OBJPROP_YDISTANCE, Zi_4_in);
             ObjectSet(Zi_3_st, OBJPROP_BACK, 0.0);
             ObjectSetString(0, Zi_3_st, 1001, Zong_21_st_F8);
            }
          ObjectSetText(Zi_3_st, Lin_st_247, Lin_in_244, Lin_st_245, Lin_ui_246);
          Zi_3_st = Zong_17_st_D0 + "SellOrders" + "P" ;
          Lin_in_248 = Zong_19_in_EC;
          Lin_st_249 = Zong_21_st_F8;
          Lin_in_250 = Panel_Corner_type;
          Lin_ui_251 = (Zi_9_do >= 0.0) ? 9109504 : 3937500 ;
          Lin_st_252 = DoubleToString(Zi_9_do, 2) + Zi_1_st;
          if(ObjectFind(Zi_3_st) == -1)
            {
             ObjectCreate(Zi_3_st, OBJ_LABEL, 0, 0, 0.0, 0, 0.0, 0, 0.0);
             ObjectSet(Zi_3_st, OBJPROP_CORNER, Lin_in_250);
             ObjectSet(Zi_3_st, OBJPROP_XDISTANCE, 25+Panel_Text_shift+20);
             ObjectSet(Zi_3_st, OBJPROP_YDISTANCE, Zi_4_in);
             ObjectSet(Zi_3_st, OBJPROP_BACK, 0.0);
             ObjectSetString(0, Zi_3_st, 1001, Lin_st_249);
            }
          ObjectSetText(Zi_3_st, Lin_st_252, Lin_in_248, Lin_st_249, Lin_ui_251);
          Zi_2_in ++;
          Zi_4_in += Zong_19_in_EC * 2;
          Zi_3_st = Zong_17_st_D0 + "AllOrders" + "N" ;
          Lin_in_253 = Zong_19_in_EC;
          Lin_st_254 = Zong_21_st_F8;
          Lin_ui_255 = Green;
          Lin_st_256 = "总共:";
          if(ObjectFind(Zi_3_st) == -1)
            {
             ObjectCreate(Zi_3_st, OBJ_LABEL, 0, 0, 0.0, 0, 0.0, 0, 0.0);
             ObjectSet(Zi_3_st, OBJPROP_CORNER, Panel_Corner_type);
             ObjectSet(Zi_3_st, OBJPROP_XDISTANCE, 255+Panel_Text_shift-10);
             ObjectSet(Zi_3_st, OBJPROP_YDISTANCE, Zi_4_in);
             ObjectSet(Zi_3_st, OBJPROP_BACK, 0.0);
             ObjectSetString(0, Zi_3_st, 1001, Zong_21_st_F8);
            }
          ObjectSetText(Zi_3_st, Lin_st_256, Lin_in_253, Lin_st_254, Lin_ui_255);
          Zi_3_st = Zong_17_st_D0 + "AllOrders" + "L" ;
          Lin_in_257 = Zong_19_in_EC;
          Lin_st_258 = Zong_21_st_F8;
          Lin_ui_259 = DarkBlue;
          Lin_st_260 = DoubleToString(Zi_6_do + Zi_7_do, 2) + "手";
          if(ObjectFind(Zi_3_st) == -1)
            {
             ObjectCreate(Zi_3_st, OBJ_LABEL, 0, 0, 0.0, 0, 0.0, 0, 0.0);
             ObjectSet(Zi_3_st, OBJPROP_CORNER, Panel_Corner_type);
             ObjectSet(Zi_3_st, OBJPROP_XDISTANCE, 120+Panel_Text_shift+20);
             ObjectSet(Zi_3_st, OBJPROP_YDISTANCE, Zi_4_in);
             ObjectSet(Zi_3_st, OBJPROP_BACK, 0.0);
             ObjectSetString(0, Zi_3_st, 1001, Zong_21_st_F8);
            }
          ObjectSetText(Zi_3_st, Lin_st_260, Lin_in_257, Lin_st_258, Lin_ui_259);
          Zi_3_st = Zong_17_st_D0 + "AllOrders" + "P" ;
          Lin_in_261 = Zong_19_in_EC;
          Lin_st_262 = Zong_21_st_F8;
          Lin_in_263 = Panel_Corner_type;
          Lin_ui_264 = (Zi_8_do + Zi_9_do >= 0.0) ? 9109504 : 3937500 ;
          Lin_st_265 = DoubleToString(Zi_8_do + Zi_9_do, 2) + Zi_1_st;
          if(ObjectFind(Zi_3_st) == -1)
            {
             ObjectCreate(Zi_3_st, OBJ_LABEL, 0, 0, 0.0, 0, 0.0, 0, 0.0);
             ObjectSet(Zi_3_st, OBJPROP_CORNER, Lin_in_263);
             ObjectSet(Zi_3_st, OBJPROP_XDISTANCE, 25+Panel_Text_shift+20);
             ObjectSet(Zi_3_st, OBJPROP_YDISTANCE, Zi_4_in);
             ObjectSet(Zi_3_st, OBJPROP_BACK, 0.0);
             ObjectSetString(0, Zi_3_st, 1001, Lin_st_262);
            }
          ObjectSetText(Zi_3_st, Lin_st_265, Lin_in_261, Lin_st_262, Lin_ui_264);
          Zi_4_in = int(Zi_4_in + Zong_19_in_EC * 2.5) ;
          Lin_ui_266 = PowderBlue;
          Lin_lo_267 = 0;
          if(ObjectFind(0, Zong_17_st_D0 + "Separetor1") <  0)
            {
             ObjectCreate(0, Zong_17_st_D0 + "Separetor1", OBJ_RECTANGLE_LABEL, 0, 0, 0.0);
             ObjectSetInteger(0, Zong_17_st_D0 + "Separetor1", OBJPROP_XDISTANCE, 298);
             ObjectSetInteger(0, Zong_17_st_D0 + "Separetor1", OBJPROP_YDISTANCE, Zi_4_in);
             ObjectSetInteger(0, Zong_17_st_D0 + "Separetor1", OBJPROP_XSIZE, 280);
             ObjectSetInteger(0, Zong_17_st_D0 + "Separetor1", OBJPROP_YSIZE, 1);
             ObjectSetInteger(0, Zong_17_st_D0 + "Separetor1", OBJPROP_BORDER_TYPE, 0);
             ObjectSetInteger(0, Zong_17_st_D0 + "Separetor1", OBJPROP_CORNER, Panel_Corner_type);
             ObjectSetInteger(0, Zong_17_st_D0 + "Separetor1", OBJPROP_COLOR, 15453831);
             ObjectSetInteger(0, Zong_17_st_D0 + "Separetor1", OBJPROP_STYLE, 0);
             ObjectSetInteger(0, Zong_17_st_D0 + "Separetor1", OBJPROP_WIDTH, 1);
             ObjectSetInteger(0, Zong_17_st_D0 + "Separetor1", OBJPROP_BACK, 0);
             ObjectSetInteger(0, Zong_17_st_D0 + "Separetor1", OBJPROP_SELECTABLE, 0);
             ObjectSetInteger(0, Zong_17_st_D0 + "Separetor1", OBJPROP_SELECTED, 0);
             ObjectSetInteger(0, Zong_17_st_D0 + "Separetor1", OBJPROP_HIDDEN, 1);
             ObjectSetInteger(0, Zong_17_st_D0 + "Separetor1", OBJPROP_ZORDER, 0);
            }
          ObjectSetInteger(Lin_lo_267, Zong_17_st_D0 + "Separetor1", OBJPROP_BGCOLOR, Lin_ui_266);
          Zi_4_in = int(Zi_4_in + Zong_19_in_EC * 0.5);
          Zi_3_st = Zong_17_st_D0 + "copyright" + "N" ;
          Lin_in_268 = Zong_19_in_EC;
          Lin_st_269 = Zong_21_st_F8;
          Lin_ui_270 = Green;
          Lin_st_271 = MQLInfoString(MQL_PROGRAM_NAME);
          if(ObjectFind(Zi_3_st) == -1)
            {
             ObjectCreate(Zi_3_st, OBJ_LABEL, 0, 0, 0.0, 0, 0.0, 0, 0.0);
             ObjectSet(Zi_3_st, OBJPROP_CORNER, Panel_Corner_type);
             ObjectSet(Zi_3_st, OBJPROP_XDISTANCE, 125+Panel_Text_shift+100);
             ObjectSet(Zi_3_st, OBJPROP_YDISTANCE, Zi_4_in);
             ObjectSet(Zi_3_st, OBJPROP_BACK, 0.0);
             ObjectSetString(0, Zi_3_st, 1001, Zong_21_st_F8);
            }
          ObjectSetText(Zi_3_st, Lin_st_271, Lin_in_268, Lin_st_269, Lin_ui_270);
          Zi_4_in += Zong_19_in_EC * 2;
          Zi_3_st = Zong_17_st_D0 + "Expiration" + "N" ;
          Lin_in_272 = Zong_19_in_EC;
          Lin_st_273 = Zong_21_st_F8;
          Lin_ui_274 = Green;
          Lin_st_275 = " "; // "授权剩余时间:";
          /*
          if(ObjectFind(Zi_3_st) == -1)
            {
             ObjectCreate(Zi_3_st, OBJ_LABEL, 0, 0, 0.0, 0, 0.0, 0, 0.0);
             ObjectSet(Zi_3_st, OBJPROP_CORNER, Panel_Corner_type);
             ObjectSet(Zi_3_st, OBJPROP_XDISTANCE, 203+Panel_Text_shift+20);
             ObjectSet(Zi_3_st, OBJPROP_YDISTANCE, Zi_4_in);
             ObjectSet(Zi_3_st, OBJPROP_BACK, 0.0);
             ObjectSetString(0, Zi_3_st, 1001, Zong_21_st_F8);
            }
          ObjectSetText(Zi_3_st, Lin_st_275, Lin_in_272, Lin_st_273, Lin_ui_274);
          Zi_3_st = Zong_17_st_D0 + "Expiration" + "V" ;
          Lin_in_276 = Zong_19_in_EC;
          Lin_st_277 = Zong_21_st_F8;
          Lin_ui_278 = Green;
          Lin_st_279 = "";//string(Zong_14_in_C8) + "天";
          if(ObjectFind(Zi_3_st) == -1)
            {
             ObjectCreate(Zi_3_st, OBJ_LABEL, 0, 0, 0.0, 0, 0.0, 0, 0.0);
             ObjectSet(Zi_3_st, OBJPROP_CORNER, Panel_Corner_type);
             ObjectSet(Zi_3_st, OBJPROP_XDISTANCE, 155+Panel_Text_shift+20);
             ObjectSet(Zi_3_st, OBJPROP_YDISTANCE, Zi_4_in);
             ObjectSet(Zi_3_st, OBJPROP_BACK, 0.0);
             ObjectSetString(0, Zi_3_st, 1001, Zong_21_st_F8);
            }
          ObjectSetText(Zi_3_st, Lin_st_279, Lin_in_276, Lin_st_277, Lin_ui_278);
            */
          Zi_12_st = "▼" ;
          if(Zong_16_bo_CD == true)
            {
             Zi_12_st = "▲" ;
            }
          lizong_22(Zong_17_st_D0 + "OpenBoard", Zi_12_st, Zi_12_st, 80, Zi_4_in, 40, 20, Panel_Corner_type, 0, 0, Snow, Snow, Zong_21_st_F8, Zong_19_in_EC);
         }
       Zong_24_in_110 = Zi_4_in + Zong_19_in_EC + 25;
       WindowRedraw();
      }
    //lizong_20 <<==--------   --------
    void lizong_21(long Mu_0_lo, string Mu_1_st, int Mu_2_in, int Mu_3_in, int Mu_4_in, int Mu_5_in, int Mu_6_in, string Mu_7_st, string Mu_8_st, int Mu_9_in, bool Mu_10_bo)
      {
       int       Zi_1_in;
       int       Zi_2_in;
    //----- -----
       Zi_1_in = (int) ChartGetInteger(Mu_0_lo, 106, 0) ;
       Zi_2_in = (Zi_1_in - Mu_5_in) / 2;
       if(Mu_3_in != 0)
         {
          Zi_2_in = Mu_3_in ;
         }
       if(ObjectFind(Mu_0_lo, Mu_1_st) <  0)
         {
          ObjectCreate(Mu_0_lo, Mu_1_st, OBJ_BITMAP_LABEL, 0, 0, 0.0);
          ObjectSetString(Mu_0_lo, Mu_1_st, OBJPROP_BMPFILE, 0, Mu_7_st);
          ObjectSetString(Mu_0_lo, Mu_1_st, OBJPROP_BMPFILE, 1, Mu_8_st);
          ObjectSetInteger(Mu_0_lo, Mu_1_st, OBJPROP_XDISTANCE, Zi_2_in);
          ObjectSetInteger(Mu_0_lo, Mu_1_st, OBJPROP_YDISTANCE, Mu_4_in);
          ObjectSetInteger(Mu_0_lo, Mu_1_st, OBJPROP_XSIZE, Mu_5_in);
          ObjectSetInteger(Mu_0_lo, Mu_1_st, OBJPROP_YSIZE, Mu_6_in);
          ObjectSetInteger(Mu_0_lo, Mu_1_st, OBJPROP_XOFFSET, 0);
          ObjectSetInteger(Mu_0_lo, Mu_1_st, OBJPROP_YOFFSET, 0);
          ObjectSetInteger(Mu_0_lo, Mu_1_st, OBJPROP_STATE, 0);
          ObjectSetInteger(Mu_0_lo, Mu_1_st, OBJPROP_ANCHOR, Mu_9_in);
          ObjectSetInteger(Mu_0_lo, Mu_1_st, OBJPROP_COLOR, 255);
          ObjectSetInteger(Mu_0_lo, Mu_1_st, OBJPROP_STYLE, 0);
          ObjectSetInteger(Mu_0_lo, Mu_1_st, OBJPROP_WIDTH, 1);
          ObjectSetInteger(Mu_0_lo, Mu_1_st, OBJPROP_BACK, Mu_10_bo);
          ObjectSetInteger(Mu_0_lo, Mu_1_st, OBJPROP_SELECTABLE, 1);
          ObjectSetInteger(Mu_0_lo, Mu_1_st, OBJPROP_SELECTED, 0);
          ObjectSetInteger(Mu_0_lo, Mu_1_st, OBJPROP_HIDDEN, 1);
          ObjectSetInteger(Mu_0_lo, Mu_1_st, OBJPROP_CORNER, Mu_9_in);
          ObjectSetInteger(Mu_0_lo, Mu_1_st, OBJPROP_ZORDER, 0);
         }
       ObjectSetInteger(Mu_0_lo, Mu_1_st, OBJPROP_XDISTANCE, Zi_2_in);
      }
    //lizong_21 <<==--------   --------
    void lizong_22(string Mu_0_st, string Mu_1_st, string Mu_2_st, int Mu_3_in, int Mu_4_in, int Mu_5_in, int Mu_6_in, int Mu_7_in, uint Mu_8_ui, uint Mu_9_ui, uint Mu_10_ui, uint Mu_11_ui, string Mu_12_st, int Mu_13_in, bool set_state = false, bool state = false)
      {
       if(ObjectFind(0, Mu_0_st) == -1)
         {
          ObjectCreate(0, Mu_0_st, OBJ_BUTTON, 0, 0, 0.0);
         }
       ObjectSetInteger(0, Mu_0_st, OBJPROP_XDISTANCE, Mu_3_in);
       ObjectSetInteger(0, Mu_0_st, OBJPROP_YDISTANCE, Mu_4_in);
       ObjectSetInteger(0, Mu_0_st, OBJPROP_XSIZE, Mu_5_in);
       ObjectSetInteger(0, Mu_0_st, OBJPROP_YSIZE, Mu_6_in);
       ObjectSetString(0, Mu_0_st, OBJPROP_FONT, Mu_12_st);
       ObjectSetInteger(0, Mu_0_st, OBJPROP_FONTSIZE, Mu_13_in);
       ObjectSetInteger(0, Mu_0_st, OBJPROP_CORNER, Mu_7_in);
       ObjectSetInteger(0, Mu_0_st, OBJPROP_HIDDEN, 1);
       ObjectSetInteger(0, Mu_0_st, OBJPROP_BACK, 0);
       ObjectSetInteger(0, Mu_0_st, OBJPROP_SELECTABLE, 0);
       ObjectSetInteger(0, Mu_0_st, OBJPROP_SELECTED, 0);
       ObjectSetInteger(0, Mu_0_st, OBJPROP_ZORDER, 1);
       ObjectSetInteger(0, Mu_0_st, OBJPROP_BORDER_TYPE, 0);
       if(set_state == true)
          ObjectSetInteger(0, Mu_0_st, OBJPROP_STATE, state);
       if(ObjectGetInteger(0, Mu_0_st, OBJPROP_STATE, 0) == 1)
         {
          ObjectSetInteger(0, Mu_0_st, OBJPROP_COLOR, Mu_8_ui);
          ObjectSetInteger(0, Mu_0_st, OBJPROP_BGCOLOR, Mu_10_ui);
          ObjectSetInteger(0, Mu_0_st, OBJPROP_BORDER_COLOR, Mu_10_ui);
          ObjectSetString(0, Mu_0_st, OBJPROP_TEXT, Mu_2_st);
          return;
         }
       ObjectSetInteger(0, Mu_0_st, OBJPROP_COLOR, Mu_9_ui);
       ObjectSetInteger(0, Mu_0_st, OBJPROP_BGCOLOR, Mu_11_ui);
       ObjectSetInteger(0, Mu_0_st, OBJPROP_BORDER_COLOR, Mu_11_ui);
       ObjectSetString(0, Mu_0_st, OBJPROP_TEXT, Mu_1_st);
      }
    //<<==lizong_22 <<==
    //+------------------------------------------------------------------+
    //|                                                                  |
    //+------------------------------------------------------------------+
    bool UseCheck()
      {
       bool res = false;
       string   accountErrorPrompt;
       string   timeErrorPrompt;
       string   promptMsg = "";
       string   useAccount[];
       string   setAccount = Bind_Account;
       datetime useExpiration = Use_Expiration_Time;
       bool     accountSW = Account_Control;
       bool     expirationSW = Time_Control;
       accountErrorPrompt = Account_Error_Reminder_Content;
       timeErrorPrompt = The_Deadline_Has_Reached_The_Reminder_Content;
       promptMsg = accountErrorPrompt;
       string separator = "+";
       ushort separatorUshort;
       if(accountSW == true)
         {
          separatorUshort = StringGetCharacter(separator, 0);
          int k = StringSplit(setAccount, separatorUshort, useAccount);
          for(int i = 0; i < k; i++)
            {
             if(AccountInfoInteger(ACCOUNT_LOGIN) == int(useAccount))
               {
                promptMsg = "";
                res = true;
                break;
               }
            }
         }
       else
         {
          promptMsg = "";
          res = true;
         }
       if(expirationSW == true && TimeCurrent() > useExpiration)
         {
          if(promptMsg != "")
             promptMsg = promptMsg + "\n" + timeErrorPrompt;
          else
             promptMsg = promptMsg + timeErrorPrompt;
          res = false;
         }
       if(res == false)
         {
          Alert(promptMsg);
         }
       return(res);
      }
    //+------------------------------------------------------------------+
    //|                                                                  |
    //+------------------------------------------------------------------+
    int StringSplit(string string_value, string & result[], string separator, string SEP = NULL)
      {
       StringTrimLeft(string_value);
       StringTrimRight(string_value);
       if(SEP != NULL)
          StringReplace(string_value, SEP, separator);
       ArrayFree(result);
       ushort u_sep = StringGetCharacter(separator, 0);
       return StringSplit(string_value, u_sep, result);
      }

    //+------------------------------------------------------------------+
    //|                                                                  |
    //+------------------------------------------------------------------+
    void Initialization()
      {
       On_top_of_this_price_not_Buy_first_order = input_On_top_of_this_price_not_Buy_first_order;
       On_under_of_this_price_not_Sell_first_order = input_On_under_of_this_price_not_Sell_first_order;
       On_top_of_this_price_not_Buy_order = input_On_top_of_this_price_not_Buy_order;
       On_under_of_this_price_not_Sell_order = input_On_under_of_this_price_not_Sell_order;
       Limit_StartTime = input_Limit_StartTime;
       Limit_StopTime = input_Limit_StopTime;
       CloseBuySell = input_CloseBuySell;
       HomeopathyCloseAll = input_HomeopathyCloseAll;
       Homeopathy = input_Homeopathy;
       Over = input_Over;
       NextTime = input_NextTime;
       Money = input_Money;
       FirstStep = input_FirstStep;
       MinDistance = input_MinDistance;
       TwoMinDistance = input_TwoMinDistance;
       StepTrallOrders = input_StepTrallOrders;
       Step = input_Step;
       TwoStep = input_TwoStep;
       OpenMode = input_OpenMode;
       TimeZone = input_TimeZone;
       sleep = input_sleep;
       MaxLoss = input_MaxLoss;
       MaxLossCloseAll = input_MaxLossCloseAll;
       lot = input_lot;
       Maxlot = input_Maxlot;
       PlusLot = input_PlusLot;
       K_Lot = input_K_Lot;
       DigitsLot = input_DigitsLot;
       CloseAll = input_CloseAll;
       Profit = input_Profit;
       StopProfit = input_StopProfit;
       StopLoss = input_StopLoss;
       Magic = input_Magic;
       Totals = input_Totals;
       MaxSpread = input_MaxSpread;
       Leverage = input_Leverage;
       EA_StartTime = input_EA_StartTime;
       EA_StopTime = input_EA_StopTime;
       clr1 = input_clr1;
       clr2 = input_clr2;
       Com_1 = input_Com_1;
       Com_2 = input_Com_2;
      }

    //+------------------------------------------------------------------+
    //|                                                                  |
    //+------------------------------------------------------------------+
    double MarketInfo(string symbol,int type)
      {
       switch(type)
         {
          case MODE_LOW:
             return(SymbolInfoDouble(symbol,SYMBOL_BIDLOW));
          case MODE_HIGH:
             return(SymbolInfoDouble(symbol,SYMBOL_BIDHIGH));
          case MODE_TIME:
             return((double)SymbolInfoInteger(symbol,SYMBOL_TIME));
          case MODE_BID:
             return(SymbolInfoDouble(symbol,SYMBOL_BID));
          case MODE_ASK:
             return(SymbolInfoDouble(symbol,SYMBOL_ASK));
          case MODE_POINT:
             return(SymbolInfoDouble(symbol,SYMBOL_POINT));
          case MODE_DIGITS:
             return((double)SymbolInfoInteger(symbol,SYMBOL_DIGITS));
          case MODE_SPREAD:
             return((double)SymbolInfoInteger(symbol,SYMBOL_SPREAD));
          case MODE_STOPLEVEL:
             return((double)SymbolInfoInteger(symbol,SYMBOL_TRADE_STOPS_LEVEL));
          case MODE_LOTSIZE:
             return(SymbolInfoDouble(symbol,SYMBOL_TRADE_CONTRACT_SIZE));
          case MODE_TICKSIZE:
             return(SymbolInfoDouble(symbol,SYMBOL_TRADE_TICK_SIZE));
          case MODE_SWAPLONG:
             return(SymbolInfoDouble(symbol,SYMBOL_SWAP_LONG));
          case MODE_SWAPSHORT:
             return(SymbolInfoDouble(symbol,SYMBOL_SWAP_SHORT));
          case MODE_STARTING:
             return((double)SymbolInfoInteger(symbol,SYMBOL_START_TIME));
          case MODE_EXPIRATION:
             return((double)SymbolInfoInteger(symbol,SYMBOL_EXPIRATION_TIME));
          case MODE_TRADEALLOWED:
            {
             if(SymbolInfoInteger(symbol,SYMBOL_TRADE_MODE)==SYMBOL_TRADE_MODE_DISABLED)
                return(false);
             if(SymbolInfoInteger(symbol,SYMBOL_TRADE_MODE)!=SYMBOL_TRADE_MODE_FULL)
               {
                //---
                string text="Allowed only long positions: ";
                text=(SymbolInfoInteger(symbol,SYMBOL_TRADE_MODE)==SYMBOL_TRADE_MODE_LONGONLY)?text+"true":text+"false";
                text=text+"\n";
                text=text+"Allowed only short positions: ";
                text=(SymbolInfoInteger(symbol,SYMBOL_TRADE_MODE)==SYMBOL_TRADE_MODE_SHORTONLY)?text+"true":text+"false";
                text=text+"\n";
                text=text+"Allowed only position close operations: ";
                text=(SymbolInfoInteger(symbol,SYMBOL_TRADE_MODE)==SYMBOL_TRADE_MODE_CLOSEONLY)?text+"true":text+"false";
                Alert(text);
                Print(text);
               }
             return(true);
            }
          case MODE_MINLOT:
             return(SymbolInfoDouble(symbol,SYMBOL_VOLUME_MIN));
          case MODE_LOTSTEP:
             return(SymbolInfoDouble(symbol,SYMBOL_VOLUME_STEP));
          case MODE_MAXLOT:
             return(SymbolInfoDouble(symbol,SYMBOL_VOLUME_MAX));
          case MODE_SWAPTYPE:
            {
             ENUM_SYMBOL_SWAP_MODE swap_type=(ENUM_SYMBOL_SWAP_MODE)SymbolInfoInteger(symbol,SYMBOL_SWAP_MODE);
             switch(swap_type)
               {
                case  SYMBOL_SWAP_MODE_DISABLED:
                  {
                   string text="MQL4 MODE_SWAPTYPE returned MQL5 SYMBOL_SWAP_MODE_DISABLED";
                   Alert(text);
                   Print(text);
                   return(double("nan"));
                  }
                case  SYMBOL_SWAP_MODE_POINTS:
                   return((double)0);
                case  SYMBOL_SWAP_MODE_CURRENCY_SYMBOL:
                   return((double)1);
                case  SYMBOL_SWAP_MODE_CURRENCY_MARGIN:
                   return((double)3);
                case  SYMBOL_SWAP_MODE_CURRENCY_DEPOSIT:
                  {
                   string text="MQL4 MODE_SWAPTYPE returned MQL5 SYMBOL_SWAP_MODE_CURRENCY_DEPOSIT";
                   Alert(text);
                   Print(text);
                   return(double("nan"));
                  }
                case  SYMBOL_SWAP_MODE_INTEREST_CURRENT:
                   return((double)2);
                case  SYMBOL_SWAP_MODE_INTEREST_OPEN:
                   return((double)2);
                case  SYMBOL_SWAP_MODE_REOPEN_CURRENT:
                  {
                   string text="MQL4 MODE_SWAPTYPE returned MQL5 SYMBOL_SWAP_MODE_REOPEN_CURRENT";
                   Alert(text);
                   Print(text);
                   return(double("nan"));
                  }
                case  SYMBOL_SWAP_MODE_REOPEN_BID:
                  {
                   string text="MQL4 MODE_SWAPTYPE returned MQL5 SYMBOL_SWAP_MODE_REOPEN_BID";
                   Alert(text);
                   Print(text);
                   return(double("nan"));
                  }
               }
             return(0);
            }
          case MODE_PROFITCALCMODE:
            {
             ENUM_SYMBOL_CALC_MODE profit_calc_mode=(ENUM_SYMBOL_CALC_MODE)SymbolInfoInteger(symbol,SYMBOL_TRADE_CALC_MODE);
             switch(profit_calc_mode)
               {
                case  SYMBOL_CALC_MODE_FOREX:
                   return((double)0);
                case  SYMBOL_CALC_MODE_FUTURES:
                   return((double)2);
                case  SYMBOL_CALC_MODE_CFD:
                   return((double)1);
                default :
                  {
                   string text="MQL4 MODE_PROFITCALCMODE returned MQL5 "+EnumToString(profit_calc_mode);
                   Alert(text);
                   Print(text);
                   return(double("nan"));
                  }
               }
            }
          case MODE_MARGINCALCMODE:
            {
             ENUM_SYMBOL_CALC_MODE profit_calc_mode=(ENUM_SYMBOL_CALC_MODE)SymbolInfoInteger(symbol,SYMBOL_TRADE_CALC_MODE);
             switch(profit_calc_mode)
               {
                case  SYMBOL_CALC_MODE_FOREX:
                   return((double)0);
                case  SYMBOL_CALC_MODE_FUTURES:
                   return((double)2);
                case  SYMBOL_CALC_MODE_CFD:
                   return((double)1);
                default :
                  {
                   string text="MQL4 MODE_MARGINCALCMODE returned MQL5 "+EnumToString(profit_calc_mode);
                   Alert(text);
                   Print(text);
                   return(double("nan"));
                  }
               }
            }
          case MODE_MARGININIT:
             return(SymbolInfoDouble(symbol,SYMBOL_MARGIN_INITIAL));
          case MODE_MARGINMAINTENANCE:
             return(SymbolInfoDouble(symbol,SYMBOL_MARGIN_MAINTENANCE));
          case MODE_MARGINHEDGED:
             return(SymbolInfoDouble(symbol,SYMBOL_MARGIN_HEDGED));
          case MODE_MARGINREQUIRED:
            {
             double price=SymbolInfoDouble(symbol,SYMBOL_ASK);
             double margin_check=EMPTY_VALUE;
             double margin=EMPTY_VALUE;
             margin_check=(!OrderCalcMargin(ORDER_TYPE_BUY,symbol,1.0,price,margin))?EMPTY_VALUE:margin;
             return(margin_check);
            }
          case MODE_FREEZELEVEL:
             return((double)SymbolInfoInteger(symbol,SYMBOL_TRADE_FREEZE_LEVEL));
          case MODE_CLOSEBY_ALLOWED:
            {
             if(SymbolInfoInteger(symbol,SYMBOL_ORDER_MODE)==SYMBOL_ORDER_CLOSEBY)
                return((double)1);
             return((double)0);
            }
         }
       return(0);
      }
    //+------------------------------------------------------------------+
    //|                                                                  |
    //+------------------------------------------------------------------+
    bool TimeIntradayCheck(bool timeSwitch, string star_time, string end_time, datetime time)
      {
       if(timeSwitch == false)
         {
          return(true);
         }
       if(int(star_time) < 0)
         {
          star_time = "00:00";
         }
       if(int(end_time) >= 24)
         {
          end_time = "23:59:59";
         }
       datetime START = datetime(::TimeToString(time, TIME_DATE) + " " + star_time);
       datetime END = datetime(::TimeToString(time, TIME_DATE) + " " + end_time);
       if(END < START)
         {
          if(time <= END || time >= START)
            {
             return(true);
            }
         }
       else
         {
          if(time >= START && time <= END)
             return(true);
         }
       return(false);
      }
    //+------------------------------------------------------------------+
    //|                                                                  |
    //+------------------------------------------------------------------+
    bool ObjectDelete(const string name)
      {
       return ObjectDelete(0, name);
      }

    //+------------------------------------------------------------------+
    //|                                                                  |
    //+------------------------------------------------------------------+
    bool ObjectCreate(const string name, const ENUM_OBJECT type, const int subwindow, const datetime time1, const double price1)
      {
       return ObjectCreate(0, name, type, subwindow, time1, price1);
      }
    //+------------------------------------------------------------------+
    //|                                                                  |
    //+------------------------------------------------------------------+
    bool ObjectCreate(const string name, const ENUM_OBJECT type, const int subwindow,
                      const datetime time1, const double price1,
                      const datetime time2, const double price2,
                      const datetime time3, const double price3
                     )
      {
       return ObjectCreate(0, name, type, subwindow, time1, price1, time2, price2, time3, price3);
      }

    //+------------------------------------------------------------------+
    //|                                                                  |
    //+------------------------------------------------------------------+
    template<typename T>
    bool ObjectSet(string  name, int  index, T  value)
      {
       ENUM_OBJECT_PROPERTY_INTEGER  type = ObjectNumberInt(index, false);
       if(type != -1)
         {
          return ObjectSet(name, type, long(value));
         }
       else
         {
          ENUM_OBJECT_PROPERTY_DOUBLE  type = ObjectNumberDbl(index, false);
          if(type != -1)
            {
             if(type == OBJPROP_LEVELVALUE)
               {
                return ObjectSetDouble(0, name, OBJPROP_LEVELVALUE, index - 210, value);
               }
             else
                return ObjectSet(name, type,  double(value));
            }
          else
            {
             OBJPROP_BROKER_D type = ObjectNumberBrokerD(index, false);
             if(type.i != -1)
               {
                return ObjectSet(name, type,  double(value));
               }
             else
               {
                OBJPROP_BROKER_I type = ObjectNumberBrokerI(index, false);
                if(type.i != -1)
                  {
                   return ObjectSet(name, type,  long(value));
                  }
               }
            }
         }
       Alert(string(index) + "Object SET 序号未转译");
       return false;
      }
    //+------------------------------------------------------------------+
    //|                                                                  |
    //+------------------------------------------------------------------+
    bool ObjectSet(const string name, const ENUM_OBJECT_PROPERTY_INTEGER property, const long value)
      {
       return ObjectSetInteger(0, name, property, value);
      }
    //+------------------------------------------------------------------+
    //|                                                                  |
    //+------------------------------------------------------------------+
    bool ObjectSet(const string name, const ENUM_OBJECT_PROPERTY_INTEGER property, const double value)
      {
       return ObjectSetInteger(0, name, property, long(value));
      }
    //+------------------------------------------------------------------+
    //|                                                                  |
    //+------------------------------------------------------------------+
    bool ObjectSet(const string name, const ENUM_OBJECT_PROPERTY_DOUBLE property, const double value)
      {
       return ObjectSetDouble(0, name, property, value);
      }

    //+------------------------------------------------------------------+
    //|                                                                  |
    //+------------------------------------------------------------------+
    bool ObjectSet(const string name, const ENUM_OBJECT_PROPERTY_STRING property, const string value)
      {
       return ObjectSetString(0, name, property, value);
      }

    //+------------------------------------------------------------------+
    //|                                                                  |
    //+------------------------------------------------------------------+
    bool ObjectSet(const string name, const OBJPROP_BROKER_I &property, const long value)
      {
       return ObjectSetInteger(0, name, property.p, property.i, value);
      }

    //+------------------------------------------------------------------+
    //|                                                                  |
    //+------------------------------------------------------------------+
    bool ObjectSet(const string name, const OBJPROP_BROKER_D &property, const double value)
      {
       return ObjectSetDouble(0, name, property.p, property.i, value);
      }
    //+------------------------------------------------------------------+
    //|                                                                  |
    //+------------------------------------------------------------------+
    bool ObjectSetText(const string object_name,
                       const string text,
                       const int font_size = 0,
                       string   font_name = NULL,
                       color    text_color = clrNONE)
      {
       bool res = ObjectSetString(0, object_name, OBJPROP_TEXT, text);
       if(font_size != 0)
          ObjectSetInteger(0, object_name, OBJPROP_FONTSIZE, font_size);
       if(font_name != NULL)
          ObjectSetString(0, object_name, OBJPROP_FONT, font_name);
       if(text_color != clrNONE)
          ObjectSetInteger(0, object_name, OBJPROP_COLOR, text_color);
       return res;
      }
    //+------------------------------------------------------------------+
    //|                                                                  |
    //+------------------------------------------------------------------+
    double ObjectGet(string name, int  index)
      {
       ENUM_OBJECT_PROPERTY_INTEGER  type = ObjectNumberInt(index, false);
       if(type != -1)
         {
          return double(ObjectGet(name, type));
         }
       else
         {
          ENUM_OBJECT_PROPERTY_DOUBLE  type = ObjectNumberDbl(index, false);
          if(type != -1)
            {
             return ObjectGet(name, type);
            }
          else
            {
             OBJPROP_BROKER_D type = ObjectNumberBrokerD(index, false);
             if(type.i != -1)
               {
                return ObjectGet(name, type);
               }
             else
               {
                OBJPROP_BROKER_I type = ObjectNumberBrokerI(index, false);
                if(type.i != -1)
                  {
                   return double(ObjectGet(name, type));
                  }
               }
            }
         }
       Alert(string(index) + "Object GET 序号未转译");
       return 0;
      }

    //+------------------------------------------------------------------+
    //|                                                                  |
    //+------------------------------------------------------------------+
    long  ObjectGet(string name, ENUM_OBJECT_PROPERTY_INTEGER  prop_id, int   prop_modifier = 0)
      {
       return ObjectGetInteger(0, name, prop_id, prop_modifier);
      }
    //+------------------------------------------------------------------+
    //|                                                                  |
    //+------------------------------------------------------------------+
    double  ObjectGet(string name, ENUM_OBJECT_PROPERTY_DOUBLE  prop_id, int   prop_modifier = 0)
      {
       return ObjectGetDouble(0, name, prop_id, prop_modifier);
      }

    //+------------------------------------------------------------------+
    //|                                                                  |
    //+------------------------------------------------------------------+
    double ObjectGet(const string name, const OBJPROP_BROKER_D &property)
      {
       return ObjectGetDouble(0, name, property.p, property.i);
      }
    //+------------------------------------------------------------------+
    //|                                                                  |
    //+------------------------------------------------------------------+
    long ObjectGet(const string name, const OBJPROP_BROKER_I &property)
      {
       return ObjectGetInteger(0, name, property.p, property.i);
      }
    //+------------------------------------------------------------------+
    //|                                                                  |
    //+------------------------------------------------------------------+
    long  ObjectGetInteger(long                             chart_id,
                           string                           name,
                           int                              prop_id,
                           int                              prop_modifier = 0
                          )
      {
       ENUM_OBJECT_PROPERTY_INTEGER  type = ObjectNumberInt(prop_id);
       return ObjectGetInteger(chart_id, name, type, prop_modifier);
      }
    //+------------------------------------------------------------------+
    //|                                                                  |
    //+------------------------------------------------------------------+
    double  ObjectGetDouble(long                             chart_id,
                            string                           name,
                            int                              prop_id,
                            int                              prop_modifier = 0
                           )
      {
       ENUM_OBJECT_PROPERTY_DOUBLE  type = ObjectNumberDbl(prop_id);
       return ObjectGetDouble(chart_id, name, type, prop_modifier);
      }
    //+------------------------------------------------------------------+
    //|                                                                  |
    //+------------------------------------------------------------------+
    string  ObjectGetString(long                             chart_id,
                            string                           name,
                            int                              prop_id,
                            int                              prop_modifier = 0
                           )
      {
       ENUM_OBJECT_PROPERTY_STRING  type = ObjectNumberStr(prop_id);
       return ObjectGetString(chart_id, name, type, prop_modifier);
      }
    //+------------------------------------------------------------------+
    //|                                                                  |
    //+------------------------------------------------------------------+
    bool  ObjectSetInteger(long                             chart_id,
                           string                           name,
                           int                              prop_id,
                           long                             prop_value
                          )
      {
       ENUM_OBJECT_PROPERTY_INTEGER  type = ObjectNumberInt(prop_id);
       return ObjectSetInteger(chart_id, name, type, prop_value);
      }
    //+------------------------------------------------------------------+
    //|                                                                  |
    //+------------------------------------------------------------------+
    bool  ObjectSetDouble(long                             chart_id,
                          string                           name,
                          int                              prop_id,
                          double                           prop_value
                         )
      {
       ENUM_OBJECT_PROPERTY_DOUBLE  type = ObjectNumberDbl(prop_id);
       return ObjectSetDouble(chart_id, name, type, prop_value);
      }
    //+------------------------------------------------------------------+
    //|                                                                  |
    //+------------------------------------------------------------------+
    bool  ObjectSetString(long                             chart_id,
                          string                           name,
                          int                              prop_id,
                          string                           prop_value
                         )
      {
       ENUM_OBJECT_PROPERTY_STRING    type = ObjectNumberStr(prop_id);
       return ObjectSetString(chart_id, name, type, prop_value);
      }
    //+------------------------------------------------------------------+
    //|                                                                  |
    //+------------------------------------------------------------------+
    OBJPROP_BROKER_D ObjectNumberBrokerD(int number, bool alert = true)
      {
       switch(number)
         {
          case 1:
             return (OBJPROP_PRICE1);
          case 3:
             return (OBJPROP_PRICE2);
          case 5:
             return (OBJPROP_PRICE3);
          default:
            {
             if(alert == true)
                Alert(string(number) + " Object Broker double 序号未转译");
             OBJPROP_BROKER_D res;
             res.i = -1;
             return (res);
            }
         }
      }
    //+------------------------------------------------------------------+
    //|                                                                  |
    //+------------------------------------------------------------------+
    OBJPROP_BROKER_I ObjectNumberBrokerI(int number, bool alert = true)
      {
       switch(number)
         {
          case 0:
             return (OBJPROP_TIME1);
          case 2:
             return (OBJPROP_TIME2);
          case 4:
             return (OBJPROP_TIME3);
          default:
            {
             if(alert == true)
                Alert(string(number) + " Object Broker int 序号未转译");
             OBJPROP_BROKER_I res;
             res.i = -1;
             return (res);
            }
         }
      }
    //+------------------------------------------------------------------+
    //|                                                                  |
    //+------------------------------------------------------------------+
    ENUM_OBJECT_PROPERTY_INTEGER ObjectNumberInt(int number, bool alert = true)
      {
       switch(number)
         {
          case 6:
             return (OBJPROP_COLOR);
          case 7:
             return (OBJPROP_STYLE);
          case 8:
             return (OBJPROP_WIDTH);
          case 9:
             return (OBJPROP_BACK);
          case 10:
             return (OBJPROP_RAY);
          case 11:
             return (OBJPROP_ELLIPSE);
          case 14:
             return (OBJPROP_ARROWCODE);
          case 15:
             return (OBJPROP_TIMEFRAMES);
          case 17:
             return (OBJPROP_SELECTED);
          case 18:
             return (OBJPROP_TYPE);
          case 19:
             return (OBJPROP_TIME);
          case 100:
             return (OBJPROP_FONTSIZE);
          case 101:
             return (OBJPROP_CORNER);
          case 102:
             return (OBJPROP_XDISTANCE);
          case 103:
             return (OBJPROP_YDISTANCE);
          case 201:
             return (OBJPROP_LEVELCOLOR);
          case 202:
             return (OBJPROP_LEVELSTYLE);
          case 203:
             return (OBJPROP_LEVELWIDTH);
          case 207:
             return (OBJPROP_ZORDER);
          case 208:
             return (OBJPROP_HIDDEN);
          case 1000:
             return (OBJPROP_SELECTABLE);
          case 1004:
             return (OBJPROP_RAY_RIGHT);
          case 1011:
             return (OBJPROP_ANCHOR);
          case 1018:
             return (OBJPROP_STATE);
          case 1019:
             return (OBJPROP_XSIZE);
          case 1020:
             return (OBJPROP_YSIZE);
          case 1025:
             return (OBJPROP_BGCOLOR);
          case 1029:
             return (OBJPROP_BORDER_TYPE);
          case 1035:
             return (OBJPROP_BORDER_COLOR);
          default:
             if(alert == true)
                Alert(string(number) + " Object INT序号未转译");
             return (-1);
         }
      }


    //+------------------------------------------------------------------+
    //|                                                                  |
    //+------------------------------------------------------------------+
    ENUM_OBJECT_PROPERTY_DOUBLE ObjectNumberDbl(int number, bool alert = true)
      {
       switch(number)
         {
          case 12:
             return (OBJPROP_SCALE);
          case 13:
             return (OBJPROP_ANGLE);
          case 16:
             return (OBJPROP_DEVIATION);
          default:
             if(number>=210 && number<=210+31)
               {
                return (OBJPROP_LEVELVALUE);
               }
             else
                if(alert == true)
                   Alert(string(number) + "Object DBL序号未转译");
             return (-1);
         }
      }

    //+------------------------------------------------------------------+
    //|                                                                  |
    //+------------------------------------------------------------------+
    ENUM_OBJECT_PROPERTY_STRING ObjectNumberStr(int number, bool alert = true)
      {
       switch(number)
         {
          case 999:
             return (OBJPROP_TEXT);
          case 1001:
             return (OBJPROP_FONT);
          default:
             if(alert == true)
                Alert(string(number) + "Object Str序号未转译");
             return (-1);
         }
      }
    //+------------------------------------------------------------------+

    //+------------------------------------------------------------------+
    //|                                                                  |
    //+------------------------------------------------------------------+
    void  M_SymbolData::M_SymbolData(string symbol_)
      {
       Init(symbol_);
      }
    //+------------------------------------------------------------------+
    //|                                                                  |
    //+------------------------------------------------------------------+
    void  M_SymbolData::Init(string symbol_)
      {
       symbol = symbol_;
       point = ::SymbolInfoDouble(symbol, SYMBOL_POINT);
       digits = int(::SymbolInfoInteger(symbol, SYMBOL_DIGITS));
       minStopLevel = int(::SymbolInfoInteger(symbol, SYMBOL_TRADE_STOPS_LEVEL));
       lot_min = SymbolInfoDouble(symbol, SYMBOL_VOLUME_MIN);
       lot_max = SymbolInfoDouble(symbol, SYMBOL_VOLUME_MAX);
       lot_step = SymbolInfoDouble(symbol, SYMBOL_VOLUME_STEP);
       lot_digits = 0;
       double step_digits = lot_step - int(lot_step);
       if(step_digits > 0)
         {
          lot_digits = int(MathCeil(MathAbs(MathLog(step_digits) / MathLog(10))));
         }
       Refresh(true);
      }

    //+------------------------------------------------------------------+
    //|                                                                  |
    //+------------------------------------------------------------------+
    void M_SymbolData::NormalizeLot(double & lots, bool rounding)
      {
       if(lots < lot_min)
         {
          printf("计算手数%f小于平台最小手数%f以最小手数为准", lots, lot_min);
          lots = lot_min;
          return;
         }
       if(lots > lot_max)
         {
          printf("计算手数%f大于平台最大手数%f以最大手数为准", lots, lot_max);
          lots = lot_max;
          return;
         }
       NormalizeDouble(lots, lot_digits, rounding);
       if(lot_step > 0)
         {
          double mul =  NormalizeDouble((lots - lot_min) / lot_step, 0);
          lots = lot_min + lot_step * mul;
          NormalizeDouble(lots, lot_digits, rounding);
         }
       lots = lots < lot_min ? lot_min : lots > lot_max ? lot_max : lots;
      }
    //+------------------------------------------------------------------+
    //|                                                                  |
    //+------------------------------------------------------------------+
    void  M_SymbolData::Refresh(bool refresh_pre = false)
      {
       if(refresh_pre == true)
         {
          bidpre = bid;
          askpre = ask;
         }
       MqlTick m_tick;
       SymbolInfoTick(symbol, m_tick);
       bid = m_tick.bid;
       ask = m_tick.ask;
       time_msc = m_tick.time_msc;
       spread = int(::SymbolInfoInteger(symbol, SYMBOL_SPREAD));
      }
    //+------------------------------------------------------------------+
    //|                                                                  |
    //+------------------------------------------------------------------+
    void  NormalizeDouble(double & lots, int digits_, bool rounding)
      {
       if(rounding == false)
         {
          int amendDigits = int(MathPow(10, digits_));
          double buffer = int(lots * amendDigits);
          lots = double(buffer / double(amendDigits));
         }
       lots = ::NormalizeDouble(lots, digits_);
      }

    //+------------------------------------------------------------------+
    //|                                                                  |
    //+------------------------------------------------------------------+
    COrder::COrder(ENUM_ORDER_STATUS order_status, long ticket)
      {
       this.Init(order_status, ticket);
      }
    //+------------------------------------------------------------------+
    //|                                                                  |
    //+------------------------------------------------------------------+
    void COrder::Init(ENUM_ORDER_STATUS order_status, long ticket)
      {
       order.status = order_status;
       order.ticket = ticket;
       if(ticket > 0)
          this.Refresh();
       else
          this.ZeroMemory();
      }
    //+------------------------------------------------------------------+
    //|                                                                  |
    //+------------------------------------------------------------------+
    void COrder::ZeroMemory()
      {
       ZeroOrder(order);
      }
    //+------------------------------------------------------------------+
    //|                                                                  |
    //+------------------------------------------------------------------+
    void COrder::Refresh()
      {
       order.position_id     = this.OrderPositionID();
       order.position_by_id  = this.OrderPositionByID();
       order.type         = (int)this.OrderType();
       order.magic        = this.OrderMagicNumber();
       order.close_time   = this.OrderCloseTime();
       order.open_time    = this.OrderOpenTime();
       order.direction    = this.OrderTypeByDirection();
       order.reason       = this.OrderReason();
       order.deal_order   = this.DealOrder();
       order.deal_entry   = this.DealEntry();
       order.time_exp     = this.OrderExpiration();
       order.open_time_msc   = this.OrderOpenTimeMSC();
       order.close_time_msc  = this.OrderCloseTimeMSC();
       order.update_time     = this.PositionTimeUpdate();
       order.update_time_msc = this.PositionTimeUpdateMSC();
    //+------
       order.open_price   = this.OrderOpenPrice();
       order.close_price  = this.OrderClosePrice();
       order.sl_price     = this.OrderStopLoss();
       order.tp_price     = this.OrderTakeProfit();
       order.volume       = this.OrderVolume();
       order.profit       = this.OrderProfit();
       order.commission   = this.OrderCommission();
       order.swap         = this.OrderSwap();
       order.volume_current   = this.OrderVolumeCurrent();
       order.price_stop_limit = this.OrderPriceStopLimit();
    //+------
       order.symbol       = this.OrderSymbol();
       order.comment      = this.OrderComment();
       order.external_id  = this.OrderExternalID();
    //+------
       order.point        = ::SymbolInfoDouble(order.symbol, SYMBOL_POINT);
       order.profit_full  = order.profit + order.commission + order.swap;
       order.close_by_sl  = this.OrderCloseByStopLoss(order.comment);
       order.close_by_tp  = this.OrderCloseByTakeProfit(order.comment);
       order.profit_pt    = this.ProfitInPoints();
      }
    //+------------------------------------------------------------------+
    //|                                                                  |
    //+------------------------------------------------------------------+
    string COrder::OrderSymbol(void) const
      {
       string res = "";
       switch(order.status)
         {
          case ORDER_STATUS_MARKET_ACTIVE     :
             res =::PositionGetString(POSITION_SYMBOL);
             break;
          case ORDER_STATUS_MARKET_PENDING    :
             res =::OrderGetString(ORDER_SYMBOL);
             break;
          case ORDER_STATUS_HISTORY_PENDING   :
          case ORDER_STATUS_HISTORY_ORDER     :
             res =::HistoryOrderGetString(order.ticket, ORDER_SYMBOL);
             break;
          case ORDER_STATUS_DEAL              :
             res =::HistoryDealGetString(order.ticket, DEAL_SYMBOL);
             break;
          default                             :
             res = "";
             break;
         }
       return res;
      }

    //+------------------------------------------------------------------+
    //|                                                                  |
    //+------------------------------------------------------------------+
    string COrder::OrderComment(void) const
      {
       string res = "";
       switch(order.status)
         {
          case ORDER_STATUS_MARKET_ACTIVE     :
             res =::PositionGetString(POSITION_COMMENT);
             break;
          case ORDER_STATUS_MARKET_PENDING    :
             res =::OrderGetString(ORDER_COMMENT);
             break;
          case ORDER_STATUS_HISTORY_PENDING   :
          case ORDER_STATUS_HISTORY_ORDER     :
             res =::HistoryOrderGetString(order.ticket, ORDER_COMMENT);
             break;
          case ORDER_STATUS_DEAL              :
             res =::HistoryDealGetString(order.ticket, DEAL_COMMENT);
             break;
          default                             :
             res = "";
             break;
         }
       return res;
      }

    //+------------------------------------------------------------------+
    //|                                                                  |
    //+------------------------------------------------------------------+
    string COrder::OrderExternalID(void) const
      {
       string res = "";
       switch(order.status)
         {
          case ORDER_STATUS_MARKET_PENDING    :
             res =::OrderGetString(ORDER_EXTERNAL_ID);
             break;
          case ORDER_STATUS_HISTORY_PENDING   :
          case ORDER_STATUS_HISTORY_ORDER     :
             res =::HistoryOrderGetString(order.ticket, ORDER_EXTERNAL_ID);
             break;
          case ORDER_STATUS_DEAL              :
             res =::HistoryDealGetString(order.ticket, DEAL_EXTERNAL_ID);
             break;
          default                             :
             res = "";
             break;
         }
       return res;
      }
    //+------------------------------------------------------------------+
    //|                                                                  |
    //+------------------------------------------------------------------+
    double COrder::OrderOpenPrice(void) const
      {
       double res = 0;
       switch(order.status)
         {
          case ORDER_STATUS_MARKET_ACTIVE     :
             res =::PositionGetDouble(POSITION_PRICE_OPEN);
             break;
          case ORDER_STATUS_MARKET_PENDING    :
             res =::OrderGetDouble(ORDER_PRICE_OPEN);
             break;
          case ORDER_STATUS_HISTORY_PENDING   :
          case ORDER_STATUS_HISTORY_ORDER     :
             res =::HistoryOrderGetDouble(order.ticket, ORDER_PRICE_OPEN);
             break;
          case ORDER_STATUS_DEAL              :
             res =::HistoryDealGetDouble(order.ticket, DEAL_PRICE);
             break;
          default                             :
             res = 0;
             break;
         }
       return res;
      }
    //+------------------------------------------------------------------+
    //|                                                                  |
    //+------------------------------------------------------------------+
    double COrder::OrderClosePrice(void) const
      {
       double res = 0;
       switch(order.status)
         {
          case ORDER_STATUS_HISTORY_PENDING   :
          case ORDER_STATUS_HISTORY_ORDER     :
             res =::HistoryOrderGetDouble(order.ticket, ORDER_PRICE_OPEN);
             break;
          case ORDER_STATUS_DEAL              :
             res =::HistoryDealGetDouble(order.ticket, DEAL_PRICE);
             break;
          default                             :
             res = 0;
             break;
         }
       return res;
      }

    //+------------------------------------------------------------------+
    //|                                                                  |
    //+------------------------------------------------------------------+
    double COrder::OrderProfit(void) const
      {
       double res = 0;
       switch(order.status)
         {
          case ORDER_STATUS_MARKET_ACTIVE  :
             res =::PositionGetDouble(POSITION_PROFIT);
             break;
          case ORDER_STATUS_DEAL           :
             res =::HistoryDealGetDouble(order.ticket, DEAL_PROFIT);
             break;
          default                          :
             res = 0;
             break;
         }
       return res;
      }

    //+------------------------------------------------------------------+
    //|                                                                  |
    //+------------------------------------------------------------------+
    double COrder::OrderCommission(void) const
      {
       double res = 0;
       switch(order.status)
         {
          case ORDER_STATUS_DEAL  :
             res =::HistoryDealGetDouble(order.ticket, DEAL_COMMISSION);
             break;
          default                 :
             res = 0;
             break;
         }
       return res;
      }

    //+------------------------------------------------------------------+
    //|                                                                  |
    //+------------------------------------------------------------------+
    double COrder::OrderSwap(void) const
      {
       double res = 0;
       switch(order.status)
         {
          case ORDER_STATUS_MARKET_ACTIVE  :
             res =::PositionGetDouble(POSITION_SWAP);
             break;
          case ORDER_STATUS_DEAL           :
             res =::HistoryDealGetDouble(order.ticket, DEAL_SWAP);
             break;
          default                          :
             res = 0;
             break;
         }
       return res;
      }

    //+------------------------------------------------------------------+
    //|                                                                  |
    //+------------------------------------------------------------------+
    double COrder::OrderVolume(void) const
      {
       double res = 0;
       switch(order.status)
         {
          case ORDER_STATUS_MARKET_ACTIVE     :
             res =::PositionGetDouble(POSITION_VOLUME);
             break;
          case ORDER_STATUS_MARKET_PENDING    :
             res =::OrderGetDouble(ORDER_VOLUME_INITIAL);
             break;
          case ORDER_STATUS_HISTORY_PENDING   :
          case ORDER_STATUS_HISTORY_ORDER     :
             res =::HistoryOrderGetDouble(order.ticket, ORDER_VOLUME_INITIAL);
             break;
          case ORDER_STATUS_DEAL              :
             res =::HistoryDealGetDouble(order.ticket, DEAL_VOLUME);
             break;
          default                             :
             res = 0;
             break;
         }
       return res;
      }

    //+------------------------------------------------------------------+
    //|                                                                  |
    //+------------------------------------------------------------------+
    double COrder::OrderVolumeCurrent(void) const
      {
       double res = 0;
       switch(order.status)
         {
          case ORDER_STATUS_MARKET_PENDING    :
             res =::OrderGetDouble(ORDER_VOLUME_CURRENT);
             break;
          case ORDER_STATUS_HISTORY_PENDING   :
          case ORDER_STATUS_HISTORY_ORDER     :
             res =::HistoryOrderGetDouble(order.ticket, ORDER_VOLUME_CURRENT);
             break;
          default                             :
             res = 0;
             break;
         }
       return res;
      }

    //+------------------------------------------------------------------+
    //|                                                                  |
    //+------------------------------------------------------------------+
    double COrder::OrderStopLoss(void) const
      {
       double res = 0;
       switch(order.status)
         {
          case ORDER_STATUS_MARKET_ACTIVE     :
             res =::PositionGetDouble(POSITION_SL);
             break;
          case ORDER_STATUS_MARKET_PENDING    :
             res =::OrderGetDouble(ORDER_SL);
             break;
          case ORDER_STATUS_HISTORY_PENDING   :
          case ORDER_STATUS_HISTORY_ORDER     :
             res =::HistoryOrderGetDouble(order.ticket, ORDER_SL);
             break;
          default                             :
             res = 0;
             break;
         }
       return res;
      }

    //+------------------------------------------------------------------+
    //|                                                                  |
    //+------------------------------------------------------------------+
    double COrder::OrderTakeProfit(void) const
      {
       double res = 0;
       switch(order.status)
         {
          case ORDER_STATUS_MARKET_ACTIVE     :
             res =::PositionGetDouble(POSITION_TP);
             break;
          case ORDER_STATUS_MARKET_PENDING    :
             res =::OrderGetDouble(ORDER_TP);
             break;
          case ORDER_STATUS_HISTORY_PENDING   :
          case ORDER_STATUS_HISTORY_ORDER     :
             res =::HistoryOrderGetDouble(order.ticket, ORDER_TP);
             break;
          default                             :
             res = 0;
             break;
         }
       return res;
      }

    //+------------------------------------------------------------------+
    //|                                                                  |
    //+------------------------------------------------------------------+
    double COrder::OrderPriceStopLimit(void) const
      {
       double res = 0;
       switch(order.status)
         {
          case ORDER_STATUS_MARKET_PENDING    :
             res =::OrderGetDouble(ORDER_PRICE_STOPLIMIT);
             break;
          case ORDER_STATUS_HISTORY_PENDING   :
          case ORDER_STATUS_HISTORY_ORDER     :
             res =::HistoryOrderGetDouble(order.ticket, ORDER_PRICE_STOPLIMIT);
             break;
          default                             :
             res = 0;
             break;
         }
       return res;
      }

    //+------------------------------------------------------------------+
    //|                                                                  |
    //+------------------------------------------------------------------+
    long COrder::OrderMagicNumber() const
      {
       long res = 0;
       switch(order.status)
         {
          case ORDER_STATUS_MARKET_ACTIVE     :
             res =::PositionGetInteger(POSITION_MAGIC);
             break;
          case ORDER_STATUS_MARKET_PENDING    :
             res =::OrderGetInteger(ORDER_MAGIC);
             break;
          case ORDER_STATUS_DEAL              :
             res =::HistoryDealGetInteger(order.ticket, DEAL_MAGIC);
             break;
          case ORDER_STATUS_HISTORY_PENDING   :
          case ORDER_STATUS_HISTORY_ORDER     :
             res =::HistoryOrderGetInteger(order.ticket, ORDER_MAGIC);
             break;
          default                             :
             res = 0;
             break;
         }
       return res;
      }

    //+------------------------------------------------------------------+
    //|                                                                  |
    //+------------------------------------------------------------------+
    datetime COrder::OrderOpenTime(void) const
      {
       datetime res = 0;
       switch(order.status)
         {
          case ORDER_STATUS_MARKET_ACTIVE     :
             res = (datetime)::PositionGetInteger(POSITION_TIME);
             break;
          case ORDER_STATUS_MARKET_PENDING    :
             res = (datetime)::OrderGetInteger(ORDER_TIME_SETUP);
             break;
          case ORDER_STATUS_HISTORY_PENDING   :
          case ORDER_STATUS_HISTORY_ORDER     :
             res = (datetime)::HistoryOrderGetInteger(order.ticket, ORDER_TIME_SETUP);
             break;
          case ORDER_STATUS_DEAL              :
             res = (datetime)::HistoryDealGetInteger(order.ticket, DEAL_TIME);
             break;
          default                             :
             res = 0;
             break;
         }
       return res;
      }

    //+------------------------------------------------------------------+
    //|                                                                  |
    //+------------------------------------------------------------------+
    datetime COrder::OrderCloseTime() const
      {
       datetime res = 0;
       switch(order.status)
         {
          case ORDER_STATUS_HISTORY_PENDING   :
          case ORDER_STATUS_HISTORY_ORDER     :
             res = (datetime)::HistoryOrderGetInteger(order.ticket, ORDER_TIME_DONE);
             break;
          case ORDER_STATUS_DEAL              :
             res = (datetime)::HistoryDealGetInteger(order.ticket, DEAL_TIME);
             break;
          default                             :
             res = 0;
             break;
         }
       return res;
      }

    //+------------------------------------------------------------------+
    //|                                                                  |
    //+------------------------------------------------------------------+
    datetime COrder::OrderExpiration() const
      {
       datetime res = 0;
       switch(order.status)
         {
          case ORDER_STATUS_MARKET_PENDING    :
             res = (datetime)::OrderGetInteger(ORDER_TIME_EXPIRATION);
             break;
          case ORDER_STATUS_HISTORY_PENDING   :
             res = (datetime)::HistoryOrderGetInteger(order.ticket, ORDER_TIME_EXPIRATION);
             break;
          default                             :
             res = 0;
             break;
         }
       return res;
      }

    //+------------------------------------------------------------------+
    //|                                                                  |
    //+------------------------------------------------------------------+
    long COrder::OrderType() const
      {
       long res = 0;
       switch(order.status)
         {
          case ORDER_STATUS_MARKET_ACTIVE     :
             res =::PositionGetInteger(POSITION_TYPE);
             break;
          case ORDER_STATUS_MARKET_PENDING    :
             res =::OrderGetInteger(ORDER_TYPE);
             break;
          case ORDER_STATUS_HISTORY_PENDING   :
          case ORDER_STATUS_HISTORY_ORDER     :
             res =::HistoryOrderGetInteger(order.ticket, ORDER_TYPE);
             break;
          case ORDER_STATUS_DEAL              :
             res =::HistoryDealGetInteger(order.ticket, DEAL_TYPE);
             break;
          default                             :
             res = 0;
             break;
         }
       return res;
      }

    //+------------------------------------------------------------------+
    //|                                                                  |
    //+------------------------------------------------------------------+
    long COrder::OrderTypeByDirection() const
      {
       if(order.status == ORDER_STATUS_MARKET_ACTIVE)
         {
          return(order.type == POSITION_TYPE_BUY ? ORDER_TYPE_BUY : ORDER_TYPE_SELL);
         }
       if(order.status == ORDER_STATUS_MARKET_PENDING || order.status == ORDER_STATUS_HISTORY_PENDING)
         {
          return
             (
                order.type == ORDER_TYPE_BUY_LIMIT ||
                order.type == ORDER_TYPE_BUY_STOP ||
                order.type == ORDER_TYPE_BUY_STOP_LIMIT ?
                ORDER_TYPE_BUY :
                ORDER_TYPE_SELL
             );
         }
       if(order.status == ORDER_STATUS_HISTORY_ORDER)
         {
          return order.type ;
         }
       return WRONG_VALUE;
      }

    //+------------------------------------------------------------------+
    //|                                                                  |
    //+------------------------------------------------------------------+
    long COrder::OrderPositionID(void) const
      {
       long res = 0;
       switch(order.status)
         {
          case ORDER_STATUS_MARKET_ACTIVE     :
             res =::PositionGetInteger(POSITION_IDENTIFIER);
             break;
          case ORDER_STATUS_MARKET_PENDING    :
             res =::OrderGetInteger(ORDER_POSITION_ID);
             break;
          case ORDER_STATUS_HISTORY_PENDING   :
          case ORDER_STATUS_HISTORY_ORDER     :
             res =::HistoryOrderGetInteger(order.ticket, ORDER_POSITION_ID);
             break;
          case ORDER_STATUS_DEAL              :
             res =::HistoryDealGetInteger(order.ticket, DEAL_POSITION_ID);
             break;
          default                             :
             res = 0;
             break;
         }
       return res;
      }

    //+------------------------------------------------------------------+
    //|                                                                  |
    //+------------------------------------------------------------------+
    long COrder::OrderReason(void) const
      {
       long res = WRONG_VALUE;
       switch(order.status)
         {
          case ORDER_STATUS_MARKET_ACTIVE     :
             res =::PositionGetInteger(POSITION_REASON);
             break;
          case ORDER_STATUS_MARKET_PENDING    :
             res =::OrderGetInteger(ORDER_REASON);
             break;
          case ORDER_STATUS_HISTORY_PENDING   :
          case ORDER_STATUS_HISTORY_ORDER     :
             res =::HistoryOrderGetInteger(order.ticket, ORDER_REASON);
             break;
          case ORDER_STATUS_DEAL              :
             res =::HistoryDealGetInteger(order.ticket, DEAL_REASON);
             break;
          default                             :
             res = WRONG_VALUE;
             break;
         }
       return res;
      }

    //+------------------------------------------------------------------+
    //|                                                                  |
    //+------------------------------------------------------------------+
    long COrder::DealOrder(void) const
      {
       long res = 0;
       switch(order.status)
         {
          case ORDER_STATUS_MARKET_ACTIVE     :
             res =::PositionGetInteger(POSITION_IDENTIFIER);
             break;
          case ORDER_STATUS_MARKET_PENDING    :
             res =::OrderGetInteger(ORDER_POSITION_ID);
             break;
          case ORDER_STATUS_HISTORY_PENDING   :
          case ORDER_STATUS_HISTORY_ORDER     :
             res =::HistoryOrderGetInteger(order.ticket, ORDER_POSITION_ID);
             break;
          case ORDER_STATUS_DEAL              :
             res =::HistoryDealGetInteger(order.ticket, DEAL_ORDER);
             break;
          default                             :
             res = 0;
             break;
         }
       return res;
      }

    //+------------------------------------------------------------------+
    //|                                                                  |
    //+------------------------------------------------------------------+
    long COrder::DealEntry(void) const
      {
       long res = WRONG_VALUE;
       switch(order.status)
         {
          case ORDER_STATUS_DEAL  :
             res =::HistoryDealGetInteger(order.ticket, DEAL_ENTRY);
             break;
          default                 :
             res = WRONG_VALUE;
             break;
         }
       return res;
      }

    //+------------------------------------------------------------------+
    //|                                                                  |
    //+------------------------------------------------------------------+
    long COrder::OrderPositionByID(void) const
      {
       long res = 0;
       switch(order.status)
         {
          case ORDER_STATUS_MARKET_PENDING    :
             res =::OrderGetInteger(ORDER_POSITION_BY_ID);
             break;
          case ORDER_STATUS_HISTORY_PENDING   :
          case ORDER_STATUS_HISTORY_ORDER     :
             res =::HistoryOrderGetInteger(order.ticket, ORDER_POSITION_BY_ID);
             break;
          default                             :
             res = 0;
             break;
         }
       return res;
      }

    //+------------------------------------------------------------------+
    //|                                                                  |
    //+------------------------------------------------------------------+
    long COrder::OrderOpenTimeMSC(void) const
      {
       long res = 0;
       switch(order.status)
         {
          case ORDER_STATUS_MARKET_ACTIVE     :
             res =::PositionGetInteger(POSITION_TIME_MSC);
             break;
          case ORDER_STATUS_MARKET_PENDING    :
             res =::OrderGetInteger(ORDER_TIME_SETUP_MSC);
             break;
          case ORDER_STATUS_HISTORY_PENDING   :
          case ORDER_STATUS_HISTORY_ORDER     :
             res =::HistoryOrderGetInteger(order.ticket, ORDER_TIME_SETUP_MSC);
             break;
          case ORDER_STATUS_DEAL              :
             res =::HistoryDealGetInteger(order.ticket, DEAL_TIME_MSC);
             break;
          default                             :
             res = 0;
             break;
         }
       return res;
      }

    //+------------------------------------------------------------------+
    //|                                                                  |
    //+------------------------------------------------------------------+
    long COrder::OrderCloseTimeMSC(void) const
      {
       long res = 0;
       switch(order.status)
         {
          case ORDER_STATUS_HISTORY_PENDING   :
          case ORDER_STATUS_HISTORY_ORDER     :
             res =::HistoryOrderGetInteger(order.ticket, ORDER_TIME_DONE_MSC);
             break;
          case ORDER_STATUS_DEAL              :
             res = (datetime)::HistoryDealGetInteger(order.ticket, DEAL_TIME_MSC);
             break;
          default                             :
             res = 0;
             break;
         }
       return res;
      }

    //+------------------------------------------------------------------+
    //|                                                                  |
    //+------------------------------------------------------------------+
    datetime COrder::PositionTimeUpdate(void) const
      {
       datetime res = 0;
       switch(order.status)
         {
          case ORDER_STATUS_MARKET_ACTIVE  :
             res = (datetime)::PositionGetInteger(POSITION_TIME_UPDATE);
             break;
          default                          :
             res = 0;
             break;
         }
       return res;
      }

    //+------------------------------------------------------------------+
    //|                                                                  |
    //+------------------------------------------------------------------+
    long  COrder::PositionTimeUpdateMSC(void) const
      {
       long res = 0;
       switch(order.status)
         {
          case ORDER_STATUS_MARKET_ACTIVE  :
             res =  ::PositionGetInteger(POSITION_TIME_UPDATE_MSC);
             break;
          default                          :
             res = 0;
             break;
         }
       return res;
      }
    //+------------------------------------------------------------------+
    //|                                                                  |
    //+------------------------------------------------------------------+
    bool COrder::OrderCloseByStopLoss(string com_) const
      {
       return
          (
             order.status == ORDER_STATUS_HISTORY_ORDER ? order.reason == ORDER_REASON_SL :
             order.status == ORDER_STATUS_DEAL ? order.reason == DEAL_REASON_SL : false
          );
      }

    //+------------------------------------------------------------------+
    //|                                                                  |
    //+------------------------------------------------------------------+
    bool COrder::OrderCloseByTakeProfit(string com_) const
      {
       return
          (
             order.status == ORDER_STATUS_HISTORY_ORDER ? order.reason == ORDER_REASON_TP :
             order.status == ORDER_STATUS_DEAL ? order.reason == DEAL_REASON_TP : false
          );
      }

    //+------------------------------------------------------------------+
    //|                                                                  |
    //+------------------------------------------------------------------+
    int COrder::ProfitInPoints() const
      {
       int res = 0;
       if(order.type > ORDER_TYPE_SELL || order.point == 0)
          return 0;
       if(order.status == ORDER_STATUS_HISTORY_ORDER)
          return int(order.type == ORDER_TYPE_BUY ? (order.close_price - order.open_price) / order.point : order.type == ORDER_TYPE_SELL ? (order.open_price - order.close_price) / order.point : 0);
       else
          if(order.status == ORDER_STATUS_MARKET_ACTIVE)
            {
             if(order.type == ORDER_TYPE_BUY)
                return int((::SymbolInfoDouble(order.symbol, SYMBOL_BID) - order.open_price) / order.point);
             else
                if(order.type == ORDER_TYPE_SELL)
                   return int((order.open_price -::SymbolInfoDouble(order.symbol, SYMBOL_ASK)) / order.point);
            }
       return (res);
      }

    //+------------------------------------------------------------------+
    //|                                                                  |
    //+------------------------------------------------------------------+
    CPosition::~CPosition()
      {
       this.Clear();
      }

    //+------------------------------------------------------------------+
    //|                                                                  |
    //+------------------------------------------------------------------+
    CPosition::CPosition(ENUM_SORT_ORDERS_MODE sort, ENUM_ORDER_TYPES type, string symbol, long mag, string com, datetime startTime, datetime endTime)
      {
       this.Init(sort, type, symbol, mag, com, startTime, endTime);
      }
    //+------------------------------------------------------------------+
    //|                                                                  |
    //+------------------------------------------------------------------+
    void CPosition::Init(ENUM_SORT_ORDERS_MODE sort, ENUM_ORDER_TYPES type, string symbol, long mag, string com, datetime startTime, datetime endTime)
      {
       this.Clear();
       ZeroOrderTotal(total_init);
       total_init.sort = sort;
       total_init.type = type;
       total_init.symbol = symbol;
       total_init.magic = mag;
       total_init.comment = com;
       total_init.start_time = startTime;
       total_init.end_time = endTime;
       m_total = total_init;
       this.Refresh();
      }
    //+------------------------------------------------------------------+
    //|                                                                  |
    //+------------------------------------------------------------------+
    CPosition::CPosition(ENUM_SORT_ORDERS_MODE sort, ENUM_ORDER_TYPES type, string symbol, int &mag[], string com, datetime startTime, datetime endTime)
      {
       this.Init(sort, type, symbol, mag, com, startTime, endTime);
      }
    //+------------------------------------------------------------------+
    //|                                                                  |
    //+------------------------------------------------------------------+
    void CPosition::Init(ENUM_SORT_ORDERS_MODE sort, ENUM_ORDER_TYPES type, string symbol, int &mag[], string com, datetime startTime, datetime endTime)
      {
       this.Clear();
       ZeroOrderTotal(total_init);
    //
       total_init.sort = sort;
       total_init.type = type;
       total_init.symbol = symbol;
       ArrayCopy(total_init.magics, mag);
       total_init.comment = com;
       total_init.start_time = startTime;
       total_init.end_time = endTime;
       m_total = total_init;
       this.Refresh();
      }
    //+------------------------------------------------------------------+
    //|                                                                  |
    //+------------------------------------------------------------------+
    CPosition::CPosition(ENUM_SORT_ORDERS_MODE sort, ENUM_ORDER_TYPES type, string symbol, int &mag[], string &com[], datetime startTime, datetime endTime)
      {
       this.Init(sort, type, symbol, mag, com, startTime, endTime);
      }
    //+------------------------------------------------------------------+
    //|                                                                  |
    //+------------------------------------------------------------------+
    void CPosition::Init(ENUM_SORT_ORDERS_MODE sort, ENUM_ORDER_TYPES type, string symbol, int &mag[], string &com[], datetime startTime, datetime endTime)
      {
       this.Clear();
       ZeroOrderTotal(total_init);
    //
       total_init.sort = sort;
       total_init.type = type;
       total_init.symbol = symbol;
       ArrayCopy(total_init.magics, mag);
       ArrayCopy(total_init.comments, com);
       total_init.start_time = startTime;
       total_init.end_time = endTime;
       m_total = total_init;
       this.Refresh();
      }
    //+------------------------------------------------------------------+
    //|                                                                  |
    //+------------------------------------------------------------------+
    CPosition::CPosition(ENUM_SORT_ORDERS_MODE sort, ENUM_ORDER_TYPES type, string symbol, long mag, string &com[], datetime startTime, datetime endTime)
      {
       this.Init(sort, type, symbol, mag, com, startTime, endTime);
      }
    //+------------------------------------------------------------------+
    //|                                                                  |
    //+------------------------------------------------------------------+
    void CPosition::Init(ENUM_SORT_ORDERS_MODE sort, ENUM_ORDER_TYPES type, string symbol, long mag, string &com[], datetime startTime, datetime endTime)
      {
       this.Clear();
       ZeroOrderTotal(total_init);
    //
       total_init.sort = sort;
       total_init.type = type;
       total_init.symbol = symbol;
       total_init.magic = mag;
       ArrayCopy(total_init.comments, com);
       total_init.start_time = startTime;
       total_init.end_time = endTime;
       m_total = total_init;
       this.Refresh();
      }
    //+------------------------------------------------------------------+
    //|                                                                  |
    //+------------------------------------------------------------------+
    void CPosition::Clear()
      {
       int total = ArraySize(m_list);
       for(int i = 0; i < total; i++)
         {
          ZeroOrder(m_list);
         }
       ::ArrayFree(m_list);
       ZeroOrderTotal(m_total);
       m_total = total_init;
       total_all_deal = 0;
       total_all_order = 0;
      }
    //+------------------------------------------------------------------+
    //|                                                                  |
    //+------------------------------------------------------------------+
    void CPosition::Refresh()
      {
       this.Clear();
       double price_total = 0;
       if(m_total.type == ORDER_TYPES_BUY_DEAL || m_total.type == ORDER_TYPES_SELL_DEAL || m_total.type == ORDER_TYPES_ALL_DEAL ||
          m_total.type == ORDER_TYPES_ALL_DEAL_PENDING || m_total.type == ORDER_TYPES_BUY_DEAL_PENDING  || m_total.type == ORDER_TYPES_SELL_DEAL_PENDING ||
          m_total.type ==  ORDER_TYPES_ALL_FULL)
         {
          int total = ::PositionsTotal();
          if(total > 0)
            {
             int cnt = ::ArraySize(m_list);
             for(int i = 0; i < total; i++)
               {
                long ticket = (long)::PositionGetTicket(i);
                if(ticket > 0)
                  {
                   COrder  buffer(ORDER_STATUS_MARKET_ACTIVE, ticket);
                   if(m_total.symbol == NULL || buffer.order.symbol == m_total.symbol)
                      if(CheckMagic(buffer.order.magic, m_total.magic, m_total.magics) == true)
                         if(CheckComment(buffer.order.comment, m_total.comment, m_total.comments) == true)
                            if(buffer.order.open_time >= m_total.start_time && (m_total.end_time == 0 || buffer.order.open_time <= m_total.end_time))
                               if(CheckType(buffer.order.type, m_total.type) == true)
                                 {
                                  if(cnt >= ::ArraySize(m_list))
                                    {
                                     ::ArrayResize(m_list, ::ArraySize(m_list) + 64);
                                    }
                                  Sort(total_init.sort, m_list, buffer.order, cnt);
                                  m_total.profit = m_total.profit + buffer.order.profit_full;
                                  m_total.total_volume = m_total.total_volume + buffer.order.volume;
                                  price_total = price_total + (buffer.order.volume * buffer.order.open_price);
                                  cnt++;
                                 }
                  }
               }
             ArrayResize(m_list, cnt);
             m_total.total_record = cnt;
             total_all_deal = total;
            }
         }
       if(m_total.type == ORDER_TYPES_BUY_LIMIT || m_total.type == ORDER_TYPES_BUY_STOP || m_total.type == ORDER_TYPES_BUY_STOP_LIMIT ||
          m_total.type == ORDER_TYPES_SELL_LIMIT || m_total.type == ORDER_TYPES_SELL_STOP || m_total.type == ORDER_TYPES_SELL_STOP_LIMIT ||
          m_total.type == ORDER_TYPES_ALL_PENDING || m_total.type == ORDER_TYPES_BUY_PENDING || m_total.type == ORDER_TYPES_SELL_PENDING ||
          m_total.type == ORDER_TYPES_BUY_DEAL_PENDING ||  m_total.type == ORDER_TYPES_SELL_DEAL_PENDING || m_total.type == ORDER_TYPES_ALL_DEAL_PENDING ||
          m_total.type == ORDER_TYPES_ALL_FULL)
         {
          int total = ::OrdersTotal();
          if(total > 0)
            {
             int cnt = ::ArraySize(m_list);
             for(int i = 0; i < total; i++)
               {
                long ticket = (long)::OrderGetTicket(i);
                if(ticket > 0)
                  {
                   COrder  buffer(ORDER_STATUS_MARKET_PENDING, ticket);
                   if(buffer.order.type != ORDER_TYPE_BUY && buffer.order.type != ORDER_TYPE_SELL)
                      if(m_total.symbol == NULL || buffer.order.symbol == m_total.symbol)
                         if(CheckMagic(buffer.order.magic, m_total.magic, m_total.magics) == true)
                            if(CheckComment(buffer.order.comment, m_total.comment, m_total.comments) == true)
                               if(buffer.order.open_time >= m_total.start_time && (m_total.end_time == 0 || buffer.order.open_time <= m_total.end_time))
                                  if(CheckType(buffer.order.type, m_total.type) == true)
                                    {
                                     if(cnt >= ::ArraySize(m_list))
                                       {
                                        ::ArrayResize(m_list, ::ArraySize(m_list) + 64);
                                       }
                                     Sort(total_init.sort, m_list, buffer.order, cnt);
                                     m_total.profit = m_total.profit + buffer.order.profit_full;
                                     m_total.total_volume = m_total.total_volume + buffer.order.volume;
                                     price_total = price_total + (buffer.order.volume * buffer.order.open_price);
                                     cnt++;
                                    }
                  }
               }
             ArrayResize(m_list, cnt);
             m_total.total_record = cnt;
             total_all_order = total;
            }
         }
       if(m_total.total_volume > 0)
          m_total.average_price = price_total / m_total.total_volume;
      }

    //+------------------------------------------------------------------+
    //|                                                                  |
    //+------------------------------------------------------------------+
    bool CheckSingleMagic(long order_mag, long check_mag)
      {
       return (check_mag == -1 || check_mag == order_mag);
      }
    //+------------------------------------------------------------------+
    //|                                                                  |
    //+------------------------------------------------------------------+
    bool CheckMagic(long order_mag, long mag, long &mags[])
      {
       int total = ArraySize(mags);
       if(total > 0)
         {
          for(int i = 0; i < total; i++)
            {
             if(CheckSingleMagic(order_mag, mags))
                return true;
            }
         }
       else
         {
          return CheckSingleMagic(order_mag, mag);
         }
       return false;
      }
    //+------------------------------------------------------------------+
    //|                                                                  |
    //+------------------------------------------------------------------+
    bool CheckMagic(long order_mag, long mag)
      {
       return CheckSingleMagic(order_mag, mag);
      }


    //+------------------------------------------------------------------+
    //|                                                                  |
    //+------------------------------------------------------------------+
    bool CheckSingleComment(string order_com, string check_com)
      {
       return (check_com == NULL || check_com == "" ||
               ::StringFind(order_com, check_com) == 0);
      }

    //+------------------------------------------------------------------+
    //|                                                                  |
    //+------------------------------------------------------------------+
    bool CheckComment(string order_com, string com, string &coms[])
      {
       int total = ArraySize(coms);
       if(total > 0)
         {
          for(int i = 0; i < total; i++)
            {
             if(CheckSingleComment(order_com, coms))
                return true;
            }
         }
       else
         {
          return CheckSingleComment(order_com, com);
         }
       return false;
      }
    //+------------------------------------------------------------------+
    //|                                                                  |
    //+------------------------------------------------------------------+
    bool CheckComment(string order_com, string com)
      {
       return CheckSingleComment(order_com, com);
      }

    //+------------------------------------------------------------------+
    //|                                                                  |
    //+------------------------------------------------------------------+
    bool CheckType(int order_type, ENUM_ORDER_TYPES type)
      {
       if(type == ORDER_TYPES_ALL_FULL)
          return(true);
       switch(order_type)
         {
          case ORDER_TYPE_BUY:
             return (type == ORDER_TYPES_BUY_DEAL ||
                     type == ORDER_TYPES_BUY_DEAL_PENDING ||
                     type == ORDER_TYPES_ALL_DEAL ||
                     type == ORDER_TYPES_ALL_DEAL_PENDING);
          case ORDER_TYPE_SELL:
             return (type == ORDER_TYPES_SELL_DEAL ||
                     type == ORDER_TYPES_SELL_DEAL_PENDING ||
                     type == ORDER_TYPES_ALL_DEAL ||
                     type == ORDER_TYPES_ALL_DEAL_PENDING);
          case ORDER_TYPE_BUY_LIMIT:
             return (type == ORDER_TYPES_BUY_PENDING ||
                     type == ORDER_TYPES_BUY_DEAL_PENDING ||
                     type == ORDER_TYPES_ALL_PENDING ||
                     type == ORDER_TYPES_ALL_DEAL_PENDING ||
                     type == ORDER_TYPES_BUY_LIMIT);
          case ORDER_TYPE_SELL_LIMIT:
             return (type == ORDER_TYPES_SELL_PENDING ||
                     type == ORDER_TYPES_SELL_DEAL_PENDING ||
                     type == ORDER_TYPES_ALL_PENDING ||
                     type == ORDER_TYPES_ALL_DEAL_PENDING ||
                     type == ORDER_TYPES_SELL_LIMIT);
          case ORDER_TYPE_BUY_STOP:
             return (type == ORDER_TYPES_BUY_PENDING ||
                     type == ORDER_TYPES_BUY_DEAL_PENDING ||
                     type == ORDER_TYPES_ALL_PENDING ||
                     type == ORDER_TYPES_ALL_DEAL_PENDING ||
                     type == ORDER_TYPES_BUY_STOP);
          case ORDER_TYPE_SELL_STOP:
             return (type == ORDER_TYPES_SELL_PENDING ||
                     type == ORDER_TYPES_SELL_DEAL_PENDING ||
                     type == ORDER_TYPES_ALL_PENDING ||
                     type == ORDER_TYPES_ALL_DEAL_PENDING ||
                     type == ORDER_TYPES_SELL_STOP);
          case ORDER_TYPE_BUY_STOP_LIMIT:
             return (type == ORDER_TYPES_BUY_PENDING ||
                     type == ORDER_TYPES_BUY_DEAL_PENDING ||
                     type == ORDER_TYPES_ALL_PENDING ||
                     type == ORDER_TYPES_ALL_DEAL_PENDING ||
                     type == ORDER_TYPES_BUY_STOP_LIMIT);
          case ORDER_TYPE_SELL_STOP_LIMIT:
             return (type == ORDER_TYPES_SELL_PENDING ||
                     type == ORDER_TYPES_SELL_DEAL_PENDING ||
                     type == ORDER_TYPES_ALL_PENDING ||
                     type == ORDER_TYPES_ALL_DEAL_PENDING ||
                     type == ORDER_TYPES_SELL_STOP_LIMIT);
          default:
             return false;
         }
      }

    //+------------------------------------------------------------------+
    //|                                                                  |
    //+------------------------------------------------------------------+
    int  CheckTicket(OrderData &list[], int start_pos, int end_pos, long tk)
      {
       int total = ArraySize(list);
       if(end_pos <= 0 || end_pos > total)
          end_pos = total;
       for(int j = start_pos; j < end_pos; j++)
         {
          if(list[j].ticket == tk)
            {
             return(j);
            }
         }
       return(-1);
      }

    //+------------------------------------------------------------------+
    //|                                                                  |
    //+------------------------------------------------------------------+
    void   Sort(ENUM_SORT_ORDERS_MODE sort, OrderData &list[], OrderData &order, int end_pos)
      {
       if(sort == SORT_BY_ORDER_NULL || end_pos <= 0)
         {
          list[end_pos] = order;
          return;
         }
       for(int j = 0; j < end_pos; j++)
         {
          if(CompareValues(sort, order, list[j], LESS) == true)
            {
             for(int z = end_pos; z > j; z--)
               {
                list[z] = list[z - 1];
               }
             list[j] = order;
             return;
            }
         }
       list[end_pos] = order;
      }

    //+------------------------------------------------------------------+
    //|                                                                  |
    //+------------------------------------------------------------------+
    bool  CompareValues(ENUM_SORT_ORDERS_MODE sort, OrderData &order1, OrderData &order2, ENUM_COMPARER_TYPE mode)
      {
       switch(sort)
         {
          case SORT_BY_ORDER_TIME_OPEN_MSC:
             return(CompareValues(order1.open_time_msc, order2.open_time_msc, mode));
          case SORT_BY_ORDER_TIME_CLOSE_MSC:
             return(CompareValues(order1.close_time_msc, order2.close_time_msc, mode));
          case SORT_BY_ORDER_STATUS:
             return(CompareValues(order1.status, order2.status, mode));
          case SORT_BY_ORDER_REASON:
             return(CompareValues(order1.reason, order2.reason, mode));
          case SORT_BY_ORDER_POSITION_ID:
             return(CompareValues(order1.position_id, order2.position_id, mode));
          case SORT_BY_ORDER_POSITION_BY_ID:
             return(CompareValues(order1.position_by_id, order2.position_by_id, mode));
          case SORT_BY_ORDER_DEAL_ORDER:
             return(CompareValues(order1.deal_order, order2.deal_order, mode));
          case SORT_BY_ORDER_DEAL_ENTRY:
             return(CompareValues(order1.deal_entry, order2.deal_entry, mode));
          case SORT_BY_ORDER_TIME_UPDATE:
             return(CompareValues(order1.update_time, order2.update_time, mode));
          case SORT_BY_ORDER_TIME_UPDATE_MSC:
             return(CompareValues(order1.update_time_msc, order2.update_time_msc, mode));
          //+------
          case SORT_BY_ORDER_VOLUME_CURRENT:
             return(CompareValues(order1.volume_current, order2.volume_current, mode));
          case SORT_BY_ORDER_PRICE_STOP_LIMIT:
             return(CompareValues(order1.price_stop_limit, order2.price_stop_limit, mode));
          //+------
          case SORT_BY_ORDER_EXT_ID:
             return(CompareValues(order1.external_id, order2.external_id, mode));
          //+------
          case SORT_BY_ORDER_TICKET:
             return(CompareValues(order1.ticket, order2.ticket, mode));
          case SORT_BY_ORDER_MAGIC:
             return(CompareValues(order1.magic, order2.magic, mode));
          case SORT_BY_ORDER_TIME_OPEN:
             return(CompareValues(order1.open_time, order2.open_time, mode));
          case SORT_BY_ORDER_TIME_CLOSE:
             return(CompareValues(order1.close_time, order2.close_time, mode));
          case SORT_BY_ORDER_TIME_EXP:
             return(CompareValues(order1.time_exp, order2.time_exp, mode));
          case SORT_BY_ORDER_TYPE:
             return(CompareValues(order1.type, order2.type, mode));
          case SORT_BY_ORDER_PROFIT_PT:
             return(CompareValues(order1.profit_pt, order2.profit_pt, mode));
          case SORT_BY_ORDER_CLOSE_BY_SL:
             return(CompareValues(order1.close_by_sl, order2.close_by_sl, mode));
          case SORT_BY_ORDER_CLOSE_BY_TP:
             return(CompareValues(order1.close_by_tp, order2.close_by_tp, mode));
          case SORT_BY_ORDER_PRICE_OPEN:
             return(CompareValues(order1.open_price, order2.open_price, mode));
          case SORT_BY_ORDER_PRICE_CLOSE:
             return(CompareValues(order1.close_price, order2.close_price, mode));
          case SORT_BY_ORDER_SL:
             return(CompareValues(order1.sl_price, order2.sl_price, mode));
          case SORT_BY_ORDER_TP:
             return(CompareValues(order1.tp_price, order2.tp_price, mode));
          case SORT_BY_ORDER_PROFIT:
             return(CompareValues(order1.profit, order2.profit, mode));
          case SORT_BY_ORDER_COMMISSION:
             return(CompareValues(order1.commission, order2.commission, mode));
          case SORT_BY_ORDER_SWAP:
             return(CompareValues(order1.swap, order2.swap, mode));
          case SORT_BY_ORDER_VOLUME:
             return(CompareValues(order1.volume, order2.volume, mode));
          case SORT_BY_ORDER_PROFIT_FULL:
             return(CompareValues(order1.profit_full, order2.profit_full, mode));
          case SORT_BY_ORDER_SYMBOL:
             return(CompareValues(order1.symbol, order2.symbol, mode));
          case SORT_BY_ORDER_COMMENT:
             return(CompareValues(order1.comment, order2.comment, mode));
          default:
             return(false);
             break;
         }
      }

    template<typename T>
    bool CompareValues(T value1, T value2, ENUM_COMPARER_TYPE mode)
      {
       switch(mode)
         {
          case EQUAL:
             return value1 == value2;
          case NO_EQUAL:
             return value1 != value2;
          case MORE:
             return value1 > value2;
          case LESS:
             return value1 < value2;
          case EQUAL_OR_MORE:
             return value1 >= value2;
          case EQUAL_OR_LESS:
             return value1 <= value2;
          default:
             return false;
         }
      }
    //+------------------------------------------------------------------+
    //|                                                                  |
    //+------------------------------------------------------------------+
    ENUM_ORDER_TYPE_FILLING GetFilling(const string symbol, const uint type = ORDER_FILLING_FOK)
      {
       const ENUM_SYMBOL_TRADE_EXECUTION ExeMode = (ENUM_SYMBOL_TRADE_EXECUTION)::SymbolInfoInteger(symbol, SYMBOL_TRADE_EXEMODE);
       const int FillingMode = (int)::SymbolInfoInteger(symbol, SYMBOL_FILLING_MODE);
       return ((FillingMode == 0 || (type >= ORDER_FILLING_RETURN) || ((FillingMode & (type + 1)) != type + 1)) ?
               (((ExeMode == SYMBOL_TRADE_EXECUTION_EXCHANGE) || (ExeMode == SYMBOL_TRADE_EXECUTION_INSTANT)) ?
                ORDER_FILLING_RETURN : ((FillingMode == SYMBOL_FILLING_IOC) ? ORDER_FILLING_IOC : ORDER_FILLING_FOK)) :
               (ENUM_ORDER_TYPE_FILLING)type);
      }

    //+------------------------------------------------------------------+
    //|                                                                  |
    //+------------------------------------------------------------------+
    void SetupCommonOrderRequest(MqlTradeRequest& request, M_SymbolData& symbols, double volume, long mag, string com, int slippage, ENUM_ORDER_TYPE orderType, bool isPending = false)
      {
       ::ZeroMemory(request);
       request.action = isPending ? TRADE_ACTION_PENDING : TRADE_ACTION_DEAL;
       request.magic = mag;
       request.symbol = symbols.symbol;
       symbols.NormalizeLot(volume, true);
       request.volume = volume;
       request.deviation = slippage;
       request.type = orderType;
       request.type_filling = GetFilling(request.symbol);
       request.comment = com;
      }
    //+------------------------------------------------------------------+
    //|                                                                  |
    //+------------------------------------------------------------------+
    void SetStopLossTakeProfit(MqlTradeRequest& request, M_SymbolData& symbols, double sl, double tp, double price, bool isBuy)
      {
       if((int)sl > 0 && sl < symbols.minStopLevel + 5)
          sl = symbols.minStopLevel + 5;
       if((int)tp > 0 && tp < symbols.minStopLevel + 5)
          tp = symbols.minStopLevel + 5;
       if(request.sl == 0 && (int)sl > 0)
          request.sl = isBuy ? price - sl * symbols.point : price + sl * symbols.point;
       if(request.tp == 0 && (int)tp > 0)
          request.tp = isBuy ? price + tp * symbols.point : price - tp * symbols.point;
      }


    //+------------------------------------------------------------------+
    //|                                                                  |
    //+------------------------------------------------------------------+
    bool IsEnoughMoney(M_SymbolData &symbols, double volume, ENUM_ORDER_TYPE orderType)
      {
       double price = 0;
       if(orderType == ORDER_TYPE_BUY || orderType == ORDER_TYPE_BUY_LIMIT || orderType == ORDER_TYPE_BUY_STOP || orderType == ORDER_TYPE_BUY_STOP_LIMIT)
         {
          orderType = ORDER_TYPE_BUY;
          price = symbols.ask;
         }
       else
         {
          orderType = ORDER_TYPE_SELL;
          price = symbols.bid;
         }
       double requiredMargin = 0;
       bool res = OrderCalcMargin(orderType, symbols.symbol, volume, price, requiredMargin);
       double freeMargin = AccountInfoDouble(ACCOUNT_MARGIN_FREE);
       if(freeMargin < requiredMargin)
         {
          printf("可用保证金不足开仓%f手,无法开仓!", volume);
          return false;
         }
       return true;
      }

    //+------------------------------------------------------------------+
    //|                                                                  |
    //+------------------------------------------------------------------+
    long  OrderSend(string   symbol,
                    int      cmd,
                    double   volume,
                    double   price,
                    int      slippage,
                    double   stoploss,
                    double   takeprofit,
                    string   comment = NULL,
                    int      magic = 0,
                    datetime expiration = 0,
                    color    arrow_color = clrNONE
                   )
      {
       M_SymbolData symbolC(symbol);
       ENUM_ORDER_TYPE type=ENUM_ORDER_TYPE(cmd);
       return OpenOrder(symbolC, type, volume, 0, 0,magic, comment, stoploss, takeprofit, slippage, price,expiration);
      }
    //+------------------------------------------------------------------+
    //|                                                                  |
    //+------------------------------------------------------------------+
    long OpenOrder(M_SymbolData& symbols,
                   ENUM_ORDER_TYPE orderType,
                   double volume,
                   double sl,
                   double tp,
                   long mag,
                   string com,
                   double stopPrice = 0,
                   double takePrice = 0,
                   int slippage = 0,
                   double price = 0,
                   datetime expiration = 0,
                   int cycles = 2)
      {
       ResetLastError();
       long ticket = 0;
       MqlTradeRequest request;
       MqlTradeResult result;
       if(!CheckTradeConditions(volume, sl, tp, symbols.symbol))
         {
          return -1;
         }
       if(IsEnoughMoney(symbols, volume, orderType) == false)
          return 0;
       bool isPending = (orderType == ORDER_TYPE_BUY_LIMIT || orderType == ORDER_TYPE_BUY_STOP || orderType == ORDER_TYPE_BUY_STOP_LIMIT ||
                         orderType == ORDER_TYPE_SELL_LIMIT || orderType == ORDER_TYPE_SELL_STOP || orderType == ORDER_TYPE_SELL_STOP_LIMIT);
       SetupCommonOrderRequest(request, symbols, volume, mag, com, slippage, orderType, isPending);
       if(isPending)
         {
          price = NormalizeDouble(price, symbols.digits);
          request.price = price;
          request.expiration = expiration;
          symbols.Refresh();
          if(orderType == ORDER_TYPE_BUY_LIMIT || orderType == ORDER_TYPE_BUY_STOP || orderType == ORDER_TYPE_BUY_STOP_LIMIT)
            {
             if(MathAbs(symbols.ask - request.price) < symbols.minStopLevel * symbols.point)
               {
                printf("挂单价 %f,挂单距离小于平台最小要求距离", DoubleToString(request.price, symbols.digits));
                return 0;
               }
             request.type = (symbols.ask > price) ? ORDER_TYPE_BUY_LIMIT : ORDER_TYPE_BUY_STOP;
            }
          else
            {
             if(MathAbs(symbols.bid - request.price) < symbols.minStopLevel * symbols.point)
               {
                printf("挂单价 %f,挂单距离小于平台最小要求距离", DoubleToString(request.price, symbols.digits));
                return 0;
               }
             request.type = (symbols.bid < price) ? ORDER_TYPE_SELL_LIMIT : ORDER_TYPE_SELL_STOP;
            }
         }
       else
         {
          symbols.Refresh();
          request.price = (orderType == ORDER_TYPE_BUY) ? symbols.ask : symbols.bid;
         }
       request.sl = 0;
       request.tp = 0;
       bool isBuy = (orderType == ORDER_TYPE_BUY || orderType == ORDER_TYPE_BUY_LIMIT || orderType == ORDER_TYPE_BUY_STOP || orderType == ORDER_TYPE_BUY_STOP_LIMIT);
       SetStopLossTakeProfit(request, symbols, sl, tp, request.price, isBuy);
       double open_price = 0;
       for(int j = 0; j < cycles; j++)
         {
          if(::OrderSend(request, result))
            {
             ticket = (long)result.order;
             open_price = result.price;
             break;
            }
          else
            {
             ::Sleep(100);
            }
         }
       if(ticket > 0)
         {
          SetSLTP(ticket, sl, tp, stopPrice, takePrice, open_price);
         }
       else
         {
          string orderTypeStr = "";
          switch(request.type)
            {
             case ORDER_TYPE_BUY:
                orderTypeStr = "BUY";
                break;
             case ORDER_TYPE_SELL:
                orderTypeStr = "SELL";
                break;
             case ORDER_TYPE_BUY_LIMIT:
                orderTypeStr = "BUY LIMIT";
                break;
             case ORDER_TYPE_SELL_LIMIT:
                orderTypeStr = "SELL LIMIT";
                break;
             case ORDER_TYPE_BUY_STOP:
                orderTypeStr = "BUY STOP";
                break;
             case ORDER_TYPE_SELL_STOP:
                orderTypeStr = "SELL STOP";
                break;
            }
          printf("%s %s 价格 %f,手数 %f,开单失败,错误代码=%d,止损价格 %f,止盈价格 %f",
                 symbols.symbol, orderTypeStr, request.price, volume, GetLastError(), request.sl, request.tp);
         }
       return ticket;
      }

    //+------------------------------------------------------------------+
    //|                                                                  |
    //+------------------------------------------------------------------+
    bool CheckTradeConditions(double volume, double sl, double tp, string symbol)
      {
       if(volume <= 0)
         {
          Print("错误: 手数必须大于 0,当前手数: ", volume);
          return false;
         }
       if(sl < 0 || tp < 0)
         {
          Print("错误: 止损和止盈值不能为负数,当前止损: ", sl, ",当前止盈: ", tp);
          return false;
         }
       if(!MQLInfoInteger(MQL_TESTER))
         {
          if(!SymbolInfoInteger(symbol, SYMBOL_TRADE_MODE))
            {
             Print("错误: 该交易品种当前不可交易: ", symbol);
             return false;
            }
          if(SymbolInfoDouble(symbol, SYMBOL_BID) <= 0 || SymbolInfoDouble(symbol, SYMBOL_ASK) <= 0)
            {
             Print(symbol, " 交易品种不可用!");
             return false;
            }
         }
       return true;
      }

    //+------------------------------------------------------------------+
    //|                                                                  |
    //+------------------------------------------------------------------+
    int CloseOrders(OrderData &list[],
                    int    slippage = 0,
                    color  arrow_color = clrFireBrick,
                    int cycles = 2)
      {
       int cnt = 0;
       for(int j = 1; j <= cycles; j++)
         {
          bool res = true;
          int total = ArraySize(list);
          for(int i = 0; i < total; i++)
            {
             if(CloseTicket(list.ticket, 0, slippage, arrow_color) == false)
               {
                res = false;
               }
             else
               {
                cnt++;
               }
            }
          if(res == true)
            {
             break;
            }
          else
            {
             ::Sleep(200);
            }
         }
       return(cnt);
      }

    //+------------------------------------------------------------------+
    //|                                                                  |
    //+------------------------------------------------------------------+
    int CloseOrders(string symbol,
                    int   mag,
                    ENUM_ORDER_TYPES type,
                    string com,
                    int    slippage = 0,
                    color  arrow_color = clrFireBrick,
                    int cycles = 2)
      {
       CPosition orders(SORT_BY_ORDER_NULL, type, symbol, mag, com, 0, 0);
       return CloseOrders(orders.m_list, slippage, arrow_color, cycles);
      }
    //+------------------------------------------------------------------+
    //|                                                                  |
    //+------------------------------------------------------------------+
    double  CloseTicket(long   ticket,
                        double closeVolume = 0,
                        int    slippage = 0,
                        bool   rounding = true,
                        color  arrow_color = clrNONE)
      {
       if(PositionSelectByTicket(ticket))
         {
          MqlTradeRequest request;
          MqlTradeResult result;
          ZeroMemory(request);
          ZeroMemory(result);
          request.action = TRADE_ACTION_DEAL;
          request.position = ticket;
          request.symbol = PositionGetString(POSITION_SYMBOL);
          double positionVolume = PositionGetDouble(POSITION_VOLUME);
          if(closeVolume <= 0 || closeVolume > positionVolume)
             request.volume = positionVolume;
          else
            {
             request.volume = closeVolume;
             M_SymbolData symbols(request.symbol);
             symbols.NormalizeLot(request.volume, rounding);
            }
          request.deviation = slippage;
          request.magic = PositionGetInteger(POSITION_MAGIC);
          request.type_filling = GetFilling(request.symbol);
          if(PositionGetInteger(POSITION_TYPE) == POSITION_TYPE_BUY)
            {
             request.type = ORDER_TYPE_SELL;
             request.price = SymbolInfoDouble(request.symbol, SYMBOL_BID);
            }
          else
            {
             request.type = ORDER_TYPE_BUY;
             request.price = SymbolInfoDouble(request.symbol, SYMBOL_ASK);
            }
          if(!OrderSend(request, result))
            {
             printf("平仓持仓订单 #%d 失败, 错误代码: %d", ticket, GetLastError());
             return 0;
            }
          return request.volume;
         }
       if(OrderSelect(ticket))
         {
          MqlTradeRequest request;
          MqlTradeResult result;
          ZeroMemory(request);
          ZeroMemory(result);
          request.volume = OrderGetDouble(ORDER_VOLUME_CURRENT);
          request.action = TRADE_ACTION_REMOVE;
          request.order = ticket;
          request.symbol   = OrderGetString(ORDER_SYMBOL);
          request.type_filling = GetFilling(request.symbol);
          if(!OrderSend(request, result))
            {
             printf("删除挂单 #%d 失败, 错误代码: %d", ticket, GetLastError());
             return 0;
            }
          return request.volume;
         }
       printf("错误: 无法找到订单 #%d", ticket);
       return 0;
      }
    //+------------------------------------------------------------------+
    //|                                                                  |
    //+------------------------------------------------------------------+
    double CalFinalPrice(double inputPrice, double defaultPrice, double orderPrice, double slOrTp, M_SymbolData & symbols, ENUM_ORDER_TYPE orderType, bool isSL)
      {
       double finalPrice = inputPrice;
       if(finalPrice < 0)
         {
          if((int)slOrTp > 0)
            {
             int min = symbols.minStopLevel + symbols.spread + 5;
             if(slOrTp < min)
               {
                slOrTp = min;
               }
             if(orderType == ORDER_TYPE_BUY || orderType == ORDER_TYPE_BUY_LIMIT || orderType == ORDER_TYPE_BUY_STOP || orderType == ORDER_TYPE_BUY_STOP_LIMIT)
               {
                finalPrice = orderPrice + (isSL ? -1 : 1) * slOrTp * symbols.point;
               }
             else
               {
                finalPrice = orderPrice + (isSL ? 1 : -1) * slOrTp * symbols.point;
               }
            }
         }
       if(finalPrice < 0)
         {
          finalPrice = defaultPrice;
         }
       return ::NormalizeDouble(finalPrice, symbols.digits);
      }

    //+------------------------------------------------------------------+
    //|                                                                  |
    //+------------------------------------------------------------------+
    bool SetSLTP(ulong ticket, double sl, double tp, double stopPrice = -1, double takePrice = -1, double price = 0, color arrow_color = clrNONE, int cycles = 2)
      {
       if(PositionSelectByTicket(ticket))
         {
          M_SymbolData symbols(PositionGetString(POSITION_SYMBOL));
          price = PositionGetDouble(POSITION_PRICE_OPEN);
          ENUM_ORDER_TYPE orderType = (ENUM_ORDER_TYPE)PositionGetInteger(POSITION_TYPE);
          double finalStopPrice = CalFinalPrice(stopPrice, PositionGetDouble(POSITION_SL), price, sl, symbols, orderType, true);
          double finalTakePrice = CalFinalPrice(takePrice, PositionGetDouble(POSITION_TP), price, tp, symbols, orderType, false);
          if(MathAbs(finalStopPrice - PositionGetDouble(POSITION_SL)) <= symbols.point &&
             MathAbs(finalTakePrice - PositionGetDouble(POSITION_TP)) <= symbols.point)
            {
             return false;
            }
          MqlTradeRequest request;
          MqlTradeResult result;
          ZeroMemory(request);
          ZeroMemory(result);
          request.action = TRADE_ACTION_SLTP;
          request.position = ticket;
          request.symbol = OrderGetString(ORDER_SYMBOL);
          request.price = price;
          request.sl = finalStopPrice;
          request.tp = finalTakePrice;
          request.type_filling = GetFilling(request.symbol);
          if(!OrderSend(request, result))
            {
             printf("订单%d设置止盈%f止损%f失败,错误码:%d", ticket, finalTakePrice, finalStopPrice, GetLastError());
             return false;
            }
          return true;
         }
       if(OrderSelect(ticket))
         {
          M_SymbolData symbols(OrderGetString(ORDER_SYMBOL));
          if(price <= 0)
             price = OrderGetDouble(ORDER_PRICE_OPEN);
          ENUM_ORDER_TYPE orderType = (ENUM_ORDER_TYPE)OrderGetInteger(ORDER_TYPE);
          double finalStopPrice = CalFinalPrice(stopPrice, OrderGetDouble(ORDER_SL), price, sl, symbols, orderType, true);
          double finalTakePrice = CalFinalPrice(takePrice, OrderGetDouble(ORDER_TP), price, tp, symbols, orderType, false);
          if(MathAbs(finalStopPrice - OrderGetDouble(ORDER_SL)) <= symbols.point &&
             MathAbs(finalTakePrice - OrderGetDouble(ORDER_TP)) <= symbols.point &&
             price == OrderGetDouble(ORDER_PRICE_OPEN))
            {
             return false;
            }
          MqlTradeRequest request;
          MqlTradeResult result;
          ZeroMemory(request);
          request.action = TRADE_ACTION_MODIFY;
          request.order = ticket;
          request.symbol = OrderGetString(ORDER_SYMBOL);
          request.price = price;
          request.sl = finalStopPrice;
          request.tp = finalTakePrice;
          request.type_filling = GetFilling(request.symbol);
          if(!OrderSend(request, result))
            {
             printf("订单%d设置止盈%f止损%f失败,错误码:%d", ticket, finalTakePrice, finalStopPrice, GetLastError());
             return false;
            }
          return true;
         }
       printf("错误: 无法找到订单 #%d", ticket);
       return false;
      }

    //+------------------------------------------------------------------+
    //|                                                                  |
    //+------------------------------------------------------------------+
    void ZeroOrder(OrderData &order)
      {
       order.status = 0;
       order.ticket = order.magic = order.position_id = order.position_by_id =
                                       order.deal_order = order.deal_entry = order.reason =
                                             order.open_time_msc = order.close_time_msc = order.update_time_msc = 0;
       order.type = order.profit_pt = 0;
       order.close_by_sl = order.close_by_tp = false;
       order.point = order.volume = order.volume_current = order.open_price =
                                       order.close_price = order.sl_price = order.tp_price = order.profit =
                                             order.commission = order.swap = order.profit_full = order.price_stop_limit = 0.0;
       order.open_time = order.close_time = order.time_exp = order.update_time = 0;
       order.symbol = order.comment = order.external_id = "";
      }


    //+------------------------------------------------------------------+
    //|                                                                  |
    //+------------------------------------------------------------------+
    void ZeroOrderTotal(OrderTotal &total)
      {
       total.type = 0;
       total.sort = 0;
       total.magic = 0;
       total.total_record = total.change_number = 0;
       total.profit = total.total_volume = total.average_price = 0.0;
       total.start_time = total.end_time = 0;
       total.symbol = total.comment = "";
       ArrayFree(total.magics);
       ArrayFree(total.comments);
       ArrayResize(total.magics, 0);
       ArrayResize(total.comments, 0);
      }

    //+------------------------------------------------------------------+
    //|                                                                  |
    //+------------------------------------------------------------------+
    int  AccountLeverage(void)
      {
       return (int)AccountInfoInteger(ACCOUNT_LEVERAGE);
      }
    //+------------------------------------------------------------------+
    //|                                                                  |
    //+------------------------------------------------------------------+
    bool IsTradeAllowed()
      {
       return (bool)MQLInfoInteger(MQL_TRADE_ALLOWED);
      }
    //+------------------------------------------------------------------+
    //|                                                                  |
    //+------------------------------------------------------------------+
    bool IsExpertEnabled()
      {
       return (bool)TerminalInfoInteger(TERMINAL_TRADE_ALLOWED);
      }
    //+------------------------------------------------------------------+
    //|                                                                  |
    //+------------------------------------------------------------------+
    int ObjectFind(const string name)
      {
       return ObjectFind(0, name);
      }
    //+------------------------------------------------------------------+
    //|                                                                  |
    //+------------------------------------------------------------------+
    bool  ObjectMove(string  name,int point_index,datetime time,double price)
      {
       return ObjectMove(0,  name, point_index, time, price);
      }
    //+------------------------------------------------------------------+
    //|                                                                  |
    //+------------------------------------------------------------------+
    void  WindowRedraw()
      {
       ChartRedraw(0);
      }

    //+------------------------------------------------------------------+
    //|                                                                  |
    //+------------------------------------------------------------------+
    double  AccountFreeMargin(void)
      {
       return AccountInfoDouble(ACCOUNT_MARGIN_FREE);
      }
    //+------------------------------------------------------------------+

    //+------------------------------------------------------------------+
    //|                                                                  |
    //+------------------------------------------------------------------+
    bool  OrderClose(long        ticket,
                     double     lots,
                     double     price,
                     int        slippage,
                     color      arrow_color = clrNONE
                    )
      {
       if(CloseTicket(ticket, lots, slippage, true, arrow_color)>0)
          return true;
       return false;
      }
    //+------------------------------------------------------------------+
    //|                                                                  |
    //+------------------------------------------------------------------+
    bool  OrderModify(long       ticket,
                      double     price,
                      double     stoploss,
                      double     takeprofit,
                      datetime   expiration,
                      color      arrow_color = clrNONE
                     )
      {
       return SetSLTP(ticket,0,0,stoploss,takeprofit,price,arrow_color);
      }

    //+------------------------------------------------------------------+
    //|                                                                  |
    //+------------------------------------------------------------------+
    int CloseProfitLoss(int  pt,
                        double money,
                        ENUM_COMPARER_TYPE type_comparer,
                        string symbol,
                        int mag,
                        ENUM_ORDER_TYPES type,
                        string com,
                        int    slippage = 0,
                        color  arrow_color = clrFireBrick)
      {
       CPosition orders(SORT_BY_ORDER_NULL, type, symbol, mag, com, 0, END_TIME);
       return CloseProfitLoss(orders.m_list, pt, money, type_comparer, slippage, arrow_color);
      }

    //+------------------------------------------------------------------+
    //|                                                                  |
    //+------------------------------------------------------------------+
    int CloseProfitLoss(OrderData &list[],
                        int  pt,
                        double money,
                        ENUM_COMPARER_TYPE type_comparer,
                        int    slippage = 0,
                        color  arrow_color = clrFireBrick)
      {
       int res = 0;
       int total = ArraySize(list);
       for(int i = 0; i < total; i++)
         {
          if(CompareValues(list.profit_full, money, type_comparer) == true)
             if(CompareValues(list.profit_pt, pt, type_comparer) == true)
               {
                if(CloseTicket(list.ticket, 0, slippage, arrow_color) == true)
                   res++;
               }
         }
       return res;
      }
    //+------------------------------------------------------------------+
    //|                                                                  |
    //+------------------------------------------------------------------+
    string   AccountCurrency(void)
      {
       return AccountInfoString(ACCOUNT_CURRENCY);
      }
    //+------------------------------------------------------------------+
    //|                                                                  |
    //+------------------------------------------------------------------+
    int TimeYear(const datetime dt)
      {
       MqlDateTime mdts;
       TimeToStruct(dt, mdts);
       return mdts.year;
      }

    //+------------------------------------------------------------------+
    //|                                                                  |
    //+------------------------------------------------------------------+
    int TimeMonth(const datetime dt)
      {
       MqlDateTime mdts;
       TimeToStruct(dt, mdts);
       return mdts.mon;
      }

    //+------------------------------------------------------------------+
    //|                                                                  |
    //+------------------------------------------------------------------+
    int TimeDay(const datetime dt)
      {
       MqlDateTime mdts;
       TimeToStruct(dt, mdts);
       return mdts.day;
      }

    //+------------------------------------------------------------------+
    //|                                                                  |
    //+------------------------------------------------------------------+
    CHistory::~CHistory()
      {
       this.Clear();
      }
    //+------------------------------------------------------------------+
    //|                                                                  |
    //+------------------------------------------------------------------+
    CHistory::CHistory(ENUM_SORT_ORDERS_MODE sort, ENUM_ORDER_TYPES type, string symbol, int mag, string com, datetime startTime, datetime endTime, bool basis_open = false)
      {
       this.Init(sort, type, symbol, mag, com, startTime, endTime, basis_open);
      }
    //+------------------------------------------------------------------+
    //|                                                                  |
    //+------------------------------------------------------------------+
    void CHistory::Init(ENUM_SORT_ORDERS_MODE sort, ENUM_ORDER_TYPES type, string symbol, int mag, string com, datetime startTime, datetime endTime, bool basis_open = false)
      {
       this.Clear();
       ZeroOrderTotal(total_init);
    //
       total_init.sort = sort;
       total_init.type = type;
       total_init.symbol = symbol;
       total_init.magic = mag;
       total_init.comment = com;
       total_init.start_time = startTime;
       total_init.end_time = endTime;
       m_total = total_init;
       addNumber = 5;
       m_basis_open = basis_open;
       this.Refresh();
      }
    //+------------------------------------------------------------------+
    //|                                                                  |
    //+------------------------------------------------------------------+
    CHistory::CHistory(ENUM_SORT_ORDERS_MODE sort, ENUM_ORDER_TYPES type, string symbol, int &mag[], string com, datetime startTime, datetime endTime, bool basis_open = false)
      {
       this.Init(sort, type, symbol, mag, com, startTime, endTime, basis_open);
      }
    //+------------------------------------------------------------------+
    //|                                                                  |
    //+------------------------------------------------------------------+
    void CHistory::Init(ENUM_SORT_ORDERS_MODE sort, ENUM_ORDER_TYPES type, string symbol, int &mag[], string com, datetime startTime, datetime endTime, bool basis_open = false)
      {
       this.Clear();
       ZeroOrderTotal(total_init);
    //
       total_init.sort = sort;
       total_init.type = type;
       total_init.symbol = symbol;
       ArrayCopy(total_init.magics, mag);
       total_init.comment = com;
       total_init.start_time = startTime;
       total_init.end_time = endTime;
       m_total = total_init;
       addNumber = 5;
       m_basis_open = basis_open;
       this.Refresh();
      }
    //+------------------------------------------------------------------+
    //|                                                                  |
    //+------------------------------------------------------------------+
    CHistory::CHistory(ENUM_SORT_ORDERS_MODE sort, ENUM_ORDER_TYPES type, string symbol, int &mag[], string &com[], datetime startTime, datetime endTime, bool basis_open = false)
      {
       this.Init(sort, type, symbol, mag, com, startTime, endTime, basis_open);
      }
    //+------------------------------------------------------------------+
    //|                                                                  |
    //+------------------------------------------------------------------+
    void CHistory::Init(ENUM_SORT_ORDERS_MODE sort, ENUM_ORDER_TYPES type, string symbol, int &mag[], string &com[], datetime startTime, datetime endTime, bool basis_open = false)
      {
       this.Clear();
       ZeroOrderTotal(total_init);
    //
       total_init.sort = sort;
       total_init.type = type;
       total_init.symbol = symbol;
       ArrayCopy(total_init.magics, mag);
       ArrayCopy(total_init.comments, com);
       total_init.start_time = startTime;
       total_init.end_time = endTime;
       m_total = total_init;
       addNumber = 5;
       m_basis_open = basis_open;
       this.Refresh();
      }
    //+------------------------------------------------------------------+
    //|                                                                  |
    //+------------------------------------------------------------------+
    CHistory::CHistory(ENUM_SORT_ORDERS_MODE sort, ENUM_ORDER_TYPES type, string symbol, int mag, string &com[], datetime startTime, datetime endTime, bool basis_open = false)
      {
       this.Init(sort, type, symbol, mag, com, startTime, endTime, basis_open);
      }
    //+------------------------------------------------------------------+
    //|                                                                  |
    //+------------------------------------------------------------------+
    void CHistory::Init(ENUM_SORT_ORDERS_MODE sort, ENUM_ORDER_TYPES type, string symbol, int mag, string &com[], datetime startTime, datetime endTime, bool basis_open = false)
      {
       this.Clear();
       ZeroOrderTotal(total_init);
    //
       total_init.sort = sort;
       total_init.type = type;
       total_init.symbol = symbol;
       total_init.magic = mag;
       ArrayCopy(total_init.comments, com);
       total_init.start_time = startTime;
       total_init.end_time = endTime;
       m_total = total_init;
       addNumber = 5;
       m_basis_open = basis_open;
       this.Refresh();
      }
    //+------------------------------------------------------------------+
    //|                                                                  |
    //+------------------------------------------------------------------+
    void CHistory::Clear()
      {
       int total = ArraySize(m_list);
       for(int i = 0; i < total; i++)
         {
          ZeroOrder(m_list);
         }
       ::ArrayFree(m_list);
       ZeroOrderTotal(m_total);
       m_total = total_init;
       total_all_deal = 0;
       total_all_order = 0;
      }
    //+------------------------------------------------------------------+
    //|                                                                  |
    //+------------------------------------------------------------------+
    void CHistory::AddNew(OrderData &order)
      {
       int cnt = ArraySize(m_list_new);
       ::ArrayResize(m_list_new, cnt + 1);
       Sort(total_init.sort, m_list_new, order, cnt);
      }
    //+------------------------------------------------------------------+
    //|                                                                  |
    //+------------------------------------------------------------------+
    bool CHistory::CheckTime(datetime open_time, datetime close_time, datetime time_start, datetime time_end, bool basis)
      {
       if(basis == false)
         {
          if(close_time > time_start && (time_end == 0 || close_time < time_end))
             return true;
         }
       else
         {
          if(open_time > time_start && (time_end == 0 || open_time < time_end))
             return true;
         }
       return false;
      }
    //+------------------------------------------------------------------+
    //|                                                                  |
    //+------------------------------------------------------------------+
    void CHistory::Refresh()
      {
       ArrayResize(m_list_new, 0);
       m_total.change_number = 0;
       HistorySelect(m_total.start_time, m_total.end_time);
       if(m_total.type == ORDER_TYPES_BUY_DEAL || m_total.type == ORDER_TYPES_SELL_DEAL || m_total.type == ORDER_TYPES_ALL_DEAL ||
          m_total.type == ORDER_TYPES_ALL_DEAL_PENDING || m_total.type == ORDER_TYPES_BUY_DEAL_PENDING  || m_total.type == ORDER_TYPES_SELL_DEAL_PENDING ||
          m_total.type ==  ORDER_TYPES_ALL_FULL)
         {
          int total = ::HistoryDealsTotal();
          int number = total - total_all_deal;
          if(number < 0)
            {
             number = addNumber;
            }
          if(number > 0)
            {
             int cnt = ::ArraySize(m_list);
             int startPos = total - number - addNumber;
             startPos = ::MathMax(startPos, 0);
             for(int i = startPos; i < total; i++)
               {
                long ticket = (long)HistoryDealGetTicket(i);
                if(ticket > 0)
                   if(HistoryDealGetInteger(ticket, DEAL_ENTRY) != DEAL_ENTRY_IN)
                     {
                      COrder  buffer(ORDER_STATUS_DEAL, ticket);
                      if(m_total.symbol == NULL || buffer.order.symbol == m_total.symbol)
                         if(CheckMagic(buffer.order.magic, m_total.magic, m_total.magics) == true)
                            if(CheckComment(buffer.order.comment, m_total.comment, m_total.comments) == true)
                               if(CheckTime(buffer.order.open_time, buffer.order.close_time, m_total.start_time, m_total.end_time, m_basis_open) == true)
                                  if(CheckType(buffer.order.type, m_total.type) == true)
                                     if(CheckTicket(m_list, 0, 0, buffer.order.ticket) < 0)
                                       {
                                        if(cnt >= ::ArraySize(m_list))
                                          {
                                           ::ArrayResize(m_list, ::ArraySize(m_list) + 64);
                                          }
                                        Sort(total_init.sort, m_list, buffer.order, cnt);
                                        m_total.profit = m_total.profit + buffer.order.profit_full;
                                        m_total.total_volume = m_total.total_volume + buffer.order.volume;
                                        cnt++;
                                        AddNew(buffer.order);
                                       }
                      if(m_total.end_time > 0 && buffer.order.close_time - m_total.end_time > 50000)
                         break;
                     }
               }
             m_total.change_number = m_total.change_number + (cnt - m_total.total_record);
             ::ArrayResize(m_list, cnt);
             m_total.total_record = cnt;
             total_all_deal = total;
            }
         }
       if(m_total.type == ORDER_TYPES_BUY_LIMIT || m_total.type == ORDER_TYPES_BUY_STOP || m_total.type == ORDER_TYPES_BUY_STOP_LIMIT ||
          m_total.type == ORDER_TYPES_SELL_LIMIT || m_total.type == ORDER_TYPES_SELL_STOP || m_total.type == ORDER_TYPES_SELL_STOP_LIMIT ||
          m_total.type == ORDER_TYPES_ALL_PENDING || m_total.type == ORDER_TYPES_BUY_PENDING || m_total.type == ORDER_TYPES_SELL_PENDING ||
          m_total.type == ORDER_TYPES_BUY_DEAL_PENDING ||  m_total.type == ORDER_TYPES_SELL_DEAL_PENDING || m_total.type == ORDER_TYPES_ALL_DEAL_PENDING ||
          m_total.type == ORDER_TYPES_ALL_FULL)
         {
          int total = ::HistoryOrdersTotal();
          int number = total - total_all_order;
          if(number < 0)
            {
             number = addNumber;
            }
          if(number > 0)
            {
             int cnt = ::ArraySize(m_list);
             int startPos = total - number - addNumber;
             startPos = ::MathMax(startPos, 0);
             for(int i = startPos; i < total; i++)
               {
                long ticket = (long)HistoryOrderGetTicket(i);
                if(ticket > 0)
                   if(HistoryOrderGetInteger(ticket, ORDER_STATE) == ORDER_STATE_CANCELED ||
                      HistoryOrderGetInteger(ticket, ORDER_STATE) == ORDER_STATE_REJECTED ||
                      HistoryOrderGetInteger(ticket, ORDER_STATE) == ORDER_STATE_EXPIRED)
                     {
                      COrder  buffer(ORDER_STATUS_HISTORY_PENDING, ticket);
                      if(m_total.symbol == NULL || buffer.order.symbol == m_total.symbol)
                         if(CheckMagic(buffer.order.magic, m_total.magic, m_total.magics) == true)
                            if(CheckComment(buffer.order.comment, m_total.comment, m_total.comments) == true)
                               if(CheckTime(buffer.order.open_time, buffer.order.close_time, m_total.start_time, m_total.end_time, m_basis_open) == true)
                                  if(CheckType(buffer.order.type, m_total.type) == true)
                                     if(CheckTicket(m_list, 0, 0, buffer.order.ticket) < 0)
                                       {
                                        if(cnt >= ::ArraySize(m_list))
                                          {
                                           ::ArrayResize(m_list, ::ArraySize(m_list) + 64);
                                          }
                                        Sort(total_init.sort, m_list, buffer.order, cnt);
                                        m_total.profit = m_total.profit + buffer.order.profit_full;
                                        m_total.total_volume = m_total.total_volume + buffer.order.volume;
                                        cnt++;
                                        AddNew(buffer.order);
                                       }
                      if(m_total.end_time > 0 && buffer.order.close_time - m_total.end_time > 50000)
                         break;
                     }
               }
             m_total.change_number = m_total.change_number + (cnt - m_total.total_record);
             ::ArrayResize(m_list, cnt);
             m_total.total_record = cnt;
             total_all_order = total;
            }
         }
      }

    //+------------------------------------------------------------------+
    //|                                                                  |
    //+------------------------------------------------------------------+
    double  AccountBalance(void)
      {
       return AccountInfoDouble(ACCOUNT_BALANCE);
      }
    //+------------------------------------------------------------------+
    //|                                                                  |
    //+------------------------------------------------------------------+
    double  AccountEquity(void)
      {
       return AccountInfoDouble(ACCOUNT_EQUITY);
      }
    //+------------------------------------------------------------------+
    //|                                                                  |
    //+------------------------------------------------------------------+
    double  AccountMargin(void)
      {
       return AccountInfoDouble(ACCOUNT_MARGIN);
      }
    //+------------------------------------------------------------------+
    //|                                                                  |
    //+------------------------------------------------------------------+
    double  AccountProfit(void)
      {
       return AccountInfoDouble(ACCOUNT_PROFIT);
      }
    //+------------------------------------------------------------------+


    补充内容 (2026-5-29 09:10):
    有人说这个代码不完整,可能是亮化代码出问题了,我又从新发了一个帖子,因为这个已经发了2个帖子,加起来1万多行。在发的话可能会加载很慢影响复制。
    13da3a42-ab5d-45b6-9745-c8f1b3e9cfff.png
    ""
    还没有人打赏,支持一下
    回复

    举报

     

    回答|共 16 个

    jianxian LV3

    发表于 2026-5-29 01:54:53 | 显示全部楼层

    #property strict
    #property version   "2.11"
    #property description "GoldKylin MT5 CTrade edition"

    #include <Trade/Trade.mqh>
    // --- Embedded USD high-impact backtest news start ---
    // Auto-generated by generate_backtest_news_include.py
    // Source: https://www.mql5.com/en/economic-calendar/content
    // Filters: USD + high importance + exact datetime
    // Range: 2025-01-01 .. 2026-04-03
    // Generated: 2026-04-03 03:28:49 UTC

    #define GOLDKING_BACKTEST_USD_HIGH_NEWS_COUNT 615
    #define GOLDKING_BACKTEST_USD_HIGH_NEWS_RANGE_LABEL "2025-01-01~2026-04-03"
    #define GOLDKING_BACKTEST_USD_HIGH_NEWS_RANGE_START D'2025.01.01 00:00:00'
    #define GOLDKING_BACKTEST_USD_HIGH_NEWS_RANGE_END D'2026.04.03 23:59:59'

    datetime GOLDKING_BACKTEST_USD_HIGH_NEWS_TIMES[GOLDKING_BACKTEST_USD_HIGH_NEWS_COUNT]=
      {
       D'2025.01.02 13:30:00',
       D'2025.01.02 14:45:00',
       D'2025.01.02 16:00:00',
       D'2025.01.03 15:00:00',
       D'2025.01.03 15:00:00',
       D'2025.01.06 14:45:00',
       D'2025.01.07 15:00:00',
       D'2025.01.07 15:00:00',
       D'2025.01.07 15:00:00',
       D'2025.01.07 18:00:00',
       D'2025.01.08 13:15:00',
       D'2025.01.08 13:30:00',
       D'2025.01.08 15:30:00',
       D'2025.01.08 18:00:00',
       D'2025.01.10 13:30:00',
       D'2025.01.10 13:30:00',
       D'2025.01.10 13:30:00',
       D'2025.01.14 13:30:00',
       D'2025.01.15 13:30:00',
       D'2025.01.15 13:30:00',
       D'2025.01.15 13:30:00',
       D'2025.01.15 13:30:00',
       D'2025.01.15 13:30:00',
       D'2025.01.15 15:30:00',
       D'2025.01.16 13:30:00',
       D'2025.01.16 13:30:00',
       D'2025.01.16 13:30:00',
       D'2025.01.16 13:30:00',
       D'2025.01.23 13:30:00',
       D'2025.01.23 17:00:00',
       D'2025.01.24 15:00:00',
       D'2025.01.27 15:00:00',
       D'2025.01.28 13:30:00',
       D'2025.01.28 15:00:00',
       D'2025.01.29 15:30:00',
       D'2025.01.29 19:00:00',
       D'2025.01.29 19:30:00',
       D'2025.01.30 13:30:00',
       D'2025.01.30 13:30:00',
       D'2025.01.30 13:30:00',
       D'2025.01.31 13:30:00',
       D'2025.01.31 13:30:00',
       D'2025.01.31 14:45:00',
       D'2025.02.03 14:45:00',
       D'2025.02.03 15:00:00',
       D'2025.02.03 15:00:00',
       D'2025.02.04 15:00:00',
       D'2025.02.05 13:15:00',
       D'2025.02.05 14:45:00',
       D'2025.02.05 15:00:00',
       D'2025.02.05 15:00:00',
       D'2025.02.05 15:30:00',
       D'2025.02.06 13:30:00',
       D'2025.02.07 13:30:00',
       D'2025.02.07 13:30:00',
       D'2025.02.07 13:30:00',
       D'2025.02.11 15:00:00',
       D'2025.02.12 13:30:00',
       D'2025.02.12 13:30:00',
       D'2025.02.12 13:30:00',
       D'2025.02.12 13:30:00',
       D'2025.02.12 13:30:00',
       D'2025.02.12 15:00:00',
       D'2025.02.12 15:30:00',
       D'2025.02.12 18:00:00',
       D'2025.02.13 13:30:00',
       D'2025.02.13 13:30:00',
       D'2025.02.13 18:00:00',
       D'2025.02.14 13:30:00',
       D'2025.02.14 13:30:00',
       D'2025.02.20 13:30:00',
       D'2025.02.20 13:30:00',
       D'2025.02.20 17:00:00',
       D'2025.02.21 15:00:00',
       D'2025.02.25 15:00:00',
       D'2025.02.26 15:00:00',
       D'2025.02.26 15:30:00',
       D'2025.02.27 13:30:00',
       D'2025.02.27 13:30:00',
       D'2025.02.27 13:30:00',
       D'2025.02.27 13:30:00',
       D'2025.02.28 13:30:00',
       D'2025.02.28 13:30:00',
       D'2025.02.28 14:45:00',
       D'2025.03.03 14:45:00',
       D'2025.03.03 15:00:00',
       D'2025.03.03 15:00:00',
       D'2025.03.05 13:15:00',
       D'2025.03.05 14:45:00',
       D'2025.03.05 15:00:00',
       D'2025.03.05 15:00:00',
       D'2025.03.05 15:30:00',
       D'2025.03.06 13:30:00',
       D'2025.03.07 13:30:00',
       D'2025.03.07 13:30:00',
       D'2025.03.07 13:30:00',
       D'2025.03.07 17:30:00',
       D'2025.03.11 14:00:00',
       D'2025.03.12 12:30:00',
       D'2025.03.12 12:30:00',
       D'2025.03.12 12:30:00',
       D'2025.03.12 12:30:00',
       D'2025.03.12 12:30:00',
       D'2025.03.12 14:30:00',
       D'2025.03.12 17:00:00',
       D'2025.03.13 12:30:00',
       D'2025.03.13 12:30:00',
       D'2025.03.13 17:00:00',
       D'2025.03.17 12:30:00',
       D'2025.03.17 12:30:00',
       D'2025.03.19 14:30:00',
       D'2025.03.19 18:00:00',
       D'2025.03.19 18:30:00',
       D'2025.03.20 12:30:00',
       D'2025.03.20 12:30:00',
       D'2025.03.20 14:00:00',
       D'2025.03.25 14:00:00',
       D'2025.03.25 14:00:00',
       D'2025.03.26 12:30:00',
       D'2025.03.26 14:30:00',
       D'2025.03.27 12:30:00',
       D'2025.03.27 12:30:00',
       D'2025.03.27 12:30:00',
       D'2025.03.28 12:30:00',
       D'2025.03.28 12:30:00',
       D'2025.03.31 13:45:00',
       D'2025.04.01 13:45:00',
       D'2025.04.01 14:00:00',
       D'2025.04.01 14:00:00',
       D'2025.04.01 14:00:00',
       D'2025.04.02 12:15:00',
       D'2025.04.02 14:30:00',
       D'2025.04.03 12:30:00',
       D'2025.04.03 13:45:00',
       D'2025.04.03 14:00:00',
       D'2025.04.03 14:00:00',
       D'2025.04.04 12:30:00',
       D'2025.04.04 12:30:00',
       D'2025.04.04 12:30:00',
       D'2025.04.04 15:25:00',
       D'2025.04.09 14:30:00',
       D'2025.04.09 17:00:00',
       D'2025.04.10 12:30:00',
       D'2025.04.10 12:30:00',
       D'2025.04.10 12:30:00',
       D'2025.04.10 12:30:00',
       D'2025.04.10 12:30:00',
       D'2025.04.10 12:30:00',
       D'2025.04.10 17:00:00',
       D'2025.04.11 12:30:00',
       D'2025.04.16 12:30:00',
       D'2025.04.16 12:30:00',
       D'2025.04.16 14:30:00',
       D'2025.04.16 17:30:00',
       D'2025.04.17 12:30:00',
       D'2025.04.17 12:30:00',
       D'2025.04.23 14:00:00',
       D'2025.04.23 14:30:00',
       D'2025.04.24 12:30:00',
       D'2025.04.24 12:30:00',
       D'2025.04.24 14:00:00',
       D'2025.04.29 14:00:00',
       D'2025.04.29 14:00:00',
       D'2025.04.30 12:15:00',
       D'2025.04.30 12:30:00',
       D'2025.04.30 12:30:00',
       D'2025.04.30 13:45:00',
       D'2025.04.30 14:00:00',
       D'2025.04.30 14:00:00',
       D'2025.04.30 14:30:00',
       D'2025.05.01 12:30:00',
       D'2025.05.01 13:45:00',
       D'2025.05.01 14:00:00',
       D'2025.05.01 14:00:00',
       D'2025.05.02 12:30:00',
       D'2025.05.02 12:30:00',
       D'2025.05.02 12:30:00',
       D'2025.05.05 13:45:00',
       D'2025.05.05 14:00:00',
       D'2025.05.05 14:00:00',
       D'2025.05.06 17:00:00',
       D'2025.05.07 14:30:00',
       D'2025.05.07 18:00:00',
       D'2025.05.07 18:30:00',
       D'2025.05.08 12:30:00',
       D'2025.05.08 17:00:00',
       D'2025.05.13 12:30:00',
       D'2025.05.13 12:30:00',
       D'2025.05.13 12:30:00',
       D'2025.05.13 12:30:00',
       D'2025.05.13 12:30:00',
       D'2025.05.14 14:30:00',
       D'2025.05.15 12:30:00',
       D'2025.05.15 12:30:00',
       D'2025.05.15 12:30:00',
       D'2025.05.15 12:30:00',
       D'2025.05.15 12:30:00',
       D'2025.05.15 12:40:00',
       D'2025.05.21 14:30:00',
       D'2025.05.22 12:30:00',
       D'2025.05.22 14:00:00',
       D'2025.05.23 14:00:00',
       D'2025.05.25 18:40:00',
       D'2025.05.27 12:30:00',
       D'2025.05.27 14:00:00',
       D'2025.05.29 12:30:00',
       D'2025.05.29 12:30:00',
       D'2025.05.29 12:30:00',
       D'2025.05.29 16:00:00',
       D'2025.05.30 12:30:00',
       D'2025.05.30 12:30:00',
       D'2025.05.30 13:45:00',
       D'2025.06.02 13:45:00',
       D'2025.06.02 14:00:00',
       D'2025.06.02 14:00:00',
       D'2025.06.02 17:00:00',
       D'2025.06.03 14:00:00',
       D'2025.06.04 12:15:00',
       D'2025.06.04 13:45:00',
       D'2025.06.04 14:00:00',
       D'2025.06.04 14:00:00',
       D'2025.06.04 14:30:00',
       D'2025.06.05 12:30:00',
       D'2025.06.06 12:30:00',
       D'2025.06.06 12:30:00',
       D'2025.06.06 12:30:00',
       D'2025.06.11 12:30:00',
       D'2025.06.11 12:30:00',
       D'2025.06.11 12:30:00',
       D'2025.06.11 12:30:00',
       D'2025.06.11 12:30:00',
       D'2025.06.11 14:30:00',
       D'2025.06.11 17:00:00',
       D'2025.06.12 12:30:00',
       D'2025.06.12 12:30:00',
       D'2025.06.12 17:00:00',
       D'2025.06.17 12:30:00',
       D'2025.06.17 12:30:00',
       D'2025.06.18 12:30:00',
       D'2025.06.18 14:30:00',
       D'2025.06.18 18:00:00',
       D'2025.06.18 18:30:00',
       D'2025.06.20 12:30:00',
       D'2025.06.23 14:00:00',
       D'2025.06.24 14:00:00',
       D'2025.06.24 14:00:00',
       D'2025.06.25 14:00:00',
       D'2025.06.25 14:00:00',
       D'2025.06.25 14:30:00',
       D'2025.06.26 12:30:00',
       D'2025.06.26 12:30:00',
       D'2025.06.26 12:30:00',
       D'2025.06.26 12:30:00',
       D'2025.06.27 12:30:00',
       D'2025.06.27 12:30:00',
       D'2025.06.30 13:45:00',
       D'2025.07.01 13:30:00',
       D'2025.07.01 13:45:00',
       D'2025.07.01 14:00:00',
       D'2025.07.01 14:00:00',
       D'2025.07.01 14:00:00',
       D'2025.07.02 12:15:00',
       D'2025.07.02 14:30:00',
       D'2025.07.03 12:30:00',
       D'2025.07.03 12:30:00',
       D'2025.07.03 12:30:00',
       D'2025.07.03 12:30:00',
       D'2025.07.03 13:45:00',
       D'2025.07.03 14:00:00',
       D'2025.07.03 14:00:00',
       D'2025.07.09 14:30:00',
       D'2025.07.09 17:00:00',
       D'2025.07.10 12:30:00',
       D'2025.07.10 17:00:00',
       D'2025.07.15 12:30:00',
       D'2025.07.15 12:30:00',
       D'2025.07.15 12:30:00',
       D'2025.07.15 12:30:00',
       D'2025.07.15 12:30:00',
       D'2025.07.16 12:30:00',
       D'2025.07.16 14:30:00',
       D'2025.07.17 12:30:00',
       D'2025.07.17 12:30:00',
       D'2025.07.17 12:30:00',
       D'2025.07.17 12:30:00',
       D'2025.07.22 12:30:00',
       D'2025.07.23 14:00:00',
       D'2025.07.23 14:30:00',
       D'2025.07.24 12:30:00',
       D'2025.07.24 14:00:00',
       D'2025.07.25 12:30:00',
       D'2025.07.29 14:00:00',
       D'2025.07.29 14:00:00',
       D'2025.07.30 12:15:00',
       D'2025.07.30 12:30:00',
       D'2025.07.30 12:30:00',
       D'2025.07.30 14:30:00',
       D'2025.07.30 18:00:00',
       D'2025.07.30 18:30:00',
       D'2025.07.31 12:30:00',
       D'2025.07.31 12:30:00',
       D'2025.07.31 12:30:00',
       D'2025.07.31 13:45:00',
       D'2025.08.01 12:30:00',
       D'2025.08.01 12:30:00',
       D'2025.08.01 12:30:00',
       D'2025.08.01 13:45:00',
       D'2025.08.01 14:00:00',
       D'2025.08.01 14:00:00',
       D'2025.08.05 13:45:00',
       D'2025.08.05 14:00:00',
       D'2025.08.05 14:00:00',
       D'2025.08.06 14:30:00',
       D'2025.08.06 17:00:00',
       D'2025.08.07 12:30:00',
       D'2025.08.07 17:00:00',
       D'2025.08.12 12:30:00',
       D'2025.08.12 12:30:00',
       D'2025.08.12 12:30:00',
       D'2025.08.12 12:30:00',
       D'2025.08.12 12:30:00',
       D'2025.08.13 14:30:00',
       D'2025.08.14 12:30:00',
       D'2025.08.14 12:30:00',
       D'2025.08.15 12:30:00',
       D'2025.08.15 12:30:00',
       D'2025.08.20 14:30:00',
       D'2025.08.21 12:30:00',
       D'2025.08.21 12:30:00',
       D'2025.08.21 14:00:00',
       D'2025.08.22 14:00:00',
       D'2025.08.25 14:00:00',
       D'2025.08.26 12:30:00',
       D'2025.08.26 14:00:00',
       D'2025.08.27 14:30:00',
       D'2025.08.28 12:30:00',
       D'2025.08.28 12:30:00',
       D'2025.08.28 12:30:00',
       D'2025.08.29 12:30:00',
       D'2025.08.29 12:30:00',
       D'2025.08.29 13:45:00',
       D'2025.09.02 13:45:00',
       D'2025.09.02 14:00:00',
       D'2025.09.02 14:00:00',
       D'2025.09.03 14:00:00',
       D'2025.09.04 12:15:00',
       D'2025.09.04 12:30:00',
       D'2025.09.04 13:45:00',
       D'2025.09.04 14:00:00',
       D'2025.09.04 14:00:00',
       D'2025.09.04 16:00:00',
       D'2025.09.05 12:30:00',
       D'2025.09.05 12:30:00',
       D'2025.09.05 12:30:00',
       D'2025.09.10 12:30:00',
       D'2025.09.10 14:30:00',
       D'2025.09.10 17:00:00',
       D'2025.09.11 12:30:00',
       D'2025.09.11 12:30:00',
       D'2025.09.11 12:30:00',
       D'2025.09.11 12:30:00',
       D'2025.09.11 12:30:00',
       D'2025.09.11 12:30:00',
       D'2025.09.11 17:00:00',
       D'2025.09.16 12:30:00',
       D'2025.09.16 12:30:00',
       D'2025.09.17 14:30:00',
       D'2025.09.17 18:00:00',
       D'2025.09.17 18:30:00',
       D'2025.09.18 12:30:00',
       D'2025.09.18 12:30:00',
       D'2025.09.23 14:00:00',
       D'2025.09.23 16:35:00',
       D'2025.09.24 14:00:00',
       D'2025.09.24 14:30:00',
       D'2025.09.25 12:30:00',
       D'2025.09.25 12:30:00',
       D'2025.09.25 12:30:00',
       D'2025.09.25 12:30:00',
       D'2025.09.26 12:30:00',
       D'2025.09.26 12:30:00',
       D'2025.09.30 13:45:00',
       D'2025.09.30 14:00:00',
       D'2025.09.30 14:00:00',
       D'2025.10.01 12:15:00',
       D'2025.10.01 13:45:00',
       D'2025.10.01 14:00:00',
       D'2025.10.01 14:00:00',
       D'2025.10.01 14:30:00',
       D'2025.10.03 13:45:00',
       D'2025.10.05 14:00:00',
       D'2025.10.05 14:00:00',
       D'2025.10.08 14:30:00',
       D'2025.10.08 17:00:00',
       D'2025.10.09 12:30:00',
       D'2025.10.09 17:00:00',
       D'2025.10.14 16:20:00',
       D'2025.10.16 12:30:00',
       D'2025.10.16 16:00:00',
       D'2025.10.22 14:30:00',
       D'2025.10.23 14:00:00',
       D'2025.10.24 12:30:00',
       D'2025.10.24 12:30:00',
       D'2025.10.24 12:30:00',
       D'2025.10.24 12:30:00',
       D'2025.10.24 12:30:00',
       D'2025.10.28 14:00:00',
       D'2025.10.29 14:30:00',
       D'2025.10.29 18:00:00',
       D'2025.10.29 18:30:00',
       D'2025.10.31 13:45:00',
       D'2025.11.03 14:45:00',
       D'2025.11.03 15:00:00',
       D'2025.11.03 15:00:00',
       D'2025.11.05 13:15:00',
       D'2025.11.05 14:45:00',
       D'2025.11.05 15:00:00',
       D'2025.11.05 15:00:00',
       D'2025.11.05 15:30:00',
       D'2025.11.12 18:00:00',
       D'2025.11.13 17:00:00',
       D'2025.11.13 18:00:00',
       D'2025.11.19 15:30:00',
       D'2025.11.20 12:30:00',
       D'2025.11.20 12:30:00',
       D'2025.11.20 12:30:00',
       D'2025.11.20 13:30:00',
       D'2025.11.20 13:30:00',
       D'2025.11.20 15:00:00',
       D'2025.11.25 12:30:00',
       D'2025.11.25 12:30:00',
       D'2025.11.25 12:30:00',
       D'2025.11.25 15:00:00',
       D'2025.11.26 12:30:00',
       D'2025.11.26 13:30:00',
       D'2025.11.26 14:45:00',
       D'2025.11.26 15:30:00',
       D'2025.12.01 14:45:00',
       D'2025.12.01 15:00:00',
       D'2025.12.01 15:00:00',
       D'2025.12.02 01:00:00',
       D'2025.12.03 13:15:00',
       D'2025.12.03 14:45:00',
       D'2025.12.03 15:00:00',
       D'2025.12.03 15:00:00',
       D'2025.12.03 15:30:00',
       D'2025.12.04 13:30:00',
       D'2025.12.05 15:00:00',
       D'2025.12.05 15:00:00',
       D'2025.12.09 15:00:00',
       D'2025.12.09 18:00:00',
       D'2025.12.10 15:30:00',
       D'2025.12.10 19:00:00',
       D'2025.12.10 19:30:00',
       D'2025.12.11 13:30:00',
       D'2025.12.11 18:00:00',
       D'2025.12.16 13:30:00',
       D'2025.12.16 13:30:00',
       D'2025.12.16 13:30:00',
       D'2025.12.16 13:30:00',
       D'2025.12.16 13:30:00',
       D'2025.12.17 15:30:00',
       D'2025.12.18 13:30:00',
       D'2025.12.18 13:30:00',
       D'2025.12.18 13:30:00',
       D'2025.12.18 13:30:00',
       D'2025.12.18 13:30:00',
       D'2025.12.18 13:30:00',
       D'2025.12.18 13:30:00',
       D'2025.12.19 15:00:00',
       D'2025.12.23 13:30:00',
       D'2025.12.23 13:30:00',
       D'2025.12.23 13:30:00',
       D'2025.12.23 15:00:00',
       D'2025.12.24 13:30:00',
       D'2025.12.24 15:30:00',
       D'2025.12.29 22:00:00',
       D'2025.12.30 14:45:00',
       D'2025.12.31 13:30:00',
       D'2026.01.02 14:45:00',
       D'2026.01.05 15:00:00',
       D'2026.01.05 15:00:00',
       D'2026.01.06 14:45:00',
       D'2026.01.07 13:15:00',
       D'2026.01.07 15:00:00',
       D'2026.01.07 15:00:00',
       D'2026.01.07 15:00:00',
       D'2026.01.07 15:30:00',
       D'2026.01.08 13:30:00',
       D'2026.01.09 13:30:00',
       D'2026.01.09 13:30:00',
       D'2026.01.09 13:30:00',
       D'2026.01.12 18:00:00',
       D'2026.01.13 13:30:00',
       D'2026.01.13 13:30:00',
       D'2026.01.13 13:30:00',
       D'2026.01.13 13:30:00',
       D'2026.01.13 13:30:00',
       D'2026.01.13 15:00:00',
       D'2026.01.13 18:00:00',
       D'2026.01.14 13:30:00',
       D'2026.01.14 13:30:00',
       D'2026.01.14 13:30:00',
       D'2026.01.14 15:30:00',
       D'2026.01.15 13:30:00',
       D'2026.01.15 13:30:00',
       D'2026.01.22 13:30:00',
       D'2026.01.22 13:30:00',
       D'2026.01.22 13:30:00',
       D'2026.01.22 15:00:00',
       D'2026.01.22 15:00:00',
       D'2026.01.22 17:00:00',
       D'2026.01.26 13:30:00',
       D'2026.01.27 15:00:00',
       D'2026.01.28 15:30:00',
       D'2026.01.28 19:00:00',
       D'2026.01.28 19:30:00',
       D'2026.01.29 13:30:00',
       D'2026.01.30 13:30:00',
       D'2026.01.30 14:45:00',
       D'2026.02.02 15:00:00',
       D'2026.02.02 15:00:00',
       D'2026.02.04 13:15:00',
       D'2026.02.04 15:00:00',
       D'2026.02.04 15:00:00',
       D'2026.02.04 15:30:00',
       D'2026.02.05 13:30:00',
       D'2026.02.05 15:00:00',
       D'2026.02.10 13:30:00',
       D'2026.02.10 13:30:00',
       D'2026.02.11 13:30:00',
       D'2026.02.11 13:30:00',
       D'2026.02.11 13:30:00',
       D'2026.02.11 15:30:00',
       D'2026.02.11 18:00:00',
       D'2026.02.12 13:30:00',
       D'2026.02.12 15:00:00',
       D'2026.02.12 18:00:00',
       D'2026.02.13 13:30:00',
       D'2026.02.13 13:30:00',
       D'2026.02.13 13:30:00',
       D'2026.02.13 13:30:00',
       D'2026.02.13 13:30:00',
       D'2026.02.18 13:30:00',
       D'2026.02.19 13:30:00',
       D'2026.02.19 13:30:00',
       D'2026.02.19 17:00:00',
       D'2026.02.20 13:30:00',
       D'2026.02.20 13:30:00',
       D'2026.02.20 13:30:00',
       D'2026.02.20 13:30:00',
       D'2026.02.20 15:00:00',
       D'2026.02.24 15:00:00',
       D'2026.02.25 15:30:00',
       D'2026.02.26 13:30:00',
       D'2026.02.27 13:30:00',
       D'2026.02.27 14:45:00',
       D'2026.03.02 14:45:00',
       D'2026.03.02 15:00:00',
       D'2026.03.02 15:00:00',
       D'2026.03.04 13:15:00',
       D'2026.03.04 14:45:00',
       D'2026.03.04 15:00:00',
       D'2026.03.04 15:00:00',
       D'2026.03.04 15:30:00',
       D'2026.03.05 13:30:00',
       D'2026.03.06 13:30:00',
       D'2026.03.06 13:30:00',
       D'2026.03.06 13:30:00',
       D'2026.03.06 13:30:00',
       D'2026.03.06 13:30:00',
       D'2026.03.10 14:00:00',
       D'2026.03.11 12:30:00',
       D'2026.03.11 12:30:00',
       D'2026.03.11 12:30:00',
       D'2026.03.11 12:30:00',
       D'2026.03.11 12:30:00',
       D'2026.03.11 14:30:00',
       D'2026.03.11 17:00:00',
       D'2026.03.12 12:30:00',
       D'2026.03.12 17:00:00',
       D'2026.03.13 12:30:00',
       D'2026.03.13 12:30:00',
       D'2026.03.13 12:30:00',
       D'2026.03.13 12:30:00',
       D'2026.03.13 12:30:00',
       D'2026.03.13 14:00:00',
       D'2026.03.18 12:30:00',
       D'2026.03.18 14:30:00',
       D'2026.03.18 18:00:00',
       D'2026.03.18 18:30:00',
       D'2026.03.19 12:30:00',
       D'2026.03.19 12:30:00',
       D'2026.03.19 14:00:00',
       D'2026.03.21 17:30:00',
       D'2026.03.25 14:30:00',
       D'2026.03.26 12:30:00',
       D'2026.03.30 14:30:00',
       D'2026.03.31 13:45:00',
       D'2026.03.31 14:00:00',
       D'2026.03.31 14:00:00',
       D'2026.04.01 12:15:00',
       D'2026.04.01 12:30:00',
       D'2026.04.01 12:30:00',
       D'2026.04.01 13:45:00',
       D'2026.04.01 14:00:00',
       D'2026.04.01 14:00:00',
       D'2026.04.01 14:30:00',
       D'2026.04.02 12:30:00',
       D'2026.04.03 12:30:00',
       D'2026.04.03 12:30:00',
       D'2026.04.03 12:30:00',
       D'2026.04.03 13:45:00',
       D'2026.04.03 14:00:00',
       D'2026.04.03 14:00:00'
      };

    string GOLDKING_BACKTEST_USD_HIGH_NEWS_NAMES[GOLDKING_BACKTEST_USD_HIGH_NEWS_COUNT]=
      {
       "Initial Jobless Claims",
       "S&P Global Manufacturing PMI",
       "EIA Crude Oil Stocks Change",
       "ISM Manufacturing PMI",
       "ISM Manufacturing Prices Paid",
       "S&P Global Services PMI",
       "ISM Non-Manufacturing PMI",
       "ISM Non-Manufacturing Prices Paid",
       "JOLTS Job Openings",
       "10-Year Note Auction",
       "ADP Nonfarm Employment Change",
       "Initial Jobless Claims",
       "EIA Crude Oil Stocks Change",
       "30-Year Bond Auction",
       "Average Hourly Earnings m/m",
       "Nonfarm Payrolls",
       "Unemployment Rate",
       "PPI m/m",
       "CPI",
       "CPI m/m",
       "CPI y/y",
       "Core CPI m/m",
       "Core CPI n.s.a. m/m",
       "EIA Crude Oil Stocks Change",
       "Core Retail Sales m/m",
       "Initial Jobless Claims",
       "Philadelphia Fed Manufacturing Index",
       "Retail Sales m/m",
       "Initial Jobless Claims",
       "EIA Crude Oil Stocks Change",
       "Existing Home Sales",
       "New Home Sales",
       "Durable Goods Orders m/m",
       "CB Consumer Confidence Index",
       "EIA Crude Oil Stocks Change",
       "Fed Interest Rate Decision",
       "FOMC Press Conference",
       "GDP Sales q/q",
       "GDP q/q",
       "Initial Jobless Claims",
       "Core PCE Price Index m/m",
       "Core PCE Price Index y/y",
       "MNI Chicago Business Barometer",
       "S&P Global Manufacturing PMI",
       "ISM Manufacturing PMI",
       "ISM Manufacturing Prices Paid",
       "JOLTS Job Openings",
       "ADP Nonfarm Employment Change",
       "S&P Global Services PMI",
       "ISM Non-Manufacturing PMI",
       "ISM Non-Manufacturing Prices Paid",
       "EIA Crude Oil Stocks Change",
       "Initial Jobless Claims",
       "Average Hourly Earnings m/m",
       "Nonfarm Payrolls",
       "Unemployment Rate",
       "Fed Chair Powell Testimony",
       "CPI",
       "CPI m/m",
       "CPI y/y",
       "Core CPI m/m",
       "Core CPI n.s.a. m/m",
       "Fed Chair Powell Testimony",
       "EIA Crude Oil Stocks Change",
       "10-Year Note Auction",
       "Initial Jobless Claims",
       "PPI m/m",
       "30-Year Bond Auction",
       "Core Retail Sales m/m",
       "Retail Sales m/m",
       "Initial Jobless Claims",
       "Philadelphia Fed Manufacturing Index",
       "EIA Crude Oil Stocks Change",
       "Existing Home Sales",
       "CB Consumer Confidence Index",
       "New Home Sales",
       "EIA Crude Oil Stocks Change",
       "Durable Goods Orders m/m",
       "GDP Sales q/q",
       "GDP q/q",
       "Initial Jobless Claims",
       "Core PCE Price Index m/m",
       "Core PCE Price Index y/y",
       "MNI Chicago Business Barometer",
       "S&P Global Manufacturing PMI",
       "ISM Manufacturing PMI",
       "ISM Manufacturing Prices Paid",
       "ADP Nonfarm Employment Change",
       "S&P Global Services PMI",
       "ISM Non-Manufacturing PMI",
       "ISM Non-Manufacturing Prices Paid",
       "EIA Crude Oil Stocks Change",
       "Initial Jobless Claims",
       "Average Hourly Earnings m/m",
       "Nonfarm Payrolls",
       "Unemployment Rate",
       "Fed Chair Powell Speech",
       "JOLTS Job Openings",
       "CPI",
       "CPI m/m",
       "CPI y/y",
       "Core CPI m/m",
       "Core CPI n.s.a. m/m",
       "EIA Crude Oil Stocks Change",
       "10-Year Note Auction",
       "Initial Jobless Claims",
       "PPI m/m",
       "30-Year Bond Auction",
       "Core Retail Sales m/m",
       "Retail Sales m/m",
       "EIA Crude Oil Stocks Change",
       "Fed Interest Rate Decision",
       "FOMC Press Conference",
       "Initial Jobless Claims",
       "Philadelphia Fed Manufacturing Index",
       "Existing Home Sales",
       "CB Consumer Confidence Index",
       "New Home Sales",
       "Durable Goods Orders m/m",
       "EIA Crude Oil Stocks Change",
       "GDP Sales q/q",
       "GDP q/q",
       "Initial Jobless Claims",
       "Core PCE Price Index m/m",
       "Core PCE Price Index y/y",
       "MNI Chicago Business Barometer",
       "S&P Global Manufacturing PMI",
       "ISM Manufacturing PMI",
       "ISM Manufacturing Prices Paid",
       "JOLTS Job Openings",
       "ADP Nonfarm Employment Change",
       "EIA Crude Oil Stocks Change",
       "Initial Jobless Claims",
       "S&P Global Services PMI",
       "ISM Non-Manufacturing PMI",
       "ISM Non-Manufacturing Prices Paid",
       "Average Hourly Earnings m/m",
       "Nonfarm Payrolls",
       "Unemployment Rate",
       "Fed Chair Powell Speech",
       "EIA Crude Oil Stocks Change",
       "10-Year Note Auction",
       "CPI",
       "CPI m/m",
       "CPI y/y",
       "Core CPI m/m",
       "Core CPI n.s.a. m/m",
       "Initial Jobless Claims",
       "30-Year Bond Auction",
       "PPI m/m",
       "Core Retail Sales m/m",
       "Retail Sales m/m",
       "EIA Crude Oil Stocks Change",
       "Fed Chair Powell Speech",
       "Initial Jobless Claims",
       "Philadelphia Fed Manufacturing Index",
       "New Home Sales",
       "EIA Crude Oil Stocks Change",
       "Durable Goods Orders m/m",
       "Initial Jobless Claims",
       "Existing Home Sales",
       "CB Consumer Confidence Index",
       "JOLTS Job Openings",
       "ADP Nonfarm Employment Change",
       "GDP Sales q/q",
       "GDP q/q",
       "MNI Chicago Business Barometer",
       "Core PCE Price Index m/m",
       "Core PCE Price Index y/y",
       "EIA Crude Oil Stocks Change",
       "Initial Jobless Claims",
       "S&P Global Manufacturing PMI",
       "ISM Manufacturing PMI",
       "ISM Manufacturing Prices Paid",
       "Average Hourly Earnings m/m",
       "Nonfarm Payrolls",
       "Unemployment Rate",
       "S&P Global Services PMI",
       "ISM Non-Manufacturing PMI",
       "ISM Non-Manufacturing Prices Paid",
       "10-Year Note Auction",
       "EIA Crude Oil Stocks Change",
       "Fed Interest Rate Decision",
       "FOMC Press Conference",
       "Initial Jobless Claims",
       "30-Year Bond Auction",
       "CPI",
       "CPI m/m",
       "CPI y/y",
       "Core CPI m/m",
       "Core CPI n.s.a. m/m",
       "EIA Crude Oil Stocks Change",
       "Core Retail Sales m/m",
       "Initial Jobless Claims",
       "PPI m/m",
       "Philadelphia Fed Manufacturing Index",
       "Retail Sales m/m",
       "Fed Chair Powell Speech",
       "EIA Crude Oil Stocks Change",
       "Initial Jobless Claims",
       "Existing Home Sales",
       "New Home Sales",
       "Fed Chair Powell Speech",
       "Durable Goods Orders m/m",
       "CB Consumer Confidence Index",
       "GDP Sales q/q",
       "GDP q/q",
       "Initial Jobless Claims",
       "EIA Crude Oil Stocks Change",
       "Core PCE Price Index m/m",
       "Core PCE Price Index y/y",
       "MNI Chicago Business Barometer",
       "S&P Global Manufacturing PMI",
       "ISM Manufacturing PMI",
       "ISM Manufacturing Prices Paid",
       "Fed Chair Powell Speech",
       "JOLTS Job Openings",
       "ADP Nonfarm Employment Change",
       "S&P Global Services PMI",
       "ISM Non-Manufacturing PMI",
       "ISM Non-Manufacturing Prices Paid",
       "EIA Crude Oil Stocks Change",
       "Initial Jobless Claims",
       "Average Hourly Earnings m/m",
       "Nonfarm Payrolls",
       "Unemployment Rate",
       "CPI",
       "CPI m/m",
       "CPI y/y",
       "Core CPI m/m",
       "Core CPI n.s.a. m/m",
       "EIA Crude Oil Stocks Change",
       "10-Year Note Auction",
       "Initial Jobless Claims",
       "PPI m/m",
       "30-Year Bond Auction",
       "Core Retail Sales m/m",
       "Retail Sales m/m",
       "Initial Jobless Claims",
       "EIA Crude Oil Stocks Change",
       "Fed Interest Rate Decision",
       "FOMC Press Conference",
       "Philadelphia Fed Manufacturing Index",
       "Existing Home Sales",
       "CB Consumer Confidence Index",
       "Fed Chair Powell Testimony",
       "Fed Chair Powell Testimony",
       "New Home Sales",
       "EIA Crude Oil Stocks Change",
       "Durable Goods Orders m/m",
       "GDP Sales q/q",
       "GDP q/q",
       "Initial Jobless Claims",
       "Core PCE Price Index m/m",
       "Core PCE Price Index y/y",
       "MNI Chicago Business Barometer",
       "Fed Chair Powell Speech",
       "S&P Global Manufacturing PMI",
       "ISM Manufacturing PMI",
       "ISM Manufacturing Prices Paid",
       "JOLTS Job Openings",
       "ADP Nonfarm Employment Change",
       "EIA Crude Oil Stocks Change",
       "Average Hourly Earnings m/m",
       "Initial Jobless Claims",
       "Nonfarm Payrolls",
       "Unemployment Rate",
       "S&P Global Services PMI",
       "ISM Non-Manufacturing PMI",
       "ISM Non-Manufacturing Prices Paid",
       "EIA Crude Oil Stocks Change",
       "10-Year Note Auction",
       "Initial Jobless Claims",
       "30-Year Bond Auction",
       "CPI",
       "CPI m/m",
       "CPI y/y",
       "Core CPI m/m",
       "Core CPI n.s.a. m/m",
       "PPI m/m",
       "EIA Crude Oil Stocks Change",
       "Core Retail Sales m/m",
       "Initial Jobless Claims",
       "Philadelphia Fed Manufacturing Index",
       "Retail Sales m/m",
       "Fed Chair Powell Speech",
       "Existing Home Sales",
       "EIA Crude Oil Stocks Change",
       "Initial Jobless Claims",
       "New Home Sales",
       "Durable Goods Orders m/m",
       "CB Consumer Confidence Index",
       "JOLTS Job Openings",
       "ADP Nonfarm Employment Change",
       "GDP Sales q/q",
       "GDP q/q",
       "EIA Crude Oil Stocks Change",
       "Fed Interest Rate Decision",
       "FOMC Press Conference",
       "Core PCE Price Index m/m",
       "Core PCE Price Index y/y",
       "Initial Jobless Claims",
       "MNI Chicago Business Barometer",
       "Average Hourly Earnings m/m",
       "Nonfarm Payrolls",
       "Unemployment Rate",
       "S&P Global Manufacturing PMI",
       "ISM Manufacturing PMI",
       "ISM Manufacturing Prices Paid",
       "S&P Global Services PMI",
       "ISM Non-Manufacturing PMI",
       "ISM Non-Manufacturing Prices Paid",
       "EIA Crude Oil Stocks Change",
       "10-Year Note Auction",
       "Initial Jobless Claims",
       "30-Year Bond Auction",
       "CPI",
       "CPI m/m",
       "CPI y/y",
       "Core CPI m/m",
       "Core CPI n.s.a. m/m",
       "EIA Crude Oil Stocks Change",
       "Initial Jobless Claims",
       "PPI m/m",
       "Core Retail Sales m/m",
       "Retail Sales m/m",
       "EIA Crude Oil Stocks Change",
       "Initial Jobless Claims",
       "Philadelphia Fed Manufacturing Index",
       "Existing Home Sales",
       "Fed Chair Powell Speech",
       "New Home Sales",
       "Durable Goods Orders m/m",
       "CB Consumer Confidence Index",
       "EIA Crude Oil Stocks Change",
       "GDP Sales q/q",
       "GDP q/q",
       "Initial Jobless Claims",
       "Core PCE Price Index m/m",
       "Core PCE Price Index y/y",
       "MNI Chicago Business Barometer",
       "S&P Global Manufacturing PMI",
       "ISM Manufacturing PMI",
       "ISM Manufacturing Prices Paid",
       "JOLTS Job Openings",
       "ADP Nonfarm Employment Change",
       "Initial Jobless Claims",
       "S&P Global Services PMI",
       "ISM Non-Manufacturing PMI",
       "ISM Non-Manufacturing Prices Paid",
       "EIA Crude Oil Stocks Change",
       "Average Hourly Earnings m/m",
       "Nonfarm Payrolls",
       "Unemployment Rate",
       "PPI m/m",
       "EIA Crude Oil Stocks Change",
       "10-Year Note Auction",
       "CPI",
       "CPI m/m",
       "CPI y/y",
       "Core CPI m/m",
       "Core CPI n.s.a. m/m",
       "Initial Jobless Claims",
       "30-Year Bond Auction",
       "Core Retail Sales m/m",
       "Retail Sales m/m",
       "EIA Crude Oil Stocks Change",
       "Fed Interest Rate Decision",
       "FOMC Press Conference",
       "Initial Jobless Claims",
       "Philadelphia Fed Manufacturing Index",
       "Existing Home Sales",
       "Fed Chair Powell Speech",
       "New Home Sales",
       "EIA Crude Oil Stocks Change",
       "Durable Goods Orders m/m",
       "GDP Sales q/q",
       "GDP q/q",
       "Initial Jobless Claims",
       "Core PCE Price Index m/m",
       "Core PCE Price Index y/y",
       "MNI Chicago Business Barometer",
       "CB Consumer Confidence Index",
       "JOLTS Job Openings",
       "ADP Nonfarm Employment Change",
       "S&P Global Manufacturing PMI",
       "ISM Manufacturing PMI",
       "ISM Manufacturing Prices Paid",
       "EIA Crude Oil Stocks Change",
       "S&P Global Services PMI",
       "ISM Non-Manufacturing PMI",
       "ISM Non-Manufacturing Prices Paid",
       "EIA Crude Oil Stocks Change",
       "10-Year Note Auction",
       "Fed Chair Powell Speech",
       "30-Year Bond Auction",
       "Fed Chair Powell Speech",
       "Philadelphia Fed Manufacturing Index",
       "EIA Crude Oil Stocks Change",
       "EIA Crude Oil Stocks Change",
       "Existing Home Sales",
       "CPI",
       "CPI m/m",
       "CPI y/y",
       "Core CPI m/m",
       "Core CPI n.s.a. m/m",
       "CB Consumer Confidence Index",
       "EIA Crude Oil Stocks Change",
       "Fed Interest Rate Decision",
       "FOMC Press Conference",
       "MNI Chicago Business Barometer",
       "S&P Global Manufacturing PMI",
       "ISM Manufacturing PMI",
       "ISM Manufacturing Prices Paid",
       "ADP Nonfarm Employment Change",
       "S&P Global Services PMI",
       "ISM Non-Manufacturing PMI",
       "ISM Non-Manufacturing Prices Paid",
       "EIA Crude Oil Stocks Change",
       "10-Year Note Auction",
       "EIA Crude Oil Stocks Change",
       "30-Year Bond Auction",
       "EIA Crude Oil Stocks Change",
       "Average Hourly Earnings m/m",
       "Nonfarm Payrolls",
       "Unemployment Rate",
       "Initial Jobless Claims",
       "Philadelphia Fed Manufacturing Index",
       "Existing Home Sales",
       "Core Retail Sales m/m",
       "PPI m/m",
       "Retail Sales m/m",
       "CB Consumer Confidence Index",
       "Durable Goods Orders m/m",
       "Initial Jobless Claims",
       "MNI Chicago Business Barometer",
       "EIA Crude Oil Stocks Change",
       "S&P Global Manufacturing PMI",
       "ISM Manufacturing PMI",
       "ISM Manufacturing Prices Paid",
       "Fed Chair Powell Speech",
       "ADP Nonfarm Employment Change",
       "S&P Global Services PMI",
       "ISM Non-Manufacturing PMI",
       "ISM Non-Manufacturing Prices Paid",
       "EIA Crude Oil Stocks Change",
       "Initial Jobless Claims",
       "Core PCE Price Index m/m",
       "Core PCE Price Index y/y",
       "JOLTS Job Openings",
       "10-Year Note Auction",
       "EIA Crude Oil Stocks Change",
       "Fed Interest Rate Decision",
       "FOMC Press Conference",
       "Initial Jobless Claims",
       "30-Year Bond Auction",
       "Average Hourly Earnings m/m",
       "Core Retail Sales m/m",
       "Nonfarm Payrolls",
       "Retail Sales m/m",
       "Unemployment Rate",
       "EIA Crude Oil Stocks Change",
       "CPI",
       "CPI m/m",
       "CPI y/y",
       "Core CPI m/m",
       "Core CPI n.s.a. m/m",
       "Initial Jobless Claims",
       "Philadelphia Fed Manufacturing Index",
       "Existing Home Sales",
       "Durable Goods Orders m/m",
       "GDP Sales q/q",
       "GDP q/q",
       "CB Consumer Confidence Index",
       "Initial Jobless Claims",
       "EIA Crude Oil Stocks Change",
       "EIA Crude Oil Stocks Change",
       "MNI Chicago Business Barometer",
       "Initial Jobless Claims",
       "S&P Global Manufacturing PMI",
       "ISM Manufacturing PMI",
       "ISM Manufacturing Prices Paid",
       "S&P Global Services PMI",
       "ADP Nonfarm Employment Change",
       "ISM Non-Manufacturing PMI",
       "ISM Non-Manufacturing Prices Paid",
       "JOLTS Job Openings",
       "EIA Crude Oil Stocks Change",
       "Initial Jobless Claims",
       "Average Hourly Earnings m/m",
       "Nonfarm Payrolls",
       "Unemployment Rate",
       "10-Year Note Auction",
       "CPI",
       "CPI m/m",
       "CPI y/y",
       "Core CPI m/m",
       "Core CPI n.s.a. m/m",
       "New Home Sales",
       "30-Year Bond Auction",
       "Core Retail Sales m/m",
       "PPI m/m",
       "Retail Sales m/m",
       "EIA Crude Oil Stocks Change",
       "Initial Jobless Claims",
       "Philadelphia Fed Manufacturing Index",
       "GDP Sales q/q",
       "GDP q/q",
       "Initial Jobless Claims",
       "Core PCE Price Index m/m",
       "Core PCE Price Index y/y",
       "EIA Crude Oil Stocks Change",
       "Durable Goods Orders m/m",
       "CB Consumer Confidence Index",
       "EIA Crude Oil Stocks Change",
       "Fed Interest Rate Decision",
       "FOMC Press Conference",
       "Initial Jobless Claims",
       "PPI m/m",
       "MNI Chicago Business Barometer",
       "ISM Manufacturing PMI",
       "ISM Manufacturing Prices Paid",
       "ADP Nonfarm Employment Change",
       "ISM Non-Manufacturing PMI",
       "ISM Non-Manufacturing Prices Paid",
       "EIA Crude Oil Stocks Change",
       "Initial Jobless Claims",
       "JOLTS Job Openings",
       "Core Retail Sales m/m",
       "Retail Sales m/m",
       "Average Hourly Earnings m/m",
       "Nonfarm Payrolls",
       "Unemployment Rate",
       "EIA Crude Oil Stocks Change",
       "10-Year Note Auction",
       "Initial Jobless Claims",
       "Existing Home Sales",
       "30-Year Bond Auction",
       "CPI",
       "CPI m/m",
       "CPI y/y",
       "Core CPI m/m",
       "Core CPI n.s.a. m/m",
       "Durable Goods Orders m/m",
       "Initial Jobless Claims",
       "Philadelphia Fed Manufacturing Index",
       "EIA Crude Oil Stocks Change",
       "Core PCE Price Index m/m",
       "Core PCE Price Index y/y",
       "GDP Sales q/q",
       "GDP q/q",
       "New Home Sales",
       "CB Consumer Confidence Index",
       "EIA Crude Oil Stocks Change",
       "Initial Jobless Claims",
       "PPI m/m",
       "MNI Chicago Business Barometer",
       "S&P Global Manufacturing PMI",
       "ISM Manufacturing PMI",
       "ISM Manufacturing Prices Paid",
       "ADP Nonfarm Employment Change",
       "S&P Global Services PMI",
       "ISM Non-Manufacturing PMI",
       "ISM Non-Manufacturing Prices Paid",
       "EIA Crude Oil Stocks Change",
       "Initial Jobless Claims",
       "Average Hourly Earnings m/m",
       "Core Retail Sales m/m",
       "Nonfarm Payrolls",
       "Retail Sales m/m",
       "Unemployment Rate",
       "Existing Home Sales",
       "CPI",
       "CPI m/m",
       "CPI y/y",
       "Core CPI m/m",
       "Core CPI n.s.a. m/m",
       "EIA Crude Oil Stocks Change",
       "10-Year Note Auction",
       "Initial Jobless Claims",
       "30-Year Bond Auction",
       "Core PCE Price Index m/m",
       "Core PCE Price Index y/y",
       "Durable Goods Orders m/m",
       "GDP Sales q/q",
       "GDP q/q",
       "JOLTS Job Openings",
       "PPI m/m",
       "EIA Crude Oil Stocks Change",
       "Fed Interest Rate Decision",
       "FOMC Press Conference",
       "Initial Jobless Claims",
       "Philadelphia Fed Manufacturing Index",
       "New Home Sales",
       "Fed Chair Powell Speech",
       "EIA Crude Oil Stocks Change",
       "Initial Jobless Claims",
       "Fed Chair Powell Speech",
       "MNI Chicago Business Barometer",
       "CB Consumer Confidence Index",
       "JOLTS Job Openings",
       "ADP Nonfarm Employment Change",
       "Core Retail Sales m/m",
       "Retail Sales m/m",
       "S&P Global Manufacturing PMI",
       "ISM Manufacturing PMI",
       "ISM Manufacturing Prices Paid",
       "EIA Crude Oil Stocks Change",
       "Initial Jobless Claims",
       "Average Hourly Earnings m/m",
       "Nonfarm Payrolls",
       "Unemployment Rate",
       "S&P Global Services PMI",
       "ISM Non-Manufacturing PMI",
       "ISM Non-Manufacturing Prices Paid"
      };
    // --- Embedded USD high-impact backtest news end ---

    enum OpenModeEnum
      {
       OpenMode_Bar      = 1,
       OpenMode_Interval = 2,
       OpenMode_NoDelay  = 3
      };

    input group "Grid"
    input double         On_top_of_this_price_not_Buy_order      = 0.0;     // B以上不开(补)
    input double         On_under_of_this_price_not_Sell_order   = 0.0;     // S以下不开(补)
    input string         Limit_StartTime                         = "00:00"; // 限价开始时间
    input string         Limit_StopTime                          = "24:00"; // 限价结束时间
    input bool           CloseBuySell                            = true;    // 逆势保护开关
    input bool           HomeopathyCloseAll                      = true;    // 顺势保护开关
    input bool           Homeopathy                              = false;   // 完全对锁时挂上顺势开关
    input bool           Over                                    = false;   // 平仓后停止交易
    input int            NextTime                                = 0;       // 整体平仓后多少秒后新局
    input double         Money                                   = 0.0;     // 浮亏多少启用第二参数
    input int            FirstStep                               = 30;      // 首单距离
    input int            MinDistance                             = 60;      // 最小距离
    input int            TwoMinDistance                          = 60;      // 第二最小距离
    input int            StepTrallOrders                         = 5;       // 挂单追踪点数
    input int            Step                                    = 100;     // 补单间距
    input int            TwoStep                                 = 100;     // 第二补单间距
    input OpenModeEnum   OpenMode                                = OpenMode_NoDelay;
    input ENUM_TIMEFRAMES TimeZone                               = PERIOD_M1; // 开单时区
    input int            sleep                                   = 30;      // 开单时间间距(秒)
    input double         MaxLoss                                 = 100000.0;// 单边浮亏超过多少不继续加仓
    input double         MaxLossCloseAll                         = 50.0;    // 单边平仓限制

    input group "Risk"
    input double         lot                                     = 0.01;    // 起始手数
    input double         Maxlot                                  = 10.0;    // 最大开单手数
    input double         PlusLot                                 = 0.0;     // 累加手数
    input double         K_Lot                                   = 1.3;     // 倍率
    input int            DigitsLot                               = 2;       // 下单量小数位
    input double         CloseAll                                = 0.5;     // 整体平仓金额
    input bool           Profit                                  = true;    // 单边平仓金额累加开关
    input double         StopProfit                              = 2.0;     // 单边平仓金额
    input double         StopLoss                                = 0.0;     // 止损金额
    input long           Magic                                   = 958999848;
    input int            Totals                                  = 50;      // 最大单量
    input int            MaxSpread                               = 60;      // 点差限制(点)
    input int            Leverage                                = 100;     // 平台杠杆限制

    input group "Session"
    input bool           EnableTradingSessionWindow             = true;    // 启用工作时间段控制
    input string         EA_StartTime                            = "00:00"; // EA开始时间
    input string         EA_StopTime                             = "24:00"; // EA结束时间
    input bool           EnableDailyWrapUpPhase                 = true;    // 启用日内收尾阶段
    input string         DailyWrapUpStartTime                   = "20:00"; // 收尾开始(盘面/服务器时间)
    input string         DailyWrapUpStopTime                    = "24:00"; // 收尾结束(盘面/服务器时间)
    input bool           EnableDailyProfitTarget                = true;    // 启用每日盈利目标
    input double         DailyProfitTarget                       = 50.0;    // 每日盈利目标,达到后封盘
    input bool           EnableHighImpactNewsPause              = true;    // 启用高影响新闻暂停
    input int            NewsLeadMinutes                        = 180;     // 新闻前等待平仓分钟
    input int            NewsCooldownMinutes                    = 180;     // 新闻后暂停分钟

    input group "Visual"
    input color          clr1                                    = MediumSeaGreen; // 多单均价线
    input color          clr2                                    = Crimson;        // 空单均价线

    struct EAStats
      {
       int               buy_positions;
       int               sell_positions;
       int               buy_pending;
       int               sell_pending;
       double            buy_lots;
       double            sell_lots;
       double            buy_profit;
       double            sell_profit;
       double            total_profit;
       double            buy_weighted_sum;
       double            sell_weighted_sum;
       double            buy_avg_price;
       double            sell_avg_price;
       double            buy_highest_any;
       double            buy_lowest_position;
       double            sell_highest_position;
       double            sell_lowest_any;
       double            buy_pending_price;
       double            sell_pending_price;
       ulong             buy_pending_ticket;
       ulong             sell_pending_ticket;
       datetime          last_buy_open_time;
       datetime          last_sell_open_time;
      };

    struct PanelMetrics
      {
       int               margin_x;
       int               margin_y;
       int               width;
       int               pad;
       int               section_gap;
       int               header_h;
       int               row_h;
       int               gap;
       int               button_h;
       int               inner_w;
       int               half_w;
       int               card_status_h;
       int               card_metrics_h;
       int               card_actions_h;
       int               button_font;
       int               font_sm;
       int               font_xs;
       int               font_md;
       int               font_lg;
       int               panel_h;
       int               toggle_w;
      };

    struct NewsWindowState
      {
       bool              enabled;
       bool              calendar_available;
       bool              using_embedded_history;
       bool              has_active_window;
       bool              in_pre_window;
       bool              in_post_window;
       bool              has_upcoming_event;
       bool              block_entries;
       datetime          server_now;
       datetime          event_time;
       datetime          window_start;
       datetime          resume_time;
       string            currency;
       string            event_name;
      string            error_text;
      };

    struct NewsEvalAccumulator
      {
       bool              any_success;
       string            first_error;
       datetime          active_block_start;
       datetime          active_block_end;
       datetime          active_future_time;
       string            active_future_currency;
       string            active_future_name;
       datetime          active_past_time;
       string            active_past_currency;
       string            active_past_name;
       datetime          next_upcoming_time;
       string            next_upcoming_currency;
       string            next_upcoming_name;
      };

    CTrade               g_trade;
    bool                 g_allow_buy              = true;
    bool                 g_allow_sell             = true;
    bool                 g_panel_open             = true;
    datetime             g_pause_until            = 0;
    datetime             g_last_open_bar_time     = 0;
    datetime             g_last_panel_refresh     = 0;
    double               g_max_loss_limit         = 0.0;
    double               g_max_loss_close_all     = 0.0;
    double               g_stop_loss_limit        = 0.0;
    double               g_second_loss_threshold  = 0.0;
    double               g_deposit_base           = 100.0;
    double               g_buy_protection_peak    = 0.0;
    double               g_sell_protection_peak   = 0.0;
    string               g_today_key              = "";
    bool                 g_daily_target_locked    = false;
    double               g_daily_target_hit_value = 0.0;
    NewsWindowState      g_news_state;
    datetime             g_news_cache_minute      = 0;
    string               g_panel_prefix           = "GoldKylinMT5.";

    #define GOLDKING_ORDER_COMMENT_PRIMARY   "FXKiller_GoldKing"
    #define GOLDKING_ORDER_COMMENT_SECONDARY "FXKiller_GoldKing_SS"

    bool       IsTestingMode();
    datetime   ReferenceNow();
    datetime   ReferenceNewsNow();
    string     CleanTimeString(const string value);
    datetime   TodayAt(const string time_text,const datetime now_value);
    bool       IsInWindow(const string start_text,const string stop_text,const datetime now_value);
    bool       IsAfterSessionStop(const datetime now_value);
    bool       IsTradingSessionOpen(const datetime now_value);
    bool       IsTradingSessionAfterStop(const datetime now_value);
    bool       IsDailyWrapUpWindow(const datetime now_value);
    void       ResetNewsState(NewsWindowState &state);
    void       ResetNewsEvalAccumulator(NewsEvalAccumulator &eval);
    void       AppendUniqueText(string &items[],const string value);
    void       BuildNewsCurrencies(string &currencies[]);
    string     CalendarErrorText(const int error_code);
    void       ConsiderNewsEvent(const datetime now_server,const datetime event_time,const string currency,const string event_name,const int lead_seconds,const int cooldown_seconds,NewsEvalAccumulator &eval);
    void       ApplyNewsAccumulator(const NewsEvalAccumulator &eval);
    void       RefreshEmbeddedBacktestNewsState(const datetime now_server);
    void       RefreshNewsState(const bool force);
    double     PipDivisor();
    double     CurrentSpreadPoints();
    int        VolumeDigits(const double step);
    double     NormalizeVolumeToSymbol(double volume);
    double     NormalizePriceToSymbol(double price);
    int        BrokerMinDistancePoints();
    bool       IsHedgingAccount();
    void       ResetStats(EAStats &stats);
    void       CollectStats(EAStats &stats);
    double     CalculateDepositBase();
    double     CalculateClosedProfit(const datetime from_time,const datetime to_time,const long magic_filter,const bool current_symbol_only);
    string     TradingDayKey(const datetime now_value);
    double     TodayClosedProfit(const datetime now_value);
    double     TodayProgressProfit(const datetime now_value,const EAStats &stats);
    bool       HasOpenPositions(const EAStats &stats);
    bool       HasActiveExposure(const EAStats &stats);
    void       RefreshDailyLocks(const datetime now_value,const EAStats &stats);
    double     AccountProfitForPanel();
    int        CountPositionsWithComment(const string comment_text,const ENUM_POSITION_TYPE type);
    double     SumExtremePositionProfits(const ENUM_POSITION_TYPE type,const bool positive,const int count);
    ulong      FindExtremePositionTicket(const ENUM_POSITION_TYPE type,const bool positive);
    double     FindExtremePositionLot(const ENUM_POSITION_TYPE type,const bool positive);
    void       CloseExtremePositions(const ENUM_POSITION_TYPE type,int count,const bool positive);
    ulong      FindNewestPositionTicket(const ENUM_POSITION_TYPE type,const bool current_symbol_only,const long magic_filter);
    bool       CloseByPair(const ulong position_ticket,const ulong opposite_ticket);
    void       CloseOppositePairs();
    bool       TradeRetcodeOk(const uint retcode);
    bool       CheckTradeResult(const bool request_ok,const string action);
    bool       CheckOrderSendResult(const bool request_ok,const MqlTradeResult &result,const string action);
    bool       ClosePositionTicket(const ulong ticket);
    bool       DeletePendingOrder(const ulong ticket);
    void       DeleteEaPendingOrders();
    bool       ModifyPendingPrice(const ulong ticket,const double new_price);
    void       CloseEaOrders(const int direction,const bool use_pairs,const bool arm_cooldown);
    void       ClosePositionsByProfitState(const bool close_profit);
    void       CloseCurrentSymbolPositions();
    void       CloseAllAccountPositions();
    bool       IsTradingEnvironmentOk(const EAStats &stats,string &reason);
    void       UpdateLimitLines();
    void       UpdateAverageLines(const EAStats &stats);
    bool       ShouldUsePrimaryParameters(const EAStats &stats);
    bool       AllowBuyOrderByPriceLimit(const EAStats &stats,const double target_price,const bool limit_window_active);
    bool       AllowSellOrderByPriceLimit(const EAStats &stats,const double target_price,const bool limit_window_active);
    bool       CanOpenThisCycle(const bool is_buy,const EAStats &stats);
    bool       TryProtectiveCloseBySide(const EAStats &stats);
    bool       ApplyCloseBuySellProtection(const EAStats &stats);
    bool       TryAutoCloseLogic(const EAStats &stats);
    void       TryPlacePendingOrders(const EAStats &stats,const bool allow_buy,const bool allow_sell);
    void       TryTrailPendingOrders(const EAStats &stats,const bool allow_buy,const bool allow_sell);
    void       ExecuteStrategy();
    double     UiScale();
    double     UiFontScale();
    int        ScalePx(const int value);
    int        ScaleFont(const int value);
    void       BuildPanelMetrics(PanelMetrics &m);
    void       EnsureRectangle(const string name,const int x,const int y,const int w,const int h,const color bg,const color border,const int corner);
    void       EnsureLabel(const string name,const string text,const int x,const int y,const int font_size,const color clr,const int corner,const string font="Microsoft YaHei");
    void       EnsureButton(const string name,const string text,const int x,const int y,const int w,const int h,const color bg,const color fg,const int corner);
    string     BoolText(const bool enabled,const string on_text,const string off_text);
    string     FormatSignedMoney(const double value);
    string     FormatPercent(const double value);
    string     FormatPanelMoment(const datetime when,const datetime now_value);
    string     NewsPauseReason(const EAStats &stats);
    string     WrapUpPauseReason(const EAStats &stats);
    string     SessionStateText(const datetime now_value,const EAStats &stats);
    string     WrapUpStateText(const EAStats &stats);
    string     GoalStateText(const double target_progress_display);
    string     NewsStateText(const EAStats &stats);
    string     EntryStateText(const string stop_reason);
    string     CloseReasonText();
    string     ClipText(const string text,const int max_chars);
    string     TimeframeLabel(const ENUM_TIMEFRAMES timeframe);
    void       DrawPanel(const EAStats &stats);
    void       RefreshPanel(const bool force);
    void       DeleteObjectsByPrefix(const string prefix);

    int OnInit()
      {
       g_trade.SetExpertMagicNumber(Magic);
       g_trade.SetTypeFillingBySymbol(_Symbol);
       g_trade.SetDeviationInPoints((_Digits == 3 || _Digits == 5) ? 30 : 3);

       g_allow_buy             = true;
       g_allow_sell            = true;
       g_panel_open            = true;
       g_pause_until           = 0;
       g_last_open_bar_time    = 0;
       g_last_panel_refresh    = 0;
       g_buy_protection_peak   = 0.0;
       g_sell_protection_peak  = 0.0;
       g_max_loss_limit        = -MathAbs(MaxLoss);
       g_max_loss_close_all    = -MathAbs(MaxLossCloseAll);
       g_stop_loss_limit       = -MathAbs(StopLoss);
       g_second_loss_threshold = -MathAbs(Money);
       g_deposit_base          = CalculateDepositBase();
       ResetNewsState(g_news_state);
       g_news_cache_minute     = 0;

       DeleteObjectsByPrefix(g_panel_prefix);
       RefreshNewsState(true);
       EventSetTimer(1);
       RefreshPanel(true);
       return(INIT_SUCCEEDED);
      }

    void OnDeinit(const int reason)
      {
       EventKillTimer();
       DeleteObjectsByPrefix(g_panel_prefix);
      }

    void OnTick()
      {
       ExecuteStrategy();
      }

    void OnTimer()
      {
       RefreshPanel(false);
      }

    void OnChartEvent(const int id,const long &lparam,const double &dparam,const string &sparam)
      {
       if(id != CHARTEVENT_OBJECT_CLICK)
          return;

       const string key=sparam;
       if(key == g_panel_prefix + "toggle_panel")
         {
          g_panel_open = !g_panel_open;
          RefreshPanel(true);
          return;
         }

       if(key == g_panel_prefix + "stop_all")
         {
          const bool currently_on=(g_allow_buy || g_allow_sell);
          g_allow_buy = !currently_on;
          g_allow_sell = !currently_on;
          RefreshPanel(true);
          return;
         }

       if(key == g_panel_prefix + "stop_buy")
         {
          g_allow_buy = !g_allow_buy;
          RefreshPanel(true);
          return;
         }

       if(key == g_panel_prefix + "stop_sell")
         {
          g_allow_sell = !g_allow_sell;
          RefreshPanel(true);
          return;
         }

       if(key == g_panel_prefix + "close_profit")
         {
          ClosePositionsByProfitState(true);
          RefreshPanel(true);
          return;
         }

       if(key == g_panel_prefix + "close_loss")
         {
          ClosePositionsByProfitState(false);
          RefreshPanel(true);
          return;
         }

       if(key == g_panel_prefix + "close_buy")
         {
          CloseEaOrders(1,false,false);
          RefreshPanel(true);
          return;
         }

       if(key == g_panel_prefix + "close_sell")
         {
          CloseEaOrders(-1,false,false);
          RefreshPanel(true);
          return;
         }

       if(key == g_panel_prefix + "close_symbol")
         {
          CloseCurrentSymbolPositions();
          RefreshPanel(true);
          return;
         }

       if(key == g_panel_prefix + "close_ea")
         {
          CloseEaOrders(0,false,false);
          RefreshPanel(true);
          return;
         }

       if(key == g_panel_prefix + "close_account")
         {
          CloseAllAccountPositions();
          RefreshPanel(true);
         }
      }

    bool IsTestingMode()
      {
       return((bool)MQLInfoInteger(MQL_TESTER));
      }

    datetime ReferenceNow()
      {
       return(IsTestingMode() ? TimeCurrent() : TimeLocal());
      }

    datetime ReferenceNewsNow()
      {
       if(IsTestingMode())
          return(TimeCurrent());

       datetime server_time=TimeTradeServer();
       if(server_time > 0)
          return(server_time);

       server_time=TimeCurrent();
       if(server_time > 0)
          return(server_time);

       return(TimeLocal());
      }

    string CleanTimeString(const string value)
      {
       string result=value;
       StringReplace(result," ","");
       StringTrimLeft(result);
       StringTrimRight(result);
       if(result == "24:00")
          result="23:59:59";
       return(result);
      }

    datetime TodayAt(const string time_text,const datetime now_value)
      {
       string t=CleanTimeString(time_text);
       if(StringLen(t) == 5)
          t+=":00";
       return(StringToTime(TimeToString(now_value,TIME_DATE) + " " + t));
      }

    bool IsInWindow(const string start_text,const string stop_text,const datetime now_value)
      {
       const datetime start_time=TodayAt(start_text,now_value);
       const datetime stop_time=TodayAt(stop_text,now_value);
       if(start_time <= stop_time)
          return(now_value >= start_time && now_value <= stop_time);
       return(now_value >= start_time || now_value <= stop_time);
      }

    bool IsAfterSessionStop(const datetime now_value)
      {
       if(IsInWindow(EA_StartTime,EA_StopTime,now_value))
          return(false);

       const datetime start_time=TodayAt(EA_StartTime,now_value);
       const datetime stop_time=TodayAt(EA_StopTime,now_value);
       if(start_time <= stop_time)
          return(now_value > stop_time);
       return(now_value > stop_time && now_value < start_time);
      }

    bool IsTradingSessionOpen(const datetime now_value)
      {
       if(!EnableTradingSessionWindow)
          return(true);
       return(IsInWindow(EA_StartTime,EA_StopTime,now_value));
      }

    bool IsTradingSessionAfterStop(const datetime now_value)
      {
       if(!EnableTradingSessionWindow)
          return(false);
       return(IsAfterSessionStop(now_value));
      }

    bool IsDailyWrapUpWindow(const datetime now_value)
      {
       if(!EnableDailyWrapUpPhase)
          return(false);
       return(IsInWindow(DailyWrapUpStartTime,DailyWrapUpStopTime,now_value));
      }

    void ResetNewsState(NewsWindowState &state)
      {
       state.enabled=false;
       state.calendar_available=false;
       state.using_embedded_history=false;
       state.has_active_window=false;
       state.in_pre_window=false;
       state.in_post_window=false;
       state.has_upcoming_event=false;
       state.block_entries=false;
       state.server_now=0;
       state.event_time=0;
       state.window_start=0;
       state.resume_time=0;
       state.currency="";
       state.event_name="";
       state.error_text="";
      }

    void ResetNewsEvalAccumulator(NewsEvalAccumulator &eval)
      {
       eval.any_success=false;
       eval.first_error="";
       eval.active_block_start=0;
       eval.active_block_end=0;
       eval.active_future_time=0;
       eval.active_future_currency="";
       eval.active_future_name="";
       eval.active_past_time=0;
       eval.active_past_currency="";
       eval.active_past_name="";
       eval.next_upcoming_time=0;
       eval.next_upcoming_currency="";
       eval.next_upcoming_name="";
      }

    void AppendUniqueText(string &items[],const string value)
      {
       string item=value;
       StringTrimLeft(item);
       StringTrimRight(item);
       if(item == "")
          return;

       for(int i=0; i<ArraySize(items); ++i)
         {
          if(items[i] == item)
             return;
         }

       const int size=ArraySize(items);
       ArrayResize(items,size + 1);
       items[size]=item;
      }

    void BuildNewsCurrencies(string &currencies[])
      {
       ArrayResize(currencies,0);
       AppendUniqueText(currencies,SymbolInfoString(_Symbol,SYMBOL_CURRENCY_PROFIT));
       AppendUniqueText(currencies,SymbolInfoString(_Symbol,SYMBOL_CURRENCY_BASE));
       AppendUniqueText(currencies,SymbolInfoString(_Symbol,SYMBOL_CURRENCY_MARGIN));
      }

    string CalendarErrorText(const int error_code)
      {
       switch(error_code)
         {
          case 0:
             return("");
          case 5400:
             return("经济日历返回过多数据");
          case 5401:
             return("经济日历请求超时");
          case 5402:
             return("经济日历无可用数据");
         default:
             return("经济日历错误 " + IntegerToString(error_code));
         }
      }

    void ConsiderNewsEvent(const datetime now_server,const datetime event_time,const string currency,const string event_name,const int lead_seconds,const int cooldown_seconds,NewsEvalAccumulator &eval)
      {
       if(event_time <= 0)
          return;

       const datetime window_start=event_time - lead_seconds;
       const datetime window_end=event_time + cooldown_seconds;

       if(now_server >= window_start && now_server < window_end)
         {
          if(eval.active_block_start == 0 || window_start < eval.active_block_start)
             eval.active_block_start=window_start;
          if(window_end > eval.active_block_end)
             eval.active_block_end=window_end;

          if(event_time >= now_server)
            {
             if(eval.active_future_time == 0 || event_time < eval.active_future_time)
               {
                eval.active_future_time=event_time;
                eval.active_future_currency=currency;
                eval.active_future_name=event_name;
               }
            }
          else
            {
             if(eval.active_past_time == 0 || event_time > eval.active_past_time)
               {
                eval.active_past_time=event_time;
                eval.active_past_currency=currency;
                eval.active_past_name=event_name;
               }
            }
          return;
         }

       if(event_time > now_server && (eval.next_upcoming_time == 0 || event_time < eval.next_upcoming_time))
         {
          eval.next_upcoming_time=event_time;
          eval.next_upcoming_currency=currency;
          eval.next_upcoming_name=event_name;
         }
      }

    void ApplyNewsAccumulator(const NewsEvalAccumulator &eval)
      {
       g_news_state.calendar_available=eval.any_success;
       if(!eval.any_success)
         {
          g_news_state.error_text=(eval.first_error != "" ? eval.first_error : "经济日历不可用,已忽略");
          return;
         }

       if(eval.active_block_start != 0)
         {
          g_news_state.has_active_window=true;
          g_news_state.block_entries=true;
          g_news_state.window_start=eval.active_block_start;
          g_news_state.resume_time=eval.active_block_end;
          g_news_state.in_pre_window=(eval.active_future_time != 0);
          g_news_state.in_post_window=(eval.active_past_time != 0) || !g_news_state.in_pre_window;

          if(g_news_state.in_pre_window)
            {
             g_news_state.event_time=eval.active_future_time;
             g_news_state.currency=eval.active_future_currency;
             g_news_state.event_name=eval.active_future_name;
            }
          else
            {
             g_news_state.event_time=eval.active_past_time;
             g_news_state.currency=eval.active_past_currency;
             g_news_state.event_name=eval.active_past_name;
            }
          return;
         }

       if(eval.next_upcoming_time != 0)
         {
          g_news_state.has_upcoming_event=true;
          g_news_state.event_time=eval.next_upcoming_time;
          g_news_state.currency=eval.next_upcoming_currency;
          g_news_state.event_name=eval.next_upcoming_name;
         }
      }

    void RefreshEmbeddedBacktestNewsState(const datetime now_server)
      {
       g_news_state.using_embedded_history=true;

       NewsEvalAccumulator eval;
       ResetNewsEvalAccumulator(eval);
       eval.any_success=(GOLDKING_BACKTEST_USD_HIGH_NEWS_COUNT > 0);
       if(!eval.any_success)
         {
          eval.first_error="回测内置新闻为空";
          ApplyNewsAccumulator(eval);
          return;
         }

       const int lead_seconds=MathMax(0,NewsLeadMinutes) * 60;
       const int cooldown_seconds=MathMax(0,NewsCooldownMinutes) * 60;
       for(int i=0; i<GOLDKING_BACKTEST_USD_HIGH_NEWS_COUNT; ++i)
          ConsiderNewsEvent(now_server,GOLDKING_BACKTEST_USD_HIGH_NEWS_TIMES[i],"USD",GOLDKING_BACKTEST_USD_HIGH_NEWS_NAMES[i],lead_seconds,cooldown_seconds,eval);

       ApplyNewsAccumulator(eval);
      }

    void RefreshNewsState(const bool force)
      {
       const datetime now_server=ReferenceNewsNow();
       const datetime minute_key=now_server - now_server % 60;

       if(!force && g_news_cache_minute == minute_key && g_news_state.server_now != 0)
         {
          g_news_state.server_now=now_server;
          return;
         }

       g_news_cache_minute=minute_key;
       ResetNewsState(g_news_state);
       g_news_state.enabled=EnableHighImpactNewsPause;
       g_news_state.server_now=now_server;

       if(!EnableHighImpactNewsPause)
          return;

       if(IsTestingMode())
         {
          RefreshEmbeddedBacktestNewsState(now_server);
          return;
         }

       string currencies[];
       BuildNewsCurrencies(currencies);
       if(ArraySize(currencies) == 0)
         {
          g_news_state.error_text="新闻过滤无可用货币";
          return;
         }

       const int lead_seconds=MathMax(0,NewsLeadMinutes) * 60;
       const int cooldown_seconds=MathMax(0,NewsCooldownMinutes) * 60;
       const datetime query_from=now_server - cooldown_seconds;
       const datetime query_to=now_server + 86400;

       NewsEvalAccumulator eval;
       ResetNewsEvalAccumulator(eval);

       for(int c=0; c<ArraySize(currencies); ++c)
         {
          MqlCalendarValue values[];
          ResetLastError();
          const int count=CalendarValueHistory(values,query_from,query_to,NULL,currencies[c]);
          const int error_code=GetLastError();

          if(count < 0)
            {
             if(eval.first_error == "" && error_code != 0)
                eval.first_error=CalendarErrorText(error_code);
             continue;
            }

          eval.any_success=true;
          for(int i=0; i<count; ++i)
            {
             if(values[i].event_id == 0 || values[i].time <= 0)
                continue;

             MqlCalendarEvent event={};
             if(!CalendarEventById(values[i].event_id,event))
                continue;
             if(event.importance != CALENDAR_IMPORTANCE_HIGH)
                continue;
             if(event.time_mode != CALENDAR_TIMEMODE_DATETIME)
                continue;

             ConsiderNewsEvent(now_server,values[i].time,currencies[c],event.name,lead_seconds,cooldown_seconds,eval);
            }
         }

       ApplyNewsAccumulator(eval);
      }

    double PipDivisor()
      {
       return((_Digits == 3 || _Digits == 5) ? 10.0 : 1.0);
      }

    double CurrentSpreadPoints()
      {
       double ask_price=0.0;
       double bid_price=0.0;
       if(!SymbolInfoDouble(_Symbol,SYMBOL_ASK,ask_price) || !SymbolInfoDouble(_Symbol,SYMBOL_BID,bid_price))
          return(0.0);
       return((ask_price - bid_price) / _Point);
      }

    int VolumeDigits(const double step)
      {
       string step_text=DoubleToString(step,8);
       int end_index=StringLen(step_text) - 1;
       while(end_index >= 0 && StringGetCharacter(step_text,end_index) == '0')
          end_index--;
       const int dot_index=StringFind(step_text,".");
       if(dot_index < 0 || end_index <= dot_index)
          return(0);
       return(end_index - dot_index);
      }

    double NormalizeVolumeToSymbol(double volume)
      {
       const double min_volume=SymbolInfoDouble(_Symbol,SYMBOL_VOLUME_MIN);
       const double max_volume=SymbolInfoDouble(_Symbol,SYMBOL_VOLUME_MAX);
       const double step=SymbolInfoDouble(_Symbol,SYMBOL_VOLUME_STEP);
       const int digits=MathMax(DigitsLot,VolumeDigits(step));

       volume=MathMin(volume,MathMin(Maxlot,max_volume));
       volume=MathMax(volume,min_volume);
       if(step > 0.0)
          volume=MathRound(volume / step) * step;
       return(NormalizeDouble(volume,digits));
      }

    double NormalizePriceToSymbol(double price)
      {
       const double tick_size=SymbolInfoDouble(_Symbol,SYMBOL_TRADE_TICK_SIZE);
       if(tick_size > 0.0)
          price=MathRound(price / tick_size) * tick_size;
       return(NormalizeDouble(price,_Digits));
      }

    int BrokerMinDistancePoints()
      {
       const long freeze_level=SymbolInfoInteger(_Symbol,SYMBOL_TRADE_FREEZE_LEVEL);
       const long stop_level=SymbolInfoInteger(_Symbol,SYMBOL_TRADE_STOPS_LEVEL);
       return((int)MathMax(freeze_level,stop_level) + 1);
      }

    bool IsHedgingAccount()
      {
       return((ENUM_ACCOUNT_MARGIN_MODE)AccountInfoInteger(ACCOUNT_MARGIN_MODE) == ACCOUNT_MARGIN_MODE_RETAIL_HEDGING);
      }

    void ResetStats(EAStats &stats)
      {
       ZeroMemory(stats);
       stats.buy_highest_any    = 0.0;
       stats.buy_lowest_position= 0.0;
       stats.sell_highest_position=0.0;
       stats.sell_lowest_any    = 0.0;
       stats.buy_pending_price  = 0.0;
       stats.sell_pending_price = 0.0;
       stats.buy_pending_ticket = 0;
       stats.sell_pending_ticket= 0;
      }

    void CollectStats(EAStats &stats)
      {
       ResetStats(stats);

       for(int i=PositionsTotal()-1; i>=0; --i)
         {
          const ulong ticket=PositionGetTicket(i);
          if(ticket == 0 || !PositionSelectByTicket(ticket))
             continue;
          if(PositionGetString(POSITION_SYMBOL) != _Symbol)
             continue;
          if((long)PositionGetInteger(POSITION_MAGIC) != Magic)
             continue;

          const ENUM_POSITION_TYPE type=(ENUM_POSITION_TYPE)PositionGetInteger(POSITION_TYPE);
          const double open_price=PositionGetDouble(POSITION_PRICE_OPEN);
          const double volume=PositionGetDouble(POSITION_VOLUME);
          const double profit=PositionGetDouble(POSITION_PROFIT) + PositionGetDouble(POSITION_SWAP);
          const datetime open_time=(datetime)PositionGetInteger(POSITION_TIME);

          if(type == POSITION_TYPE_BUY)
            {
             stats.buy_positions++;
             stats.buy_lots+=volume;
             stats.buy_profit+=profit;
             stats.buy_weighted_sum+=open_price * volume;
             if(open_price > stats.buy_highest_any || stats.buy_highest_any == 0.0)
                stats.buy_highest_any=open_price;
             if(open_price < stats.buy_lowest_position || stats.buy_lowest_position == 0.0)
                stats.buy_lowest_position=open_price;
             if(open_time > stats.last_buy_open_time)
                stats.last_buy_open_time=open_time;
            }
          else if(type == POSITION_TYPE_SELL)
            {
             stats.sell_positions++;
             stats.sell_lots+=volume;
             stats.sell_profit+=profit;
             stats.sell_weighted_sum+=open_price * volume;
             if(open_price > stats.sell_highest_position || stats.sell_highest_position == 0.0)
                stats.sell_highest_position=open_price;
             if(open_price < stats.sell_lowest_any || stats.sell_lowest_any == 0.0)
                stats.sell_lowest_any=open_price;
             if(open_time > stats.last_sell_open_time)
                stats.last_sell_open_time=open_time;
            }
         }

       for(int i=OrdersTotal()-1; i>=0; --i)
         {
          const ulong ticket=OrderGetTicket(i);
          if(ticket == 0 || !OrderSelect(ticket))
             continue;
          if(OrderGetString(ORDER_SYMBOL) != _Symbol)
             continue;
          if((long)OrderGetInteger(ORDER_MAGIC) != Magic)
             continue;

          const ENUM_ORDER_TYPE type=(ENUM_ORDER_TYPE)OrderGetInteger(ORDER_TYPE);
          const double open_price=OrderGetDouble(ORDER_PRICE_OPEN);

          if(type == ORDER_TYPE_BUY_STOP)
            {
             stats.buy_pending++;
             if(open_price > stats.buy_highest_any || stats.buy_highest_any == 0.0)
                stats.buy_highest_any=open_price;
             if(ticket > stats.buy_pending_ticket)
               {
                stats.buy_pending_ticket=ticket;
                stats.buy_pending_price=open_price;
               }
            }
          else if(type == ORDER_TYPE_SELL_STOP)
            {
             stats.sell_pending++;
             if(open_price < stats.sell_lowest_any || stats.sell_lowest_any == 0.0)
                stats.sell_lowest_any=open_price;
             if(ticket > stats.sell_pending_ticket)
               {
                stats.sell_pending_ticket=ticket;
                stats.sell_pending_price=open_price;
               }
            }
         }

       if(stats.buy_lots > 0.0)
          stats.buy_avg_price=NormalizePriceToSymbol(stats.buy_weighted_sum / stats.buy_lots);
       if(stats.sell_lots > 0.0)
          stats.sell_avg_price=NormalizePriceToSymbol(stats.sell_weighted_sum / stats.sell_lots);
       stats.total_profit=stats.buy_profit + stats.sell_profit;
      }

    double CalculateDepositBase()
      {
       double deposit_sum=0.0;
       if(!HistorySelect(0,TimeCurrent()))
          return(100.0);

       const int deals_total=(int)HistoryDealsTotal();
       for(int i=0; i<deals_total; ++i)
         {
          const ulong deal_ticket=HistoryDealGetTicket(i);
          if(deal_ticket == 0)
             continue;
          const ENUM_DEAL_TYPE deal_type=(ENUM_DEAL_TYPE)HistoryDealGetInteger(deal_ticket,DEAL_TYPE);
          if(deal_type != DEAL_TYPE_BALANCE && deal_type != DEAL_TYPE_CREDIT)
             continue;
          const double deal_profit=HistoryDealGetDouble(deal_ticket,DEAL_PROFIT);
          if(deal_profit > 0.0)
             deposit_sum+=deal_profit;
         }

       if(deposit_sum <= 0.0)
          deposit_sum=100.0;
       return(deposit_sum);
      }

    double CalculateClosedProfit(const datetime from_time,const datetime to_time,const long magic_filter,const bool current_symbol_only)
      {
       double total=0.0;
       if(!HistorySelect(from_time,to_time))
          return(0.0);

       const int deals_total=(int)HistoryDealsTotal();
       for(int i=0; i<deals_total; ++i)
         {
          const ulong deal_ticket=HistoryDealGetTicket(i);
          if(deal_ticket == 0)
             continue;

          const ENUM_DEAL_ENTRY entry=(ENUM_DEAL_ENTRY)HistoryDealGetInteger(deal_ticket,DEAL_ENTRY);
          if(entry != DEAL_ENTRY_OUT && entry != DEAL_ENTRY_OUT_BY && entry != DEAL_ENTRY_INOUT)
             continue;

          if(current_symbol_only && HistoryDealGetString(deal_ticket,DEAL_SYMBOL) != _Symbol)
             continue;

          if(magic_filter != -1 && (long)HistoryDealGetInteger(deal_ticket,DEAL_MAGIC) != magic_filter)
             continue;

          total+=HistoryDealGetDouble(deal_ticket,DEAL_PROFIT);
          total+=HistoryDealGetDouble(deal_ticket,DEAL_SWAP);
          total+=HistoryDealGetDouble(deal_ticket,DEAL_COMMISSION);
         }

       return(total);
      }

    string TradingDayKey(const datetime now_value)
      {
       return(TimeToString(now_value,TIME_DATE));
      }

    double TodayClosedProfit(const datetime now_value)
      {
       return(CalculateClosedProfit(TodayAt("00:00",now_value),TimeCurrent(),Magic,true));
      }

    double TodayProgressProfit(const datetime now_value,const EAStats &stats)
      {
       return(TodayClosedProfit(now_value) + stats.total_profit);
      }

    bool HasOpenPositions(const EAStats &stats)
      {
       return((stats.buy_positions + stats.sell_positions) > 0);
      }

    bool HasActiveExposure(const EAStats &stats)
      {
       return(HasOpenPositions(stats) || (stats.buy_pending + stats.sell_pending) > 0);
      }

    void RefreshDailyLocks(const datetime now_value,const EAStats &stats)
      {
       const string day_key=TradingDayKey(now_value);
       if(day_key != g_today_key)
         {
          g_today_key=day_key;
          g_daily_target_locked=false;
          g_daily_target_hit_value=0.0;
         }

       if(!EnableDailyProfitTarget || DailyProfitTarget <= 0.0)
         {
          g_daily_target_locked=false;
          g_daily_target_hit_value=0.0;
          return;
         }

       if(g_daily_target_locked)
          return;

       const double today_progress=TodayProgressProfit(now_value,stats);
       if(today_progress >= DailyProfitTarget)
         {
          g_daily_target_locked=true;
          g_daily_target_hit_value=today_progress;
         }
      }

    double AccountProfitForPanel()
      {
       return(AccountInfoDouble(ACCOUNT_PROFIT));
      }

    int CountPositionsWithComment(const string comment_text,const ENUM_POSITION_TYPE type)
      {
       int count=0;
       for(int i=PositionsTotal()-1; i>=0; --i)
         {
          const ulong ticket=PositionGetTicket(i);
          if(ticket == 0 || !PositionSelectByTicket(ticket))
             continue;
          if(PositionGetString(POSITION_SYMBOL) != _Symbol)
             continue;
          if((long)PositionGetInteger(POSITION_MAGIC) != Magic)
             continue;
          if((ENUM_POSITION_TYPE)PositionGetInteger(POSITION_TYPE) != type)
             continue;
          if(PositionGetString(POSITION_COMMENT) == comment_text)
             count++;
         }
       return(count);
      }

    double SumExtremePositionProfits(const ENUM_POSITION_TYPE type,const bool positive,const int count)
      {
       if(count <= 0)
          return(0.0);

       double values[];
       ArrayResize(values,0);

       for(int i=PositionsTotal()-1; i>=0; --i)
         {
          const ulong ticket=PositionGetTicket(i);
          if(ticket == 0 || !PositionSelectByTicket(ticket))
             continue;
          if(PositionGetString(POSITION_SYMBOL) != _Symbol)
             continue;
          if((long)PositionGetInteger(POSITION_MAGIC) != Magic)
             continue;
          if((ENUM_POSITION_TYPE)PositionGetInteger(POSITION_TYPE) != type)
             continue;

          const double profit=PositionGetDouble(POSITION_PROFIT);
          if(positive && profit >= 0.0)
            {
             const int size=ArraySize(values);
             ArrayResize(values,size + 1);
             values[size]=profit;
            }
          if(!positive && profit < 0.0)
            {
             const int size=ArraySize(values);
             ArrayResize(values,size + 1);
             values[size]=-profit;
            }
         }

       if(ArraySize(values) == 0)
          return(0.0);

       ArraySort(values);
       double sum=0.0;
       int taken=0;
       for(int i=ArraySize(values)-1; i>=0 && taken<count; --i)
         {
          sum+=values[i];
          taken++;
         }
       return(sum);
      }

    ulong FindExtremePositionTicket(const ENUM_POSITION_TYPE type,const bool positive)
      {
       bool found=false;
       double best_profit=0.0;
       ulong best_ticket=0;

       for(int i=PositionsTotal()-1; i>=0; --i)
         {
          const ulong ticket=PositionGetTicket(i);
          if(ticket == 0 || !PositionSelectByTicket(ticket))
             continue;
          if(PositionGetString(POSITION_SYMBOL) != _Symbol)
             continue;
          if((long)PositionGetInteger(POSITION_MAGIC) != Magic)
             continue;
          if((ENUM_POSITION_TYPE)PositionGetInteger(POSITION_TYPE) != type)
             continue;

          const double profit=PositionGetDouble(POSITION_PROFIT);
          if(positive)
            {
             if(profit < 0.0)
                continue;
             if(!found || profit > best_profit)
               {
                found=true;
                best_profit=profit;
                best_ticket=ticket;
               }
            }
          else
            {
             if(profit >= 0.0)
                continue;
             if(!found || profit < best_profit)
               {
                found=true;
                best_profit=profit;
                best_ticket=ticket;
               }
            }
         }

       return(best_ticket);
      }

    double FindExtremePositionLot(const ENUM_POSITION_TYPE type,const bool positive)
      {
       const ulong ticket=FindExtremePositionTicket(type,positive);
       if(ticket == 0 || !PositionSelectByTicket(ticket))
          return(0.0);
       return(PositionGetDouble(POSITION_VOLUME));
      }

    void CloseExtremePositions(const ENUM_POSITION_TYPE type,int count,const bool positive)
      {
       while(count > 0)
         {
          const ulong ticket=FindExtremePositionTicket(type,positive);
          if(ticket == 0)
             break;
          ClosePositionTicket(ticket);
          count--;
         }
      }

    ulong FindNewestPositionTicket(const ENUM_POSITION_TYPE type,const bool current_symbol_only,const long magic_filter)
      {
       ulong newest_ticket=0;
       for(int i=PositionsTotal()-1; i>=0; --i)
         {
          const ulong ticket=PositionGetTicket(i);
          if(ticket == 0 || !PositionSelectByTicket(ticket))
             continue;
          if(current_symbol_only && PositionGetString(POSITION_SYMBOL) != _Symbol)
             continue;
          if(magic_filter != -1 && (long)PositionGetInteger(POSITION_MAGIC) != magic_filter)
             continue;
          if((ENUM_POSITION_TYPE)PositionGetInteger(POSITION_TYPE) != type)
             continue;
          if(ticket > newest_ticket)
             newest_ticket=ticket;
         }
       return(newest_ticket);
      }

    bool CloseByPair(const ulong position_ticket,const ulong opposite_ticket)
      {
       MqlTradeRequest request={};
       MqlTradeResult  result={};
       request.action=TRADE_ACTION_CLOSE_BY;
       request.position=position_ticket;
       request.position_by=opposite_ticket;
       request.magic=Magic;

       return(CheckOrderSendResult(OrderSend(request,result),result,"CloseByPair"));
      }

    void CloseOppositePairs()
      {
       while(true)
         {
          const ulong buy_ticket=FindNewestPositionTicket(POSITION_TYPE_BUY,true,Magic);
          const ulong sell_ticket=FindNewestPositionTicket(POSITION_TYPE_SELL,true,Magic);
          if(buy_ticket == 0 || sell_ticket == 0)
             break;

          if(CloseByPair(buy_ticket,sell_ticket))
             continue;
          if(CloseByPair(sell_ticket,buy_ticket))
             continue;
          break;
         }
      }

    bool TradeRetcodeOk(const uint retcode)
      {
       return(retcode == TRADE_RETCODE_DONE ||
              retcode == TRADE_RETCODE_DONE_PARTIAL ||
              retcode == TRADE_RETCODE_PLACED ||
              retcode == TRADE_RETCODE_NO_CHANGES);
      }

    bool CheckTradeResult(const bool request_ok,const string action)
      {
       const uint retcode=g_trade.ResultRetcode();
       if(request_ok && TradeRetcodeOk(retcode))
          return(true);

       PrintFormat("%s failed on %s: request_ok=%s retcode=%u detail=%s",
                   action,
                   _Symbol,
                   request_ok ? "true" : "false",
                   retcode,
                   g_trade.ResultRetcodeDescription());
       return(false);
      }

    bool CheckOrderSendResult(const bool request_ok,const MqlTradeResult &result,const string action)
      {
       if(request_ok && TradeRetcodeOk(result.retcode))
          return(true);

       PrintFormat("%s failed on %s: request_ok=%s retcode=%u order=%I64u deal=%I64u",
                   action,
                   _Symbol,
                   request_ok ? "true" : "false",
                   result.retcode,
                   result.order,
                   result.deal);
       return(false);
      }

    bool ClosePositionTicket(const ulong ticket)
      {
       if(ticket == 0 || !PositionSelectByTicket(ticket))
          return(false);
       return(CheckTradeResult(g_trade.PositionClose(ticket),"ClosePositionTicket"));
      }

    bool DeletePendingOrder(const ulong ticket)
      {
       if(ticket == 0)
          return(false);
       return(CheckTradeResult(g_trade.OrderDelete(ticket),"DeletePendingOrder"));
      }

    void DeleteEaPendingOrders()
      {
       for(int i=OrdersTotal()-1; i>=0; --i)
         {
          const ulong ticket=OrderGetTicket(i);
          if(ticket == 0 || !OrderSelect(ticket))
             continue;
          if(OrderGetString(ORDER_SYMBOL) != _Symbol)
             continue;
          if((long)OrderGetInteger(ORDER_MAGIC) != Magic)
             continue;

          const ENUM_ORDER_TYPE type=(ENUM_ORDER_TYPE)OrderGetInteger(ORDER_TYPE);
          if(type != ORDER_TYPE_BUY_STOP && type != ORDER_TYPE_SELL_STOP)
             continue;
          DeletePendingOrder(ticket);
         }
      }

    bool ModifyPendingPrice(const ulong ticket,const double new_price)
      {
       if(ticket == 0 || !OrderSelect(ticket))
          return(false);

       MqlTradeRequest request={};
       MqlTradeResult  result={};
       request.action=TRADE_ACTION_MODIFY;
       request.order=ticket;
       request.symbol=OrderGetString(ORDER_SYMBOL);
       request.magic=(ulong)OrderGetInteger(ORDER_MAGIC);
       request.price=new_price;
       request.sl=0.0;
       request.tp=0.0;
       request.type_time=ORDER_TIME_GTC;
       request.expiration=0;

       return(CheckOrderSendResult(OrderSend(request,result),result,"ModifyPendingPrice"));
      }

    void CloseEaOrders(const int direction,const bool use_pairs,const bool arm_cooldown)
      {
       if(use_pairs && direction == 0)
          CloseOppositePairs();

       for(int i=PositionsTotal()-1; i>=0; --i)
         {
          const ulong ticket=PositionGetTicket(i);
          if(ticket == 0 || !PositionSelectByTicket(ticket))
             continue;
          if(PositionGetString(POSITION_SYMBOL) != _Symbol)
             continue;
          if((long)PositionGetInteger(POSITION_MAGIC) != Magic)
             continue;

          const ENUM_POSITION_TYPE type=(ENUM_POSITION_TYPE)PositionGetInteger(POSITION_TYPE);
          if(direction == 1 && type != POSITION_TYPE_BUY)
             continue;
          if(direction == -1 && type != POSITION_TYPE_SELL)
             continue;
          ClosePositionTicket(ticket);
         }

       for(int i=OrdersTotal()-1; i>=0; --i)
         {
          const ulong ticket=OrderGetTicket(i);
          if(ticket == 0 || !OrderSelect(ticket))
             continue;
          if(OrderGetString(ORDER_SYMBOL) != _Symbol)
             continue;
          if((long)OrderGetInteger(ORDER_MAGIC) != Magic)
             continue;

          const ENUM_ORDER_TYPE type=(ENUM_ORDER_TYPE)OrderGetInteger(ORDER_TYPE);
          if(direction == 1 && type != ORDER_TYPE_BUY_STOP)
             continue;
          if(direction == -1 && type != ORDER_TYPE_SELL_STOP)
             continue;
          if(direction == 0 && type != ORDER_TYPE_BUY_STOP && type != ORDER_TYPE_SELL_STOP)
             continue;
          DeletePendingOrder(ticket);
         }

       if(arm_cooldown && NextTime > 0)
          g_pause_until=TimeCurrent() + NextTime;
      }

    void ClosePositionsByProfitState(const bool close_profit)
      {
       for(int i=PositionsTotal()-1; i>=0; --i)
         {
          const ulong ticket=PositionGetTicket(i);
          if(ticket == 0 || !PositionSelectByTicket(ticket))
             continue;
          if((long)PositionGetInteger(POSITION_MAGIC) != Magic)
             continue;

          const double profit=PositionGetDouble(POSITION_PROFIT) + PositionGetDouble(POSITION_SWAP);
          if(close_profit && profit >= 0.0)
             ClosePositionTicket(ticket);
          if(!close_profit && profit < 0.0)
             ClosePositionTicket(ticket);
         }
      }

    void CloseCurrentSymbolPositions()
      {
       for(int i=PositionsTotal()-1; i>=0; --i)
         {
          const ulong ticket=PositionGetTicket(i);
          if(ticket == 0 || !PositionSelectByTicket(ticket))
             continue;
          if(PositionGetString(POSITION_SYMBOL) != _Symbol)
             continue;
          ClosePositionTicket(ticket);
         }
      }

    void CloseAllAccountPositions()
      {
       for(int i=PositionsTotal()-1; i>=0; --i)
         {
          const ulong ticket=PositionGetTicket(i);
          if(ticket == 0 || !PositionSelectByTicket(ticket))
             continue;
          ClosePositionTicket(ticket);
         }
      }

    bool IsTradingEnvironmentOk(const EAStats &stats,string &reason)
      {
       reason="";

       if(!IsHedgingAccount())
         {
          reason="MT5净额账户不支持该EA,请切换到对冲账户";
          return(false);
         }

       if((int)AccountInfoInteger(ACCOUNT_LEVERAGE) < Leverage)
         {
          reason="杠杆低于限制";
          return(false);
         }

       if(!TerminalInfoInteger(TERMINAL_TRADE_ALLOWED) || !MQLInfoInteger(MQL_TRADE_ALLOWED))
         {
          reason="终端未启用交易";
          return(false);
         }

       long trade_mode=SYMBOL_TRADE_MODE_DISABLED;
       if(!SymbolInfoInteger(_Symbol,SYMBOL_TRADE_MODE,trade_mode))
         {
          reason="无法读取品种交易状态";
          return(false);
         }

       if(trade_mode == SYMBOL_TRADE_MODE_DISABLED || trade_mode == SYMBOL_TRADE_MODE_CLOSEONLY)
         {
          reason="当前品种禁止开新单";
          return(false);
         }

       if(IsStopped())
         {
          reason="EA已停止";
          return(false);
         }

       if(stats.buy_positions + stats.sell_positions >= Totals)
         {
          reason="达到最大持仓数";
          return(false);
         }

       if(CurrentSpreadPoints() > MaxSpread)
         {
          reason="点差超限";
          return(false);
         }

       return(true);
      }

    void UpdateLimitLines()
      {
       const datetime now_value=ReferenceNow();
       const bool limit_window_active=IsInWindow(Limit_StartTime,Limit_StopTime,now_value);
       const string buy_line=g_panel_prefix + "limit_buy_add";
       const string sell_line=g_panel_prefix + "limit_sell_add";

       if(limit_window_active && On_top_of_this_price_not_Buy_order > 0.0)
         {
          if(ObjectFind(0,buy_line) < 0)
             ObjectCreate(0,buy_line,OBJ_HLINE,0,0,On_top_of_this_price_not_Buy_order);
          ObjectSetDouble(0,buy_line,OBJPROP_PRICE,On_top_of_this_price_not_Buy_order);
          ObjectSetInteger(0,buy_line,OBJPROP_COLOR,clr1);
          ObjectSetInteger(0,buy_line,OBJPROP_STYLE,STYLE_DASH);
         }
       else if(ObjectFind(0,buy_line) >= 0)
          ObjectDelete(0,buy_line);

       if(limit_window_active && On_under_of_this_price_not_Sell_order > 0.0)
         {
          if(ObjectFind(0,sell_line) < 0)
             ObjectCreate(0,sell_line,OBJ_HLINE,0,0,On_under_of_this_price_not_Sell_order);
          ObjectSetDouble(0,sell_line,OBJPROP_PRICE,On_under_of_this_price_not_Sell_order);
          ObjectSetInteger(0,sell_line,OBJPROP_COLOR,clr2);
          ObjectSetInteger(0,sell_line,OBJPROP_STYLE,STYLE_DASH);
         }
       else if(ObjectFind(0,sell_line) >= 0)
          ObjectDelete(0,sell_line);
      }

    void UpdateAverageLines(const EAStats &stats)
      {
       const string buy_line=g_panel_prefix + "avg_buy";
       const string sell_line=g_panel_prefix + "avg_sell";

       if(stats.buy_positions > 0 && stats.buy_avg_price > 0.0)
         {
          if(ObjectFind(0,buy_line) < 0)
             ObjectCreate(0,buy_line,OBJ_HLINE,0,0,stats.buy_avg_price);
          ObjectSetDouble(0,buy_line,OBJPROP_PRICE,stats.buy_avg_price);
          ObjectSetInteger(0,buy_line,OBJPROP_COLOR,clr1);
          ObjectSetInteger(0,buy_line,OBJPROP_WIDTH,2);
         }
       else if(ObjectFind(0,buy_line) >= 0)
          ObjectDelete(0,buy_line);

       if(stats.sell_positions > 0 && stats.sell_avg_price > 0.0)
         {
          if(ObjectFind(0,sell_line) < 0)
             ObjectCreate(0,sell_line,OBJ_HLINE,0,0,stats.sell_avg_price);
          ObjectSetDouble(0,sell_line,OBJPROP_PRICE,stats.sell_avg_price);
          ObjectSetInteger(0,sell_line,OBJPROP_COLOR,clr2);
          ObjectSetInteger(0,sell_line,OBJPROP_WIDTH,2);
         }
       else if(ObjectFind(0,sell_line) >= 0)
          ObjectDelete(0,sell_line);
      }

    bool ShouldUsePrimaryParameters(const EAStats &stats)
      {
       if(Money == 0.0)
          return(true);
       return(stats.total_profit > g_second_loss_threshold);
      }

    bool AllowBuyOrderByPriceLimit(const EAStats &stats,const double target_price,const bool limit_window_active)
      {
       if(stats.buy_positions == 0)
          return(true);
       if(!limit_window_active)
          return(true);
       if(On_top_of_this_price_not_Buy_order == 0.0)
          return(true);
       return(target_price < On_top_of_this_price_not_Buy_order);
      }

    bool AllowSellOrderByPriceLimit(const EAStats &stats,const double target_price,const bool limit_window_active)
      {
       if(stats.sell_positions == 0)
          return(true);
       if(!limit_window_active)
          return(true);
       if(On_under_of_this_price_not_Sell_order == 0.0)
          return(true);
       return(target_price > On_under_of_this_price_not_Sell_order);
      }

    bool CanOpenThisCycle(const bool is_buy,const EAStats &stats)
      {
       if(OpenMode == OpenMode_NoDelay || OpenMode == OpenMode_Bar)
          return(true);
       const datetime last_open=is_buy ? stats.last_buy_open_time : stats.last_sell_open_time;
       return((TimeCurrent() - last_open) >= sleep);
      }

    bool TryProtectiveCloseBySide(const EAStats &stats)
      {
       const int buy_ss_count=CountPositionsWithComment(GOLDKING_ORDER_COMMENT_SECONDARY,POSITION_TYPE_BUY);
       const int sell_ss_count=CountPositionsWithComment(GOLDKING_ORDER_COMMENT_SECONDARY,POSITION_TYPE_SELL);

       if((buy_ss_count < 1 || !HomeopathyCloseAll) &&
          stats.buy_profit > g_max_loss_close_all &&
          stats.sell_profit > g_max_loss_close_all)
         {
          const double buy_target=Profit ? StopProfit * stats.buy_positions : StopProfit;
          const double sell_target=Profit ? StopProfit * stats.sell_positions : StopProfit;

          if(stats.buy_positions > 0 && stats.buy_profit > buy_target)
            {
             CloseEaOrders(1,false,false);
             return(true);
            }

          if(stats.sell_positions > 0 && stats.sell_profit > sell_target)
            {
             CloseEaOrders(-1,false,false);
             return(true);
            }
         }

       if(HomeopathyCloseAll && (buy_ss_count > 0 || sell_ss_count > 0) && stats.total_profit >= CloseAll)
         {
          CloseEaOrders(0,true,true);
          return(true);
         }

       if(stats.total_profit >= CloseAll &&
          (stats.buy_profit <= g_max_loss_close_all || stats.sell_profit <= g_max_loss_close_all))
         {
          CloseEaOrders(0,true,true);
          return(true);
         }
       return(false);
      }

    bool ApplyCloseBuySellProtection(const EAStats &stats)
      {
       if(!CloseBuySell)
          return(false);

       const double buy_delta=SumExtremePositionProfits(POSITION_TYPE_BUY,true,1) - SumExtremePositionProfits(POSITION_TYPE_BUY,false,2);
       if(g_buy_protection_peak < buy_delta)
          g_buy_protection_peak=buy_delta;
       if(g_buy_protection_peak > 0.0 && buy_delta > 0.0)
         {
          const double biggest_win_lot=FindExtremePositionLot(POSITION_TYPE_BUY,true);
          if(stats.buy_lots > biggest_win_lot * 3.0 + stats.sell_lots && stats.buy_positions > 3)
            {
             CloseExtremePositions(POSITION_TYPE_BUY,1,true);
             CloseExtremePositions(POSITION_TYPE_BUY,2,false);
             g_buy_protection_peak=0.0;
             g_sell_protection_peak=0.0;
             return(true);
            }
         }

       const double sell_delta=SumExtremePositionProfits(POSITION_TYPE_SELL,true,1) - SumExtremePositionProfits(POSITION_TYPE_SELL,false,2);
       if(g_sell_protection_peak < sell_delta)
          g_sell_protection_peak=sell_delta;
       if(g_sell_protection_peak > 0.0 && sell_delta > 0.0)
         {
          const double biggest_win_lot=FindExtremePositionLot(POSITION_TYPE_SELL,true);
          if(stats.sell_lots > biggest_win_lot * 3.0 + stats.buy_lots && stats.sell_positions > 3)
            {
             CloseExtremePositions(POSITION_TYPE_SELL,1,true);
             CloseExtremePositions(POSITION_TYPE_SELL,2,false);
             g_buy_protection_peak=0.0;
             g_sell_protection_peak=0.0;
             return(true);
            }
         }
       return(false);
      }

    bool TryAutoCloseLogic(const EAStats &stats)
      {
       if(Over && stats.total_profit >= CloseAll)
         {
          CloseEaOrders(0,true,true);
          return(true);
         }

       if(!Over)
         {
          if(TryProtectiveCloseBySide(stats))
             return(true);
         }

       if(StopLoss != 0.0 && stats.total_profit <= g_stop_loss_limit)
         {
          CloseEaOrders(0,false,true);
          return(true);
         }

       return(ApplyCloseBuySellProtection(stats));
      }

    void TryPlacePendingOrders(const EAStats &stats,const bool allow_buy,const bool allow_sell)
      {
       const int min_distance=BrokerMinDistancePoints();
       const int first_step=MathMax(FirstStep,min_distance);
       const int buy_min_distance=MathMax(MinDistance,min_distance);
       const int sell_min_distance=MathMax(MinDistance,min_distance);
       const int buy_two_min_distance=MathMax(TwoMinDistance,min_distance);
       const int sell_two_min_distance=MathMax(TwoMinDistance,min_distance);
       const int buy_step=MathMax(Step,min_distance);
       const int sell_step=MathMax(Step,min_distance);
       const int buy_two_step=MathMax(TwoStep,min_distance);
       const int sell_two_step=MathMax(TwoStep,min_distance);
       const bool primary_params=ShouldUsePrimaryParameters(stats);
       const bool limit_window_active=IsInWindow(Limit_StartTime,Limit_StopTime,ReferenceNow());
       const bool lots_equal=(MathAbs(stats.buy_lots - stats.sell_lots) < 0.0000001);
       const bool buy_rebalance=(stats.buy_lots > 0.0 && stats.sell_lots / stats.buy_lots > 3.0 && stats.sell_lots - stats.buy_lots > 0.2);
       const bool sell_rebalance=(stats.sell_lots > 0.0 && stats.buy_lots / stats.sell_lots > 3.0 && stats.buy_lots - stats.sell_lots > 0.2);
       const double ask_price=SymbolInfoDouble(_Symbol,SYMBOL_ASK);
       const double bid_price=SymbolInfoDouble(_Symbol,SYMBOL_BID);

       bool can_process_cycle=true;
       datetime current_bar=0;
       if(OpenMode == OpenMode_Bar)
         {
          current_bar=iTime(_Symbol,TimeZone,0);
          can_process_cycle=(current_bar != 0 && current_bar != g_last_open_bar_time);
         }
       if(!can_process_cycle)
          return;

       if(allow_buy && stats.buy_pending == 0 && stats.buy_profit > g_max_loss_limit)
         {
          double target_price=0.0;
          if(stats.buy_positions == 0)
             target_price=NormalizePriceToSymbol(ask_price + first_step * _Point);
          else
            {
             target_price=NormalizePriceToSymbol(ask_price + (primary_params ? buy_min_distance : buy_two_min_distance) * _Point);
             if(stats.buy_lowest_position != 0.0 && target_price < NormalizePriceToSymbol(stats.buy_lowest_position - (primary_params ? buy_step : buy_two_step) * _Point))
                target_price=NormalizePriceToSymbol(ask_price + (primary_params ? buy_step : buy_two_step) * _Point);
            }

          const bool buy_condition=
             (stats.buy_positions == 0) ||
             (stats.buy_highest_any != 0.0 && target_price >= NormalizePriceToSymbol(stats.buy_highest_any + buy_step * _Point) && buy_rebalance && primary_params) ||
             (stats.buy_highest_any != 0.0 && target_price >= NormalizePriceToSymbol(stats.buy_highest_any + buy_two_step * _Point) && buy_rebalance && !primary_params && Money != 0.0) ||
             (stats.buy_lowest_position != 0.0 && target_price <= NormalizePriceToSymbol(stats.buy_lowest_position - buy_step * _Point) && primary_params) ||
             (stats.buy_lowest_position != 0.0 && target_price <= NormalizePriceToSymbol(stats.buy_lowest_position - buy_two_step * _Point) && !primary_params && Money != 0.0) ||
             (Homeopathy && stats.buy_highest_any != 0.0 && target_price >= NormalizePriceToSymbol(stats.buy_highest_any + buy_step * _Point) && lots_equal);

          if(buy_condition && AllowBuyOrderByPriceLimit(stats,target_price,limit_window_active) && CanOpenThisCycle(true,stats))
            {
             double volume=(stats.buy_positions == 0) ? lot : (stats.buy_positions * PlusLot + lot * MathPow(K_Lot,stats.buy_positions));
             volume=NormalizeVolumeToSymbol(volume);
             const bool use_secondary_comment=
                ((stats.buy_highest_any != 0.0 && target_price >= NormalizePriceToSymbol(stats.buy_highest_any + buy_step * _Point) && buy_rebalance && primary_params) ||
                 (stats.buy_highest_any != 0.0 && target_price >= NormalizePriceToSymbol(stats.buy_highest_any + buy_two_step * _Point) && buy_rebalance && !primary_params && Money != 0.0) ||
                 (Homeopathy && stats.buy_highest_any != 0.0 && target_price >= NormalizePriceToSymbol(stats.buy_highest_any + buy_step * _Point) && lots_equal));

             CheckTradeResult(g_trade.BuyStop(volume,target_price,_Symbol,0.0,0.0,ORDER_TIME_GTC,0,use_secondary_comment ? GOLDKING_ORDER_COMMENT_SECONDARY : GOLDKING_ORDER_COMMENT_PRIMARY),"BuyStop");
            }
         }

       if(allow_sell && stats.sell_pending == 0 && stats.sell_profit > g_max_loss_limit)
         {
          double target_price=0.0;
          if(stats.sell_positions == 0)
             target_price=NormalizePriceToSymbol(bid_price - first_step * _Point);
          else
            {
             target_price=NormalizePriceToSymbol(bid_price - (primary_params ? sell_min_distance : sell_two_min_distance) * _Point);
             if(stats.sell_highest_position != 0.0 && target_price < NormalizePriceToSymbol(stats.sell_highest_position + (primary_params ? sell_step : sell_two_step) * _Point))
                target_price=NormalizePriceToSymbol(bid_price - (primary_params ? sell_step : sell_two_step) * _Point);
            }

          const bool sell_condition=
             (stats.sell_positions == 0) ||
             (stats.sell_lowest_any != 0.0 && target_price <= NormalizePriceToSymbol(stats.sell_lowest_any - sell_step * _Point) && sell_rebalance && primary_params) ||
             (stats.sell_lowest_any != 0.0 && target_price <= NormalizePriceToSymbol(stats.sell_lowest_any - sell_two_step * _Point) && sell_rebalance && !primary_params && Money != 0.0) ||
             (stats.sell_highest_position != 0.0 && target_price >= NormalizePriceToSymbol(stats.sell_highest_position + sell_step * _Point) && primary_params) ||
             (stats.sell_highest_position != 0.0 && target_price >= NormalizePriceToSymbol(stats.sell_highest_position + sell_two_step * _Point) && !primary_params && Money != 0.0) ||
             (Homeopathy && stats.sell_lowest_any != 0.0 && target_price <= NormalizePriceToSymbol(stats.sell_lowest_any - sell_step * _Point) && lots_equal);

          if(sell_condition && AllowSellOrderByPriceLimit(stats,target_price,limit_window_active) && CanOpenThisCycle(false,stats))
            {
             double volume=(stats.sell_positions == 0) ? lot : (stats.sell_positions * PlusLot + lot * MathPow(K_Lot,stats.sell_positions));
             volume=NormalizeVolumeToSymbol(volume);
             const bool use_secondary_comment=
                ((stats.sell_lowest_any != 0.0 && target_price <= NormalizePriceToSymbol(stats.sell_lowest_any - sell_step * _Point) && sell_rebalance && primary_params) ||
                 (stats.sell_lowest_any != 0.0 && target_price <= NormalizePriceToSymbol(stats.sell_lowest_any - sell_two_step * _Point) && sell_rebalance && !primary_params && Money != 0.0) ||
                 (Homeopathy && stats.sell_lowest_any != 0.0 && target_price <= NormalizePriceToSymbol(stats.sell_lowest_any - sell_step * _Point) && lots_equal));

             CheckTradeResult(g_trade.SellStop(volume,target_price,_Symbol,0.0,0.0,ORDER_TIME_GTC,0,use_secondary_comment ? GOLDKING_ORDER_COMMENT_SECONDARY : GOLDKING_ORDER_COMMENT_PRIMARY),"SellStop");
            }
         }

       if(OpenMode == OpenMode_Bar && current_bar != 0)
          g_last_open_bar_time=current_bar;
      }

    void TryTrailPendingOrders(const EAStats &stats,const bool allow_buy,const bool allow_sell)
      {
       const int min_distance=BrokerMinDistancePoints();
       const int first_step=MathMax(FirstStep,min_distance);
       const int primary_min=MathMax(MinDistance,min_distance);
       const int second_min=MathMax(TwoMinDistance,min_distance);
       const int primary_step=MathMax(Step,min_distance);
       const int second_step=MathMax(TwoStep,min_distance);
       const bool primary_params=ShouldUsePrimaryParameters(stats);
       const bool buy_rebalance=(stats.buy_lots > 0.0 && stats.sell_lots / stats.buy_lots > 3.0 && stats.sell_lots - stats.buy_lots > 0.2);
       const bool sell_rebalance=(stats.sell_lots > 0.0 && stats.buy_lots / stats.sell_lots > 3.0 && stats.buy_lots - stats.sell_lots > 0.2);
       const double ask_price=SymbolInfoDouble(_Symbol,SYMBOL_ASK);
       const double bid_price=SymbolInfoDouble(_Symbol,SYMBOL_BID);

       if(allow_buy && stats.buy_pending_ticket > 0)
         {
          double target_price=(stats.buy_positions == 0) ? NormalizePriceToSymbol(ask_price + first_step * _Point)
                                                         : NormalizePriceToSymbol(ask_price + (primary_params ? primary_min : second_min) * _Point);
          if(stats.buy_positions > 0 && stats.buy_lowest_position != 0.0 && target_price < NormalizePriceToSymbol(stats.buy_lowest_position - (primary_params ? primary_step : second_step) * _Point))
             target_price=NormalizePriceToSymbol(ask_price + (primary_params ? primary_step : second_step) * _Point);

          const bool trail_ok=
             primary_params ?
             (target_price <= NormalizePriceToSymbol(stats.buy_lowest_position - primary_step * _Point) || stats.buy_lowest_position == 0.0 || (buy_rebalance && stats.buy_positions == 0) || target_price >= NormalizePriceToSymbol(stats.buy_highest_any + primary_step * _Point))
             :
             (target_price <= NormalizePriceToSymbol(stats.buy_lowest_position - second_step * _Point) || stats.buy_lowest_position == 0.0 || (buy_rebalance && stats.buy_positions == 0) || target_price >= NormalizePriceToSymbol(stats.buy_highest_any + second_step * _Point));

          if(stats.buy_pending_price != 0.0 && NormalizePriceToSymbol(stats.buy_pending_price - StepTrallOrders * _Point) > target_price && trail_ok)
             ModifyPendingPrice(stats.buy_pending_ticket,target_price);
         }

       if(allow_sell && stats.sell_pending_ticket > 0)
         {
          double target_price=(stats.sell_positions == 0) ? NormalizePriceToSymbol(bid_price - first_step * _Point)
                                                          : NormalizePriceToSymbol(bid_price - (primary_params ? primary_min : second_min) * _Point);
          if(stats.sell_positions > 0 && stats.sell_highest_position != 0.0 && target_price < NormalizePriceToSymbol(stats.sell_highest_position + (primary_params ? primary_step : second_step) * _Point))
             target_price=NormalizePriceToSymbol(bid_price - (primary_params ? primary_step : second_step) * _Point);

          const bool trail_ok=
             primary_params ?
             (target_price >= NormalizePriceToSymbol(stats.sell_highest_position + primary_step * _Point) || stats.sell_highest_position == 0.0 || (sell_rebalance && stats.sell_positions == 0) || target_price <= NormalizePriceToSymbol(stats.sell_lowest_any - primary_step * _Point))
             :
             (target_price >= NormalizePriceToSymbol(stats.sell_highest_position + second_step * _Point) || stats.sell_highest_position == 0.0 || (sell_rebalance && stats.sell_positions == 0) || target_price <= NormalizePriceToSymbol(stats.sell_lowest_any - second_step * _Point));

          if(stats.sell_pending_price != 0.0 && NormalizePriceToSymbol(stats.sell_pending_price + StepTrallOrders * _Point) < target_price && trail_ok)
             ModifyPendingPrice(stats.sell_pending_ticket,target_price);
         }
      }

    void ExecuteStrategy()
      {
       EAStats stats;
       CollectStats(stats);
       const datetime now_value=ReferenceNow();
       const datetime news_now=ReferenceNewsNow();
       RefreshDailyLocks(now_value,stats);
       RefreshNewsState(false);

       const bool session_after_stop=IsTradingSessionAfterStop(now_value);
       const bool session_ok=IsTradingSessionOpen(now_value);
       const bool wrap_up_blocked=IsDailyWrapUpWindow(news_now);
       const bool target_locked=g_daily_target_locked;
       const bool news_blocked=g_news_state.block_entries;

       if((session_after_stop || wrap_up_blocked || target_locked || news_blocked) && (stats.buy_pending > 0 || stats.sell_pending > 0))
         {
          DeleteEaPendingOrders();
          CollectStats(stats);
          RefreshDailyLocks(now_value,stats);
          RefreshNewsState(false);
         }

       UpdateLimitLines();
       UpdateAverageLines(stats);

       string env_reason="";
       const bool env_ok=IsTradingEnvironmentOk(stats,env_reason);

       bool allow_buy=g_allow_buy;
       bool allow_sell=g_allow_sell;

       if(Over && stats.buy_positions == 0)
          allow_buy=false;
       if(Over && stats.sell_positions == 0)
          allow_sell=false;

       if(g_pause_until > TimeCurrent())
         {
          allow_buy=false;
          allow_sell=false;
         }

       if(!session_ok || session_after_stop || wrap_up_blocked || target_locked || news_blocked)
         {
          allow_buy=false;
          allow_sell=false;
         }

       if(!env_ok)
         {
          allow_buy=false;
          allow_sell=false;
         }

       if(TryAutoCloseLogic(stats))
         {
          RefreshPanel(true);
          return;
         }

       if(OpenMode == OpenMode_Bar && !(allow_buy || allow_sell))
         {
          const datetime current_bar=iTime(_Symbol,TimeZone,0);
          if(current_bar != 0 && current_bar != g_last_open_bar_time)
             g_last_open_bar_time=current_bar;
         }

       if(allow_buy || allow_sell)
          TryPlacePendingOrders(stats,allow_buy,allow_sell);

       if(allow_buy || allow_sell)
          TryTrailPendingOrders(stats,allow_buy,allow_sell);

       RefreshPanel(false);
      }

    double UiScale()
      {
       const long chart_width=ChartGetInteger(0,CHART_WIDTH_IN_PIXELS,0);
       const long dpi=TerminalInfoInteger(TERMINAL_SCREEN_DPI);
       double scale=1.0;

       if(dpi >= 192)
          scale=1.08;
       else if(dpi >= 160)
          scale=1.04;
       else if(dpi <= 96)
          scale=0.98;

       if(chart_width <= 1280)
          scale=MathMin(scale,0.94);
       else if(chart_width >= 2400)
          scale=MathMin(MathMax(scale,1.0),1.08);

       return(MathMax(0.90,MathMin(scale,1.10)));
      }

    double UiFontScale()
      {
       const long chart_width=ChartGetInteger(0,CHART_WIDTH_IN_PIXELS,0);
       const long dpi=TerminalInfoInteger(TERMINAL_SCREEN_DPI);
       double scale=1.0;

       if(dpi >= 192)
          scale=1.05;
       else if(dpi >= 160)
          scale=1.02;
       else if(dpi <= 96)
          scale=0.97;

       if(chart_width <= 1280)
          scale=MathMin(scale,0.96);

       return(MathMax(0.92,MathMin(scale,1.06)));
      }

    int ScalePx(const int value)
      {
       return((int)MathRound(value * UiScale()));
      }

    int ScaleFont(const int value)
      {
       return((int)MathRound(value * UiFontScale()));
      }

    void BuildPanelMetrics(PanelMetrics &m)
      {
       const long chart_width=ChartGetInteger(0,CHART_WIDTH_IN_PIXELS,0);
       const int available_w=(int)MathMax(300.0,(double)chart_width - ScalePx(36));

       m.margin_x       = ScalePx(16);
       m.margin_y       = ScalePx(18);
       m.width          = (int)MathMax(300.0,MathMin((double)ScalePx(440),(double)available_w));
       m.pad            = ScalePx(14);
       m.section_gap    = ScalePx(10);
       m.header_h       = ScalePx(56);
       m.row_h          = ScalePx(18);
       m.gap            = ScalePx(8);
       m.button_h       = ScalePx(30);
       m.inner_w        = m.width - m.pad * 2;
       m.half_w         = (m.inner_w - m.gap) / 2;
       m.card_status_h  = g_panel_open ? ScalePx(184) : ScalePx(172);
       m.card_metrics_h = g_panel_open ? ScalePx(236) : ScalePx(164);
       m.card_actions_h = g_panel_open ? (m.pad * 2 + ScalePx(22) + m.gap + m.button_h * 6 + m.gap * 5) : (m.pad * 2 + ScalePx(22) + m.gap + m.button_h);
       m.button_font    = ScaleFont(9);
       m.font_xs        = ScaleFont(9);
       m.font_sm        = ScaleFont(10);
       m.font_md        = ScaleFont(11);
       m.font_lg        = ScaleFont(15);
       m.toggle_w       = (m.width <= ScalePx(340)) ? ScalePx(56) : ScalePx(64);
       m.panel_h        = m.header_h + m.section_gap + m.card_status_h + m.section_gap + m.card_metrics_h + m.section_gap + m.card_actions_h;
      }

    void EnsureRectangle(const string name,const int x,const int y,const int w,const int h,const color bg,const color border,const int corner)
      {
       if(ObjectFind(0,name) < 0)
          ObjectCreate(0,name,OBJ_RECTANGLE_LABEL,0,0,0);
       ObjectSetInteger(0,name,OBJPROP_CORNER,corner);
       ObjectSetInteger(0,name,OBJPROP_XDISTANCE,x);
       ObjectSetInteger(0,name,OBJPROP_YDISTANCE,y);
       ObjectSetInteger(0,name,OBJPROP_XSIZE,w);
       ObjectSetInteger(0,name,OBJPROP_YSIZE,h);
       ObjectSetInteger(0,name,OBJPROP_BGCOLOR,bg);
       ObjectSetInteger(0,name,OBJPROP_COLOR,border);
       ObjectSetInteger(0,name,OBJPROP_BORDER_TYPE,BORDER_FLAT);
       ObjectSetInteger(0,name,OBJPROP_SELECTABLE,false);
       ObjectSetInteger(0,name,OBJPROP_SELECTED,false);
       ObjectSetInteger(0,name,OBJPROP_HIDDEN,true);
       ObjectSetInteger(0,name,OBJPROP_BACK,false);
      }

    void EnsureLabel(const string name,const string text,const int x,const int y,const int font_size,const color clr,const int corner,const string font="Microsoft YaHei")
      {
       if(ObjectFind(0,name) < 0)
          ObjectCreate(0,name,OBJ_LABEL,0,0,0);
       ObjectSetInteger(0,name,OBJPROP_CORNER,corner);
       ObjectSetInteger(0,name,OBJPROP_XDISTANCE,x);
       ObjectSetInteger(0,name,OBJPROP_YDISTANCE,y);
       ObjectSetInteger(0,name,OBJPROP_COLOR,clr);
       ObjectSetInteger(0,name,OBJPROP_FONTSIZE,font_size);
       ObjectSetString(0,name,OBJPROP_FONT,font);
       ObjectSetString(0,name,OBJPROP_TEXT,text);
       ObjectSetInteger(0,name,OBJPROP_SELECTABLE,false);
       ObjectSetInteger(0,name,OBJPROP_SELECTED,false);
       ObjectSetInteger(0,name,OBJPROP_HIDDEN,true);
       ObjectSetInteger(0,name,OBJPROP_BACK,false);
      }

    void EnsureButton(const string name,const string text,const int x,const int y,const int w,const int h,const color bg,const color fg,const int corner)
      {
       if(ObjectFind(0,name) < 0)
          ObjectCreate(0,name,OBJ_BUTTON,0,0,0);
       ObjectSetInteger(0,name,OBJPROP_CORNER,corner);
       ObjectSetInteger(0,name,OBJPROP_XDISTANCE,x);
       ObjectSetInteger(0,name,OBJPROP_YDISTANCE,y);
       ObjectSetInteger(0,name,OBJPROP_XSIZE,w);
       ObjectSetInteger(0,name,OBJPROP_YSIZE,h);
       ObjectSetInteger(0,name,OBJPROP_COLOR,fg);
       ObjectSetInteger(0,name,OBJPROP_BGCOLOR,bg);
       ObjectSetInteger(0,name,OBJPROP_BORDER_COLOR,bg);
       ObjectSetInteger(0,name,OBJPROP_FONTSIZE,ScaleFont(9));
       ObjectSetString(0,name,OBJPROP_FONT,"Microsoft YaHei");
       ObjectSetString(0,name,OBJPROP_TEXT,text);
       ObjectSetInteger(0,name,OBJPROP_SELECTABLE,false);
       ObjectSetInteger(0,name,OBJPROP_SELECTED,false);
       ObjectSetInteger(0,name,OBJPROP_HIDDEN,true);
       ObjectSetInteger(0,name,OBJPROP_BACK,false);
      }

    string BoolText(const bool enabled,const string on_text,const string off_text)
      {
       return(enabled ? on_text : off_text);
      }

    string FormatSignedMoney(const double value)
      {
       const string sign=(value > 0.0) ? "+" : "";
       return(sign + DoubleToString(value,2));
      }

    string FormatPercent(const double value)
      {
       return(DoubleToString(value,2) + "%");
      }

    string FormatPanelMoment(const datetime when,const datetime now_value)
      {
       if(when <= 0)
          return("--");

       MqlDateTime stamp={};
       MqlDateTime now_stamp={};
       TimeToStruct(when,stamp);
       TimeToStruct(now_value,now_stamp);

       if(stamp.year == now_stamp.year && stamp.mon == now_stamp.mon && stamp.day == now_stamp.day)
          return(StringFormat("%02d:%02d",stamp.hour,stamp.min));

       return(StringFormat("%02d-%02d %02d:%02d",stamp.mon,stamp.day,stamp.hour,stamp.min));
      }

    string NewsPauseReason(const EAStats &stats)
      {
       if(!g_news_state.block_entries)
          return("");

       const string resume_text=FormatPanelMoment(g_news_state.resume_time,g_news_state.server_now);
       if(g_news_state.in_pre_window)
          return(HasOpenPositions(stats) ? "高影响新闻前3小时,等待全部平仓" : "高影响新闻前3小时,暂停至 服" + resume_text);

       return(HasOpenPositions(stats) ? "高影响新闻后3小时,等待全部平仓" : "高影响新闻后3小时,暂停至 服" + resume_text);
      }

    string WrapUpPauseReason(const EAStats &stats)
      {
       if(!IsDailyWrapUpWindow(g_news_state.server_now))
          return("");

       return(HasOpenPositions(stats) ? "日内收尾阶段,等待全部平仓"
                                      : "日内收尾阶段,今日停止交易");
      }

    string SessionStateText(const datetime now_value,const EAStats &stats)
      {
       if(!EnableTradingSessionWindow)
          return("已关闭");

       if(IsTradingSessionAfterStop(now_value))
          return(HasOpenPositions(stats) ? "结束时间已到,等待平仓" : "今日已收工");

       if(!IsTradingSessionOpen(now_value))
          return("未到工作时间");

       return("工作时段内");
      }

    string WrapUpStateText(const EAStats &stats)
      {
       if(!EnableDailyWrapUpPhase)
          return("已关闭");

       const string slot=DailyWrapUpStartTime + "-" + DailyWrapUpStopTime;
       if(!IsDailyWrapUpWindow(g_news_state.server_now))
          return("服" + slot + " 未触发");

       return(HasOpenPositions(stats) ? "服" + slot + " 等待平仓" : "服" + slot + " 已收尾");
      }

    string GoalStateText(const double target_progress_display)
      {
       if(!EnableDailyProfitTarget)
          return("已关闭");

       if(DailyProfitTarget <= 0.0)
          return("金额<=0");

       if(g_daily_target_locked)
          return("已达 " + FormatSignedMoney(MathMax(target_progress_display,g_daily_target_hit_value)) + " / +" + DoubleToString(DailyProfitTarget,2));

       return("进度 " + FormatSignedMoney(target_progress_display) + " / +" + DoubleToString(DailyProfitTarget,2));
      }

    string NewsStateText(const EAStats &stats)
      {
       const string source_prefix=(g_news_state.using_embedded_history ? "回测内置" : "实时日历");

       if(!EnableHighImpactNewsPause)
          return("已关闭");

       if(!g_news_state.calendar_available)
          return(source_prefix + " | " + (g_news_state.error_text == "" ? "新闻源不可用,已忽略" : g_news_state.error_text));

       const string event_time="服" + FormatPanelMoment(g_news_state.event_time,g_news_state.server_now);
       const string event_prefix=(g_news_state.currency == "" ? "" : g_news_state.currency + " ");
       const string event_suffix=(g_news_state.event_name == "" ? "" : " " + g_news_state.event_name);

       if(g_news_state.block_entries)
         {
          if(g_news_state.in_pre_window)
             return(source_prefix + " | " + (HasOpenPositions(stats) ? "前3h等待平仓" : "前3h暂停") + " | " + event_prefix + event_time + event_suffix);

          return(source_prefix + " | " + (HasOpenPositions(stats) ? "后3h等待平仓" : "后3h冷静期") + " | " + event_prefix + event_time + event_suffix);
         }

       if(g_news_state.has_upcoming_event)
          return(source_prefix + " | 下个高影响 | " + event_prefix + event_time + event_suffix);

       if(g_news_state.using_embedded_history)
         {
          if(g_news_state.server_now < GOLDKING_BACKTEST_USD_HIGH_NEWS_RANGE_START || g_news_state.server_now > GOLDKING_BACKTEST_USD_HIGH_NEWS_RANGE_END)
             return("回测内置 | 范围外 " + GOLDKING_BACKTEST_USD_HIGH_NEWS_RANGE_LABEL);

          return("回测内置 | 未触发");
         }

       return("未触发");
      }

    string EntryStateText(const string stop_reason)
      {
       if(g_allow_buy && g_allow_sell)
          return("允许");

       if(!g_allow_buy && !g_allow_sell)
          return("手动停止");

       if(stop_reason != "")
          return("暂停");

       return("部分允许");
      }

    string CloseReasonText()
      {
       string reason="";
       EAStats stats;
       CollectStats(stats);
       const datetime now_value=ReferenceNow();
       RefreshDailyLocks(now_value,stats);
       RefreshNewsState(false);

       if(g_daily_target_locked)
          return(HasOpenPositions(stats) ? "今日盈利达标,等待全部平仓" : "今日盈利目标已达成");

       const string news_reason=NewsPauseReason(stats);
       if(news_reason != "")
          return(news_reason);

       const string wrap_reason=WrapUpPauseReason(stats);
       if(wrap_reason != "")
          return(wrap_reason);

       if(IsTradingSessionAfterStop(now_value))
          return(HasOpenPositions(stats) ? "已到结束时间,等待全部平仓" : "今日已收工");

       if(!IsTradingSessionOpen(now_value))
          return("等待工作时段开始");

       if(!g_allow_buy && !g_allow_sell)
          return("已手动停止交易");

       if(g_pause_until > TimeCurrent())
          return("冷却中 " + IntegerToString((int)(g_pause_until - TimeCurrent())) + " 秒");

       if(!IsTradingEnvironmentOk(stats,reason))
          return(reason);

       return("");
      }

    string ClipText(const string text,const int max_chars)
      {
       if(max_chars <= 0)
          return("");
       if(StringLen(text) <= max_chars)
          return(text);
       if(max_chars <= 3)
          return(StringSubstr(text,0,max_chars));
       return(StringSubstr(text,0,max_chars - 3) + "...");
      }

    string TimeframeLabel(const ENUM_TIMEFRAMES timeframe)
      {
       const string enum_text=EnumToString(timeframe);
       if(StringFind(enum_text,"PERIOD_",0) == 0)
          return(StringSubstr(enum_text,7));
       return(enum_text);
      }

    void DrawPanel(const EAStats &stats)
      {
       PanelMetrics m;
       BuildPanelMetrics(m);
       const int corner=CORNER_LEFT_UPPER;
       const color panel_bg=C'15,20,27';
       const color panel_border=C'45,58,74';
       const color header_bg=C'20,29,40';
       const color card_bg=C'24,33,45';
       const color muted=C'150,164,181';
       const color ok_color=C'88,199,135';
       const color warn_color=C'255,183,77';
       const color bad_color=C'239,100,97';
       const color accent=C'66,153,225';
       const color accent_alt=C'34,197,154';
       const color cream=C'244,248,252';

       const int x=m.margin_x;
       const int inner_x=x + m.pad;
       const int inner_x2=inner_x + m.half_w + m.gap;
       const int right_button_x=x + m.width - m.pad - m.toggle_w;
       const int reason_chars=(int)MathMax(24.0,MathMin(42.0,(double)m.width / 10.0 - 2.0));
       const int info_chars=(int)MathMax(26.0,MathMin(48.0,(double)m.width / 8.0));
       const datetime now_value=ReferenceNow();
       RefreshDailyLocks(now_value,stats);
       RefreshNewsState(false);

       const double spread_pips=CurrentSpreadPoints() / PipDivisor();
       const double today_profit=TodayClosedProfit(now_value);
       const double today_progress=TodayProgressProfit(now_value,stats);
       const double yesterday_profit=CalculateClosedProfit(TodayAt("00:00",now_value) - 86400,TodayAt("00:00",now_value) - 1,Magic,true);
       const double total_closed=CalculateClosedProfit(0,TimeCurrent(),Magic,true);
       const double balance=AccountInfoDouble(ACCOUNT_BALANCE);
       const double equity=AccountInfoDouble(ACCOUNT_EQUITY);
       const double margin=AccountInfoDouble(ACCOUNT_MARGIN);
       const double margin_level=(margin > 0.0) ? equity / margin * 100.0 : 0.0;
       const bool target_enabled=(EnableDailyProfitTarget && DailyProfitTarget > 0.0);
       const double target_progress_display=g_daily_target_locked ? MathMax(today_progress,g_daily_target_hit_value) : today_progress;
       const double target_remaining=target_enabled ? MathMax(0.0,DailyProfitTarget - target_progress_display) : 0.0;
       const bool session_open=IsTradingSessionOpen(now_value);
       const bool session_after_stop=IsTradingSessionAfterStop(now_value);
       const bool waiting_start=(!session_open && !session_after_stop);
       const bool wrap_up_active=IsDailyWrapUpWindow(g_news_state.server_now);
       const bool wrap_up_waiting_close=wrap_up_active && HasOpenPositions(stats);
       const bool news_waiting_close=g_news_state.block_entries && HasOpenPositions(stats);
       const bool waiting_close=(session_after_stop && HasOpenPositions(stats)) || (g_daily_target_locked && HasOpenPositions(stats)) || news_waiting_close || wrap_up_waiting_close;
       const string stop_reason=CloseReasonText();
       const string stop_reason_display=(stop_reason == "" ? "环境正常,可开新单" : stop_reason);
       const string entry_state=EntryStateText(stop_reason);
       const string session_state=SessionStateText(now_value,stats);
       const string wrap_state=WrapUpStateText(stats);
       const string goal_state=GoalStateText(target_progress_display);
       const string news_state=NewsStateText(stats);
       string work_state="工作中";
       color  work_color=ok_color;
       if(g_daily_target_locked)
         {
          work_state=waiting_close ? "盈利达标,待平仓" : "今日盈利达标";
          work_color=accent_alt;
         }
       else if(g_news_state.block_entries)
         {
          if(g_news_state.in_pre_window)
            {
             work_state=news_waiting_close ? "新闻前等待平仓" : "新闻前暂停";
             work_color=warn_color;
            }
          else
            {
             work_state=news_waiting_close ? "新闻后等待平仓" : "新闻后冷静期";
             work_color=accent;
            }
         }
       else if(wrap_up_active)
         {
          work_state=wrap_up_waiting_close ? "日内收尾,待平仓" : "日内收尾";
          work_color=warn_color;
         }
       else if(waiting_close)
         {
          work_state="已到结束时间,待平仓";
          work_color=warn_color;
         }
       else if(session_after_stop)
         {
          work_state="今日已收工";
          work_color=accent;
         }
       else if(waiting_start)
         {
          work_state="等待工作时段";
          work_color=muted;
         }
       else if(!g_allow_buy && !g_allow_sell)
         {
          work_state="手动暂停";
          work_color=bad_color;
         }
       else if(stop_reason != "")
         {
          work_state="暂停中";
          work_color=warn_color;
         }
       else if(!g_allow_buy || !g_allow_sell)
         {
          work_state="单边运行";
          work_color=accent_alt;
         }
       const string subtitle=ClipText(_Symbol + "  |  " + TimeframeLabel((ENUM_TIMEFRAMES)TimeZone) + "  |  " + AccountInfoString(ACCOUNT_CURRENCY),
                                      (int)MathMax(20.0,MathMin(34.0,(double)m.width / 12.0)));

       EnsureRectangle(g_panel_prefix + "panel",x,m.margin_y,m.width,m.panel_h,panel_bg,panel_border,corner);
       EnsureRectangle(g_panel_prefix + "header",x,m.margin_y,m.width,m.header_h,header_bg,panel_border,corner);
       EnsureRectangle(g_panel_prefix + "header_accent",x,m.margin_y,ScalePx(5),m.header_h,accent,accent,corner);
       EnsureLabel(g_panel_prefix + "title","金麒麟 MT5",inner_x + ScalePx(6),m.margin_y + ScalePx(10),m.font_lg,cream,corner);
       EnsureLabel(g_panel_prefix + "subtitle",subtitle,inner_x + ScalePx(6),m.margin_y + ScalePx(31),m.font_sm,muted,corner);
       EnsureButton(g_panel_prefix + "toggle_panel",g_panel_open ? "收起" : "展开",right_button_x,m.margin_y + ScalePx(13),m.toggle_w,m.button_h,accent,White,corner);

       int y=m.margin_y + m.header_h + m.section_gap;
       EnsureRectangle(g_panel_prefix + "card_status",x,y,m.width,m.card_status_h,card_bg,panel_border,corner);
       EnsureLabel(g_panel_prefix + "status_title","工作状态",inner_x,y + m.pad - ScalePx(1),m.font_md,cream,corner);
       EnsureLabel(g_panel_prefix + "status_line1","当前  " + work_state,inner_x,y + m.pad + ScalePx(20),m.font_sm,work_color,corner);
       EnsureLabel(g_panel_prefix + "status_line2",ClipText("交易  " + entry_state + "  |  多空  " + BoolText(g_allow_buy,"多开","多停") + "/" + BoolText(g_allow_sell,"空开","空停"),info_chars),inner_x,y + m.pad + ScalePx(40),m.font_sm,cream,corner);
       EnsureLabel(g_panel_prefix + "status_line3",ClipText("时段  " + (EnableTradingSessionWindow ? EA_StartTime + "-" + EA_StopTime : "--") + "  |  " + session_state,info_chars),inner_x,y + m.pad + ScalePx(60),m.font_sm,muted,corner);
       EnsureLabel(g_panel_prefix + "status_line4",ClipText("收尾  " + wrap_state,info_chars),inner_x,y + m.pad + ScalePx(80),m.font_xs,wrap_up_active ? warn_color : muted,corner);
       EnsureLabel(g_panel_prefix + "status_line5",ClipText("新闻  " + news_state,info_chars),inner_x,y + m.pad + ScalePx(100),m.font_xs,g_news_state.block_entries ? warn_color : muted,corner);
       EnsureLabel(g_panel_prefix + "status_line6",ClipText("目标  " + goal_state,info_chars),inner_x,y + m.pad + ScalePx(120),m.font_xs,g_daily_target_locked ? accent_alt : cream,corner);
       EnsureLabel(g_panel_prefix + "status_line7","原因  " + ClipText(stop_reason_display,reason_chars),inner_x,y + m.pad + ScalePx(140),m.font_xs,stop_reason == "" ? muted : warn_color,corner);

       y+=m.card_status_h + m.section_gap;
       EnsureRectangle(g_panel_prefix + "card_metrics",x,y,m.width,m.card_metrics_h,card_bg,panel_border,corner);
       EnsureLabel(g_panel_prefix + "metrics_title","今日目标与账户",inner_x,y + m.pad - ScalePx(1),m.font_md,cream,corner);

       int line_y=y + m.pad + ScalePx(22);
       EnsureLabel(g_panel_prefix + "metrics_a_l","今日已平  " + FormatSignedMoney(today_profit),inner_x,line_y,m.font_sm,today_profit >= 0.0 ? ok_color : bad_color,corner);
       EnsureLabel(g_panel_prefix + "metrics_a_r",
                   !EnableDailyProfitTarget ? "目标  已关闭" :
                   (target_enabled ? ("目标  +" + DoubleToString(DailyProfitTarget,2)) : "目标  金额<=0"),
                   inner_x2,
                   line_y,
                   m.font_sm,
                   target_enabled ? accent : muted,
                   corner);

       line_y+=m.row_h + m.gap / 2;
       EnsureLabel(g_panel_prefix + "metrics_b","今日进度  " + FormatSignedMoney(target_progress_display),inner_x,line_y,m.font_sm,target_progress_display >= 0.0 ? ok_color : bad_color,corner);
       line_y+=m.row_h + m.gap / 2;
       EnsureLabel(g_panel_prefix + "metrics_c",
                   !EnableDailyProfitTarget ? "今日目标  已关闭" :
                   (target_enabled ? (g_daily_target_locked ? "今日目标  已达成并封盘" : "目标剩余  " + DoubleToString(target_remaining,2)) : "今日目标  金额<=0"),
                   inner_x,
                   line_y,
                   m.font_sm,
                   g_daily_target_locked ? accent_alt : muted,
                   corner);
       line_y+=m.row_h + m.gap / 2;
       EnsureLabel(g_panel_prefix + "metrics_d_l","Buy  " + IntegerToString(stats.buy_positions) + "单  " + DoubleToString(stats.buy_lots,2) + "手",inner_x,line_y,m.font_sm,cream,corner);
       EnsureLabel(g_panel_prefix + "metrics_d_r","Sell  " + IntegerToString(stats.sell_positions) + "单  " + DoubleToString(stats.sell_lots,2) + "手",inner_x2,line_y,m.font_sm,cream,corner);
       line_y+=m.row_h + m.gap / 2;
       EnsureLabel(g_panel_prefix + "metrics_e_l","Buy浮盈  " + FormatSignedMoney(stats.buy_profit),inner_x,line_y,m.font_sm,stats.buy_profit >= 0.0 ? ok_color : bad_color,corner);
       EnsureLabel(g_panel_prefix + "metrics_e_r","Sell浮盈  " + FormatSignedMoney(stats.sell_profit),inner_x2,line_y,m.font_sm,stats.sell_profit >= 0.0 ? ok_color : bad_color,corner);
       line_y+=m.row_h + m.gap / 2;
       EnsureLabel(g_panel_prefix + "metrics_f_l","EA浮盈亏  " + FormatSignedMoney(stats.total_profit),inner_x,line_y,m.font_sm,stats.total_profit >= 0.0 ? ok_color : bad_color,corner);
       EnsureLabel(g_panel_prefix + "metrics_f_r","昨日已平  " + FormatSignedMoney(yesterday_profit),inner_x2,line_y,m.font_sm,yesterday_profit >= 0.0 ? ok_color : bad_color,corner);

       if(g_panel_open)
         {
          line_y+=m.row_h + m.gap / 2;
          EnsureLabel(g_panel_prefix + "metrics_g_l","累计已平  " + FormatSignedMoney(total_closed),inner_x,line_y,m.font_sm,total_closed >= 0.0 ? ok_color : bad_color,corner);
          EnsureLabel(g_panel_prefix + "metrics_g_r","保证金比  " + FormatPercent(margin_level),inner_x2,line_y,m.font_sm,margin_level >= 200.0 ? ok_color : warn_color,corner);

          line_y+=m.row_h + m.gap / 2;
          EnsureLabel(g_panel_prefix + "metrics_h_l","余额  " + FormatSignedMoney(balance),inner_x,line_y,m.font_sm,cream,corner);
          EnsureLabel(g_panel_prefix + "metrics_h_r","净值  " + FormatSignedMoney(equity),inner_x2,line_y,m.font_sm,accent_alt,corner);

          line_y+=m.row_h + m.gap / 2;
          EnsureLabel(g_panel_prefix + "metrics_i_l","点差  " + DoubleToString(spread_pips,1) + " pips",inner_x,line_y,m.font_sm,muted,corner);
          EnsureLabel(g_panel_prefix + "metrics_i_r","杠杆  " + IntegerToString((int)AccountInfoInteger(ACCOUNT_LEVERAGE)) + "x",inner_x2,line_y,m.font_sm,muted,corner);
         }
       else
         {
          line_y+=m.row_h + m.gap / 2;
          EnsureLabel(g_panel_prefix + "metrics_g_l","余额  " + FormatSignedMoney(balance),inner_x,line_y,m.font_sm,cream,corner);
          EnsureLabel(g_panel_prefix + "metrics_g_r","净值  " + FormatSignedMoney(equity),inner_x2,line_y,m.font_sm,accent_alt,corner);
          ObjectDelete(0,g_panel_prefix + "metrics_h_l");
          ObjectDelete(0,g_panel_prefix + "metrics_h_r");
          ObjectDelete(0,g_panel_prefix + "metrics_i_l");
          ObjectDelete(0,g_panel_prefix + "metrics_i_r");
         }

       y+=m.card_metrics_h + m.section_gap;
       EnsureRectangle(g_panel_prefix + "card_actions",x,y,m.width,m.card_actions_h,card_bg,panel_border,corner);
       EnsureLabel(g_panel_prefix + "actions_title","快捷操作",inner_x,y + m.pad - ScalePx(1),m.font_md,cream,corner);

       int button_y=y + m.pad + ScalePx(24);
       EnsureButton(g_panel_prefix + "stop_all",BoolText(!(g_allow_buy || g_allow_sell),"开启交易","停止交易"),inner_x,button_y,m.inner_w,m.button_h,(g_allow_buy || g_allow_sell) ? bad_color : accent_alt,White,corner);

       if(g_panel_open)
         {
          button_y+=m.button_h + m.gap;
          EnsureButton(g_panel_prefix + "stop_buy",BoolText(g_allow_buy,"停止做多","开启做多"),inner_x,button_y,m.half_w,m.button_h,g_allow_buy ? warn_color : accent_alt,White,corner);
          EnsureButton(g_panel_prefix + "stop_sell",BoolText(g_allow_sell,"停止做空","开启做空"),inner_x2,button_y,m.half_w,m.button_h,g_allow_sell ? warn_color : accent_alt,White,corner);

          button_y+=m.button_h + m.gap;
          EnsureButton(g_panel_prefix + "close_symbol","平当前品种",inner_x,button_y,m.half_w,m.button_h,accent,White,corner);
          EnsureButton(g_panel_prefix + "close_profit","平盈利单",inner_x2,button_y,m.half_w,m.button_h,accent_alt,White,corner);

          button_y+=m.button_h + m.gap;
          EnsureButton(g_panel_prefix + "close_loss","平亏损单",inner_x,button_y,m.half_w,m.button_h,bad_color,White,corner);
          EnsureButton(g_panel_prefix + "close_buy","平多单",inner_x2,button_y,m.half_w,m.button_h,C'29,78,216',White,corner);

          button_y+=m.button_h + m.gap;
          EnsureButton(g_panel_prefix + "close_sell","平空单",inner_x,button_y,m.half_w,m.button_h,C'185,74,72',White,corner);
          EnsureButton(g_panel_prefix + "close_ea","平本EA全部",inner_x2,button_y,m.half_w,m.button_h,C'121,89,214',White,corner);

          button_y+=m.button_h + m.gap;
          EnsureButton(g_panel_prefix + "close_account","平账号全部",inner_x,button_y,m.inner_w,m.button_h,C'92,141,146',White,corner);
         }
       else
         {
          ObjectDelete(0,g_panel_prefix + "stop_buy");
          ObjectDelete(0,g_panel_prefix + "stop_sell");
          ObjectDelete(0,g_panel_prefix + "close_symbol");
          ObjectDelete(0,g_panel_prefix + "close_profit");
          ObjectDelete(0,g_panel_prefix + "close_loss");
          ObjectDelete(0,g_panel_prefix + "close_buy");
          ObjectDelete(0,g_panel_prefix + "close_sell");
          ObjectDelete(0,g_panel_prefix + "close_ea");
          ObjectDelete(0,g_panel_prefix + "close_account");
         }
      }

    void RefreshPanel(const bool force)
      {
       const datetime now_second=TimeCurrent();
       if(!force && now_second == g_last_panel_refresh)
          return;

       EAStats stats;
       CollectStats(stats);
       RefreshNewsState(false);
       DrawPanel(stats);
       g_last_panel_refresh=now_second;
       ChartRedraw(0);
      }

    void DeleteObjectsByPrefix(const string prefix)
      {
       for(int i=ObjectsTotal(0,-1,-1)-1; i>=0; --i)
         {
          const string name=ObjectName(0,i,-1,-1);
          if(StringFind(name,prefix,0) == 0)
             ObjectDelete(0,name);
         }
      }

    jianxian LV3

    发表于 2026-5-29 01:58:40 | 显示全部楼层

    见不得那行免费的东西还拿来卖钱的这是2个版本我把图传上去,要哪个版本就下载哪个版本第一张就是第一个版本。第二张第二个版本
    13da3a42-ab5d-45b6-9745-c8f1b3e9cfff.png
    3c6aac60-a9a5-448e-b78b-37c713a6006c.png

    VX11872213 LV3

    发表于 2026-5-29 02:00:33 | 显示全部楼层

    大哥 可以发发个现成的嘛,我不会编辑啊。

    jianxian LV3

    发表于 2026-5-29 02:08:10 | 显示全部楼层

    点击MT5的IDE然后编辑器就会弹出来,然后在编辑器最前面点击那个新。选择EA交易模板。输入你想取的EA名字直接都是下一步,直到出来编辑窗口,删除里面所有代码,复制上面的2个版本进去。直接点击上面构建然后编译,EA就出现了。

    vivek LV4

    发表于 2026-5-29 08:24:02 | 显示全部楼层

    谢谢楼主,第一个版本复制几次都有好多错误
    局部截取_20260529_082231.png

    日出东方888 LV3

    发表于 2026-5-29 08:24:47 | 显示全部楼层

    jianxian 发表于 2026-5-29 01:54
    #property strict
    #property version   "2.11"
    #property description "GoldKylin MT5 CTrade edition"

    谢谢楼主的无私奉献!
    第二个检测正常。
    第一个检测有74个错误点,是不是哪儿不全?

    jianxian LV3

    发表于 2026-5-29 08:32:37 | 显示全部楼层

    本帖最后由 jianxian 于 2026-5-29 08:42 编辑
    日出东方888 发表于 2026-5-29 08:24
    谢谢楼主的无私奉献!
    第二个检测正常。
    第一个检测有74个错误点,是不是哪儿不全?


    代码是没问题,可能是我通过亮化代码出问题了,你们是7000多行还是6900多行。如果是6900的话就是亮化后{}出问题了。并没少,只是被压缩到其它的//后面去了。有时间就看一下。没时间等等,我等会在传一次。

    金色阳光 LV6

    发表于 2026-5-29 09:50:58 | 显示全部楼层

    不行呢
    有错误

    gogjcn LV3

    发表于 2026-5-29 15:13:25 | 显示全部楼层

    mt4 的,EX平台不能运行,那个大哥知道怎么调吗。
    12下一页
    您需要登录后才可以回帖 登录 | 注册

    提醒: 禁止引战、谩骂、灌水内容

    微信二维码

    有问题联系客服