OrderClosePrice() or Bid/Ask? - page 2

 
fxsaber #:

He does not understand.

I understand😄

I wrote why I think so. I'm still writing for MT4, but it's been a few years since I last selected an order before closing. Because at the time of closing the order I already have all the information ready.

Market order class of one of my recent advisors:

#define _normPrc(a_val) NormalizeDouble(a_val, Digits())

class COrder
  {
public:
   const double   prcOpen;
   const double   volume;
   const datetime dtOpen;
   const int      ticket;
   const int      type;
protected:
                  COrder()
                     : prcOpen(_normPrc(OrderOpenPrice())),
                       volume(OrderLots()),
                       dtOpen(OrderOpenTime()),
                       ticket(OrderTicket()),
                       type(OrderType()) {}
  };

class CMarketOrd : public COrder
  {
public:
   const double   sl;
   const double   tp;
   const datetime expir;
   const double   profitPointsOnSl;
   const double   profitPointsOnTp;
                  CMarketOrd(double a_profitPointsOnSl, double a_profitPointsOnTp)
                     : COrder(),
                       sl(_normPrc(OrderStopLoss())),
                       tp(_normPrc(OrderTakeProfit())),
                       expir(OrderExpiration()),
                       profitPointsOnSl(a_profitPointsOnSl),
                       profitPointsOnTp(a_profitPointsOnTp) {}
  };

Such classes vary greatly depending on the information required. For example, this could be a structure that completely calculates itself in the constructor, in which case, when collecting information about orders, I just need to select an order and change the size of the structure array.

Therefore, for me personally, using OrderSelect + OrderClosePrice makes no sense at all, moreover, it would work worse in terms of performance.

 
Vladislav Boyko #:

William Roeder will throw stones at me for normalizing order prices😄

But this is done deliberately so that I can use these prices in comparisons without thinking about the precision of the double type

 
anuj71 #:
This is correct

SL and TP must be normalized.

And this already looks quite cumbersome. So personally I wouldn't use the ternary operator in the case you showed. But this is just my subjective opinion. Do as you wish.

 
anuj71 #:

So, it always good to use Ask/Bid instead of OrderClosePrice()?

Use what you like. I posted my opinion here, but I do not impose it on anyone

 
When closing several positions from an array, you may encounter a situation where some position no longer exists - it was closed at TP/SL/MC, for example.
 
fxsaber #:
When closing several positions from an array, you may encounter a situation where some position no longer exists - it was closed at TP/SL/MC, for example.

An absolutely neutral event that does not affect anything

 
Vladislav Boyko #:

An absolutely neutral event that does not affect anything

Unlike this one on MT5, for example.

This is one of the reasons why switching to MT5 is not economically feasible for me as a freelancer. MT5 has a number of nuances that greatly increase the time spent on developing reliable advisors.

For MT4, I can somehow compete in terms of cost of work with the guys who write unreliable, low-quality advisors for a couple of dollars. That is, thanks to my own developments/templates, I can offer the development of high-quality advisors at the price of a low-quality advisor.

 
Vladislav Boyko #:
I can offer the development of high-quality advisors at the price of a low-quality advisor

I cannot do this for MT5 because developing a reliable advisor on MT5 will take much more time than its counterpart on MT4. Customers have dozens of offers from developers for a couple of dollars. It's very hard to compete with this. Of course, the quality of advisors for a couple of dollars is usually very low, but customers don’t understand this.

[if the moderators want to delete my last couple of posts, then I don’t mind]

 
Vladislav Boyko #: William Roeder will throw stones at me for normalizing order prices😄
Vladislav Boyko #: SL and TP must be normalized.

SL/TP (stops) need to be normalized to tick size (not Point) — code fails on non-currencies.
          On 5Digit Broker Stops are only allowed to be placed on full pip values. How to find out in mql? - MQL4 programming forum #10 (2011)

And abide by the limits Requirements and Limitations in Making Trades - Appendixes - MQL4 Tutorial and that requires understanding floating point equality Can price != price ? - MQL4 programming forum (2012)

 
William Roeder #:

SL/TP (stops) need to be normalized to tick size (not Point) — code fails on non-currencies.
          On 5Digit Broker Stops are only allowed to be placed on full pip values. How to find out in mql? - MQL4 programming forum #10 (2011)

And abide by the limits Requirements and Limitations in Making Trades - Appendixes - MQL4 Tutorial and that requires understanding floating point equality Can price != price ? - MQL4 programming forum (2012)

I've never had a problem with SL/TP not being normalized to tick size. I wrote a small script to find the desired symbol and found it (metaquotes demo).

Tomorrow (when the market opens) I will try to place SL, TP and pending orders “within” the tick size

2024.04.07 08:23:05.491 Script scriptTest EURUSD,M15: removed
2024.04.07 08:23:05.491 scriptTest EURUSD,M15: uninit reason 0
2024.04.07 08:23:05.491 scriptTest EURUSD,M15: There were no errors.
2024.04.07 08:23:05.491 scriptTest EURUSD,M15: EURCAD.wt point 0.00001000 tick size 0.00001000, is equal: true
2024.04.07 08:23:05.491 scriptTest EURUSD,M15: GBPUSD.wt point 0.00001000 tick size 0.00001000, is equal: true
2024.04.07 08:23:05.491 scriptTest EURUSD,M15: XAUUSDcheck point 0.01000000 tick size 0.01000000, is equal: true
2024.04.07 08:23:05.491 scriptTest EURUSD,M15: GBPUSDcheck point 0.00001000 tick size 0.00001000, is equal: true
2024.04.07 08:23:05.491 scriptTest EURUSD,M15: XAGUSD point 0.01000000 tick size 0.01000000, is equal: true
2024.04.07 08:23:05.491 scriptTest EURUSD,M15: XAUUSD point 0.01000000 tick size 0.01000000, is equal: true
2024.04.07 08:23:05.491 scriptTest EURUSD,M15: NZDUSD point 0.00001000 tick size 0.00001000, is equal: true
2024.04.07 08:23:05.491 scriptTest EURUSD,M15: NZDJPY point 0.00100000 tick size 0.00100000, is equal: true
2024.04.07 08:23:05.491 scriptTest EURUSD,M15: CADCHF point 0.00001000 tick size 0.00001000, is equal: true
2024.04.07 08:23:05.491 scriptTest EURUSD,M15: EURCAD point 0.00001000 tick size 0.00001000, is equal: true
2024.04.07 08:23:05.491 scriptTest EURUSD,M15: EURNZD point 0.00001000 tick size 0.00001000, is equal: true
2024.04.07 08:23:05.491 scriptTest EURUSD,M15: CHFJPY point 0.00100000 tick size 0.00100000, is equal: true
2024.04.07 08:23:05.491 scriptTest EURUSD,M15: AUDJPY point 0.00100000 tick size 0.00100000, is equal: true
2024.04.07 08:23:05.491 scriptTest EURUSD,M15: AUDCHF point 0.00001000 tick size 0.00001000, is equal: true
2024.04.07 08:23:05.491 scriptTest EURUSD,M15: AUDCAD point 0.00001000 tick size 0.00005000, is equal: false
2024.04.07 08:23:05.491 scriptTest EURUSD,M15: AUDNZD point 0.00001000 tick size 0.00001000, is equal: true
2024.04.07 08:23:05.491 scriptTest EURUSD,M15: GBPJPY point 0.00100000 tick size 0.00100000, is equal: true
2024.04.07 08:23:05.491 scriptTest EURUSD,M15: CADJPY point 0.00100000 tick size 0.00100000, is equal: true
2024.04.07 08:23:05.491 scriptTest EURUSD,M15: GBPCHF point 0.00001000 tick size 0.00001000, is equal: true
2024.04.07 08:23:05.491 scriptTest EURUSD,M15: EURJPY point 0.00100000 tick size 0.00100000, is equal: true
2024.04.07 08:23:05.491 scriptTest EURUSD,M15: EURCHF point 0.00001000 tick size 0.00001000, is equal: true
2024.04.07 08:23:05.491 scriptTest EURUSD,M15: EURAUD point 0.00001000 tick size 0.00001000, is equal: true
2024.04.07 08:23:05.491 scriptTest EURUSD,M15: EURGBP point 0.00001000 tick size 0.00001000, is equal: true
2024.04.07 08:23:05.491 scriptTest EURUSD,M15: AUDUSD point 0.00001000 tick size 0.00001000, is equal: true
2024.04.07 08:23:05.491 scriptTest EURUSD,M15: USDCAD point 0.00001000 tick size 0.00001000, is equal: true
2024.04.07 08:23:05.491 scriptTest EURUSD,M15: USDJPY point 0.00100000 tick size 0.00100000, is equal: true
2024.04.07 08:23:05.491 scriptTest EURUSD,M15: EURUSD point 0.00001000 tick size 0.00001000, is equal: true
2024.04.07 08:23:05.491 scriptTest EURUSD,M15: GBPUSD point 0.00001000 tick size 0.00001000, is equal: true
2024.04.07 08:23:05.491 scriptTest EURUSD,M15: USDCHF point 0.00001000 tick size 0.00001000, is equal: true
2024.04.07 08:23:05.491 scriptTest EURUSD,M15: Symbols total 29, are all symbols selected: true
2024.04.07 08:23:05.491 scriptTest EURUSD,M15: initialized
2024.04.07 08:23:05.471 Script scriptTest EURUSD,M15: loaded successfully
#property strict
#define _selected true
#define _formatPrc "%.8f"

bool errorOccured = false;

void OnStart()
  {
   int total = SymbolsTotal(_selected);
   Print("Symbols total ", total, ", are all symbols selected: ", total == SymbolsTotal(false));
   for(int i = 0; i < total; i++)
     {
      string name = SymbolName(i, _selected);
      double tickSize = marketInfo(name, MODE_TICKSIZE);
      double point = marketInfo(name, MODE_POINT);
      if(errorOccured)
         break;
      PrintFormat("%s point "_formatPrc" tick size "_formatPrc", is equal: %s", name, point, tickSize, point == tickSize ? "true" : "false");
     }
   Print(errorOccured ? "An error has occurred!" : "There were no errors.");
  }

double marketInfo(string symbol, ENUM_MARKETINFO type)
  {
   ResetLastError();
   double result = MarketInfo(symbol, type);
   if(_LastError == ERR_NO_ERROR && result > 0.0)
      return(result);
   errorOccured = true;
   PrintFormat("MarketInfo(%s) failed! Error %i, result "_formatPrc, EnumToString(type), _LastError, result);
   return(result);
  }