Any rookie question, so as not to clutter up the forum. Professionals, don't pass by. Nowhere without you - 6. - page 191

 
Go to
 Alert("Исполнение программы");
    double p[100];
    int i =0;
    int n = OrdersTotal ();
    int t =0;
    
    for (i=0; i<=n+1; i++)
    {
    
    OrderSelect(i,SELECT_BY_POS,MODE_TRADES);
    if (OrderSelect(i,SELECT_BY_POS,MODE_TRADES)==true)
     {
     
      p[i+1] = OrderProfit();      // р - це прибуток ордера
     
     } 
    }
    for (i=0; i<=n+1; i++)
    {
    if (p[i+1]>0)                  // якщо ордер прибутковий, то його 
    {
      Alert("Є прибуток ордер ",i+1);
      OrderSelect(i+1,SELECT_BY_POS,MODE_TRADES); 
      Alert("Маємо помилку ",GetLastError());
      Alert("Вибрали ордер ",i+1);
      double ld_Price;
      if (OrderType() == 0) ld_Price = NormalizeDouble (Bid, Digits);
      else ld_Price = NormalizeDouble (Ask, Digits);
      OrderClose (OrderTicket(), OrderLots(), ld_Price, 2);  // треба зачинити 
      Alert("Маємо помилку ",GetLastError());
      Alert("Закрили ордер ",i+1); 
       if ( OrderType()==OP_BUY)                              //  в залежності від того, якого типу ордер ми зачинили
       { 
        Alert("Ордер типу бай");
        OrderSend(Symbol(),OP_SELL,0.1,Bid,3,Bid-25*Point,Ask+25*Point);   // змінюється порядок відкривання наступних ордерів
        Alert("Відкрили ордер типу селл");
        Sleep(10000);
        OrderSend(Symbol(),OP_BUY,0.1,Ask,3,Bid-25*Point,Ask+25*Point);
        Alert("Відкрили ордер типу бай");
        }else
      {
        OrderSend(Symbol(),OP_BUY,0.1,Ask,3,Bid-25*Point,Ask+25*Point);
        Alert("Відкрили ордер типу бай");
        Sleep(10000);
        OrderSend(Symbol(),OP_SELL,0.1,Bid,3,Bid-25*Point,Ask+25*Point);    
        Alert("Відкрили ордер типу селл");
      }
    } 
   } 
    Alert("Последняя ошыбка ",GetLastError()); 
//----
   return(0);
  }

find that "stupidity" be merciful, have mercy on a man tortured by Pascal.

 
artmedia70:
When modifying a market position, the price must be set and equal to the opening price of the position: OrderOpenPrise()

Then this function, in your opinion, will not work? I haven't tested it but it seems to me to be a part of a working code (this Ilan was obviously rebuilt from something debugged at best). Or is it still a crummy code?

void TrailingAlls(int pType, int stop, double AvgPrice) {
   int profit;
   double stoptrade;
   double stopcal;
   if (stop != 0) {
      for (int trade = OrdersTotal() - 1; trade >= 0; trade--) {
         if (OrderSelect(trade, SELECT_BY_POS, MODE_TRADES)) {
            if (OrderSymbol() != Symbol() || OrderMagicNumber() != MagicNumber) continue;
            if (OrderSymbol() == Symbol() || OrderMagicNumber() == MagicNumber) {
               if (OrderType() == OP_BUY) {
                  profit = NormalizeDouble((Bid - AvgPrice) / Point, 0);
                  if (profit < pType) continue;
                  stoptrade = OrderStopLoss();
                  stopcal = Bid - stop * Point;
                  if (stoptrade == 0.0 || (stoptrade != 0.0 && stopcal > stoptrade)) OrderModify(OrderTicket(), AvgPrice, stopcal, OrderTakeProfit(), 0, Aqua);
               }
               if (OrderType() == OP_SELL) {
                  profit = NormalizeDouble((AvgPrice - Ask) / Point, 0);
                  if (profit < pType) continue;
                  stoptrade = OrderStopLoss();
                  stopcal = Ask + stop * Point;
                  if (stoptrade == 0.0 || (stoptrade != 0.0 && stopcal < stoptrade)) OrderModify(OrderTicket(), AvgPrice, stopcal, OrderTakeProfit(), 0, Red);
               }
            }
            Sleep(1000);
         }
      }
   }
}
 
Hello, you need to write an Expert Advisor on the strategy 3 candles.trade is conducted on the Renko charts which are cleared of market noise.When three consecutive bars in the same direction to open an order to buy or sell,stop loss put on top of the preceding bar,after closing the candle takes a stop loss on prevedshego bar
 
artmedia70:

PS If I were you, I wouldn't look for "efficient algorithms" in that code - it looks like the guy wrote the code without really knowing what he's doing there...

Yes, the code is very specific with a lot of redundancy and not only that. But I'm interested not so much in algorithms as such but in the approach to implementing the idea behind them. I'm looking at the general picture, or something like that. What is put into individual functions, how the same trailing arm is implemented, as opposed to my own, etc. I am self-taught and it is just useful for me :)
 
artmedia70:
In the right place - which place is that?


For example an order is in the 1200 point position already... and the price e.g. went down and the stars aligned so that in this place an order must be placed... and the order is already there and not to lower the balance below the required one not to place 2 orders each, for example
 
yan720:

Then do you think this function won't work? I haven't tested it, but it seems to me to be part of working code (this Ilan was obviously rebuilt from something debugged at best). Or is it still a crummy code?

Well... the code is not for real. At the very least.

 
The essence of the question is the following. I want to change the standard MACD simple Expert Advisor, but I am a total zero in programming.
I want to change the EA to work with a grid, stops and a magik instead of a single order.
Here are the variables I wanted to add:
Stoploss = is placed at the same level for the entire grid, for example, is equal to EUR/USD = 200pp and is placed at the level of 1.3450 for all orders in the grid
MaxOnDer = Maximum number of orders in the grid, e.g. if=3, then max orders in the grid will be 3
Dist = Distance between two pending orders

Lommultiplicator = The ratio of the lot size of the next order in the grid.

Magic= magic number

We exit the trade as in the initial code, i.e. all orders in the grid will be closed when the 1st order is closed.

That is all
If anyone otvezvayut would be very grateful!
I would be very thankful! Maybe someone has a ready-made Expert Advisor, which is already implemented in life, too, will do.
 
sannin:

there is for example an order at 1200 points already... and the price went down, for example, and the stars are lined up so that in this place the order must be placed... and the order is already there and not to lower the balance below the required one so as not to place 2 orders by one, let's say

It goes something like this:

//+----------------------------------------------------------------------------+
bool ExistOrdersByPrice(string sy, int op, int mn, double pp) {
   int i, k=OrdersTotal()-1;
   for (i=k; i>=0; i--) {
      if (OrderSelect(i,SELECT_BY_POS)) {
         if (OrderMagicNumber()!=mn)   continue;
         if (OrderSymbol()!=sy)        continue;
         if (OrderType()!=op)          continue;
         if (MathAbs(OrderOpenPrice()-pp)<0.5*Point) return(true);
         }
      else Print("FUNC ExistOrdersByPrice() : ошибка выбора ордера "+GetLastError());
      }
   return(false);
}
//+----------------------------------------------------------------------------+

To check if there is a BuyStop order on the current symbol at the price of 1.35000 with Magic, we call the function:

//+----------------------------------------------------------------------------+
   if (!ExistOrdersByPrice(Symbol(), OP_BUYSTOP, Magic, 1.35000)) {
      // тут код, если нет такого ордера
      }
   else {
      // тут код, если есть такой ордер
      }
//+----------------------------------------------------------------------------+
 
atztek:

If you are talking about documentation, highlight the word in the MetEditor and press F1. Or go online, for example:
https://docs.mql4.com/ru/customind/SetLevelStyle

Of course thank you, but if you're too lazy to read the question, then what's the point of answering? I can change the value, thickness, colour and style of the levels in the indicator in the two functions I have. I don't have access to the description. I'm asking again, does anybody know the answer? I don't know if I've seen it before.

I attached a picture to show what I need.

 
Desead:

Of course thank you, but if you're too lazy to read the question, then what's the point of answering? I can change the value, thickness, colour and style of the levels in the indicator in the two functions I have. I don't have access to the description. I'm asking again, does anybody know the answer? I don't know if I've seen it before.

I attached a picture to show what I need.


It wasn't and probably never will be in this form.
Reason: