Jump to content

pure Martingale Hedging EA --- need add 4 features


leonytham

Recommended Posts

dear friend,

 

i am a martingale fans, and found a clean martingale+hedging EA.

 

but like martingale 'way' --- gamble, i would like to increase trading frequent.

 

This Martingale EA, is a price action EA, immediately open 2 orders (one is buy, one is sell). The TP order will closed and waiting for the losing order(s) to close before restart the cycle.

 

anybody, could help to:

 

1) add IMMEDIATELY reopen new-TP-order.

(current version only open new TP-order AFTER ALL orders closed)

example 8:15am = 0.1buy + 0.1sell + 0.2sell + 0.4sell,

when 8.20am TP for sell, now have 0.1buy.

 

can add IMMEDIATELY reopen new-TP-order, that is...

example 8:15am = 0.1buy + 0.1sell + 0.2sell + 0.4sell,

when 8.20am TP for sell, now have 0.1buy AND NEWLY opened 0.1sell.

 

2) add profit_target_all_buy (total dollar OP_BUY reach and close the OP_BUY only)

3) add profit_target_all_sell (total dollar OP_SELL reach and close the OP_SELL only)

4) add stop_loss_total_in_order (when balance below DEFINED-SL, then close ALL orders)

 

==========================================================

 

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

//| Martingale.mq4 |

//| @abc |

//| http://abc.com |

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

#property copyright "abc"

#property link "http://abc.com"

 

 

extern int TakeProfit = 8;

extern int PipStep = 8;

extern double Lots = 0.1;

extern double Multiply = 2.0;

extern int MaxTrade = 11;

 

string EAName = "Martingale";

string EAComment = "Martingale";

int magicbuy = 123;

int magicsell = 321;

double SetPoint = 0; // Variabel SetPoint for broker 4 or 5 digits

int Slippage = 3;

 

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

//| expert initialization function |

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

int init()

{

//----

 

SetBroker();

 

//----

return(0);

}

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

//| expert deinitialization function |

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

int deinit()

{

//----

 

//----

return(0);

}

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

//| expert start function |

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

int start()

{

//----

 

int iTrade=0;

 

 

 

Comment(EAName,"\nServer Time: ",Hour(),"\nPairs : ",Symbol(),"\nEquity : ",AccountEquity(),"\nBalance : ",AccountBalance()); // Tampilkan Nama EA di layar

 

/* -- 0 opening order? starting FIRST order --*/

 

if(OrdersTotal()==0)

{

OrderSend(Symbol(), OP_BUY, Lots, Ask, Slippage, 0, Ask+TakeProfit*SetPoint, EAComment, magicbuy);

OrderSend(Symbol(), OP_SELL, Lots, Bid, Slippage, 0, Bid-TakeProfit*SetPoint, EAComment, magicsell);

}

 

 

 

/* -- Martingale function starts --*/

if(OrdersTotal()>=1)

{

GoMartingale();

}

 

 

//----

return(0);

}

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

 

/*--managing 4 or 5 digits broker--*/

void SetBroker()

{

if (Digits==3 || Digits==5) // Instruct 4 digits broker

{SetPoint=Point*10;}

else // Instruct 4 digits broker

{SetPoint=Point;}

}

 

/*-- Function to start Martingale --*/

void GoMartingale()

{

int iCount = 0;

double LastOP = 0;

double LastLots = 0;

bool LastIsBuy = FALSE;

int iTotalBuy = 0;

int iTotalSell = 0;

int Spread=0;

 

Spread= MarketInfo(Symbol(), MODE_SPREAD);

 

 

for(iCount=0;iCount<OrdersTotal();iCount++)

{

 

OrderSelect(iCount,SELECT_BY_POS,MODE_TRADES);

 

if(OrderType()==OP_BUY && OrderSymbol()==Symbol() && OrderComment()==EAComment && OrderMagicNumber()==magicbuy)

{

if(LastOP==0) {LastOP=OrderOpenPrice();}

if(LastOP>OrderOpenPrice()) {LastOP=OrderOpenPrice();}

if(LastLots<OrderLots()) {LastLots=OrderLots();}

LastIsBuy=TRUE;

iTotalBuy++;

 

/* Maximum trades */

if(iTotalBuy==MaxTrade) {return(0);}

}

 

if(OrderType()==OP_SELL && OrderSymbol()==Symbol() && OrderComment()==EAComment && OrderMagicNumber()==magicsell)

{

if(LastOP==0) {LastOP=OrderOpenPrice();}

if(LastOP<OrderOpenPrice()) {LastOP=OrderOpenPrice();}

if(LastLots<OrderLots()) {LastLots=OrderLots();}

LastIsBuy=FALSE;

iTotalSell++;

 

/* Maximum trades */

if(iTotalBuy==MaxTrade) {return(0);}

}

 

}

 

if(LastIsBuy)

{

if(Bid<=LastOP-(Spread*SetPoint)-(PipStep*SetPoint))

{

OrderSend(Symbol(), OP_BUY, Multiply*LastLots, Ask, Slippage, 0, Ask+TakeProfit*SetPoint, EAComment, magicbuy);

ModifyTP();

LastIsBuy=FALSE;

return(0);

}

}

 

else if(!LastIsBuy)

{

if(Ask>=LastOP+(Spread*SetPoint)+(PipStep*SetPoint ))

{

OrderSend(Symbol(), OP_SELL, Multiply*LastLots, Bid, Slippage, 0, Bid-TakeProfit*SetPoint, EAComment, magicsell);

ModifyTP();

return(0);

}

}

 

}

 

/*-- Align Take Profit to SAME point--*/

void ModifyTP()

{

int iCount=0;

double NewTP=0;

 

/*- Taking LAST Take Profit point -*/

for(iCount=0;iCount<OrdersTotal();iCount++)

{

 

OrderSelect(iCount,SELECT_BY_POS,MODE_TRADES);

 

if(OrderType()==OP_BUY && OrderSymbol()==Symbol() && OrderComment()==EAComment && OrderMagicNumber()==magicbuy)

{

if(NewTP==0) {NewTP=OrderTakeProfit();}

if(NewTP>OrderTakeProfit()) {NewTP=OrderTakeProfit();}

 

}

 

if(OrderType()==OP_SELL && OrderSymbol()==Symbol() && OrderComment()==EAComment && OrderMagicNumber()==magicsell)

{

if(NewTP==0) {NewTP=OrderTakeProfit();}

if(NewTP<OrderTakeProfit()) {NewTP=OrderTakeProfit();}

}

 

}

 

for(iCount=0;iCount<OrdersTotal();iCount++)

{

 

OrderSelect(iCount,SELECT_BY_POS,MODE_TRADES);

 

if(OrderType()==OP_BUY && OrderSymbol()==Symbol() && OrderComment()==EAComment && OrderMagicNumber()==magicbuy)

{

OrderModify(OrderTicket(), OrderLots(), 0, NewTP, 0);

}

 

if(OrderType()==OP_SELL && OrderSymbol()==Symbol() && OrderComment()==EAComment && OrderMagicNumber()==magicsell)

{

OrderModify(OrderTicket(), OrderLots(), 0, NewTP, 0);

}

 

}

}

Edited by leonytham
Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...