Any questions from newcomers on MQL4 and MQL5, help and discussion on algorithms and codes - page 1662

 
Taras Slobodyanik #:

why do you need 3 methods?
it is enough to do everything in one

  • checked the order

- modified
- not modified

This is interesting!

Taras, let's say we have three buy orders with TP and SL, then in one order we modified SL.

Question: How do I find the order which has been modified?

 
Taras Slobodyanik #:

why do you need 3 methods?
it is enough to do everything in one

  • checked the order

- modified
- not modified

There are two already, one controls array size via OrdersTotal() where tickets of modified orders are stored, and the other one searches this array for tickets. But now I've changed code elsewhere, not related to all this, and for some reason I'm catching an error (array overrun).
 
MakarFX #:

Interesting!

Taras, let's say there are three buy orders with TP and SL, then in one order SL was changed.

Question: How do I find the order which has been changed?

Obviously, the SL (or TP) was changed for a reason, right?
We should check it based on some conditions.

Then at the next check this condition will be defined as "fulfilled" - the order has already been modified.


PS. If we are talking about manual modification, someone will change something without EA's knowledge, then of course we need to collect an array-structure and constantly compare it with market orders.

 
Taras Slobodyanik #:

why do you need 3 methods?
it is enough to do everything in one

  • checked the order

- modified
- not modified

The order is not 1, let's say there are 10 of them. I write the ticket of each modified one to an array. But so far this is a problem.
 
MakarFX #:

Removed

MakarFX, thanks! Now there is no extra non-signal first order, but now for some reason the first signal order (normal) is entering 2 candles earlier))) I attached a screenshot from the tester to my message, but even in spite of this first order - the most important thing is done, thank you very much again) With magicians got it, then I will make an external variable and when I attach the espert to a particular currency pair chart, I will change the number for each pair individually.

 
Nerd Trader #:
The order is not 1, there are 10 orders. I will write the ticket of each modified one to the array. But so far, this is a problem.

it does not matter how many orders there are - if the TP/SL do not need to be changed, according to the conditions = the order has already been modified.

 
SanAlex #:

that one is good for fun in the tester.

and this one is for you, as a gift - to make money.

\\\\\\\\\\\\\\\\\\\\\\\\\\

I ran it for testing - we'll see how it works tonight.

\\\\\\\\\\\\\\\\\\\\\\\\\\\

checked how the pattern changes on all the charts - everything worked! -how the overall profit hit the target.


SanAlex, very interesting, I will definitely look into this EA in detail, thanks!

 

Guys, good day on the code advise, here's a chart on the right of the two trades minus buy - is covered by a sell, sell buy, according to the algorithm should enter into the buy, but why - then these two fi-tions, which look and produce a minus trade the most recent in history - show both in the plus! How to write and where the error - this TS reversal, at the averaging - these same f-i work properly, in short, after the minus-sell - have to open buy, but it does not open, because In other words, it should open buy if my order is losing, but buy does not open, because f-i think if the deal is losing the most edge, this f-iia report TRUE, otherwise it's false, but they both report TRUE. Please help me decide.



// проверка предыдущего минусового селл
bool Calc_Loss_SELL()
  {
   bool ord;
   bool TotalLot=false;
   HistorySelect(TimeCurrent()-HistoryDaysLoadI*86400,TimeCurrent());
   for(int i=HistoryDealsTotal()-1; i>=0; i--)
     {
      ulong ticket=HistoryDealGetTicket(i);
      ord=HistoryDealSelect(ticket);
      if(ord && HistoryDealGetString(ticket,DEAL_SYMBOL) == _Symbol
         && HistoryDealGetInteger(ticket,DEAL_MAGIC) == MagicC
         && HistoryDealGetInteger(ticket,DEAL_ENTRY) == DEAL_ENTRY_OUT
         && HistoryDealGetInteger(ticket,DEAL_TYPE) ==  DEAL_TYPE_BUY)
        {
         if(HistoryDealGetDouble(ticket,DEAL_PROFIT) < 0)
           {
            TotalLot=true;
            if (УСРЕДНЯЛКА) Print(" усреднение в селл разрешено ",TotalLot);
            else  Print(" ПЕРЕВОРОТ В БАЙ разрешен ",TotalLot);
            break;
           }
         else
           {
            break;
           }
        }
     }
   return (TotalLot);
  }


// проверка предыдущего минусового бай
bool Calc_Loss_BUY()
  {
   bool ord;
   bool TotalLot=false;
   HistorySelect(TimeCurrent()-HistoryDaysLoadI*86400,TimeCurrent());
   for(int i=HistoryDealsTotal()-1; i>=0; i--)
     {
      ulong ticket=HistoryDealGetTicket(i);
      ord=HistoryDealSelect(ticket);
      if(ord && HistoryDealGetString(ticket,DEAL_SYMBOL) == _Symbol
         && HistoryDealGetInteger(ticket,DEAL_MAGIC) == MagicC
         && HistoryDealGetInteger(ticket,DEAL_ENTRY) == DEAL_ENTRY_OUT
         && HistoryDealGetInteger(ticket,DEAL_TYPE) == DEAL_TYPE_SELL)
        {
         if(HistoryDealGetDouble(ticket,DEAL_PROFIT) < 0)
           {
            TotalLot=true;
            if (УСРЕДНЯЛКА) Print(" усреднение в бай разрешено ",TotalLot);
            else  Print(" ПЕРЕВОРОТ В СЕЛЛ разрешен ", TotalLot);
            break;          
           }
         else
           {
            break;
           }
        }
     }
   return (TotalLot);
  }


    //----------------------------------------------
      // проверка условий ПЕРЕВОРОТА В СЕЛЛ
      // нет поз рыночных и предыдущая сделка В БАЙ была минусовая и не было минусового селла
       Print(" Calc_Loss_BUY(): ",Calc_Loss_BUY(), " Calc_Loss_SELL(): ",Calc_Loss_SELL());
      
      if(!PositionSelect(Symbol()) && Calc_Loss_BUY() && !Calc_Loss_SELL())
        {
         m_trade.Sell(CalcLot(),_Symbol,LastTick.bid,LastTick.ask+double(SLE)*_Point,LastTick.bid-double(TPE)*_Point - _Spread*_Point);
         Print(" ПЕРЕВОРОТ БАЯ В СЕЛЛ, Calc_Loss_BUY(): ",Calc_Loss_BUY());
        }

 
      // проверка условий ПЕРЕВОРОТА в SELL
      // нет поз рыночных и предыдущий селл был минусовой И НЕ БЫЛО МИНУСОВОГО БАЙ
      
      if(!PositionSelect(Symbol()) && Calc_Loss_SELL() && !Calc_Loss_BUY())
        {
         m_trade.Buy(CalcLot(),_Symbol,LastTick.ask,LastTick.bid-double(SLE)*_Point,LastTick.ask+double(TPE)*_Point + _Spread*_Point);
         Print(" ПЕРЕВОРОТ СЕЛЛА В БАЙ, Calc_Loss_SELL(): ",Calc_Loss_SELL());
        }

I can't get it to open buy, but it should open it after a ubutical sell!!!!!!!!!


In essence, the problem comes down to determining profit or loss was closed Marginal position, which became a buy or sell trade and look further on its type!

HELP! PLUS!

 

Good day!

There are two functions: a function to calculate the whole grid of orders and a function to close orders

//+------------------------------------------------------------------+
double CalculiteProfit()
{
    double oProfit = 0;
    for(int i = OrdersTotal()-1; i>=0; i--)
    {
      if(OrderSelect(i, SELECT_BY_POS, MODE_TRADES))
      {
        if(OrderSymbol() == Symbol() && OrderMagicNumber() == Magic)
        {
          if (OrderType() == OP_BUY || OrderType() == OP_SELL)
          {
            oProfit += OrderProfit();
          }
        }
      }
    }
    return(oProfit);
}
//+------------------------------------------------------------------+
 double FindLastBuyPrice()
{
   int oldticket, ticket = 0;
   double oldopenprice = 0;
   
   for(int cnt = OrdersTotal()-1; cnt>=0; cnt--)
   {
    if(OrderSelect(cnt, SELECT_BY_POS, MODE_TRADES))
     {
        if(OrderSymbol() == Symbol() && OrderMagicNumber() == Magic && OrderType() == OP_BUY)
        {
          oldticket = OrderTicket();
          if (oldticket > ticket)
          {
            ticket = oldticket;
            oldopenprice = OrderOpenPrice();
          } 
        }
     }
   }
   return(oldopenprice);
 }
//+------------------------------------------------------------------+

There are also conditions for closing orders

 double op = CalculiteProfit(); 
     if (op >= Profit)
     {
       ClosseAll();
     }

Profit - in the settings in depo currency

The idea of it all: After the order grid calculation is equal to zero plusProfit in deposit currency, the whole order grid is closed

Please help me to change the code so that there would be points instead of Profit. Thank you.

 
Taras Slobodyanik #:

Obviously, the sl (or tp) was changed for a reason, wasn't it?
But according to some conditions.

So, at the next check this condition will be defined as "fulfilled" - the order has been modified.


If we are talking about manual changes, someone will change something without EA's knowledge, then of course we need to collect an array-structure and constantly compare it with market orders.

I had already forgotten... and in the beginning I did so (good thing I've committed), but the way of condition seemed unreliable, I wanted something more obvious to indicate an order that had been changed.

Reason: