Can anyone help with this??

 

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;
for (i = 0 ; i < OrdersTotal() ; i++)
            {
               
               OrderSelect(i,SELECT_BY_POS,MODE_TRADES);
               //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 (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)); } //+------------------------------------------------------------------+
 
OrderModify(OrderTicket(),OrderOpenPrice(),OrderOpenPrice(),OrderTakeProfit...
Before you can use those function you must OrderSelect. Either loop through your array and select by ticket. or just loop:
for(int pos = OrdersTotal()-1; pos >= 0 ; pos--) if (
    OrderSelect(pos, SELECT_BY_POS)             // Only my orders w/
&&  OrderMagicNumber() == Magic.Number          // my magic number
&&  OrderSymbol()      == Symbol() ){           // and period and symbol
Note, you must code the EA to recover from restarts (power failure, terminal crash/close, etc) so you're either have to have persistent storage of your ticket array or just the above to reload the array or drop the array and just process existing orders directly.
 
WHRoeder:
Before you can use those function you must OrderSelect. Either loop through your array and select by ticket. or just loop:Note, you must code the EA to recover from restarts (power failure, terminal crash/close, etc) so you're either have to have persistent storage of your ticket array or just the above to reload the array or drop the array and just process existing orders directly.


ok, the code i have here at the minute works, it closes 50% of a trade and then moves stoploss to breakeven. This move to breakeven is stored in memory, so even if the platform is restarted it ea remembers this.

what i neeed is this code to move stop to breakeven only and not close partial profit. So really removing the orderclose part. i have tried myself for a few days to sort the problrm but i cant figure it out. I am pretty soue its only a few small adjustments to what i have already posted. I will edit my post now to add in bit more of my code..

 
gavin:


ok, the code i have here at the minute works, it closes 50% of a trade and then moves stoploss to breakeven. This move to breakeven is stored in memory, so even if the platform is restarted it ea remembers this.

what i neeed is this code to move stop to breakeven only and not close partial profit. So really removing the orderclose part. i have tried myself for a few days to sort the problrm but i cant figure it out. I am pretty soue its only a few small adjustments to what i have already posted. I will edit my post now to add in bit more of my code..


like WHRoeder said

u must use OrderSelect()
the only reason u cant figure it out is becouse u r not using OrderSelect()

try to start over but with using OrderSelect() & u will c that everything works out

 
qjol:


like WHRoeder said

u must use OrderSelect()
the only reason u cant figure it out is becouse u r not using OrderSelect()

try to start over but with using OrderSelect() & u will c that everything works out


Ok here is what i have now. its not working. Is it a change needed in s2 orders..?

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)); } //+------------------------------------------------------------------+
 

i'm sorry, can this thing be compiled ?

 
OrderModify(OrderTicket(),OrderOpenPrice(),OrderOpenPrice(),OrderTakeProfit(),0,Blue);
is definitely wrong.
 
qjol:

i'm sorry, can this thing be compiled ?


yea it can be compiled. what i have posted cannot because its not the full ea.
 
WHRoeder:
is definitely wrong.

OrderModify(OrderTicket(),OrderOpenPrice(),OrderOpenPrice(),OrderTakeProfit(),0,Blue);

what is wrong with this. i use this in my code all the time??
 
WHRoeder:
is definitely wrong.

maybe he want the SL @ the OrderOpenPrice()
 
qjol:

maybe he want the SL @ the OrderOpenPrice()

yea thats exactly what i want modifying the order to openprice"breakeven". But if you both read back on the question at hand i am sure who cill know what is wrong here. you both seen to know alot about coding. i dont.
Reason: