}
IN THE PIECE ABOVE, I UNDERSTAND HOW THIS WORKS: IF TWO BOOLS ARE TRUE, AND IF ACCOUNTPROFIT IS GREATER THAN OR EQUAL TO ZERO, IT WILL LOOP THROUGH THE ORDERS AND DEPENDING ON THE TYPE, IT WILL EITHER CLOSE THEM OR DELETE THEM. COULD SOMEONE HELP ME MAKE THIS SPECIFIC TO INCLUDE A ORDERMAGICNUMBER? THIS CODE IS PART OF A STRATEGY THAT I WANT TO RUN ON MULTIPLE PAIRS, THEREFORE, I DON'T WANT IT DELETING ORDERS FOR PAIRS I NEED ORDERS TO REMAIN IN EFFECT FOR! I THINK THIS IS PRETTY STRAIGHTFORWARD BUT I AM NOT SURE HOW TO INCORPORATE THE MAGICNUMBER IN HERE :(
ANY HELP WOULD BE GREATLY APPRECIATED!!! THANK YOU FORUM...... DANIEL
WOULD THIS WORK??????!!!!
if(order2 == true || order3 == true)
{
if(AccountProfit() >= 0)
{
for(i=OrdersTotal()-1;i>=0;i--)
{
if((OrderSelect(k,SELECT_BY_POS,MODE_TRADES))&&OrderMagicNumber()==MagicNumber11 || OrderMagicNumber()==MagicNumber21 || OrderMagicNumber()==MagicNumber31)
{
OrderSelect(i, SELECT_BY_POS);
int type = OrderType();
bool result = false;
switch(type)
{
//Close opened positions
case OP_BUY : result = OrderClose(OrderTicket(),OrderLots(),MarketInfo(OrderSymbol(),MODE_BID),Slippage,Pink);
break;
case OP_SELL : result = OrderClose(OrderTicket(),OrderLots(),MarketInfo(OrderSymbol(),MODE_ASK),Slippage,Pink);
break;
case OP_BUYLIMIT : result = OrderDelete( OrderTicket() );
break;
case OP_SELLLIMIT : result = OrderDelete( OrderTicket() );
break;
case OP_BUYSTOP : result = OrderDelete( OrderTicket() );
break;
case OP_SELLSTOP : result = OrderDelete( OrderTicket() );
}
}
}
}
}
I can't take credit for this but I think it's what you're looking for...Just add the OrderDelete code...
There is more at this
http://www.forexfactory.com/showthread.php?p=3115429#post3115429
int CBM(int intMagic)//CloseByMagic
{int intOffset=0;
int Count = OTBM(intMagic);
while(OTBM(intMagic)>0 && Count > 0)
{
OrderSelect(intOffset,SELECT_BY_POS);
if(OrderMagicNumber()==intMagic)
{
if(OrderType()==OP_BUY) OrderClose(OrderTicket(),OrderLots(),MarketInfo(OrderSymbol(),MODE_BID),999,Red);
else if(OrderType()==OP_SELL) OrderClose(OrderTicket(),OrderLots(),MarketInfo(OrderSymbol(),MODE_ASK),999,Orange);
Count--;
}
else {
intOffset++;
}
}
return(0);
}
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
}
IN THE PIECE ABOVE, I UNDERSTAND HOW THIS WORKS: IF TWO BOOLS ARE TRUE, AND IF ACCOUNTPROFIT IS GREATER THAN OR EQUAL TO ZERO, IT WILL LOOP THROUGH THE ORDERS AND DEPENDING ON THE TYPE, IT WILL EITHER CLOSE THEM OR DELETE THEM. COULD SOMEONE HELP ME MAKE THIS SPECIFIC TO INCLUDE A ORDERMAGICNUMBER? THIS CODE IS PART OF A STRATEGY THAT I WANT TO RUN ON MULTIPLE PAIRS, THEREFORE, I DON'T WANT IT DELETING ORDERS FOR PAIRS I NEED ORDERS TO REMAIN IN EFFECT FOR! I THINK THIS IS PRETTY STRAIGHTFORWARD BUT I AM NOT SURE HOW TO INCORPORATE THE MAGICNUMBER IN HERE :(
ANY HELP WOULD BE GREATLY APPRECIATED!!! THANK YOU FORUM...... DANIEL