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 minLotsdouble minLot = MarketInfo(Symbol(), MODE_MINLOT), LotStep = MarketInfo(Symbol(), MODE_LOTSTEP), closeSz = MathMax(minLot , MathFloor(OrderLots()/2/LotStep)*LotStep );
You are missing trading opportunities:
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
Registration
Log in
You agree to website policy and terms of use
If you do not have an account, please register
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));
}
//+------------------------------------------------------------------+