can somebody help with this code, it only nedds a couple of changes

 

Hi all, the following code i have, closes 50% of the open position at a certian level"using OrderClose" and then another function moved stoploss to breakeven and stores this in memory.

whet i need is for the code to move stoploss to breakeven only and not close partial position and remember this even if the platform is restarted. i am sure its only a few small adjustments to the existing code i have here.

I will be greatfull for someone to put this right. thanks.

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

int s2_orders[];

datetime last_close_time;

//--------------------------------------

nt init()
{

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

return(0);
}

//--------------------------------------

void close()
{

bool s2=false;

//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 (xxxzzzmmmxnnsbhjjjsjjjsjjs)

{
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");


}

}

//--------------------------------------

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

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));

}

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

 

 
qjol:

 
gavin:

Hi all, the following code i have, closes 50% of the open position at a certian level"using OrderClose" and then another function moved stoploss to breakeven and stores this in memory.

whet i need is for the code to move stoploss to breakeven only and not close partial position and remember this even if the platform is restarted. i am sure its only a few small adjustments to the existing code i have here.

I will be greatfull for someone to put this right. thanks.

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

int s2_orders[]; 

datetime last_close_time;

//-------------------------------------- 

nt init()
{

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

return(0);
}

//-------------------------------------- 


void close()
{

bool s2=false;

//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 (xxxzzzmmmxnnsbhjjjsjjjsjjs) 

{
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");


}

}

//-------------------------------------- 

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

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));

}

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

 
OrderLots()/2
Won't work. Lots must be a multiple of step size and at least minLots
double  minLot  = MarketInfo(Symbol(), MODE_MINLOT),
        LotStep = MarketInfo(Symbol(), MODE_LOTSTEP),
        closeSz = MathMax(minLot
                         , MathFloor(OrderLots()/2/LotStep)*LotStep
                         );
Reason: