D’Alembert Forex EA

 

Hi all,

I try to code an EA that handle with d'alembert progression (for all that don´t know progression d'alembert: D’Alembert Method - Just how safe is this roulette system? )

The plan is to start with 0.01 lots and SL 13 pips / TP 14 pips.

Each time a trade close with a loss, a new trade open immediately with additional 0.01 lots and after a win trade next trade open immediately with 0.01 lots less than the lotsize before until we arrive at 0.01 lots.

Example:

1. trade 0.01 lots loss

2. trade 0.02 lots loss

3. trade 0.03 lots loss

4. trade 0.04 lots loss

5. trade 0.05 lots win

6. trade 0.04 lots win

7. trade 0.03 lots win

8. trade 0.02 lots win

9. trade 0.01 lots win

So here is my first code try but it doesn´t work in the startegy tester. :-(

Who can help?

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

//| A4.mq4 |

//| Copyright © 2010, MetaQuotes Software Corp. |

//| http://www.metaquotes.net |

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

#property copyright "Copyright © 2010, MetaQuotes Software Corp."

#property link "http://www.metaquotes.net"

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

//| extern input parameters |

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

extern int MagicNumber_101=101000;

extern int SL=13;

extern int TP=14;

double dXPoint=1;

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

//| expert initialization function |

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

int init()

{

//----

//----

return(0);

}

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

//| expert deinitialization function |

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

int deinit()

{

//----

//----

return(0);

}

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

//| expert start function |

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

int start()

{

double Lotsize = 0.01;

if (OrdersHistoryTotal()>=1)

{

OrderSelect(OrdersHistoryTotal()-1,SELECT_BY_POS);

Lotsize = OrderLots();

}

if (OrderProfit()=1)

{

Lotsize = Lotsize + 0.01;

}

if (OrderProfit()>0 && OrdersHistoryTotal()>=1 && Lotsize>=0.02)

{

Lotsize = Lotsize - 0.01;

}

if (OrdersHistoryTotal()<1 && Minute()==00)

{

OrderSend(Symbol(),OP_BUY,0.01,MarketInfo(Symbol(),MODE_ASK),2,Bid-SL*Point,Bid+TP*Point,"buy",MagicNumber_101,0,CLR_NONE);

}

Sleep(120000);

if (OrdersTotal()==0 && Minute()==00)

{

OrderSelect(OrdersHistoryTotal()-1,SELECT_BY_POS);

if (OrderProfit()>0 && OrderType()==OP_BUY)

{

OrderSend(Symbol(),OP_BUY,0.01,MarketInfo(Symbol(),MODE_ASK),2,Bid-SL*Point,Bid+TP*Point,"buy",MagicNumber_101,0,CLR_NONE);

}

Sleep(120000);

}

if (OrdersTotal()==0 && Minute()==00)

{

if (OrderProfit()>0 && OrderType()==OP_SELL)

{

OrderSend(Symbol(),OP_SELL,0.01,MarketInfo(Symbol(),MODE_BID),2,Ask+SL*Point,Ask-TP*Point,"sell",MagicNumber_101,0,CLR_NONE);

}

Sleep(120000);

}

if (OrdersTotal()==0 && Minute()==00)

{

if (OrderProfit()<0 && OrderType()==OP_SELL)

{

OrderSend(Symbol(),OP_BUY,0.01,MarketInfo(Symbol(),MODE_ASK),2,Bid-SL*Point,Bid+TP*Point,"buy",MagicNumber_101,0,CLR_NONE);

}

Sleep(120000);

}

if (OrdersTotal()==0 && Minute()==00)

{

if (OrderProfit()<0 && OrderType()==OP_BUY)

{

OrderSend(Symbol(),OP_SELL,0.01,MarketInfo(Symbol(),MODE_BID),2,Ask+SL*Point,Ask-TP*Point,"sell",MagicNumber_101,0,CLR_NONE);

}

Sleep(120000);

}

return(0);

}

Please no comments like "Blow your account away...blabla"

Just sharing a trading strategy.

Regards.