How Can I Check If there are Orders open in the OnInit() Function ++ which magicnumber they belong to?

 

read above...


I want too save time during backtests, so I only want to check it in OnInit(). Is that possible?

Sadly the following doesnt work:(

int OnInit()
  {StartOrder =OrderSend (Symbol(),OP_BUY,Lot,Ask,10,0,0,"StartOrder",EA1_MagicNummer,0,Orange); //<-for testing purposes
Set_SL=OrderModify (OrderSelect(StartOrder,SELECT_BY_TICKET),OrderOpenPrice(),NormalizeDouble(OrderOpenPrice()/(1+(0.2/100)),Digits),OrderTakeProfit(),0,Yellow);

int total=OrdersTotal();
if(total==0) {
           return (ShortOrders=0);
            return (LongOrders=0);
           }

else if (total>0){
for(int Ordercount=0; Ordercount<=total; Ordercount++)
{
if(OrderSelect(Ordercount,SELECT_BY_POS,MODE_TRADES) && OrderMagicNumber()==EA1_MagicNummer && OrderType()==OP_BUY){LongOrders++;LongTicket=OrderTicket();} 
if(OrderSelect(Ordercount,SELECT_BY_POS,MODE_TRADES) && OrderMagicNumber()==EA1_MagicNummer && OrderType()==OP_SELL){ShortOrders++;ShortTicket=OrderTicket();}
           }
           return (LongOrders);
           return (ShortOrders);}
  
//---
   return(INIT_SUCCEEDED)
   ;
           return (ShortOrders);Print (ShortOrders);
           return (LongOrders);Print (LongOrders);

//is that Possible? I mean to get 2 Return values? And how can I return the "LongTicket" from ^straight above there ->    ^^^^^^ (I need them later for an Ordermodify)





void OnTick(){

  if (LongOrders==0){
  LongOrderSend=OrderSend(Symbol(),OP_BUY,Lot,Bid,10,0,0,"einfach Long",EA1_MagicNummer,0,Blue);
  LongOrders++;
    
    }
  {if (ShortOrders==0){
  ShortOrderSend=OrderSend(Symbol(),OP_SELL,Lot,Ask,10,0,0,"einfach Long",EA1_MagicNummer,0,Blue);}
  ShortOrders++;


  }
//---
   
  }

Or is there another way to :

Check the Count of Long & Short Orders with the right MagicNumber ->>> and choose exactly those Orders to Modyfy them (for example via Ticket) <--- AND all this with minimum Code ??

Reason: