[ARCHIVE]Any rookie question, so as not to clutter up the forum. Professionals, don't pass it by. Can't go anywhere without you - 5. - page 46

 

If you know the function for calculating the total balance of loss of CLOSED positions by SL and the total balance of OPEN profitable trades, please write.

Loss balance calculation should start from the last maximum deposit value

 

Good afternoon!!! My function is swearing with forty cuss words - I obviously didn't know very much, and also forgot how to make it up

void  SELL { double Price1_SELL= (Bid-Dist*Point) ; double TP1_SELL=Price1_SELL-TP*Point; double SL1_SELL=Price1_SELL+SL*Point;
   
   double  Price2_SELL= (Price1_SELL -Dist*Point) ;double   TP2_SELL=Price2_SELL-TP*Point;double   SL2_SELL=Price2_SELL+SL*Point;
   
   double  Price3_SELL=(Price2_SELL -Dist*Point) ; double  TP3_SELL=Price3_SELL-TP*Point; double  SL3_SELL=Price3_SELL+SL*Point;
   
   double  Price4_SELL= (Price3_SELL -Dist*Point) ; double  TP4_SELL=Price4_SELL-TP*Point; double  SL4_SELL=Price4_SELL+SL*Point;
   
   double  Price5_SELL= (Price4_SELL -Dist*Point) ;double   TP5_SELL=Price5_SELL-TP*Point; double  SL5_SELL=Price5_SELL+SL*Point;}
 
Dimka-novitsek:

Good afternoon!!! My function is swearing with forty cuss words - I obviously didn't know very much, and also forgot how to make it up


Diman! Good night! You need a rest, for not a function, but some bullshit you wrote...

 
So I said I don't remember. I'm going to finish it. Ordersends. What's wrong with the compiler?
 
Dimka-novitsek:
I'm telling you, I don't remember. I'll write it in. Ordersends. What doesn't the compiler like?

That's not how f-i's are written. Read the textbook.

 
Thank you!!! Reading.
 
А. The staples were not enough for her!
 

Hello, my Expert Advisor puts pending stops. When checking in the tester only SELL_STOP is working, instead of BUY_STOP an error Order Send error/ Error opening Buy order:130 appears.

extern int TrailingStop=30;
//-----------------------------------------------------------------------------------------------+
for(cnt=0;cnt<total;cnt++)
     {
      OrderSelect(cnt, SELECT_BY_POS, MODE_TRADES);
      if(OrderType()<=OP_SELLSTOP &&   // check for opened position 
         OrderSymbol()==Symbol())  // check for symbol
        {
         if(OrderType()==OP_BUY)   // long position is opened
           {
            // check for trailing stop
            if(TrailingStop>0)  
              {                 
               if(Bid-OrderOpenPrice()>Point*TrailingStop)
                  {
                     OrderModify(OrderTicket(),OrderOpenPrice(),Bid-Point*TrailingStop,OrderTakeProfit(),0,Green);
                     return(0);
                    }
              }
           }
         else // go to short position
           {
            // check for trailing stop
            if(TrailingStop>0)  
              {                 
               if((OrderOpenPrice()-Ask)>(Point*TrailingStop))
                    {
                     OrderModify(OrderTicket(),OrderOpenPrice(),Ask+Point*TrailingStop,OrderTakeProfit(),0,Red);
                     return(0);
                    }
              }
           }
        }
     }

   
   return(0);

Help me to find the reason!

 

The reason is a lack of logic!

for(cnt=0;cnt<total;cnt++)
     {
      OrderSelect(cnt, SELECT_BY_POS, MODE_TRADES);
      if(OrderType()<=OP_SELLSTOP &&   // check for opened position 
         OrderSymbol()==Symbol())  // check for symbol
        {
         if(OrderType()==OP_BUY)   // long position is opened
           {
How to understand? If CELLSTOP, what does BAI have to do with it?
 
Twilight:

How do I know if the last 1-2-3 orders were losing?

And in general, how do I know what the last order was?


Recently I have written a function that, in case of the last losing order, returns the type of this order. In other words, if fHistory() == 0, the last losing order was Buy, fHistory() == 1, the last losing order was Sell. If we want to track the profitable orders, then change the sign in the line like this: if(OrderProfit() > 0 ).

//+----------------------------------------------------------------------------+
// Прибыльно или убыточно закрылся последний ордер, и возврат типа такого ордера
int fHistory(){
  for(int i=OrdersHistoryTotal(); i >= 0; i--){              // Выборка в истории
     if (OrderSelect(i,SELECT_BY_POS,MODE_HISTORY)==true){   // Если есть следующий в истории
        if(OrderMagicNumber()!=magN) continue;               // Ордера не нашего эксперта
        if(OrderProfit() < 0 ) return (OrderType());         // Если убыток по посл.ордеру вернем тип ордера
     }
  }
  return(-1);
}

The variable magN is the Magic order declared globally.

Reason: