Download MetaTrader 5
To add comments, please log in or register
Unable to find the answer to your question? Use the search!
trader3000
227
trader3000 2016.03.17 10:06 

Hi Everyone.  I need help again, please.  I would like to incorporate the following into my EA, but it is completely ignored.  Why does the EA not call the Maxlots function?  When I run the EA on the Strategy tester, the Lotsize go much higher than my input.  Thank you.  EDIT:  Also I just noticed that the Stoploss feature doesn't work either.

extern double Maxlots=50;  //<------ This is ignored

int start()
  {
   int TS=TrailingStart-TrailingStop;
   int stoplevel=(MarketInfo(Symbol(),MODE_STOPLEVEL))/10;
   if(StopLoss<=stoplevel) StopLoss=stoplevel;
   if(Stoploss<=stoplevel) Stoploss=stoplevel;
   if(TS<=stoplevel) TrailingStart=stoplevel+TrailingStop;
   double Lots = NormalizeDouble(AccountEquity()*Percentage*Lotsize/100, 2);
   double SL=StopLoss*Point*10;
   double point=Point*10;
   double MinLots = MarketInfo(Symbol(),MODE_MINLOT);
   double MaxLots = MarketInfo(Symbol(),MODE_MAXLOT);
   double HedgeLots=NormalizeDouble(OrderLots()*Multiplier,2);

   if(Lots>MaxLots) Lots=MaxLots;
   if(Lots>Maxlots) Lots=Maxlots;
   if(Lots<MinLots) Lots=MinLots;
   if(HedgeLots>MaxLots) HedgeLots=MaxLots;
   if(Lots>MaxLots || Lots<MinLots || HedgeLots>MaxLots)
     {
      MessageBox("Lotsize have been adjusted automatically");
     }
   //Rest of code for OrderSelect and OrderSend, etc.
whroeder1
13602
whroeder1 2016.03.17 14:41  
Trader3000: Why does the EA not call the Maxlots function? 
  1. Not a function, it is a variable.
  2. Of course it is ignored because you declared a local variable of the same name. You would know this had you set #property strict.
    extern double Maxlots=50;  //<------ This is ignored
    int start(){
       :
       double MaxLots = MarketInfo(Symbol(),MODE_MAXLOT);

  3. Do NOT use NormalizeDouble, EVER. For ANY Reason. It's a kludge, don't use it. It's use is always wrong
    double HedgeLots=NormalizeDouble(OrderLots()*Multiplier,2);
Keith Watford
Moderator
7896
Keith Watford 2016.03.17 21:49  

Your code is easy to misread because of your use of variables with similar names

MaxLots and Maxlots

StopLoss and Stoploss

You don't show any code for OrderSend, so we don't know what variables you are using for that


   if(Lots>MaxLots || Lots<MinLots || HedgeLots>MaxLots)

There is little point in this test after you have modified the values.

  if(a!=b)
     a=b;
  if(a!-b)
     Print("This will never be printed because I have modified a to equal b");
trader3000
227
trader3000 2016.03.18 12:54  

Thank you very much to both of you for your help.  I'm not sure what I did wrong, but the MaxLots/MinLots does work now.  Thank you also for the links.  I will study the information and fix my issues such as point to ticksize because I do want to do it right.  My apologies also for the confusion I caused with using small and capital letters.  I fixed this.  In future I will also use #property strict.  Since I started using this, I now have the following warning: "possible loss of data due to type conversion" on this line:

int stoplevel=(MarketInfo(Symbol(),MODE_STOPLEVEL))/10;

I googled this and it appears as if the issue lies with whether the value that is returned is an integer or double.  I printed the stoplevel for the EURUSD, and it prints "5.0".  So I changed from int stoplevel to double stoplevel, but the warning still exists. While I read all the articles and documentation on this issue I am unable to resolve it.

My code looks like this:

extern double MyMaxlots=20;

int start()
  {
   int TS=TrailingStart-TrailingStop;
   double stoplevel=(MarketInfo(Symbol(),MODE_STOPLEVEL))/10;
   if(StopLossOriginal<=stoplevel) StopLossOriginal=stoplevel;
   if(StopLossHedge<=stoplevel) StopLossHedge=stoplevel;
   if(TS<=stoplevel) TrailingStart=stoplevel+TrailingStop;
   double Lots = AccountEquity()*Percentage*Lotsize/100;
   double point=Point*10;
   double SL=StopLossOriginal*point;
   double MinLots = MarketInfo(Symbol(),MODE_MINLOT);
   double MaxLots = MarketInfo(Symbol(),MODE_MAXLOT);
   double HedgeLots=NormalizeDouble(OrderLots()*Multiplier,2);
   
   if(Lots>MaxLots) Lots=MaxLots;
   if(Lots>MyMaxlots) Lots=MyMaxlots;
   if(Lots<MinLots) Lots=MinLots;
   //if(HedgeLots>MaxLots) HedgeLots=MaxLots;
   if(HedgeLots>MyMaxlots) HedgeLots=MyMaxlots*3;
/
To add comments, please log in or register