CODE METATRADER4 HELP WANTED

 

HI,

I would like to insert in my expert advisor a DAILY LIMIT LOSS (different from a stoploss used by the trade committed).
Idea underlying permit to lose a few pips per day to EA, it stops during the day when it overpass this limit, then it starts again the next day.

How to codify the language MQL4 "LOSS DAILY LIMIT" in pips and is visible on setting EA's? And Where put the code in the script?


THANKS

 
prosper1:

HI,

I would like to insert in my expert advisor a DAILY LIMIT LOSS (different from a stoploss used by the trade committed).
Idea underlying permit to lose a few pips per day to EA, it stops during the day when it overpass this limit, then it starts again the next day.

How to codify the language MQL4 "LOSS DAILY LIMIT" in pips and is visible on setting EA's? And Where put the code in the script?


THANKS

only for money mikael@miktrade.com

 
Mike:

only for money mikael@miktrade.com

HI,

Thanks for your answer, but i don't have money for this. Coulde you give indications to build myself this code. For example the "daily limit loss". Or someone could help me freely .

 

I took this function from russian version of the forum (thx to KimIV):

Function TimeOpenLastPos()

//+----------------------------------------------------------------------------+
//|  Автор    : Ким Игорь В. aka KimIV,  http://www.kimiv.ru                   |
//+----------------------------------------------------------------------------+
//|  Версия   : 19.02.2008                                                     |
//|  Описание : Возвращает время открытия последней открытой позиций.          |
//+----------------------------------------------------------------------------+
//|  Parametrs:                                                                |
//|    sy - symbol                       (""   - any symbol,                   |
//|                                     NULL - current symbol)                 |
//|    op - operation                   (-1   - any position)                  |
//|    mn - MagicNumber                  (-1   - any magic)                    |
//+----------------------------------------------------------------------------+
datetime TimeOpenLastPos(string sy="", int op=-1, int mn=-1) {
  datetime t;
  int      i, k=OrdersTotal();

  if (sy=="0") sy=Symbol();
  for (i=0; i<k; i++) {
    if (OrderSelect(i, SELECT_BY_POS, MODE_TRADES)) {
      if (OrderSymbol()==sy || sy=="") {
        if (OrderType()==OP_BUY || OrderType()==OP_SELL) {
          if (op<0 || OrderType()==op) {
            if (mn<0 || OrderMagicNumber()==mn) {
              if (t<OrderOpenTime()) t=OrderOpenTime();
            }
          }
        }
      }
    }
  }
  return(t);
}

Function NumberOfLossPosToday():

//+----------------------------------------------------------------------------+
//|  Автор    : Ким Игорь В. aka KimIV,  http://www.kimiv.ru                   |
//+----------------------------------------------------------------------------+
//|  Версия   : 19.02.2008                                                     |
//|  Описание : Возвращает количество убыточных позиций, закрытых сегодня.     |
//+----------------------------------------------------------------------------+
//|  Parametrs:                                                                |
//|    sy - symbol                       (""   - any symbol,                   |
//|                                     NULL - current symbol)                 |
//|    op - operation                   (-1   - any position)                  |
//|    mn - MagicNumber                  (-1   - any magic)                    |
//+----------------------------------------------------------------------------+
int NumberOfLossPosToday(string sy="", int op=-1, int mn=-1) {
  datetime t;
  int      i, k=OrdersHistoryTotal(), kp=0;

  if (sy=="0") sy=Symbol();
  for (i=0; i<k; i++) {
    if (OrderSelect(i, SELECT_BY_POS, MODE_HISTORY)) {
      if (OrderSymbol()==sy || sy=="") {
        if (OrderType()==OP_BUY || OrderType()==OP_SELL) {
          if (op<0 || OrderType()==op) {
            if (mn<0 || OrderMagicNumber()==mn) {
              t=OrderCloseTime();
              if (Year()==TimeYear(t) && DayOfYear()==TimeDayOfYear(t)) {
                if (OrderProfit()<0) kp++;
              }
            }
          }
        }
      }
    }
  }
  return(kp);
}
And also function GetProfitOpenPosInPoint() (u can modify her to get loss of open positions in points):
//+----------------------------------------------------------------------------+
//|  Автор    : Ким Игорь В. aka KimIV,  http://www.kimiv.ru                   |
//+----------------------------------------------------------------------------+
//|  Версия   : 19.02.2008                                                     |
//|  Описание : Возвращает суммарный профит открытых позиций в пунктах         |
//+----------------------------------------------------------------------------+
//|  Parametrs:                                                                |
//|    sy - symbol                       (""   - any symbol,                   |
//|                                     NULL - current symbol)                 |
//|    op - operation                   (-1   - any position)                  |
//|    mn - MagicNumber                  (-1   - any magic) 
//+----------------------------------------------------------------------------+
int GetProfitOpenPosInPoint(string sy="", int op=-1, int mn=-1) {
  double p;
  int    i, k=OrdersTotal(), pr=0;

  if (sy=="0") sy=Symbol();
  for (i=0; i<k; i++) {
    if (OrderSelect(i, SELECT_BY_POS, MODE_TRADES)) {
      if ((OrderSymbol()==sy || sy=="") && (op<0 || OrderType()==op)) {
        if (mn<0 || OrderMagicNumber()==mn) {
          p=MarketInfo(OrderSymbol(), MODE_POINT);
          if (p==0) if (StringFind(OrderSymbol(), "JPY")<0) p=0.0001; else p=0.01;
          if (OrderType()==OP_BUY) {
            pr+=(MarketInfo(OrderSymbol(), MODE_BID)-OrderOpenPrice())/p;
          }
          if (OrderType()==OP_SELL) {
            pr+=(OrderOpenPrice()-MarketInfo(OrderSymbol(), MODE_ASK))/p;
          }
        }
      }
    }
  }
  return(pr);
}

The original link where u can see all these functions is here.

Also i attach files that shows how u can use these functions :

 

If u need u will do ur expert i think. That's all I can do for u for free & without seeing the code of ur expert :)

P.S. Sorry for mistakes (english isn't my native).

Good Luck.

 

Hi Seifer,

Thank you very much for all this informations. They will help me.

 

Hi Seifer,

I have try to put the " numberoflosspostoday" in my EA but i can't. So if you want to help me freely !!!! .

Just another words, "numberoflosspostoday" must be in PIPS and i want to control this wih the settings of expert before it runs.

Thanks

Files:
ccifi03.mq4  10 kb
 

Hi prosper1,

if your intention is to play by day, you can use the DayOfYear() function, which will retrieve an int number.

Then you can:

int today;

static double initialbalance;

if (DayOfYear() > today)

{

today = DayOfYear();

initialbalance = AccountBalance();

}

afterwards you can use that data for your own means, like if (AccountBalance()-AccountProfit() > initialbalance-toploss) do something.

Hope this was useful, good luck

 

Hi Forexfordinner,

This is exactly my idea, I want to play day by day using " numberoflosspostoday" or your function "DayOfYear", in order to stop my EA if it loses some pips or trades by day. And I can control the loss possible in the settings.Then it restart the next day...

I have try to put the function" numberoflosspostoday" and "DayOfYear" in my EA (CCIFIO3), but when i compil they are many errors. I am beginner in MQL4 programmation and i don't know what to do. Anyone can help me to code this in my EA freely ???

Thanks.

Files:
ccifi03_1.mq4  10 kb