Download MetaTrader 5
To add comments, please log in or register
Publish your article. We will translate it into other languages!
Rezo_chitanava
45
Rezo_chitanava 2016.07.31 00:15 

hellow, i want to county losses trades untli one of them will not Get TakeProfit. if order gets takeprofit order count must set to 0.

i tried but my code dosn't work.

 

//+------------------------------------------------------------------+

int TotalOrderCount(int MagicNumber)

{

   int count = 0;

   

   for(int i = OrdersTotal() - 1; i >= 0; i--)

   {

      if(OrderSelect(i, SELECT_BY_POS, MODE_TRADES))

      {

         if(OrderSymbol() == Symbol() && OrderMagicNumber() == MagicNumber)

            count++;

      }

   }

   

   for(int i = OrdersHistoryTotal() - 1; i >= 0; i--)

   {

      if(OrderSelect(i, SELECT_BY_POS, MODE_HISTORY))

      {

         if(OrderSymbol() == Symbol() && OrderMagicNumber() == MagicNumber)

            if(OrderProfit() < 0) count++;

            else count = 0; 

      }

   }

   return(count);

whroeder1
13627
whroeder1 2016.07.31 15:00  
Rezo_chitanava: if order gets takeprofit order count must set to 0
my code dosn't work.
  1. Don't paste code
    Play video
    Please edit your post.
    For large amounts of code, attach it.

  2. "Doesn't work" is meaningless - just like saying the car doesn't work. Doesn't start, won't go in gear, no electrical, missing the key, flat tires - meaningless. There are no mind readers here.
  3. You assume history is ordered by date, it's not. Could EA Really Live By Order_History Alone? (ubzen) - MQL4 forum
  4. There are other things in history besides close orders, make sure the OrderType is Buy or Sell. If you're using pending orders, filter the first OrderSelect loop also.
  5. if(OrderProfit() < 0) count++;
    else count = 0; 
    Your code works just like you stated it should; as soon as you find a profitable trade you "set the count to zero." What you want is once you find a profitable trade, the count is how many losers you have had since.  Don't set it to zero, return that value.
Rezo_chitanava
45
Rezo_chitanava 2016.07.31 18:37  
extern double  Lot0         = 0.1;
extern double  Lots1_1      = 0.1;
extern double  Lots1_2      = 0.2;
extern double  Lots2_1      = 0.3;
extern double  Lots2_2      = 0.4;
extern double  Lots3_1      = 0.5;
extern double  Lots3_2      = 0.6;
extern double  Lots4_1      = 0.7;
extern double  Lots4_2      = 0.8;
extern double  Lots5_1      = 0.9;
extern double  Lots5_2      = 1.0;
extern double  Lots6_1      = 1.1;
extern double  Lots6_2      = 1.2;
extern double  Lots7_1      = 1.3;
extern double  Lots7_2      = 1.4; 


double Lot, Lot1, Lot2;
//+------------------------------------------------------------------+
//| Expert tick function                                             |
//+------------------------------------------------------------------+
void OnTick()
{
//---
   if(TotalOrderCount(Magic) == 0){ Lot = Lot0;}
   else if(TotalOrderCount(Magic) == 2){ Lot1 = Lots1_1; Lot2 = Lots1_2; }
   else if(TotalOrderCount(Magic) == 4){ Lot1 = Lots2_1; Lot2 = Lots2_2; }
   else if(TotalOrderCount(Magic) == 6){ Lot1 = Lots3_1; Lot2 = Lots3_2; }
   else if(TotalOrderCount(Magic) == 8){ Lot1 = Lots4_1; Lot2 = Lots4_2; }
   else if(TotalOrderCount(Magic) == 10){ Lot1 = Lots5_1; Lot2 = Lots5_2; }
   else if(TotalOrderCount(Magic) == 12){ Lot1 = Lots6_1; Lot2 = Lots6_2; }
   else if(TotalOrderCount(Magic) == 14){ Lot1 = Lots7_1; Lot2 = Lots7_2; }
   else{ Lot = Lot0; Lot1 = Lot0; Lot2 = Lot0; }
   
   Comment(DoubleToStr(Lot1, 3) + "       " +  DoubleToStr(Lot2, 3) + "\n" + IntegerToString(TotalOrderCount(Magic)));
   
//---
}
//+------------------------------------------------------------------+
int TotalOrderCount(int MagicNumber)
{
   int count = 0;
   
   for(int i = OrdersTotal() - 1; i >= 0; i--)
   {
      if(OrderSelect(i, SELECT_BY_POS, MODE_TRADES))
      {
         if(OrderSymbol() == Symbol() && OrderMagicNumber() == MagicNumber)
            if(iBarShift( Symbol(), PERIOD_D1, OrderOpenTime()) == 0)
            count++;
      }
   }
   
   for(int i = OrdersHistoryTotal() - 1; i >= 0; i--)
   {
      if(OrderSelect(i, SELECT_BY_POS, MODE_HISTORY))
      {
         if(OrderSymbol() == Symbol() && OrderMagicNumber() == MagicNumber)
            if(iBarShift( Symbol(), PERIOD_D1, OrderOpenTime()) == 0)
            count++;
      }
   }
   return(count);
}

Rezo_chitanava
45
Rezo_chitanava 2016.07.31 18:39  

i do this but it resets count to 0 when time is over. i want to count until ordee will not be closed at tp. could you help me?

/
To add comments, please log in or register