Download MetaTrader 5

Question stoploss

To add comments, please log in or register
Rene Noteborn
216
Rene Noteborn  

Hallo I''m working on a trailingstop wich isnt sent to the broker everytime a better stoploss is possable. The problem I have is that the EA now Opens and closes orders in rappid fire. can someone help me?

 
 bool TS;
 if(OrdersTotal()>0)
 TS=true;
   
double currentprice = Bid;
 
int total = OrdersTotal();                                                                  
int tinknr;                                  
int trailingstop = 375 ;                
    
 if (TS==true)                           // als open posities is meer dan 0
   if (trailingstop>0)                           // als trailingstop is meer dan 0
   {
   for(int i=0; i<total; i++)                     // start loop tellen voor het achterhalen vah ordernummer vanaf 0 tot ordernummergevon
   OrderSelect(i,SELECT_BY_POS,MODE_TRADES);
   double orderopenprice=OrderOpenPrice();
 
 bool STOP;
 if (OrderType()==OP_BUY)
 STOP=1;
 if(orderopenprice-trailingstop > Bid-trailingstop)    
 STOP = orderopenprice-trailingstop;
 if(orderopenprice-trailingstop < Bid-trailingstop && Bid-trailingstop > STOP )   
 STOP = Bid-trailingstop;
 
 if (Bid <= STOP)
 RefreshRates();
 OrderClose(OrderTicket(),OrderLots(),Bid,3,Red);
 
 
 if (OrderType()==OP_SELL)
 STOP=9999;
 if(orderopenprice+trailingstop < Ask+trailingstop)    
 STOP = orderopenprice+trailingstop;
 if(orderopenprice+trailingstop > Ask+trailingstop && Ask+trailingstop < STOP )   
 STOP = Ask+trailingstop;

 double crp=iClose(NULL,0,0);
 if (Bid >= STOP)
 RefreshRates();
 OrderClose(OrderTicket(),OrderLots(),Ask,3,Red);
 
 }
Simon Gniadkowski
Moderator
18042
Simon Gniadkowski  
renen:

Hallo I''m working on a trailingstop wich isnt sent to the broker everytime a better stoploss is possable. The problem I have is that the EA now Opens and closes orders in rappid fire. can someone help me?

This code . . .

for(int i=0; i<total; i++)                     // start loop tellen voor het achterhalen vah ordernummer vanaf 0 tot ordernummergevon
   OrderSelect(i,SELECT_BY_POS,MODE_TRADES);

. . . selects the orders one by one and when it gets to the last one . . . this code, and the code following it, is executed . .

double orderopenprice=OrderOpenPrice();


You haven't shown any code which opens Orders so we can't comment on any "rapid fire" order opening.


This code doesn't do what you probably intended it to do . . .

 if (Bid <= STOP)    // if Bid <= STOP . . .
    RefreshRates();     //  do this line

 OrderClose(OrderTicket(),OrderLots(),Bid,3,Red);  // this line is executed regardless of the if statement above
To add comments, please log in or register