I need help on this modification

To add comments, please log in or register
sol4live
43
sol4live  
I am just starting to learn coding. So, I tried modify a code I found on FF site, I am stuck - I don't know how to get this done smoothly. I actually wanted the EA to always use total lotsize of loosing trade to open the next trade. For example, if there are 0.01, 0.02, 0.03, 0.04 lots of four different loosing, SELL positions, the every of the following BUY trades lot should be sum of loosing positions lots until there are no loosing sell positions. Same should happen on the reverse case.
Please see the attachment
Files:
Seng Joo Thio
1219
Seng Joo Thio  
sol4live:
I am just starting to learn coding. So, I tried modify a code I found on FF site, I am stuck - I don't know how to get this done smoothly. I actually wanted the EA to always use total lotsize of loosing trade to open the next trade. For example, if there are 0.01, 0.02, 0.03, 0.04 lots of four different loosing, SELL positions, the every of the following BUY trades lot should be sum of loosing positions lots until there are no loosing sell positions. Same should happen on the reverse case.

Since you're just starting to learn coding, don't attempt too many changes at one time.

Make small changes, compile and resolve ALL compilation issues, run, and observe what happens first, before moving on.

For a start, there are a few issues with this block:

int OnInit()
{
 double CalculateLots()
  {
      double totalBuyLots = 0;
      double totalSellLots = 0;
      
      for(int i=0; i < OrdersTotal(); i++)
      {
         if(OrderSelect(i, SELECT_BY_POS, MODE_TRADES) == true)
         {
            if (OrderSymbol() != Symbol() || OrderMagicNumber() != MagicNumber) continue;
            if (OrderSymbol() == Symbol() && OrderMagicNumber() == MagicNumber)
            {
               if(OrderType() == OP_BUY)
                  totalBuyLots += OrderLots();
               if(OrderType() == OP_SELL)
                  totalSellLots += OrderLots();
            }
         }    
 

      }
      
      return (totalBuyLots, totalSellLots);
  }
	:
	:

(1) You defined CalculateLots() function, but you never call it.

(2) A function cannot return two values. Declare it as void CalculateLots(double &totalBuyLots, double &totalSellLots) and remove the two 'double' and 'return' lines if you want it to give you two values.

(3) Move your CalculateLots() function out of OnInit(). Then call it within your xBest().

sol4live
43
sol4live  
Seng Joo Thio:

Since you're just starting to learn coding, don't attempt too many changes at one time.

Make small changes, compile and resolve ALL compilation issues, run, and observe what happens first, before moving on.

For a start, there are a few issues with this block:

(1) You defined CalculateLots() function, but you never call it.

(2) A function cannot return two values. Declare it as void CalculateLots(double &totalBuyLots, double &totalSellLots) and remove the two 'double' and 'return' lines if you want it to give you two values.

(3) Move your CalculateLots() function out of OnInit(). Then call it within your xBest().

thank you, I have done as you said. But I don't know how and where to call it.

please see the attachment. I am grateful, thanks.

Files:
Seng Joo Thio
1219
Seng Joo Thio  
sol4live:

thank you, I have done as you said. But I don't know how and where to call it.

please see the attachment. I am grateful, thanks.

In xBest(), where do you need to use totalBuyLots and totalSellLots? Just call CalculateLots() before you need to use them.

sol4live
43
sol4live  
Seng Joo Thio:

In xBest(), where do you need to use totalBuyLots and totalSellLots? Just call CalculateLots() before you need to use them.

I have called it. I want to use at the two places where I put '//============================================================================================='. please see the attachment.

thank you.

Files:
Seng Joo Thio
1219
Seng Joo Thio  
sol4live:

I have called it. I want to use at the two places where I put '//============================================================================================='. please see the attachment.

thank you.

Ok, the location of the call is fine. But while test running the code, I realized that CalculateLots() will never give you the right totalBuyLots and totalSellLots, because the xBest() function, which contains the code to call OpenTrade() which calls OrderSend() in turn, does not assign the right Magic number to the right order type (unnecessary in the first place, but the code defined two different magic numbers nevertheless, and assigned them wrongly to the order types)... 

As I've mentioned before, "Make small changes, compile and resolve ALL compilation issues, run, and observe what happens first, before moving on." But from the code, there are many areas that are poorly done - either because you made too many changes at one time without thorough checking, or because the original code you downloaded from FF was already broken. Either case, it'll require huge effort to rectify all issues now.

So my suggestion is either you restart from scratch, create your own EA bit by bit, so it'll be easier to ask more specific questions and get more direct help here if you hit snags along the way. Or if you insist on getting the entire EA done up in one go, check out the freelance section where you can get someone to fix the entire code for you.

sol4live
43
sol4live  
Seng Joo Thio:

Ok, the location of the call is fine. But while test running the code, I realized that CalculateLots() will never give you the right totalBuyLots and totalSellLots, because the xBest() function, which contains the code to call OpenTrade() which calls OrderSend() in turn, does not assign the right Magic number to the right order type (unnecessary in the first place, but the code defined two different magic numbers nevertheless, and assigned them wrongly to the order types)... 

As I've mentioned before, "Make small changes, compile and resolve ALL compilation issues, run, and observe what happens first, before moving on." But from the code, there are many areas that are poorly done - either because you made too many changes at one time without thorough checking, or because the original code you downloaded from FF was already broken. Either case, it'll require huge effort to rectify all issues now.

So my suggestion is either you restart from scratch, create your own EA bit by bit, so it'll be easier to ask more specific questions and get more direct help here if you hit snags along the way. Or if you insist on getting the entire EA done up in one go, check out the freelance section where you can get someone to fix the entire code for you.

Ok. I will try to build a new one from scratch. Thank you.

To add comments, please log in or register