array problem. advanced knowledge required.

 

The following code is fully working. it closes 50% of a open trade. It then moves stoploss to breakeven point. It stores the fact that stop has noved to breakeven. "s2=true".

What i need is some changes so that the code will move stoploss to breakeven only and remember this if the platform is restarted. I do not want partial close. There is prob some mods to be made in the "s2 array", i dont know what.

If someone can sort this for me i will reward them with a payment if the wish. I need to get this sorted asap.

thanks

int s2_orders[]; 

datetime last_close_time;




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

  
  last_close_time=TimeCurrent();
//Alert(GetLastError()," ",last_close_time);

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

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

close();
   
//----
   return(0);
  }
//+------------------------------------------------------------------+

void close()
{

bool s2=false;

for (int pos=OrdersTotal()-1;  pos >=0; pos--)
            {
               
               OrderSelect(pos, SELECT_BY_POS);
               //Alert(OrdersTotal()," ",OrderTicket()," ",OrderMagicNumber());
               s2=false;
              //Alert(OrderComment()," ",cnt," ",OrderTicket(), " ",OrderMagicNumber()," ",OrderSymbol());
            if (OrderMagicNumber() == MAGIC)
               {
                  if(OrderSymbol()==Symbol())
                     {

  //Moving stop to breakeven point

  //Alert(OrderTicket()," : ",OrderComment());
  if ((StringSubstr(OrderComment(), 0, 6)=="from #" || StringSubstr(OrderComment(), 0, 12)=="split from #") && close_partial_lots==true)
    { 
  OrderModify(OrderTicket(),OrderOpenPrice(),OrderOpenPrice(),OrderTakeProfit(),0,Blue);
  //Alert(" In 2nd stage - ",OrderTicket());
  s2=true;
  //break;

           }
         }
       }
     }
   }


    if (xxxyyyzzz) 
         {
    last_close_time=TimeCurrent();
    new_trade=false;
    //Alert(GetLastError()," 3 ",MarketInfo(OrderSymbol(),MODE_BID)," ",OrderTicket()," ",OrderLots());
    Alert(GetLastError()," BUY/TP/S1"," ",OrderTicket()," ",Bid-OrderOpenPrice());
    s2_orders(OrderTicket(),"add");
        }
        
}
//+------------------------------------------------------------------+ 

void s2_orders(int ticket,string mode)
{
int i;
string s="";

for (i=0;i<ArraySize(s2_orders);i++)
{
if (s2_orders[i]!=0) s=s+","+DoubleToStr(s2_orders[i],0);
//Alert(ticket," removed from virtual repository");
}
//Alert(ArraySize(s2_orders)," S2 orders: ",s);

if (mode=="add")
{
ArrayResize(s2_orders, ArraySize(s2_orders)+1);
s2_orders[ArraySize(s2_orders)-1]=ticket;
}
if (mode=="remove")
{
for (i=0;i<ArraySize(s2_orders);i++)
{
if (s2_orders[i]==ticket) s2_orders[i]=0;
//if (s2_orders[i]!=0) s=s+DoubleToStr(s2_orders[i],0);
//Alert(ticket," removed from virtual repository");
}
}
//Alert("Virtual Details: ",ArraySize(s2_orders));

}

//+------------------------------------------------------------------+ 
 
whats the problem with the arrays?
 
zzuegg:
whats the problem with the arrays?

                           { 
                            OrderClose(OrderTicket(),OrderLots()/2,MarketInfo(OrderSymbol(),MODE_BID),3,Violet);
                            last_close_time=TimeCurrent();
                            new_trade=false;
                            //Alert(GetLastError()," 3 ",MarketInfo(OrderSymbol(),MODE_BID)," ",OrderTicket()," ",OrderLots());
                            Alert(GetLastError()," BUY/TP/S1"," ",OrderTicket()," ",Bid-OrderOpenPrice());
                            s2_orders(OrderTicket(),"add");
                            GlobalVariableSet(s2,OrderTicket());

                           }

everything worked when the ea was like this above, it was closing 50%, then moving stop to breakeven and storing the fact that "s2=true" when stop had moved to breakeven.

read the code i posted you might see the problem? hope you can. cheers.

 
can you explain what you want to do in this s2_orders function? (i don't know how mt4 behave if functions and variables have the same name)
 

basically what i need here is; when xzy happens on a position, stoploss is moved to breakeven. this then changes the bool s2 to "s2=true". the fact that s2 is then true need to be stored, so if the platform is restarted it will still be true until that order is deleted. s2 may be true on one curreny piar but false on another at the same time.

i hope this helps

 

any helpers with this

Reason: