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

 
it gives me <Stack Overflow> error! And the problem is in the library file:
<LimitTakeProfit.mqh>
Anyone figured out what went wrong?
 

hello Readers! 

did anyone else stumble upon the "stack overflow " error ?

I think the problem lies in the  "LimitTakeProfit.mqh" library!!!

 

Hello Dmitry,


Thank you for your interesting article!


Please, would you explain error "paramter passed as reference, variable expected" related of each of the following lines (line 54, 55, 56)?


CSymbolInfo    CLimitTakeProfit::c_Symbol       =  new CSymbolInfo();

CArrayLong     CLimitTakeProfit::i_TakeProfit   =  new CArrayLong();

CArrayDouble   CLimitTakeProfit::d_TakeProfit   =  new CArrayDouble();


Thanks!

 
Mario Marconi #:

Hello Dmitry,


Thank you for your interesting article!


Please, would you explain error "paramter passed as reference, variable expected" related of each of the following lines (line 54, 55, 56)?


CSymbolInfo    CLimitTakeProfit::c_Symbol       =  new CSymbolInfo();

CArrayLong     CLimitTakeProfit::i_TakeProfit   =  new CArrayLong();

CArrayDouble   CLimitTakeProfit::d_TakeProfit   =  new CArrayDouble();


Thanks!

Hi, do you use?

#include <Arrays\ArrayDouble.mqh>
#include <Arrays\ArrayLong.mqh>
#include <Trade\SymbolInfo.mqh>
 
Dmitriy Gizlyk #:

Hi, do you use?

Hi Dmitry,

The following lines are exactly written on your "LimitTakeProfit.mqh":

#include <Arrays\ArrayDouble.mqh>
#include <Arrays\ArrayLong.mqh>
#include <Trade\SymbolInfo.mqh>

More precisely, such error "paramter passed as reference, variable expected" come from compilation of your EA "MACD Sample LImitTP.mq5".


Thank you for answering!

 
Mario Marconi #:

Hi Dmitry,

The following lines are exactly written on your "LimitTakeProfit.mqh":

More precisely, such error "paramter passed as reference, variable expected" come from compilation of your EA "MACD Sample LImitTP.mq5".


Thank you for answering!

Hi, you must add * before paprameter

CSymbolInfo    *CLimitTakeProfit::c_Symbol       =  new CSymbolInfo();
CArrayLong     *CLimitTakeProfit::i_TakeProfit   =  new CArrayLong();
CArrayDouble   *CLimitTakeProfit::d_TakeProfit   =  new CArrayDouble();
 
Dmitriy Gizlyk #:

Hi, you must add * before paprameter

Hi Dmitry,


Something is still not working, the same three lines gives the following errors:

- parameter passed as reference, variable expected LimitTakeProfit.mqh 54 57

- redefinition; different type modifiers LimitTakeProfit.mqh 54 35


Thank you for answering!

 

Hi Dmitry,

I know this article was published a while ago, but I wanted to thank you for it! It is very useful, your explanation is really clear, and the class works like a charm. Thank you!

I believe I found a minor bug in the posted code. Halfway through function SetTakeProfits, we find this line:

switch((ENUM_POSITION_TYPE)PositionGetInteger(POSITION_TYPE))

This is inside a loop through all TP. The problem is that later in the loop, function CheckLimitOrder is called, who in turn calls function CheckOrderInHistory, and there another Position may be selected. This means that in the next iteration of the loop, the "switch" in the code above may be different.

To solve this, I believe that position_type should be stored in a variable, before the loop begins. Thus:

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

// (...)

   double position_volume=PositionGetDouble(POSITION_VOLUME);

//********** ADD THE NEXT LINE
   ENUM_POSITION_TYPE position_type=(ENUM_POSITION_TYPE)PositionGetInteger(POSITION_TYPE);
//****************************

   double closed=0;
   double closed_perc=0;
   double fix_closed_per=0;
//---
   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)
        {
         if(closed>=100 || fix_closed_per>=100)
            break;
//---
         double lot=position_volume*MathMin(d_TakeProfit.At(i),100-closed_perc)/(100-fix_closed_per);
         lot=MathMin(position_volume-closed,lot);
         lot=c_Symbol.LotsMin()+MathMax(0,NormalizeDouble((lot-c_Symbol.LotsMin())/c_Symbol.LotsStep(),0)*c_Symbol.LotsStep());
         lot=NormalizeDouble(lot,2);
         tp_request.volume=lot;

//********** MODIFY THE NEXT LINE
         //switch((ENUM_POSITION_TYPE)PositionGetInteger(POSITION_TYPE))
         switch(position_type)
//*******************************
           {
            case POSITION_TYPE_BUY:
              tp_request.type=ORDER_TYPE_SELL_LIMIT;
              tp_request.price=c_Symbol.NormalizePrice(open_price+i_TakeProfit.At(i)*c_Symbol.Point());

// (...)

Hope this makes sense. Again, thanks for an excellent job!

 

Hello everyone!

I'm having a [Invalid expiration] problem, anyone knows how to fix it?

 

Hello.

When testing the EA with LimitTakeProfit, it returns the following error message: "Invalid expiry".

I've tried adding expiry along with the trade request structure, but to no avail.

Someone please help me.

Machine translation applied by moderator