mladen wrote:Use calls to buffers 0 and 1 for that
Thanks Mladen... Ive already got that from you, master
Code: Select all
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()==EAMagicNumber)
{
if(LastOP==0) {LastOP=OrderOpenPrice();}
if(LastOP>OrderOpenPrice()) {LastOP=OrderOpenPrice();}
if(LastLots<OrderLots()) {LastLots=OrderLots();}
LastIsBuy=TRUE;
iTotalBuy++;
if(iTotalBuy==MaxTrade) {return(0);}
}
if(OrderType()==OP_SELL && OrderSymbol()==Symbol() && OrderComment()==EAComment && OrderMagicNumber()==EAMagicNumber)
{
if(LastOP==0) {LastOP=OrderOpenPrice();}
if(LastOP<OrderOpenPrice()) {LastOP=OrderOpenPrice();}
if(LastLots<OrderLots()) {LastLots=OrderLots();}
LastIsBuy=FALSE;
iTotalSell++;
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, EAMagicNumber);
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, EAMagicNumber);
ModifyTP();
return(0);
}
}
}
void ModifyTP()
{
int iCount=0;
double NewTP=0;
for(iCount=0;iCount<OrdersTotal();iCount++)
{
OrderSelect(iCount,SELECT_BY_POS,MODE_TRADES);
if(OrderType()==OP_BUY && OrderSymbol()==Symbol() && OrderComment()==EAComment && OrderMagicNumber()==EAMagicNumber)
{
if(NewTP==0) {NewTP=OrderTakeProfit();}
if(NewTP>OrderTakeProfit()) {NewTP=OrderTakeProfit();}
}
if(OrderType()==OP_SELL && OrderSymbol()==Symbol() && OrderComment()==EAComment && OrderMagicNumber()==EAMagicNumber)
{
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()==EAMagicNumber)
{
OrderModify(OrderTicket(), OrderLots(), 0, NewTP, 0);
}
if(OrderType()==OP_SELL && OrderSymbol()==Symbol() && OrderComment()==EAComment && OrderMagicNumber()==EAMagicNumber)
{
OrderModify(OrderTicket(), OrderLots(), 0, NewTP, 0);
}
}
}
Can u help me to add stoploss for that script? If I want only 2 level martingale, then if hit the stoploss it will be all close (same magic number) or open hedging with same lot...
btw, if open hedging... can the new open position make a new magicnumber after hedging or must be close the ea and re-start ea so they will create with new magicnumber?
Thanks