Discussion of article "Using limit orders instead of Take Profit without changing the EA's original code" - page 5

 
This is all I ever wanted, thank you SO MUCH. Love you.
 

Hi dear

i try to find the way to defined the special Take Profit for my expert that i started to write it. your text was useful for me but i could not correct mine, so , if it is possible to you , please guide me. my TP plane is: when set the for example Buy in chart and it go in right way and profit, TP value move to maximum profit point, so when the trend turn change the straight to down way , TP value placed in 70 percent of maximum profit. below cod is the code which i write. please let me know m wrongs and help me to correct them.

 double BuyPipsProfit,SellPipsProfit,BuyProfitLevel,SellProfitLevel;
   double TP_Buy=0;
   double TP_Sell=0;
  
   for(int i=OrdersTotal()-1;i>=0;i--)                                    
     {
      if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES))
      {
        BuyPipsProfit= Ask-(double)OrderOpenPrice() ;
        SellPipsProfit= (double)OrderOpenPrice()-Bid;
        BuyProfitLevel= BuyPipsProfit*.7;
        SellProfitLevel= SellPipsProfit*.7;
        TP_Buy = (50*Point)+ ((OrderOpenPrice()+ BuyProfitLevel)*Point);
        TP_Sell= (50*Point)+ ((OrderOpenPrice()+ SellProfitLevel)*Point);
       }
      }

 

Hello,

Don't work.

LimitTakeProfit.mqh error:

unresolved static variable 'CLimitTakeProfit::i_Magic' LimitTakeProfit.mqh 29 43
unresolved static variable 'CLimitTakeProfit::b_OnlyOneSymbol' LimitTakeProfit.mqh 32 52
unresolved static variable 'CLimitTakeProfit::i_TakeProfit' LimitTakeProfit.mqh 507 14
unresolved static variable 'CLimitTakeProfit::d_TakeProfit' LimitTakeProfit.mqh 512 17
unresolved static variable 'CLimitTakeProfit::c_Symbol' LimitTakeProfit.mqh 160 9

Thank you.

Files:
 

@MetaQuotes, thanks for this code!

I have found a bug  in this function and give my humble solution:

bool CLimitTakeProfit::SetTakeProfits(ulong position_ticket, double new_tp=0)


If we have 2 TP and the first one have been closed, the second one will be WRONG closed here:

if(CheckLimitOrder(tp_request))
  {
   if(tp_request.volume>=0)
     {
      closed+=tp_request.volume;
      closed_perc=closed/position_volume*100;
     }
   else
     {
      fix_closed_per-=tp_request.volume/(position_volume-tp_request.volume)*100;
     }
   continue;
  }


Why? Because when searching for the first TP in this function:

CheckOrderInHistory(PositionGetInteger(POSITION_IDENTIFIER),request.comment, request.type, request.volume);

We change the selected position, so, in the loop:

   for(int i=0;i<total;i++)
     {

      tp_request.comment="TP"+IntegerToString(i)+"_"+IntegerToString(position_ticket);
      
      if(i_TakeProfit.At(i)<tp_int && d_TakeProfit.At(i)>0)

We use the wrong position to evaluate second TP here:

switch((ENUM_POSITION_TYPE)PositionGetInteger(POSITION_TYPE))


Causing the second TP to be closed! My fix is:

for(int i=0;i<total;i++)
   {
      /****** NEW LINE **************/
      PositionSelectByTicket(position_ticket);
      /****** NEW LINE **************/

      tp_request.comment="TP"+IntegerToString(i)+"_"+IntegerToString(position_ticket);
      
      if(i_TakeProfit.At(i)<tp_int && d_TakeProfit.At(i)>0)


Thanks again!

 
Roco Deodato Giaculi #: Hello, Don't work. LimitTakeProfit.mqh error: Thank you.

Did you use the original code or did you add the code to your advisor?

 

I've never made it work.

 

Good afternoon @Dmitriy Gizlyk, Could you help with this problem? I've tried a lot of things but I can't get out of this error. If you can help, thank you.


 
Can you help me please? I don't know how to programme etc. I just wanted my profit to be plotted as a limited order (if you could describe how to use your file I would be very grateful).
 
FalconGhost2 : Can you help me please? I don't know how to programme etc. I just wanted my profit to be plotted as a limit order (if you could describe how to use your file I would be very grateful).

Hi, You can't use this file if you use manual trading. It is for use in EA.

Regards, Dmitry.

 
Dmitriy Gizlyk #: Hello, You can't use this file if you use manual trading. It's for EA use. Best regards, Dmitry.

Thanks for replying Dmitriy! Do you know if there is another way to do manual trading?

This website uses cookies. Learn more about our Cookies Policy.