Any questions from newcomers on MQL4 and MQL5, help and discussion on algorithms and codes - page 724

 
Igor Makanu:

Most likely you need variant 1, then in the indicator in the calculation cycle, where you search for bars, you use the following structure:

You have the required time in Time[i] after checking the condition

Thank you for your reply. I use theCheckTimer() functionwhere I passthe startTime,endTime as date.TimeDayOfWeek()returns values from 1 to 5 as I understand it. How can I convert them to date format to use them inCheckTimer()function? Or will I have to modify this function too?

 
Gerkl:

Thanks for the reply. I useCheckTimer() functionwhere I passstartTime,endTime as date.TimeDayOfWeek()returns values from 1 to 5 as I understand. How can I convert them to date format to use them inCheckTimer()function? Or will I have to modify this function too?

How about this

int   shift = iBarShift(NULL,PERIOD_W1,Time[i]);  
  
datetime startTime = iTime(NULL,PERIOD_W1,shift); 
datetime endTime = startTime + PeriodSeconds(PERIOD_W1); 
 
Alekseu Fedotov:

Maybe so

Thank you, but it shows all week from Sunday to Sunday and I need Monday to Friday (trading week).


Week

 

What is the best way to put 10 copies of the same EA in one EA, but with different parameters?


I think so...
The entire code of the EA in one function.
And just make the input parameters of the EA parameters of the function.

In Ontick, just register the function 10 times, with different parameters.


And we should divide the orders through comment.
To prescribe different comments for different copies of the EA.

 
multiplicator:

What is the best way to put 10 copies of the same EA in one EA, but with different parameters?


I think so...
The entire code of the EA in one function.
And just make the input parameters of the EA parameters of the function.

In Ontick, just rewrite the function 10 times, with different parameters.


And we should divide the orders through comment.
We will write different comments for different copies of the EA.

It is better to make different Majiks

 
Vladimir Pastushak:

It's better to make the Mejis different

Why better?
It's just that maybe there will still be another EA trading there.
 
Gerkl:

Thank you, but that's how it shows the whole week from Sunday to Sunday, while I need Monday to Friday (trading week).

If that suits you, add 5 days worth of time in seconds = 5 * 24 * 60 * 60 and you will get the start time of Friday.

it is hard to guess what you need, but it is always more reliable to use the opening time of a bar in TF


multiplicator:
why better?
just maybe there will still be another EA trading there.

Because the order comment is not reliable, some servers overwrite the comment at 0 o'clock or add some proprietary information.

magik is reliable, don't you feel sorry for numbers? magik is int type - read in your help what is the maximum number you can store in int.... you have enough magic numbers for several billions of Expert Advisors... don't be greedy, spend the magic numbers ))))

 
Igor Makanu:

because the order comment is unreliable, some servers overwrite the comment at 0 o'clock or append service information to it

wizard is reliable, don't you feel sorry for numbers? wizard is int type - read in your help what maximal number can be stored in int.... you have enough magic numbers for several billions of Expert Advisors... don't be greedy, spend magic numbers ))))

I have a stereotype: one EA - one magic number.


You will not have to close all the orders of the owl, so you don't need a common magik for the owl either.

 

Hello, I need some advice. There are frequent slippages in this Expert Advisor that closes all positions by Profit Equity. I.e. Profit reaches a certain value, trades are then closed, then not, not from the first time, in general

extern double EquityProfit  = 1.2;

int start()
  {
   Comment("" ,AccountName(),"\n""ACCOUNT"  ,AccountNumber(),"\n""FREE MARGIN"  ,AccountFreeMargin(),"\n""EQUITY"  ,AccountEquity(),"\n""BALANCE"  ,AccountBalance());

   if(AccountEquity() > AccountBalance()*EquityProfit)
     {
      int total=OrdersTotal();

      for(int i=total-1;i>=0;i--)
        {
         if(OrderSelect(i,SELECT_BY_POS)==true)
           {
            int type=OrderType();

            bool result=false;

            switch(type)
              {
               case OP_BUY       : result=OrderClose(OrderTicket(),OrderLots(),MarketInfo(OrderSymbol(),MODE_BID),5,Red);
               break;
               case OP_SELL      : result=OrderClose(OrderTicket(),OrderLots(),MarketInfo(OrderSymbol(),MODE_ASK),5,Red);
              }

            if(result==false)
              {
               Sleep(0);
              }
           }
        }
     }
   return(0);
  }
//+------------------------------------------------------------------+
 
Vladimir Baskakov:

Hello, I need some advice. This Expert Advisor that closes all positions on Profit Equity has frequent slippages. I.e. profit reaches the specified value, trades are either closed or not, not at all the first time.

You have to fix the excess of equity using the flag

Then you have to close all orders until they reach 0 and invert the flag.

Now, a part of orders have closed and another part have not. The equity has changed and, as a result, the condition does not function properly on the next tick.

Reason: