problem with Max Order

 

G'day fellows. I have a "base ea" I pretty much put together (many related posts of mine :P) and there's this little problem I have with the "max orders" option. Say I attach the EA to eurusd, audusd, gbpusd and set a max order of 5 for eu, 10 for au and 2 max orders for gu, as of now the EA somehow has in it 'head' the overall max orders is 10. So say theoretically I have 5 eu longs and 5au longs, the EA attached to the GU chart won't take any more trades because somehow the number 10 is set as an overall limit. Could anyone alter the programming part telling the EA to treat Max Orders according to each individual chart...


That'd be neat thanks, as clueless as I am with programming... And I really have no interest in learning (tried but lack motivation, rather prefer trading =)), I'm sure it's just a flick for someone who knows what they're looking at. Cheers!


here the code:


extern int TakeProfit = 155;
extern int TrailingStop = 55;
extern int StopLoss = 55;
extern double Lots = 1;
extern int magicnumber = 777;
extern bool PolLots = true;
extern int MaxOrders = 12;


int prevtime;
//+------------------------------------------------------------------+
//| expert initialization function |
//+------------------------------------------------------------------+
int init()
{
//----

//----
return(0);
}
//+------------------------------------------------------------------+
//| expert deinitialization function |
//+------------------------------------------------------------------+
int deinit()
{
//----

//----
return(0);
}
//+------------------------------------------------------------------+
//| expert start function |
//+------------------------------------------------------------------+
int start()
{
//----


int i=0;
int total = OrdersTotal();
for(i = 0; i <= total; i++)
{
if(TrailingStop>0)
{
OrderSelect(i, SELECT_BY_POS, MODE_TRADES);
if(OrderMagicNumber() == magicnumber)
{
TrailingStairs(OrderTicket(),TrailingStop);
}
}
}

bool BuyOp=false;
bool SellOp=false;

if (High[0]>High[1]&&High[1]>High[2]&&High[2]>High[3]&&Open[0]>Open[1]&&Open[1]>Open[2]&&Open[2]>Open[3]) BuyOp=true;
if (High[0]<High[1]&&High[1]<High[2]&&High[2]<High[3]&&Open[0]<Open[1]&&Open[1]<Open[2]&&Open[2]<Open[3]) SellOp=true;

if(Time[0] == prevtime)
return(0);
prevtime = Time[0];
if(!IsTradeAllowed())
{
prevtime = Time[1];
return(0);
}


if (total < MaxOrders || MaxOrders == 0)
{
if(BuyOp)
{
if (StopLoss!=0)
{
OrderSend(Symbol(),OP_BUY,Lots,Ask,3,Bid-(StopLoss*Point),Ask+(TakeProfit*Point),"OpenTiks_Buy",magicnumber,0,Green);
}
else
{
OrderSend(Symbol(),OP_BUY,Lots,Ask,3,0,Ask+(TakeProfit*Point),"OpenTiks_Buy",magicnumber,0,Green);
}
}
if(SellOp)
{
if (StopLoss!=0)
{
OrderSend(Symbol(),OP_SELL,Lots,Bid,3,Ask+(StopLoss*Point),Bid-(TakeProfit*Point),"OpenTiks_Sell",magicnumber,0,Red);
}
else
{
OrderSend(Symbol(),OP_SELL,Lots,Bid,3,0,Bid-(TakeProfit*Point),"OpenTiks_Sell",magicnumber,0,Red);
}
}
{

}
}

//----
return(0);
}
//+------------------------------------------------------------------+
void TrailingStairs(int ticket,int trldistance)
{
int Spred=Ask - Bid;
if (OrderType()==OP_BUY)
{
if((Bid-OrderOpenPrice())>(Point*trldistance))
{
if(OrderStopLoss()<Bid-Point*trldistance || (OrderStopLoss()==0))
{
OrderModify(ticket,OrderOpenPrice(),Bid-Point*trldistance,OrderTakeProfit(),0,Green);
if (PolLots)
if (NormalizeDouble(OrderLots()/2,2)>MarketInfo(Symbol(), MODE_MINLOT))
{
OrderClose(ticket,NormalizeDouble(OrderLots()/2,2),Ask,3,Green);
}
else
{
OrderClose(ticket,OrderLots(),Ask,3,Green);
}
}
}
}
else
{
if((OrderOpenPrice()-Ask)>(Point*trldistance))
{
if((OrderStopLoss()>(Ask+Point*trldistance)) || (OrderStopLoss()==0))
{
OrderModify(OrderTicket(),OrderOpenPrice(),Ask+Point*trldistance,OrderTakeProfit(),0,Red);
if (PolLots)
if (NormalizeDouble(OrderLots()/2,2)>MarketInfo(Symbol(), MODE_MINLOT))
{
OrderClose(ticket,NormalizeDouble(OrderLots()/2,2),Bid,3,Green);
}
else
{
OrderClose(ticket,OrderLots(),Bid,3,Green);
}
}
}
}
}



Ignore the signals, it's not the real input I have in mind :)


mank

 
Well your EA already supports this; you only have to change Magicnumber on every chart. Then your max positions per chart wil be x. If you have n charts then you may have n * x positions. The sense of magic number is exactly such situations.
 

if you dont want change magic on every chart, with precondition that you shall not apply this ea to 2 charts on same symbol with different timeframes you may patch



if(OrderMagicNumber() == magicnumber)



to



if(OrderMagicNumber() == magicnumber && OrderSymbol()==Symbol())



then you dont need to change magic but you must have n DIFFERENT symbols.I would change first variant

 
fx1.net:

if you dont want change magic on every chart, with precondition that you shall not apply this ea to 2 charts on same symbol with different timeframes you may patch



if(OrderMagicNumber() == magicnumber)



to



if(OrderMagicNumber() == magicnumber && OrderSymbol()==Symbol())



then you dont need to change magic but you must have n DIFFERENT symbols.I would change first variant


Hey. So let me get this straight, the default magic number is 777, say I attach the EA to eu with 777 and a max order of 10... Attach the EA again to au this time with the magic number of 345 and a max order of 23.. So eu and au now has a separate max order? I basically need a different magic number for every chart I attach the EA to right? Thanks for the help!

 
int total = OrdersTotal();
...
if (total < MaxOrders || MaxOrders == 0) { ...

You want to compare the total number of orders for that magic number/symbol to MaxOrders.

Currently you are comparing the total number of orders from ALL charts.

 

I'd just sat down with a mind to code this up for you but when I read this it put me right off:

"I really have no interest in learning - tried but lack motivation".


Sorry mate. Best of luck.


CB

Reason: