HYROLEAN

hyrStatus.mqh for MT5

Mar 9th, 2026 (edited)
68
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 18.45 KB | Money | 0 0
  1. // hyrStatus.mqh for MT5
  2. //   by Copyright 2026 hyrolean
  3. //---------------------------------------------------------------------------
  4. // Local:: <DataFolder>\MQL5\Include\User\hyrStatus.mqh
  5. // URL:: https://pastebin.com/d9Z8P2qD
  6. // Date:: 2026/05/01
  7. //---------------------------------------------------------------------------
  8. #include <Arrays/ArrayObj.mqh>
  9. #include <Trade/PositionInfo.mqh>
  10. #include <Trade/OrderInfo.mqh>
  11. #include <Trade/DealInfo.mqh>
  12. //---------------------------------------------------------------------------
  13. //状態チェック
  14. //-----
  15. enum ENUM_ORDERSORT {
  16.   ORDERSORT_NONE=0,
  17.   ORDERSORT_PRICE_ASCEND,
  18.   ORDERSORT_PRICE_DESCEND,
  19.   ORDERSORT_OPENTIME_ASCEND,
  20.   ORDERSORT_OPENTIME_DESCEND,
  21.   ORDERSORT_STOPLOSS_ASCEND,
  22.   ORDERSORT_STOPLOSS_DESCEND
  23. };
  24. class COrderStatus : public CObject
  25. {
  26. private:
  27.   static int inline DblComp(double v1, double v2) {
  28.     if(v1==v2) return 0 ;
  29.     return v1<v2 ? -1 : +1 ;
  30.   }
  31. public:
  32.   ulong Ticket;
  33.   double Price;
  34.   double Stoploss;
  35.   double Takeprofit;
  36.   double Lots;
  37.   double Profit;
  38.   double Commission;
  39.   double Swap;
  40.   datetime OpenTime;
  41.   datetime Expiration;
  42.   string Comment;
  43.   double BorderPrice;
  44.   double BorderPriceWithSwap;
  45.   double InitialPrice;
  46.   double InitialLots;
  47.   double InitialCommission;
  48.   string InitialComment;
  49.   datetime InitialTime;
  50.   double InitialBorderPrice;
  51.   double DealtLots;
  52.   double DealtProfit;
  53.   double DealtCommission;
  54.   double DealtSwap;
  55.   int DealtCount;
  56.   int Tag;
  57.   COrderStatus() : CObject() {
  58.     Ticket = 0 ;
  59.     Price = Stoploss = Takeprofit = Lots = Profit = 0.0 ;
  60.     InitialPrice = InitialLots = 0.0 ;
  61.     BorderPrice = BorderPriceWithSwap = InitialBorderPrice = 0.0 ;
  62.     Commission = Swap = InitialCommission = 0.0 ;
  63.     DealtLots = DealtProfit = DealtCommission = DealtSwap = 0.0 ; DealtCount=0 ;
  64.     OpenTime = Expiration = InitialTime = 0 ;
  65.     Comment = InitialComment = "" ;
  66.     Tag = 0 ;
  67.   }
  68.   COrderStatus(
  69.       ulong Ticket_,
  70.       double Price_,
  71.       double Stoploss_,
  72.       double Takeprofit_,
  73.       double Lots_,
  74.       double Profit_,
  75.       datetime OpenTime_,
  76.       string Comment_,
  77.       int Tag_=0 ) : CObject() {
  78.     Ticket = Ticket_;
  79.     Price = InitialPrice = Price_;
  80.     Stoploss = Stoploss_;
  81.     Takeprofit = Takeprofit_;
  82.     Lots = InitialLots = Lots_;
  83.     Profit = Profit_;
  84.     OpenTime = InitialTime = OpenTime_;
  85.     Comment = InitialComment = Comment_;
  86.     Tag = Tag_ ;
  87.     BorderPrice = BorderPriceWithSwap = InitialBorderPrice = Price;
  88.     DealtLots = DealtProfit = DealtCommission = DealtSwap = 0.0 ; DealtCount=0 ;
  89.     Commission = Swap = InitialCommission = 0.0 ;
  90.   }
  91.   virtual int Compare(const CObject *node,const int mode=0) const {
  92.     COrderStatus *status = (COrderStatus*) node ;
  93.     switch(mode) {
  94.       case ORDERSORT_PRICE_ASCEND:
  95.         return DblComp(Price,status.Price);
  96.       case ORDERSORT_PRICE_DESCEND:
  97.         return DblComp(status.Price,Price);
  98.       case ORDERSORT_OPENTIME_ASCEND:
  99.         return DblComp(OpenTime,status.OpenTime);
  100.       case ORDERSORT_OPENTIME_DESCEND:
  101.         return DblComp(status.OpenTime,OpenTime);
  102.       case ORDERSORT_STOPLOSS_ASCEND:
  103.         return DblComp(Stoploss,status.Stoploss);
  104.       case ORDERSORT_STOPLOSS_DESCEND:
  105.         return DblComp(status.Stoploss,Stoploss);
  106.     }
  107.     return 0;
  108.   }
  109. };
  110. //-----
  111. class STATUS {
  112. private:
  113.   void Init() {
  114.     HalfSpread = 0.0 ;
  115.     Bid = 0.0; Ask = 0.0 ;
  116.     Positions = 0 ;
  117.     PyramidPositions = 0 ;
  118.     AveragePositions = 0 ;
  119.     MinPrice = DBL_MAX ;
  120.     MaxPrice = 0.0 ;
  121.     MinPriceLots = 0.0 ;
  122.     MaxPriceLots = 0.0 ;
  123.     MinPriceProfit = 0.0 ;
  124.     MaxPriceProfit = 0.0 ;
  125.     MinPriceStoploss = 0.0 ;
  126.     MaxPriceStoploss = 0.0 ;
  127.     MinPriceTicket = 0 ;
  128.     MaxPriceTicket = 0 ;
  129.     MinStoploss = DBL_MAX ;
  130.     MaxStoploss = 0.0 ;
  131.     MinTakeprofit = DBL_MAX ;
  132.     MaxTakeprofit = 0.0 ;
  133.     MinLots = DBL_MAX ;
  134.     MaxLots = 0.0 ;
  135.     MinOpenTime = TimeCurrent() ;
  136.     MaxOpenTime = 0 ;
  137.     PyramidMinLots = DBL_MAX ;
  138.     PyramidMaxLots = 0.0 ;
  139.     AverageMinLots = DBL_MAX ;
  140.     AverageMaxLots = 0.0 ;
  141.     BorderPrice = 0.0 ;
  142.     TotalPrices = 0.0 ;
  143.     TotalLots = 0.0 ;
  144.     GrossProfit = 0.0 ;
  145.     PositiveProfit = 0.0 ;
  146.     CurrentPrices = 0.0 ;
  147.     MedianPrices = 0.0 ;
  148.     Tag = 0 ;
  149.     Orders.Clear();
  150.   }
  151.   void Append(COrderStatus *Order) {
  152.     double realProfit = Order.Profit + Order.Commission + Order.Swap ;
  153.     GrossProfit += realProfit;
  154.     if(realProfit>0.0)
  155.       PositiveProfit += realProfit;
  156.     if(Order.Price<MinPrice) {
  157.       MinPrice = Order.Price ;
  158.       MinPriceLots = Order.Lots ;
  159.       MinPriceProfit = Order.Profit ;
  160.       MinPriceStoploss = Order.Stoploss ;
  161.       MinPriceTicket = Order.Ticket ;
  162.     }
  163.     if(Order.Price>MaxPrice) {
  164.       MaxPrice = Order.Price ;
  165.       MaxPriceLots = Order.Lots ;
  166.       MaxPriceProfit = Order.Profit ;
  167.       MaxPriceStoploss = Order.Stoploss ;
  168.       MaxPriceTicket = Order.Ticket ;
  169.     }
  170.     if(Order.Stoploss<MinStoploss) MinStoploss = Order.Stoploss;
  171.     if(Order.Stoploss>MaxStoploss) MaxStoploss = Order.Stoploss;
  172.     if(Order.Takeprofit<MinTakeprofit) MinTakeprofit = Order.Takeprofit;
  173.     if(Order.Takeprofit>MaxTakeprofit) MaxTakeprofit = Order.Takeprofit;
  174.     if(Order.Lots<MinLots) MinLots = Order.Lots;
  175.     if(Order.Lots>MaxLots) MaxLots = Order.Lots;
  176.     TotalPrices += Order.BorderPrice*Order.Lots ;
  177.     TotalLots += Order.Lots;
  178.     if(Flag==FLAG_BUY) {
  179.       CurrentPrices += (Bid - Order.BorderPrice) * Order.Lots ;
  180.       MedianPrices += (Order.BorderPrice + HalfSpread) * Order.Lots ;
  181.     }
  182.     else if(Flag==FLAG_SELL) {
  183.       CurrentPrices += (Order.BorderPrice - Ask) * Order.Lots ;
  184.       MedianPrices += (Order.BorderPrice - HalfSpread) * Order.Lots ;
  185.     }
  186.     if(MaxOpenTime<Order.OpenTime) MaxOpenTime=Order.OpenTime;
  187.     if(MinOpenTime>Order.OpenTime) MinOpenTime=Order.OpenTime;
  188.     if(StringFind(Order.InitialComment,"PRMD")>=0||
  189.        StringFind(Order.Comment,"PRMD")>=0) {
  190.       if(Order.Lots>PyramidMaxLots)
  191.         PyramidMaxLots = Order.Lots ;
  192.       if(Order.Lots<PyramidMinLots)
  193.         PyramidMinLots = Order.Lots ;
  194.       PyramidPositions++;
  195.     }
  196.     if(StringFind(Order.InitialComment,"AVRG")>=0||
  197.        StringFind(Order.Comment,"AVRG")>=0) {
  198.       if(Order.Lots>AverageMaxLots)
  199.         AverageMaxLots = Order.Lots ;
  200.       if(Order.Lots<AverageMinLots)
  201.         AverageMinLots = Order.Lots ;
  202.       AveragePositions++;
  203.     }
  204.     Positions++;
  205.   }
  206.   void Finish() {
  207.     if(OrdersLastSort!=ORDERSORT_NONE)
  208.       Orders.Sort(OrdersLastSort);
  209.     if(TotalLots>0) {
  210.       BorderPrice = TotalPrices / TotalLots ;
  211.     }
  212.   }
  213. protected:
  214.   CArrayObj *Orders;
  215.   ENUM_ORDERSORT OrdersLastSort;
  216.   virtual void CheckInit() { Init() ; }
  217.   virtual void CheckOrder(COrderStatus *OrderStatus) { Append(OrderStatus); }
  218.   virtual void CheckFinish() { Finish() ; }
  219. protected:
  220.   CPositionInfo PosInfo;
  221.   COrderInfo OrdInfo;
  222.   CDealInfo DealInfo;
  223.   int AnalyzeDealt(COrderStatus *orderStatus) {
  224.     int dealtCount=0;
  225.     if(HistorySelectByPosition(orderStatus.Ticket)) {
  226.       int total = HistoryDealsTotal();
  227.       for(int i=0; i<total; i++) {
  228.         TICKET dealtTicket = HistoryDealGetTicket(i);
  229.         if(dealtTicket > 0) {
  230.           DealInfo.Ticket(dealtTicket);
  231.           ENUM_DEAL_ENTRY entryType = DealInfo.Entry() ;
  232.           if(entryType==DEAL_ENTRY_IN) {
  233.             orderStatus.InitialPrice = DealInfo.Price();
  234.             orderStatus.InitialTime = DealInfo.Time();
  235.             orderStatus.InitialLots = DealInfo.Volume();
  236.             orderStatus.InitialCommission = DealInfo.Commission();
  237.             orderStatus.InitialComment = DealInfo.Comment();
  238.           }else {
  239.             if( entryType == DEAL_ENTRY_OUT || entryType == DEAL_ENTRY_INOUT) {
  240.               orderStatus.DealtLots += DealInfo.Volume();
  241.               dealtCount++;
  242.             }
  243.             orderStatus.DealtProfit += DealInfo.Profit();
  244.             orderStatus.DealtCommission += DealInfo.Commission();
  245.             orderStatus.DealtSwap += DealInfo.Swap();
  246.           }
  247.         }
  248.       }
  249.     }
  250.     return dealtCount ;
  251.   }
  252. public:
  253.   string USDJPYFindSymbol() {
  254.     if(SymbolUSDJPY=="") {
  255.       int total = SymbolsTotal(false);
  256.       for(int i = 0; i < total; i++) {
  257.         string name = SymbolName(i, false);
  258.         if(StringFind(name, "USDJPY") >= 0) {
  259.           SymbolUSDJPY = name; break;
  260.         }
  261.       }
  262.     }
  263.     if(SymbolUSDJPY!="") SymbolSelect(SymbolUSDJPY, true);
  264.     return SymbolUSDJPY ;
  265.   }
  266.   double USDJPYRateAt(datetime time) {
  267.     MqlTick ticks[];
  268.     ulong tick = time * 1000 ;
  269.     //ティックからrateを拾ってくる
  270.     if(CopyTicks(USDJPYFindSymbol(),ticks,COPY_TICKS_ALL,tick,1)==1)
  271.       return ticks[0].bid ;
  272.     return 0.0;
  273.   }
  274.   double USDJPYCommissionPerLotAt(datetime time) {
  275.     //USDJPYFindSymbol();
  276.     string currency = AccountInfoString(ACCOUNT_CURRENCY);
  277.     double commission = 0;
  278.     if(currency == "JPY") {
  279.       commission += CommissionPerLotJPY ;
  280.       if(CommissionPerLotUSD!=0.0) {
  281.         commission += CommissionPerLotUSD * USDJPYRateAt(time);
  282.       }
  283.     }else if(currency == "USD") {
  284.       commission += CommissionPerLotUSD ;
  285.       if(CommissionPerLotJPY!=0.0) {
  286.         double rate = USDJPYRateAt(time);
  287.         if(rate>0.0) // 0 div 回避
  288.           commission += CommissionPerLotJPY / rate ;
  289.       }
  290.     }
  291.     return commission ;
  292.   }
  293. public:
  294.   OP Type;
  295.   FLAG Flag;
  296.   long Magic;
  297.   double CommissionPerLotJPY;
  298.   double CommissionPerLotUSD;
  299.   string SymbolUSDJPY;
  300.   double Bid,Ask,Spread,HalfSpread;
  301.   int Positions, PyramidPositions, AveragePositions;
  302.   double MinPrice, MaxPrice, BorderPrice;
  303.   double MinPriceLots, MaxPriceLots;
  304.   double MinPriceProfit, MaxPriceProfit;
  305.   double MinPriceStoploss, MaxPriceStoploss;
  306.   ulong MinPriceTicket, MaxPriceTicket;
  307.   double MinStoploss, MaxStoploss;
  308.   double MinTakeprofit, MaxTakeprofit;
  309.   double MinLots, MaxLots;
  310.   datetime MinOpenTime, MaxOpenTime;
  311.   double PyramidMinLots, PyramidMaxLots;
  312.   double AverageMinLots, AverageMaxLots;
  313.   double TotalPrices, TotalLots;
  314.   double CurrentPrices, MedianPrices;
  315.   double GrossProfit;
  316.   double PositiveProfit;
  317.   int Tag;
  318.   STATUS(OP Type_=OP_BUY, long Magic_=0,
  319.       double CommissionPerLotJPY_=0, double CommissionPerLotUSD_=0, string SymbolUSDJPY_="") {
  320.     Orders = new CArrayObj();
  321.     Init();
  322.     Type=Type_;
  323.     Flag=OpToFlag(Type);
  324.     Magic=Magic_;
  325.     CommissionPerLotJPY = CommissionPerLotJPY_>0? -CommissionPerLotJPY_: CommissionPerLotJPY_ ;
  326.     CommissionPerLotUSD = CommissionPerLotUSD_>0? -CommissionPerLotUSD_: CommissionPerLotUSD_ ;
  327.     SymbolUSDJPY = SymbolUSDJPY_ ;
  328.     OrdersLastSort=ORDERSORT_NONE;
  329.   }
  330.   ~STATUS() {
  331.     delete Orders;
  332.   }
  333.   virtual void Check(ENUM_POSITION_TYPE type, long magic) {
  334.     Type=(OP)type;
  335.     Flag=OpToFlag(Type);
  336.     Magic=magic;
  337.     CheckInit();
  338.     Ask = SymbolInfoDouble(_Symbol,SYMBOL_ASK) ;
  339.     Bid = SymbolInfoDouble(_Symbol,SYMBOL_BID) ;
  340.     Spread = Ask-Bid ;
  341.     HalfSpread = Spread/2.0;
  342.     double tickValue = SymbolInfoDouble(_Symbol, SYMBOL_TRADE_TICK_VALUE);
  343.     double tickSize  = SymbolInfoDouble(_Symbol, SYMBOL_TRADE_TICK_SIZE);
  344.     for(int i=PositionsTotal()-1 ; i>=0 ; i--) {
  345.       if( PosInfo.SelectByIndex(i) && PosInfo.Symbol() == _Symbol ) {
  346.         if(magic==PosInfo.Magic()) {
  347.           if(type==PosInfo.PositionType()) {
  348.             ulong orderTicket = PosInfo.Ticket() ;
  349.             double orderPrice = PosInfo.PriceOpen();
  350.             double orderStoploss = PosInfo.StopLoss();
  351.             double orderTakeprofit = PosInfo.TakeProfit();
  352.             double orderLots = PosInfo.Volume();
  353.             double orderProfit = PosInfo.Profit() ;
  354.             datetime orderOpenTime = PosInfo.Time() ;
  355.             string orderComment = PosInfo.Comment();
  356.             COrderStatus *orderStatus = new COrderStatus(
  357.               orderTicket,
  358.               orderPrice,
  359.               orderStoploss,
  360.               orderTakeprofit,
  361.               orderLots,
  362.               orderProfit,
  363.               orderOpenTime,
  364.               orderComment ) ;
  365.             orderStatus.Commission = PosInfo.Commission();
  366.             orderStatus.Swap = PosInfo.Swap();
  367.             orderStatus.DealtCount = AnalyzeDealt(orderStatus);
  368.             if(orderStatus.InitialLots==0.0) {
  369.               orderStatus.InitialLots=orderStatus.Lots+orderStatus.DealtLots;
  370.             }
  371.             if(CommissionPerLotJPY!=0||CommissionPerLotUSD!=0) {
  372.               // ※手数料が定義されている場合は、手数料を上書きする
  373.               double commissionPerLot = USDJPYCommissionPerLotAt(orderStatus.OpenTime) ;
  374.               orderStatus.InitialCommission = commissionPerLot * orderStatus.InitialLots ;
  375.               orderStatus.Commission = commissionPerLot * orderStatus.Lots ;
  376.             }
  377.             if(orderStatus.Commission==0.0) {
  378.               orderStatus.Commission = orderStatus.InitialCommission*orderStatus.Lots/orderStatus.InitialLots ;
  379.             }
  380.             if(orderStatus.InitialCommission!=0.0) {
  381.               double debt = MathMin(orderStatus.InitialCommission, 0.0) ;
  382.               if(Flag==FLAG_BUY)  // [-] -> [+]
  383.                 debt = -debt ;
  384.               double costsPerPoint = orderStatus.InitialLots * tickValue ;
  385.               orderStatus.InitialBorderPrice += (debt/costsPerPoint)*_Point ;
  386.               orderStatus.InitialBorderPrice
  387.                = NormalizeDouble(orderStatus.InitialBorderPrice, _Digits);
  388.             }
  389.             if(orderStatus.Commission!=0.0||orderStatus.Swap!=0.0) {
  390.               double debt = MathMin(orderStatus.Commission, 0.0) ;
  391.               double debtWithSwap = MathMin(orderStatus.Swap+debt, 0.0) ;
  392.               if(Flag==FLAG_BUY) {  // [-] -> [+]
  393.                 debt = -debt ;
  394.                 debtWithSwap = -debtWithSwap ;
  395.               }
  396.               double costsPerPoint = orderLots * tickValue ;
  397.               orderStatus.BorderPriceWithSwap += (debtWithSwap/costsPerPoint)*_Point ;
  398.               orderStatus.BorderPriceWithSwap = NormalizeDouble(orderStatus.BorderPriceWithSwap,_Digits);
  399.               orderStatus.BorderPrice += (debt/costsPerPoint)*_Point ;
  400.               orderStatus.BorderPrice = NormalizeDouble(orderStatus.BorderPrice,_Digits);
  401.             }
  402.             Orders.Add(orderStatus);
  403.             CheckOrder(orderStatus);
  404.           }
  405.         }
  406.       }
  407.     }
  408.     CheckFinish();
  409.   }
  410.   virtual void CheckReserved(ENUM_ORDER_TYPE type, long magic) {
  411.     Type=(OP)type;
  412.     Flag=OpToFlag(Type);
  413.     Magic=magic;
  414.     CheckInit();
  415.     Ask = SymbolInfoDouble(_Symbol,SYMBOL_ASK) ;
  416.     Bid = SymbolInfoDouble(_Symbol,SYMBOL_BID) ;
  417.     Spread = Ask-Bid ;
  418.     HalfSpread = Spread/2.0;
  419.     for(int i=OrdersTotal()-1 ; i>=0 ; i--) {
  420.       if( OrdInfo.SelectByIndex(i) && OrdInfo.Symbol() == _Symbol ) {
  421.         if(magic==OrdInfo.Magic()) {
  422.           if(type==OrdInfo.OrderType()) {
  423.             ulong orderTicket = OrdInfo.Ticket() ;
  424.             double orderPrice = OrdInfo.PriceOpen();
  425.             double orderStoploss = OrdInfo.StopLoss();
  426.             double orderTakeprofit = OrdInfo.TakeProfit();
  427.             double orderLots = OrdInfo.VolumeInitial();
  428.             double orderProfit = 0 ;
  429.             datetime orderSetupTime = OrdInfo.TimeSetup();
  430.             datetime orderExpiration = OrdInfo.TimeExpiration();
  431.             string orderComment = OrdInfo.Comment();
  432.             COrderStatus *orderStatus = new COrderStatus(
  433.               orderTicket,
  434.               orderPrice,
  435.               orderStoploss,
  436.               orderTakeprofit,
  437.               orderLots,
  438.               orderProfit,
  439.               orderSetupTime,
  440.               orderComment ) ;
  441.             orderStatus.Expiration = orderExpiration ;
  442.             Orders.Add(orderStatus);
  443.             CheckOrder(orderStatus);
  444.           }
  445.         }
  446.       }
  447.     }
  448.     CheckFinish();
  449.   }
  450.   void OrdersSort(ENUM_ORDERSORT mode) {
  451.     if(mode!=ORDERSORT_NONE&&mode!=OrdersLastSort)
  452.       Orders.Sort(mode);
  453.     OrdersLastSort = mode ;
  454.   }
  455.   int OrdersCount() const { return Orders.Total(); }
  456.   COrderStatus *OrdersAt(int index) const
  457.   { return (COrderStatus*) Orders.At(index); }
  458.   int OrdersRange(const COrderStatus *Order, int &First, int &Last) const {
  459.     if(OrdersLastSort==ORDERSORT_NONE) return -1 ;
  460.     int first = Orders.SearchFirst(Order);
  461.     if(first<0) return 0 ;
  462.     int last = Orders.SearchLast(Order);
  463.     if(last<0) return 0 ;
  464.     First = first ;
  465.     Last = last ;
  466.     return Last-First+1 ;
  467.   }
  468.   /*
  469.   double ProfitPrice(double borderPrice=0.0) const {
  470.     if(borderPrice==0.0) borderPrice = BorderPrice;
  471.     if(borderPrice>0.0) {
  472.       //double stride = PyramidingStride * Point ;
  473.       switch(Type) {
  474.         case POSITION_TYPE_BUY: {
  475.           double bar = MathMax(MaxPrice,BuyMaxPrice)-borderPrice ;
  476.           if(bar>0.0) {
  477.             return bar * (ProfitRatePer / 100.0) + borderPrice ;
  478.           }
  479.           break;
  480.         }
  481.         case POSITION_TYPE_SELL: {
  482.           double bar = MathMin(MinPrice,SellMinPrice)-borderPrice ;
  483.           if(bar<0.0) {
  484.             return bar * (ProfitRatePer / 100.0) + borderPrice ;
  485.           }
  486.           break;
  487.         }
  488.       }
  489.     }
  490.     return borderPrice ;
  491.   }
  492.   */
  493.   double MedianBorderPrice(const STATUS &revStatus, double lossPrices=0.0) const
  494.   {
  495.     double medianLots = Type==POSITION_TYPE_BUY ? TotalLots : -TotalLots ;
  496.     medianLots += revStatus.Type==POSITION_TYPE_BUY ? revStatus.TotalLots: -revStatus.TotalLots ;
  497.     if(Type==POSITION_TYPE_BUY?medianLots>0.0:medianLots<0.0) {
  498.       double medianPrices = Type==POSITION_TYPE_BUY ? MedianPrices-lossPrices : -MedianPrices+lossPrices ;
  499.       medianPrices += revStatus.Type==POSITION_TYPE_BUY ? revStatus.MedianPrices: -revStatus.MedianPrices ;
  500.       double medianBorder = medianPrices/medianLots ;
  501.       switch(Type) {
  502.         case POSITION_TYPE_BUY:
  503.             medianBorder -= HalfSpread;
  504.             break;
  505.         case POSITION_TYPE_SELL:
  506.             medianBorder += HalfSpread;
  507.             break;
  508.       }
  509.       return medianBorder ;
  510.     }
  511.     return 0.0;
  512.   }
  513. };
  514. //-----
  515. int inline CheckStatus(OP type, long magic, STATUS *status, bool reserved=false)
  516. {
  517.   if(!reserved) {
  518.     switch(type) {
  519.     case OP_BUY:
  520.     case OP_SELL:
  521.       status.Check((ENUM_POSITION_TYPE)type,magic);
  522.       break;
  523.     default:
  524.       reserved=true ;
  525.     }
  526.   }
  527.   if(reserved) {
  528.     status.CheckReserved((ENUM_ORDER_TYPE)type,magic);
  529.   }
  530.   return status.Positions;
  531. }
  532. //---------------------------------------------------------------------------
  533.  
Tags: Mt5
Advertisement
Add Comment
Please, Sign In to add comment