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

 
EVGENII SHELIPOV #:

Good day all!!!

I'm writing code for an EA for Trailing Stop of group orders from the average price of a grid of orders.

No errors in the log, but the trawl does not work either. Here is the code please suggest where the error is. Thank you!

The trawl is in the wrong place!

It should look something like this

If breakeven price+profit-tral! = TakeProfit, start trawl!

Where does this data come from?

//+----------------------------------------------------------------------------+
//| Трейлинг стоп групповых ордеров                                            |
//+----------------------------------------------------------------------------+
void TrailingGroupOrder()
{
    price += OrderOpenPrice() * OrderLots();
    order_lots += OrderLots() ;
    for(int i = OrdersTotal()-1; i>=0; i--)
    {
     if(OrderSelect(i, SELECT_BY_POS, MODE_TRADES))

OrderOpenPrice

Returns the open price of the selected order

doubleOrderOpenPrice();

Note:

The order must be pre-selected using the OrderSelect() function.

 
MakarFX #:

Thank you.)

 
MakarFX #:

That's not where the trawl is standing!

It should go like this:

if the breakeven price+profit-tral! = TakeProfit run the trawl

Good afternoon Makar!!!!

As far as I understand it this is the line in question. In this case a buy order:

if(Bid - NormalizeDouble(price / order_lots, Digits) > TrailingStopGroupOrder*Point || OrderStopLoss() == 0)

Makar if you could explain in more detail

 
MakarFX #:

That's not where the trawl is standing!

It should go like this:

if the breakeven price+profit-tral! = TakeProfit run the trawl

Where does this data come from?

Makar, you're talking in riddles today.

There may be another question why we calculate the breakeven price without checking????

 
MakarFX #:

That's not where the trawl is standing!

It should go like this:

if the breakeven price+profit-tral! = TakeProfit run the trawl

Where does this data come from?

OrderOpenPrice

Returns the open price of the selected order

doubleOrderOpenPrice();

Note:

The order must be pre-selected using the OrderSelect() function.

Yes, I thought of that and you've already written

 
EVGENII SHELIPOV #:

Good afternoon Makar!!!!

As far as I understand it, this is the line in question. In this case a buy order:

Makar if you can explain in more detail

You have a group of orders, you define a breakeven point and create a line, and this is better done as a separate function!

    avg_price = NormalizeDouble(price / order_lots, Digits);
     {
     ObjectDelete(0, "AveragePriceLine");
     ObjectCreate(0,"AveragePriceLine" ,OBJ_HLINE, 0, 0, avg_price);
     ObjectSet("AveragePriceLine",OBJPROP_COLOR, Magenta);
     }

Then you have the profit value in pips that you want to get and add / subtract to / from avg_price

    if (otype == OP_BUY) tp = NormalizeDouble (avg_price + TakeProfitGroupOrder*Point, Digits);
    if (otype == OP_SELL) tp = NormalizeDouble (avg_price - TakeProfitGroupOrder*Point, Digits);

And then a separate trawl function

for buying: if BID > avg_price = OrderModify()

for sales: if avg < avg_price = OrderModify()


Unfortunately in your code I see not logical actions (subjectively)

 
EVGENII SHELIPOV #:

That's what I was thinking and you've already written.

Separate out the functions so it's easier for you to navigate.

Here's an example of OnTick()

//+------------------------------------------------------------------+
//| Expert tick function                                             |
//+------------------------------------------------------------------+
void OnTick()
  {
//---
   if(GetProfitFromStart()>CountProfit || GetProfitFromStart()<CountLoss*-1)
     {
      CloseOrder();
     }
   sl  = MathMax(Stoploss, MarketInfo(_Symbol, MODE_STOPLEVEL)) * Point();
   SL  = NormalizeDouble(sl*Point(),Digits);
   tp  = MathMax(Takeprofit, MarketInfo(_Symbol, MODE_STOPLEVEL)) * Point();
   TP  = NormalizeDouble(tp*Point(),Digits);
   //---
   if(CountOrders()==0&&ObjectGetInteger(0,"lab_Button",OBJPROP_STATE))
     {
      if(TradeSignal()>=0)
        {
         SendOrder(TradeSignal());
        }
     }
   //---
   if (!IsTradeAllowed()) 
     {DrawLABEL("lab_Торговля",0,0,0,clrRed,"Торговля запрещена"); return;} 
   else
     {DrawLABEL("lab_Торговля",0,0,0,clrLime,"Торговля разрешена");}
  }
//+------------------------------------------------------------------+

As you can see there are only function calls

 
MakarFX #:

Separate the functions to make it easier for you to navigate.

Here's an example of OnTick()

As you can see there are only calls to functions.

Thank you, Makar. I'll concentrate my thoughts and think this way

 
EVGENII SHELIPOV #:

Thank you, Makar. I'll put my thoughts together and think in that direction.

(Speak up)
 
Question: How do I get an order out of the EA's custody? Maybe there are already some screenshots or mt4 functions that I am not aware of. Please, enlighten me. I do not have any eagerness and possibilities to study mql 3, 4, 5 etc..
Reason: