Taking Profit based on event

 

I was trying to figure out why this take profit is not working. The take profit is based on event which plot only "-1", "0" and "1". The buy side will get out when iCustom plot 1 and stay waiting for a signal if it's remain 0. The same logic for sell side take profit (-1,0). My logic is: when iCustom shows exit point get out instantaneously.


Thanks

Rodrigosm


void CheckForClose()
   {
   double BuyTakeProfit, SellTakeProfit;
   double BuyTakeProfitSignal = iCustom(Symbol(),0,"Q Breakout 2 e 20",1,0); 
   if(BuyTakeProfitSignal==-1)
   {  
      BuyTakeProfit=Close[0];
   }
   else
   {
      BuyTakeProfit=0;
   }
   
   double SellTakeProfitSignal = iCustom(Symbol(),0,"Q Breakout 2 e 20",0,0); 
   if(SellTakeProfitSignal==1)
   {  
      SellTakeProfit=Close[0];
   }
   else
   {
      SellTakeProfit=0;
   }
   
   //-----
   for(int cnt=0; cnt < OrdersTotal(); cnt++)
      {
      OrderSelect(cnt, SELECT_BY_POS, MODE_TRADES);
      if(OrderType()==OP_SELL &&   // check for opened SELL position 
      OrderSymbol()==Symbol())  // check for symbol
         {
         OrderModify(OrderTicket(),OrderOpenPrice(),0,SellTakeProfit,0,Red); 
         }
      if(OrderType()==OP_BUY &&   // check for opened BUY position 
      OrderSymbol()==Symbol())  // check for symbol
         {
         OrderModify(OrderTicket(),OrderOpenPrice(),0,BuyTakeProfit,0,Green); 
         }   
      }

   }
   
 

what error u get ?

 
rodrigosm:

I was trying to figure out why this take profit is not working. The take profit is based on event which plot only "-1", "0" and "1". The buy side will get out when iCustom plot 1 and stay waiting for a signal if it's remain 0. The same logic for sell side take profit (-1,0). My logic is: when iCustom shows exit point get out instantaneously.


Thanks

Rodrigosm


Hi Rodrigosm,

Your post says:

Buy TakeProfit = 1

Sell TakeProfit = -1

Your code says:

Buy TakeProfit = -1

Sell TakeProfit = 1

Looks like they are reversed?

Hope this helps,

Robert

 
cosmicbeing:

Hi Rodrigosm,

Your post says:

Buy TakeProfit = 1

Sell TakeProfit = -1

Your code says:

Buy TakeProfit = -1

Sell TakeProfit = 1

Looks like they are reversed?

Hope this helps,

Robert







Yeah, you are right, that was a mistake. But I corrected it and the expert still opening a position, but it never closes. The error that I got is:


OrderModify error1 and OrderModify error130.


Thanks for your help

 

SellTakeProfit=Close[0];
BuyTakeProfit=Close[0];

can never be done

 
qjol:

SellTakeProfit=Close[0];
BuyTakeProfit=Close[0];

can never be done



why? Does not it look for the last price and execute the order?
 

c MarketInfo(Symbol(), MODE_STOPLEVEL);

 
qjol:

c MarketInfo(Symbol(), MODE_STOPLEVEL);


I changed but the error still there. I create an indicator to show me the price when an event occurs and I did the modifications bellow, but it didn't work too.


void CheckForClose()
   {
   
   double SellTakeProfit = iCustom(Symbol(),0,"Q breakout 2 e 20 TakeProfit",0,0);
   double BuyTakeProfit  = iCustom(Symbol(),0,"Q breakout 2 e 20 TakeProfit",1,0);
      
   //-----

   for(int cnt=0; cnt < OrdersTotal(); cnt++)
      {
      OrderSelect(cnt, SELECT_BY_POS, MODE_TRADES);
      
      if(OrderType()==OP_SELL &&   // check for opened SELL position 
      OrderSymbol()==Symbol())  // check for symbol
         {
         OrderModify(OrderTicket(),OrderOpenPrice(),0,SellTakeProfit,0,Red); 
         }
      if(OrderType()==OP_BUY &&   // check for opened BUY position 
      OrderSymbol()==Symbol())  // check for symbol
         {
         OrderModify(OrderTicket(),OrderOpenPrice(),0,BuyTakeProfit,0,Green); 
         }   
      }

   }
 

Because I can't know what value your indicator output on the iCuston() what am I supposed to answer

 

Now it's working well. Thanks everybody that helped in this topic


void CheckForClose()
   {
   
     double SellTakeProfit = iCustom(Symbol(),0,"Q Breakout 2 e 20",0,0);
     double BuyTakeProfit  = iCustom(Symbol(),0,"Q Breakout 2 e 20",1,0);
      
   //-----

   for(int cnt=0; cnt < OrdersTotal(); cnt++)
      {
      OrderSelect(cnt, SELECT_BY_POS, MODE_TRADES);
      
      if(OrderType()==OP_SELL &&   // check for opened SELL position 
      OrderSymbol()==Symbol() && SellTakeProfit==-1)  // check for symbol
         {
            OrderClose(OrderTicket(),OrderLots(),Ask, 3,Red);
         }
      if(OrderType()==OP_BUY &&   // check for opened BUY position 
      OrderSymbol()==Symbol() && BuyTakeProfit==1)  // check for symbol
         {
            OrderClose(OrderTicket(),OrderLots(),Bid, 3,Green); /// Stop/TakeProfit for BUY position
         }   
      }

   }
Reason: