View Single Post
  #2 (permalink)  
Old 06-06-2009, 02:07 AM
wolfe's Avatar
wolfe wolfe is offline
Senior Member
 
Join Date: Jan 2006
Posts: 820
wolfe is on a distinguished road
Quote:
Originally Posted by ajk View Post
Since hedging is not allowed anymore... does anyone have any trade ea manager or something that would reverse the trade immediately after close when a trade hits a stop loss...
or can any one show me how to add a pending order as a sell (below is a buy) so that it triggers as soon as sl is hit?
Thoughts?
ANy help appreciated!.

int OpenOrder(int type)
{
int ticket=0;
int err=0;
int c = 0;

if(type==OP_BUY)
{
for(c = 0 ; c < NumberOfTries ; c++)
{
ticket=OrderSend(Symbol(),OP_BUY,Lots,Ask,Slippage ,Ask-StopLoss*Point,Ask+TakeProfit*Point,ExpertComment, MagicNumber,0,Yellow);
err=GetLastError();
if(err==0)
{
break;
}
else
{
if(err==4 || err==137 ||err==146 || err==136) //Busy errors
{
Sleep(5000);
continue;
}
else //normal error
{
break;
}
}
}
}
Something like this should work, as long as your s/l is greater than the MarketInfo(Symbol(),MODE_STOPLEVEL).

PHP Code:
 int OpenOrder(int type)
  {
   
int ticket=0;
   
int err=0;
   
int c 0;
   
double StopLoss_SellStop_Open =0;

   if(
type==OP_BUY)
    {
     for(
NumberOfTries c++)
      {
       
StopLoss_SellStop_Open Ask-StopLoss*Point;
       
ticket=OrderSend(Symbol(),OP_BUY,Lots,Ask,Slippage ,StopLoss_SellStop_Open,Ask+TakeProfit*Point,"ExpertComment"MagicNumber,0,Yellow);
       
err=GetLastError();
       if(
err==0)
        {
         
OrderSend(Symbol(),OP_SELLSTOP,Lots,StopLoss_SellStop_Open,Slippage,NULL,NULL,"ExpertComment",MagicNumber,0,Red);
         break;
        }
       else
        {
         if(
err==|| err==137 ||err==146 || err==136//Busy errors
          
{
           
Sleep(5000);
           continue;
          }
         else 
//normal error
          
{
           break;
          }
        }
      }
    } 
You of course would have to decide what to do for your s/l and t/p for the pending order.
Reply With Quote