Martingale system not working correctly

 

My martingale system doesn't work correctly.Please i need help to make it work.I won't try to explain it since it's too complicated and my eyes hurt when looking at so much variables,so i'll copy it all here and if anyone finds any errors in the code please tell me.Thanks much:

SETTING VARIABLES:

//externals
extern double start_lot=0.01; //order lot size
extern string  X________________1a="(progression=true=double all trades lot/level, progression=false=only losing trades lot double/level)";
extern bool MARTINGALE_ACTIVATOR=false;   /// wanna use martingale system?
extern int MARTINGALE_LEVELS=5; // what levels to go,ex level 5= 2^5 multiplicator for lot
extern bool MARTINGALE_PROGRESSION=true;

int i=1;
int LEVEL=1;
int magic=666;   ///magic number
double martingale_lot;     
///correction
int PositionIndex; 
int TotalNumberOfOrders;

INIT()

   martingale_lot=start_lot;
// this is in the init()

START()

    if(MARTINGALE_ACTIVATOR){
   

for(i=OrdersHistoryTotal()-1;i>=0;i--)
 {
     OrderSelect(i, SELECT_BY_POS,MODE_HISTORY);
   
   if( OrderMagicNumber() == magic      // <-- does the Order's Magic Number match our EA's magic number ? 
      && OrderSymbol() == Symbol()         // <-- does the Order's Symbol match the Symbol our EA is working on ? 
      && (OrderType() == OP_BUY           // <-- is the Order a Buy Order ? 
      ||OrderType() == OP_SELL ) )      // <-- PROFITABLE O NOT ?
   {  /////////// //////////////////////////////////
 ////////////////////////////////////////// 
 start_lot=martingale_lot;
 
  ////////////////////////////////////////////////////
   if(MARTINGALE_PROGRESSION==false){
if(OrderProfit()<0) LEVEL++; //LOSS
if(OrderProfit()>0) LEVEL=1; //PROFIT CANCEL OUT
 if(LEVEL>MARTINGALE_LEVELS) LEVEL=1;
start_lot=martingale_lot*MathPow(2,(LEVEL-1));
}
///////////////////////////////////////////////////////////////////////////////////////
   if(MARTINGALE_PROGRESSION==true){
LEVEL++;
 if(LEVEL>MARTINGALE_LEVELS) LEVEL=1;
start_lot=martingale_lot*MathPow(2,(LEVEL-1));
}
/////////////////////////////////////////////////////////


///////////////////////////////////////
  }
 }  } 



The basic idea is that if the martingale system is on by using the settings with:

1)

MARTINGALE_PROGRESSION=true;

Then double the lot size by every trade until it hits the

extern int MARTINGALE_LEVELS=5;

Then if the (in this case) 5th trade is over,reset the lot size to the base size specified,this case 0.01 lot


2)

MARTINGALE_PROGRESSION=false;

Then double the lot size at every losing trade only, and reset it to the base size (0.01 lot) if we got a winner trade

extern int MARTINGALE_LEVELS=5;

Also if it hits the maximum amount of levels set then reset it back to the base lot (0.01) to not overrisk the trades

 
Proximus:

My martingale system doesn't work correctly.

In what way does it not work correctly ? what is the result ? what are the symptoms ? what does it do that it shouldn't ? what doesn't it do that it should ?


Saying X doesn't work isn't much of a description of your issue . . .

 
RaptorUK:

In what way does it not work correctly ? what is the result ? what are the symptoms ? what does it do that it shouldn't ? what doesn't it do that it should ?


Saying X doesn't work isn't much of a description of your issue . . .


  • True, well first of all it doesn't go to level 5, aka lot size 0.32, it stops at 0.16,level 4 so i guess i missed a <,>,= sign somewhere.
  • Secondly it doesnt increase orders continuously, so by that i mean that (lets say the
MARTINGALE_PROGRESSION=true;

settings) ticket #1 is 0.01 lot

ticket 2 is 0.02 lot

ticket 3 is 0.04 lot

but ticket 4 suddently jumps to 0.16 lot and skips 0.08, or sometimes it skips the 0.02 lot and jumps from 0.01 to 0.04

  • Thirdly, sometimes if i run it it stops at 0.16 and doesnt go back to 0.01

Here is a backtest to show you what i`m talking about


PS: There are no programming errors like missing ; or (), only the fact that it's not working correctly.

Files:
backtest.zip  13 kb
 

Nevermind I figured it out :), here i post my fully working martingale code for future viewers.Although for me it's working, it would be nice if some1 could confirm it.

EXTERNALS/SETTING VARIABLES

extern double start_lot=0.01; //order lot size
extern bool MARTINGALE_ACTIVATOR=false;   /// wanna use martingale system?
extern int MARTINGALE_LEVELS=5; // what levels to go,ex level 5= 2^5 multiplicator for lot
extern bool MARTINGALE_PROGRESSION=true;
int LEVEL=0;
double martingale_lot=0.01;
int PositionIndex; 
int TotalNumberOfOrders;
int magic=666; 

INIT()

   martingale_lot=start_lot;

START()

    if(MARTINGALE_ACTIVATOR){
    static datetime lastClose;  datetime lastClosePrev = lastClose;
    for(i=0; i < OrdersHistoryTotal(); i++) {

 OrderSelect(i, SELECT_BY_POS, MODE_HISTORY);   // Only orders w/
   if( OrderMagicNumber() == magic      // <-- does the Order's Magic Number match our EA's magic number ? 
      &&  OrderCloseTime()    > lastClosePrev 
      && OrderSymbol() == Symbol()         // <-- does the Order's Symbol match the Symbol our EA is working on ? 
      && (OrderType() == OP_BUY           // <-- is the Order a Buy Order ? 
      ||OrderType() == OP_SELL ) )      // <-- PROFITABLE O NOT ?
   {  /////////// //////////////////////////////////
 ////////////////////////////////////////// 
lastClose = OrderCloseTime();
 start_lot=martingale_lot;
 
  ////////////////////////////////////////////////////
   if(MARTINGALE_PROGRESSION==false){
if(OrderProfit()<0) LEVEL++; //LOSS
if(OrderProfit()>0) LEVEL=0; //PROFIT CANCEL OUT
if(LEVEL>MARTINGALE_LEVELS) LEVEL=0;
start_lot=martingale_lot*MathPow(2,LEVEL);
}
///////////////////////////////////////////////////////////////////////////////////////
   if(MARTINGALE_PROGRESSION==true){
LEVEL++;
 if(LEVEL>MARTINGALE_LEVELS) LEVEL=0;
start_lot=martingale_lot*MathPow(2,LEVEL);
}
/////////////////////////////////////////////////////////

}
///////////////////////////////////////
 } }


Note to be fully functional you should have no more than 1 open order at a time,and the code in the start should be before placing Ordersend() orders.And it works for market buy/sell orders, if you want to have pending orders just change the second if and add a

OrderType() == BUYLIMIT

or whatever.Good luck!

 

I used martingale on one of my EA's it made 15,000 dollars from a 500 dollar account last year. Would have been awesome if it wasn't for the 12,000 dollar hit it took this past April :(

 

I'm new to Forex and new to MQ4, but after a bit of research made an early decision to avoid Martingale techniques. Google "Birt Forex Envy" for example!

I'm trying to focus on Price Action with SR, trend lines, and minimal indicators..

 
SDC:

I used martingale on one of my EA's it made 15,000 dollars from a 500 dollar account last year. Would have been awesome if it wasn't for the 12,000 dollar hit it took this past April :(

It works but you must have a 50% win rate atleast for your sistem with stoploss/tp and careful money management.Also don't never ever go above level 5= 2^5= 32x lot size because that strike will be a losing one and you probably got that 12k dollar hit because you went way above it ;)

ydrol:

I'm new to Forex and new to MQ4, but after a bit of research made an early decision to avoid Martingale techniques. Google "Birt Forex Envy" for example!

I'm trying to focus on Price Action with SR, trend lines, and minimal indicators..

It depends on your risk tolerance, it know 100% it works,but you must be careful and plan every step ahead.Never go above level 5 and always have SL levels even if you dont have TP.This martingale code is here if you want to use it fine if not fine too.Whatever works for you man and good luck building your EA.

Reason: