Takeprofit that changes within the trade

 

Hi everybody!

I'm pretty new to mql4, but I think, that I have a great strategy, however, my skills are not on the required level. I have just one simple question, that I haven't found answered yet-

when you want to have takeprofit that changes it's value within every tick, how do you do that?

To implement my question into my strategy: I want to close my trade, whenever it reaches Boillinger Bands- the center line. But if i code it simply into this line- ticket=OrderSend(Symbol(),OP_SELL,Lots,Bid,3,Bid+Stoploss*Point,BB,"bb-strategy",16384,0,Red);

where BB=iBands(NULL, 15, 12, 2, 0, PRICE_CLOSE,MODE_MAIN,0);

this creates takeprofite, that is equal to BB line at the time of the trade witout any changes within the trade.. I hope you understood my problem and that you can help me..

Thanks a lot 

 
Kecupak:

Hi everybody!

I'm pretty new to mql4, but I think, that I have a great strategy, however, my skills are not on the required level. I have just one simple question, that I haven't found answered yet-

when you want to have takeprofit that changes it's value within every tick, how do you do that?

To implement my question into my strategy: I want to close my trade, whenever it reaches Boillinger Bands- the center line. But if i code it simply into this line- ticket=OrderSend(Symbol(),OP_SELL,Lots,Bid,3,Bid+Stoploss*Point,BB,"bb-strategy",16384,0,Red);

where BB=iBands(NULL, 15, 12, 2, 0, PRICE_CLOSE,MODE_MAIN,0);

this creates takeprofite, that is equal to BB line at the time of the trade witout any changes within the trade.. I hope you understood my problem and that you can help me..

Thanks a lot 

You can use OrderModify() to change the Stop Loss and Take Profit of an open order as long as what you are doing complies with this:  Requirements and Limitations in Making Trades
 
RaptorUK:
You can use OrderModify() to change the Stop Loss and Take Profit of an open order as long as what you are doing complies with this:  Requirements and Limitations in Making Trades


Any other ideas? Because the minimum distance from price to TP has to be 50 points, and it would mean, that on bar has to overcome these 5pips.... I tried to close the order by OrderClose, but it doesn't work :( I'll semd you whole code, so you'll see....
 
#property copyright "Copyright © 2011, MetaQuotes Software Corp."
#property link      "http://www.metaquotes.net"


extern double Lots = 0.1;
extern double Stoploss = 80;
int start()
  {
   double BB, HBB, LBB;
   double i,konec, max, min;
   double ordera,orderb;
   int cnt, ticket, total;
   
   BB=iBands(NULL,15,12,2,0,PRICE_CLOSE,MODE_MAIN,0);
   HBB=iBands(NULL,15,12,2,0,PRICE_CLOSE,MODE_UPPER,0);
   LBB=iBands(NULL,15,12,2,0,PRICE_CLOSE,MODE_LOWER,0);
   konec=iClose("EURUSD",15,1);
   max=iHigh("EURUSD",15,1);
   min=iLow("EURUSD",15,1);
   
   
   total=OrdersTotal();
    if(total<1)
      {if (LBB>min&&konec>LBB)
   
         {ticket=OrderSend(Symbol(),OP_BUY,Lots,Ask,3,Ask-Stoploss*Point,BB,"bb-strategy",16348,0,Green);
         if(ticket>0)
            {
            if(OrderSelect(ticket,SELECT_BY_TICKET,MODE_TRADES)) 
            orderb=OrderTicket();
            Print("BUY order opened : ",OrderOpenPrice());
                
            }
           
          else Print("Error opening BUY order : ",GetLastError());
          
         return(0);
         }
         
         
          
       {if (HBB<max&&konec<HBB)
         {
         ticket=OrderSend(Symbol(),OP_SELL,Lots,Bid,3,Bid+Stoploss*Point,BB,"bb-strategy",16384,0,Red);
         if(ticket>0)
           {
            if(OrderSelect(ticket,SELECT_BY_TICKET,MODE_TRADES))
            ordera=OrderTicket();
             Print("SELL order opened : ",OrderOpenPrice());
           }
         else Print("Error opening SELL order : ",GetLastError()); 
         
         return(0); 
         }
         if (total>0&&Ask>BB)
         {OrderClose(orderb,Lots,Ask,3,CLR_NONE);}
         return(0);
         if (total>0&&Ask<BB)
         {OrderClose(ordera,Lots,Ask,3,CLR_NONE);}
         return(0);
            
        return(0);
      }
   
    
      return(0);}
 
Kecupak:

Any other ideas? Because the minimum distance from price to TP has to be 50 points, and it would mean, that on bar has to overcome these 5pips.... I tried to close the order by OrderClose, but it doesn't work :( I'll semd you whole code, so you'll see....
Whatever you do it has to comply with  Requirements and Limitations in Making Trades   otherwise you will get a failed OrderSend()/OrderModify()/OrderClose()

The easiest option is to get a different Broker . . .
 

Whatever I use nothing works :(

Did you try my code listed above? 

 
Kecupak:

Whatever I use nothing works :(

Did you try my code listed above? 

Nope.  Does it comply with the information in the Article I linked to ?
 
Kecupak:

Whatever I use nothing works :(

{OrderClose(orderb,Lots,Ask,3,CLR_NONE);}

Did you try my code listed above? 

Of course nothing work, your code is broken.
  1. First you ask about OrderModify. Your posted code doesn't have any.
  2. Then you try OrderClose. What is the value of orderb? ZERO! (except on the tick you opened the order.) Loops and Closing or Deleting Orders - MQL4 forum
  3. Use What are Function return values ? How do I use them ? - MQL4 forum and you would have already learned #2
Reason: