Page 3 of 5 FirstFirst 12345 LastLast
Results 21 to 30 of 46
 8 Attachment(s)    

Thread: Add a martingale

  1. #21
    Junior Member
    Join Date
    Jan 2009
    Posts
    13

    Default

    any solotion for balance please ??????????

  2. #22
    Administrator funyoo's Avatar
    Join Date
    Sep 2008
    Posts
    7,003

    Default

    Quote Originally Posted by nabelion View Post
    any solotion for balance please ??????????
    Hi nabelion,

    Here is another guide :

    In the extern parameters, add :

    Code:
    extern double lots=0.1;
    extern bool martingale=false;
    extern double multiplier=2.0;
    extern double minlot=0.01;
    extern double maxlot=10;
    After the extern parameters, add :

    Code:
    double lotsfactor=1,ilots;
    double initiallotsfactor=1;
    In the init() function, before return(), add :

    Code:
       //|---------martingale initialization
    
       int tempfactor,total=OrdersTotal();
       if(tempfactor==0 && total>0)
       {
          for(int cnt=0;cnt<total;cnt++)
          {
             if(OrderSelect(cnt,SELECT_BY_POS))
             {
                if(OrderSymbol()==Symbol() && OrderMagicNumber()==magic)
                {
                   tempfactor=NormalizeDouble(OrderLots()/lots,1+(MarketInfo(Symbol(),MODE_MINLOT)==0.01));
                   break;
                }
             }
          }
       }
       int histotal=OrdersHistoryTotal();
       if(tempfactor==0&&histotal>0)
       {
          for(cnt=0;cnt<histotal;cnt++)
          {
             if(OrderSelect(cnt,SELECT_BY_POS,MODE_HISTORY))
             {
                if(OrderSymbol()==Symbol() && OrderMagicNumber()==magic)
                {
                   tempfactor=NormalizeDouble(OrderLots()/lots,1+(MarketInfo(Symbol(),MODE_MINLOT)==0.01));
                   break;
                }
             }
          }
       }
       if(tempfactor>0)
       lotsfactor=tempfactor;
    Before each ordersend() function, add :

    Code:
    if(martingale)ilots=NormalizeDouble(lots*martingalefactor(),2);else ilots=lots;
    if(ilots<minlot)ilots=minlot;if(ilots>maxlot)ilots=maxlot;
    In the ordersend() function, replace lots by :

    Code:
    ilots
    At the end of the code, add :

    Code:
    //|---------martingale
    
    int martingalefactor()
    {
       int histotal=OrdersHistoryTotal();
       if (histotal>0)
       {
          for(int cnt=histotal-1;cnt>=0;cnt--)
          {
             if(OrderSelect(cnt,SELECT_BY_POS,MODE_HISTORY))
             {
                if(OrderSymbol()==Symbol() && OrderMagicNumber()==magic)
                {
                   if(OrderProfit()<0)
                   {
                      lotsfactor=lotsfactor*multiplier;
                      return(lotsfactor);
                   }
                   else
                   {
                      lotsfactor=initiallotsfactor;
                      if(lotsfactor<=0)
                      {
                         lotsfactor=1;
                      }
                      return(lotsfactor);
                   }
                }
             }
          }
       }
       return(lotsfactor);
    }

  3. #23
    Junior Member
    Join Date
    May 2009
    Posts
    1

    Default

    Hello funyoo, and thank you for the script.

    I try to add it to an ea that i have create with Expert Advisor Builder for MetaTrader 4 .

    I make a few of modifications to adapte the script to myine, but it seems that is wrong.

    I have search so many time but I find the solution.

    Joint, you can find the ea.

    If you can help me, it's will be so nice.

    Sorry for my English.
    Attached Files Attached Files

  4. #24
    Junior Member
    Join Date
    Nov 2009
    Posts
    2

    Default

    Hi Dreamfab.
    Thanks funyoo for previous postings clearly explaining martingale. There are already several .mq4 running. The best I have seen is Blessing V5.2 . It still suffers suicide occasionally, but you can tune it to minimize losses. When the chart does a long run in one direction, this is bad for martingale. They perform well for choppy and ranging charts. You need to spend a long time tuning (blessing) on Demo accounts before using it on real accounts. You should also learn to operate it, and develop strategies for when suicide is near! You could hedge for example, and if you set a trailing stop on the hedge, make alot of pips if you stay in the trades.
    Blessing is kindly donated by several authors who created & updated it. It is in the public domain, but please share settings, etc, don't be selfish !!


    Blessing 2 v5.2x2.mq4

  5. #25

    Default fast & furius martingale

    hi all
    i try to put code of funyoo in my ea
    no double execution
    Attached Files Attached Files

  6. #26
    Administrator funyoo's Avatar
    Join Date
    Sep 2008
    Posts
    7,003

    Default

    A new guide, an easier one :

    At the beginning of the code, in the extern parameters add :

    Code:
    extern bool martingale=false;          // enable the martingale
    extern double multiplier=2.0;          // multiplier used for the martingale
    extern double lotdigits=2;             // 1 for minilot, 2 for microlot
    After the extern parameters add :

    Code:
    double mlots,ilots,lastprofit,lastlot;
    
    int i,history;
    In the start body add :

    Code:
       history=OrdersHistoryTotal();
       if(history>0){
          for(i=0;i<history;i++){
             OrderSelect(i,SELECT_BY_POS,MODE_HISTORY);
             if(OrderSymbol()==Symbol() && OrderMagicNumber()==magic){
                lastprofit=OrderProfit();
                lastlot=OrderLots();
             }
          }
       }
       mlots=0;
       if(martingale && lastprofit<0)mlots=NormalizeDouble(lastlot*multiplier,lotdigits);else mlots=lots;
    In the mm function (if you have one), add :

    Code:
     && (martingale==false || (martingale && lastprofit>=0))
    Before each ordersend function, add :

    Code:
    if(martingale)ilots=mlots;else ilots=lots;
    Finally, replace lots in the ordersend function by ilots.

  7. #27

    Default

    Quote Originally Posted by funyoo View Post
    A new guide, an easier one :

    At the beginning of the code, in the extern parameters add :

    Code:
    extern bool martingale=false;          // enable the martingale
    extern double multiplier=2.0;          // multiplier used for the martingale
    extern double lotdigits=2;             // 1 for minilot, 2 for microlot
    After the extern parameters add :

    Code:
    double mlots,ilots,lastprofit,lastlot;
    
    int i,history;
    In the start body add :

    Code:
       history=OrdersHistoryTotal();
       if(history>0){
          for(i=0;i<history;i++){
             OrderSelect(i,SELECT_BY_POS,MODE_HISTORY);
             if(OrderSymbol()==Symbol() && OrderMagicNumber()==magic){
                lastprofit=OrderProfit();
                lastlot=OrderLots();
             }
          }
       }
       mlots=0;
       if(martingale && lastprofit<0)mlots=NormalizeDouble(lastlot*multiplier,lotdigits);else mlots=lots;
    In the mm function (if you have one), add :

    Code:
     && (martingale==false || (martingale && lastprofit>=0))
    Before each ordersend function, add :

    Code:
    if(martingale)ilots=mlots;else ilots=lots;
    Finally, replace lots in the ordersend function by ilots.

    thanks i will try !!!

  8. #28

    Default

    Quote Originally Posted by NICK35 View Post
    thanks i will try !!!
    i'm at 99%

    i have only a small error
    magic number .......
    Attached Files Attached Files

  9. #29

    Default

    Quote Originally Posted by NICK35 View Post
    i'm at 99%

    i have only a small error
    magic number .......
    'magic' - variable not defined
    C:\Program Files\FxPro - MetaTrader\experts\F and F v1.0 (Fixed martingale sl).mq4 (53, 60)


  10. #30
    Administrator funyoo's Avatar
    Join Date
    Sep 2008
    Posts
    7,003

    Default

    Quote Originally Posted by NICK35 View Post
    'magic' - variable not defined
    C:\Program Files\FxPro - MetaTrader\experts\F and F v1.0 (Fixed martingale sl).mq4 (53, 60)

    Hi NICK35,

    You have to replace magic by Magic_Number.

Similar Threads

  1. RSI + martingale
    By noiahei in forum Ideas for expert advisors
    Replies: 1
    Last Post: 06-21-2010, 17:01
  2. (REQ) Martingale
    By 626mx in forum Ideas for expert advisors
    Replies: 2
    Last Post: 05-05-2010, 01:40
  3. New Martingale EA
    By shaya in forum Scripts and other tools
    Replies: 0
    Last Post: 06-24-2009, 06:50
  4. ATR MA Martingale EA
    By funyoo in forum Expert advisors live statements
    Replies: 0
    Last Post: 02-19-2009, 22:40

Tags for this Thread

add, change, color, demo, expert, expert advisor, experts, forex, guide, hedge, high, how to, ilan, index, learn, macd, magic, martingale, metatrader, mq4, online, profit, programmer, programming, real, simple, stop, strategies, strategy, system, thank you, time, trader, trading, trading forex, trailing

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •