need advice from a trawl pro that controls two positions independently of each other, how can it be implemented? - page 6

 
charony:

That's about how it works.


only I am not interested in the criteria for activating the trawl

i need trawl to handle each open position separately from others

This trail starts trawling only positions that are in the plus, it doesn't move stops on negative positions.

"It's possible to set a 50 pips trawl for both positions,

but they won't close at the same time.

Both positions have a 50 pips trawl"

Both will close only if they are in the plus, if one is in the plus and the other in the minus then the stop will move only at the plus one.

 
PozitiF:

I haven't read all pages, but I think I've got the gist of it.

https://www.mql5.com/ru/articles/1390 here, create an array with orders, when you create an order take a magic from somewhere, you can write Magic = 1 in the input parameters of the EA, for example, and increase the value by 1 with the next open order,

If the terminal crashes, you will be able to restore the array.

The trull that Magic takes as a parameter on the previous page I wrote.



It's not the right array, you can't put int and double together in the same array.
 
charony:

The array is wrong, you can't put int and double together in the same array.
You can, it just puts an integer before the dot.
 
PozitiF:
You can, it just puts an integer before the dot.


double price EUR/USD 1.3915 in int 1

int sell = 1, in double sell = 1.0

then look for why the program doesn't work????????

or worse, Uncle "Kolya Margin" comes along.

 

And why would you put the price in int, I didn't write anything about that at all.

I wrote that you can put the int number in a variable of type double.

from double then back to int again and it all works again for you) https://www.mql5.com/ru/forum/136406

 

I put int MN= TimeCurrent(); and this OrderSend(Symbol(),OP_BUY,Lots_New,Ask,2,0,0,NULL,MN,0,Green);

i.e. a magik is assigned to each order

in the trawl after the selection

int Tip=OrderType();

if(OrderSymbol()!=Symbol()||Tip>1)continue;

if(OrderMagicNumber()==MN)

I am going to try now.

 

No it's not, something else must be wrong, I'm talking about the trawl now.

We'll look for it.

 
PozitiF:

And why would you put the price in int, I didn't write anything about that or suggest it at all.

I wrote that you can put the int number in a variable of type double.

from double then back to int again and it all works again) https://www.mql5.com/ru/forum/136406

double price EUR/USD 1.3915 into int 1 and then back into double again and you get 1.0.

double price EUR/USD 1,3915 =========> double 1.0

where laugh??????????????????



int 1------> double 1.0 ------> int 1 will probably work here, but it's not cool

 
charony:

No it's not, something else must be wrong, I'm talking about the trawl now.

I'll look for it.

Trall is 100% working, it works in almost all my EAs.

int Trall = 50;

int MN= TimeCurrent();

OrderSend(Symbol(),OP_BUY,Lots_New,Ask,2,0,0,NULL,MN,0,Green);

int Tip=OrderType();

if(OrderSymbol()!=Symbol()||Tip>1)continue;
for(int i = 0; i<OrderTotals(); i++){
   if(OrderSelect(i, SELECT_BY_POS, MODE_TRADES) == true){
      if(OrderMagicNumber()==MN) TrailingStop(Trall, 5, MN);
   }
}

It should trawl.

 
//+-----------------------------trailingstop----------------------------------------------+
 total=OrdersTotal();
    for(int n=0;n<total;n++)
     {
      if(OrderSelect(n, SELECT_BY_POS, MODE_TRADES) == true)
         { 
         int Tip=OrderType();                  
         if(OrderSymbol()==Symbol()&&OrderType()==Tip)
            {
                MN = OrderMagicNumber();
                TrailingStop(level_ts, level_step , MN);
            } 
         }    
      }
 
  

   
   return;                             // exit start()
  }
//+-----------------------------start end----------------------------------------------+

void TrailingStop(int level_ts,int level_step , int MN) 
{
   int ot, err, quantity_orders, cx;
   bool fm;
   double op, as, bd, pt, sl, tp, ut;
//----
   quantity_orders = OrdersTotal();
   if(quantity_orders >= 0) {
      for(cx = 0; cx < quantity_orders; cx++) {
         if(!OrderSelect(cx, SELECT_BY_POS, MODE_TRADES)) {
            Print("Error: SimpleTrailing(), OrderSelect: " + cx + ". Îøèáêà: " + GetLastError());
         }
         if (OrderMagicNumber()==MN ) 
         {   
            pt = MarketInfo(OrderSymbol(), MODE_POINT);
            bd = MarketInfo(OrderSymbol(), MODE_BID);
            as = MarketInfo(OrderSymbol(), MODE_ASK);
            op = OrderOpenPrice();
            ot = OrderType();
            sl = OrderStopLoss();
            tp = OrderTakeProfit();
            ut = level_ts + level_step;
         
            if(ot == OP_BUY) {
               if(sl == 0 || sl < op) {                              
                  if(op <  (bd - ut * pt)) {                         
                     sl = bd - level_ts * pt;
                  }
               }
               else {
                  if(sl < (bd - ut * pt) && bd > (op + ut * pt)) {
                     sl = bd - level_ts * pt;
                  }
               }
            }
            if(ot == OP_SELL) {
               if(sl == 0 || sl > op) {
                  if(op > (as + ut * pt)) {
                     sl = as + level_ts * pt;
                  }
               }
               else {
                  if(sl > (as + ut * pt) && as < (op - ut * pt)) {
                     sl = as + level_ts * pt;
                  }
               }
            }
            if (sl != OrderStopLoss()) {
               op = NormalizeDouble(op, Digits);
               tp = NormalizeDouble(tp, Digits);
               sl = NormalizeDouble(sl, Digits);
               fm = OrderModify(OrderTicket(), op, sl, tp, 0, CLR_NONE);
               
            }
         }
      }
   }
}

//+-----------------------------trailingstop end----------------------------------------------+

I inserted the code, the trawl works.

but the problem persists.