Magicnumber and looping

 
Could someone help point me to an article/code that can help me accomplish the following: I use Magicnumber to search history of orders so that I can remove pending trades. The downside is that each day(I set this up every evening for the asian/european session), I have to manually go into my EA and change the magicnumber and then recompile the EA before adding it back to the chart. Is there a way to build into my code, either an array or loop so that the code could simply "count up" my Magicnumber on its own? Any help or advice would be much appreciated! Daniel
 
forexman05:
Could someone help point me to an article/code that can help me accomplish the following: I use Magicnumber to search history of orders so that I can remove pending trades. The downside is that each day(I set this up every evening for the asian/european session), I have to manually go into my EA and change the magicnumber and then recompile the EA before adding it back to the chart. Is there a way to build into my code, either an array or loop so that the code could simply "count up" my Magicnumber on its own? Any help or advice would be much appreciated! Daniel

Maybe you look for something like this:

for(int k=OrdersTotal()-1;k>=0;k--)

{

if((OrderSelect(k,SELECT_BY_POS,MODE_TRADES))&&(OrderSymbol()==Symbol())&&(OrderMagicNumber()==MagicNumber))

{

if(OrderType()==OP_BUYSTOP)

{

OrderDelete(OrderTicket(),Yellow);

}

if(OrderType()==OP_SELLSTOP)

{

OrderDelete(OrderTicket(),Yellow);

}

}

}

 
robofx.org:

Maybe you look for something like this:

for(int k=OrdersTotal()-1;k>=0;k--)

{

if((OrderSelect(k,SELECT_BY_POS,MODE_TRADES))&&(OrderSymbol()==Symbol())&&(OrderMagicNumber()==MagicNumber))

{

if(OrderType()==OP_BUYSTOP)

{

OrderDelete(OrderTicket(),Yellow);

}

if(OrderType()==OP_SELLSTOP)

{

OrderDelete(OrderTicket(),Yellow);

}

}

}

Thank you for that info robo.....I have the ordersend function all set. What I need is something to change or update the magicnumber each time I place a new order without me going back into the code and changing it manually.


extern int MagicNumber11=5045;

extern int MagicNumber12=5046;

extern double lot=0.1;

extern double lot2=0.5;

int Slippage=3;

int i;


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

//| expert initialization function |

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

int init()

{

//----


//----

return(0);

}

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

//| expert deinitialization function |

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

int deinit()

{

//----

//----

return(0);

}

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

//| expert start function |

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

int start()

{


int ticket11,ticket12;

int totalO = OrdersTotal();

if(GlobalVariableCheck("audusdStop")==false)//allows trades to be placed

{

if(XXXXXXX)

{

if (XXXXXX)

{

//LONG

OrderSend(Symbol(),OP_BUY,lot,Ask,3,Ask-100*Point,Ask+5*Point,NULL,MagicNumber11,0,Green);


OrderSend(Symbol(),OP_SELLSTOP,lot2,Ask-100*Point,3,Ask-1*Point,Ask-120*Point,NULL,MagicNumber12,0,Green);

}

}

else

bool found = false;

for(int k=OrdersHistoryTotal()-1;k>=0;k--)

{

if((OrderSelect(k,SELECT_BY_POS,MODE_HISTORY))&&(OrderMagicNumber()==MagicNumber11))

{

found = true;

break;

}

}

if(found == true)

{

for(k=OrdersTotal()-1;k>=0;k--)

{

if((OrderSelect(k,SELECT_BY_POS,MODE_TRADES))&&(OrderMagicNumber()==MagicNumber12))

{

OrderDelete(OrderTicket());

}

}

}

//----

return(0);

}


ABOVE IS THE BULK OF THE CODE. AGAIN, I NEED A NEW MAGICNUMBER EACH TIME THIS THING FIRES OFF......THANKS FOR YOUR THOUGHTS!! DANIEL

 
forexman05:

Thank you for that info robo.....I have the ordersend function all set. What I need is something to change or update the magicnumber each time I place a new order without me going back into the code and changing it manually.



ABOVE IS THE BULK OF THE CODE. AGAIN, I NEED A NEW MAGICNUMBER EACH TIME THIS THING FIRES OFF......THANKS FOR YOUR THOUGHTS!! DANIEL

You can generate each time a random magic number using MathSrand() and MathRand() functions.

Reason: