[WARNING CLOSED!] Any newbie question, so as not to clutter up the forum. Professionals, don't go by. Can't go anywhere without you. - page 277

 

Yes, indeed. Had a look, but didn't see it.

Thank you. (chuckles)

I'm slowing down today. Got to rest up for the weekend.

 
rid >> :

That's about right -



Thank you!!! I'll be using....

 


DDFedor



Rid



Thank you.

 

All the same, the code did not work, did all the action on 2 candles. and had to learn that the position already have more do not open ... because it opened at all that I could all the deposit used(( Rid look, maybe what else you need to add ... would be very grateful

 

Help. I want an EA that will trade at night. I am writing code

int start()
{
string Symb;
Symb=Symbol();
string Vremya;
Vremya=TimeToStr(TimeLocal(),TIME_MINUTES);
if(Vremya > 23:00 || Vremya < 06:00 )
{
// тут торговые функции
}
}

It generates an error

'||' - condition cannot be a string

And if the condition is shortened to

if(Vremya > 23:00

it will work,

And if it goes to

if(Vremya < 06:00 )

it won't work.


I don't understand what's wrong. Can you tell me how to set the time?


 
morok >> :

Rig Rig didn't work anyway...but i should have known i had a pose and not open it anymore...but i opened it for everything i got the entire deposit.

Yes indeed....

I forgot to set the magik in the ORDERSEND fi.

It's working fine now. Checked. There can be no more than two differently directed trades or no more than one unidirectional trade in the market.

If it is necessary no more than one deal of any type, it is necessary in f-ki NumberOfPositions(c) to replace type of deal with -1 (minus one)

extern int   Magic = 777;
extern int       Ema1=14;
extern int       Ema2=48;
double Ema_1;
double Ema_2;

//+------------------------------------------------------------------+
//| expert start function                                            |
//+------------------------------------------------------------------+
int start()
  {
   //int Orders = OrdersTotal(); 
   Ema_1 =iMA(NULL, 0, Ema1, 0,MODE_SMMA, PRICE_MEDIAN, 0);
   Ema_2 =iMA(NULL, 0, Ema2, 0,MODE_SMMA, PRICE_MEDIAN, 0);   
   int ticket;
//------------------------------------------------
 if ( NumberOfPositions(NULL,OP_BUY, Magic)< 1 && Ema_1> Ema_2) 
    {
      ticket=OrderSend(Symbol(),OP_BUY,0.5,Ask,10,Ask-850*Point,Ask+550*Point,"kupil", Magic,0,Green);
    } 
//------------------------------------------------------
   if ( NumberOfPositions(NULL,OP_SELL, Magic)< 1 && Ema_1< Ema_2) 
    {
      ticket=OrderSend(Symbol(),OP_SELL,0.5,Bid,10,Ask+850*Point,Bid-550*Point,"kupil", Magic,0,Violet);
    } 
//------------------------------------------------------
   return(0);
  }

//жжжжжжжжж Пользовательские функции жжжжжжж

int NumberOfPositions(string sy="", int op=-1, int mn=-1) {
  int i, k=OrdersTotal(), kp=0;

  if ( sy=="0") sy=Symbol();
  for ( i=0; i< k; i++)                                    {
    if (OrderSelect( i, SELECT_BY_POS, MODE_TRADES))      {
      if (OrderSymbol()== sy || sy=="")                   {
        if (OrderType()==OP_BUY || OrderType()==OP_SELL) {
          if ( op<0 || OrderType()== op)                   {
            if ( mn<0 || OrderMagicNumber()== mn) kp++;
          }}}}}
  return( kp);
}




 
alderru >> :

Please tell me what the iTime function shows.

What is that gibberish of 10 digits? Seconds?

How do you translate them into year-month-day-hour-minute?

>> Like this: just set bar shift and get default time and date (if time=1 or true, you get only time).

Very handy feature, I recommend it.

string Times(int Sdvig, bool time=0)
{//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  string YAER   = TimeYear( Time[ Sdvig]);
  string DAY    = TimeDay( Time[ Sdvig]);
  string HOUR   = TimeHour( Time[ Sdvig]);
  string MINUTE = TimeMinute( Time[ Sdvig]);
  int month = TimeMonth( Time[ Sdvig]);
  string MONTH;
  switch( month)
    {case 1: MONTH = "янв ";break;
     case 2: MONTH = "фев ";break;
     case 3: MONTH = "март";break;
     case 4: MONTH = "апр ";break;
     case 5: MONTH = "май ";break;
     case 6: MONTH = "июнь";break;
     case 7: MONTH = "июль";break;
     case 8: MONTH = "авг ";break;
     case 9: MONTH = "сен ";break;
     case 10: MONTH = "окт ";break;
     case 11: MONTH = "нояб";break;
     case 12: MONTH = "дек ";break;              
     default: MONTH = "----";break;
    }
 if(TimeHour( Time[ Sdvig])<10) HOUR= "0"+ HOUR;     
 if( MINUTE=="0") MINUTE="00";
 if( time)return( HOUR+":"+ MINUTE);                   
 else return( YAER+"   "+ MONTH+" "+ DAY+"   "+ HOUR+":"+ MINUTE);
}//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
 

I tried to adjust the second level, but it didn't work.

I tried to do it but it would open and close one order immediately after the test

extern int   Magic = 777;
extern int       Ema1=14;
extern int       Ema2=48;
extern int       Ema3=100;
double Ema_1;
double Ema_2;
double Ema_3;

//+------------------------------------------------------------------+
//| expert start function                                            |
//+------------------------------------------------------------------+
int start()
  {
   //int Orders = OrdersTotal(); 
   Ema_1 =iMA(NULL, 0, Ema1, 0,MODE_SMMA, PRICE_MEDIAN, 0);
   Ema_2 =iMA(NULL, 0, Ema2, 0,MODE_SMMA, PRICE_MEDIAN, 0);
   Ema_3 =iMA(NULL, 0, Ema3, 0,MODE_SMMA, PRICE_MEDIAN, 0);     
   int ticket;
//------------------------------------------------
 if ( NumberOfPositions(NULL,OP_BUY, Magic)< 1 && Ema_1> Ema_2 && Ema_2> Ema_3) 
    {
      ticket=OrderSend(Symbol(),OP_BUY,0.1,Ask,10,0,0,"kupil", Magic,0,Green);
    } 
//------------------------------------------------------
   if ( NumberOfPositions(NULL,OP_SELL, Magic)< 1 && Ema_1< Ema_2 && Ema_2< Ema_3) 
    {
      ticket=OrderSend(Symbol(),OP_SELL,0.1,Bid,10,0,0,"kupil", Magic,0,Violet);
    } 
//--------------------------------------------------------
 if ( NumberOfPositions(NULL,OP_BUY, Magic)>= 1 && Ema_1< Ema_2) //--проверяю есть ли ордер BUY и крою его если линии ема пересеклись
    {
      ticket=OrderClose(OrderTicket(),0.1,Bid,300,Violet);
    } 
//------------------------------------------------------
 if ( NumberOfPositions(NULL,OP_SELL, Magic)>= 1 && Ema_1> Ema_2) //--проверяю есть ли ордер SEll и крою его если линии ема пересеклись
    {
      ticket=OrderClose(OrderTicket(),0.1,Ask,300,Green);
    } 
//------------------------------------------------------
   return(0);
  }

//жжжжжжжжж Пользовательские функции жжжжжжж

int NumberOfPositions(string sy="", int op=-1, int mn=-1) {
  int i, k=OrdersTotal(), kp=0;

  if ( sy=="0") sy=Symbol();
  for ( i=0; i< k; i++)                                    {
    if (OrderSelect( i, SELECT_BY_POS, MODE_TRADES))      {
      if (OrderSymbol()== sy || sy=="")                   {
        if (OrderType()==OP_BUY || OrderType()==OP_SELL) {
          if ( op<0 || OrderType()== op)                   {
            if ( mn<0 || OrderMagicNumber()== mn) kp++;
          }}}}}
  return( kp);
}
 
rid писал(а) >>

Got it. To determine if there were positions on the history, you can do this:

But then your code will only work in tester. Otherwise, you will have to change the magik every time you switch on the EA online.


Exactly, that's exactly what we need!

Please advise how to insert this code correctly in this grid:

(If I put it directly, the tester just stops at the opening of the first position)

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

    if (!(OrderSelect( i, SELECT_BY_POS, MODE_HISTORY ))) continue;

//выбираем из истории счета

    if (OrderSymbol() != Symbol()) continue;    

     if ( OrderMagicNumber()== Magic)                            {

              позиции = true;

                                                             }}



//Открытие позиции:



bool Open_Buy() {

   bool res=false; 

if( условие_1)      {

            if ( советник еще не открывал позиций с Магическим номером)    {

                    res=true;     }}

else    {

    if( условие_1)       { 

   if ( условие_2 опирается на данные прошлого ордера)       { 

   res=true;     }}}

return( res);

}
 
morok >> :

I tried to adjust the second level, but it didn't work.

It seems to be quite logical but in the test it opens and covers orders at once

I dealt with closing positions at my time here -

https://www.mql5.com/ru/forum/105913

//==================Закрытие позиций ============================
 
//----------------------------------------------------------------------
  for (int v=0; v<OrdersTotal(); v++)                             {       
      if (OrderSelect( v, SELECT_BY_POS, MODE_TRADES))               {           
        if (OrderSymbol()==Symbol()&& OrderMagicNumber()== Magic)      { 
//-----------------------------------------------------                  
if(OrderType()== OP_BUY) { // если открыта бай-позиция                                   
  if( вот здесь вставляй свои условия закрытия)  {
    OrderClose(OrderTicket(),OrderLots(),Bid,3,Вlack); // закрываем позицию
                                 }       
                               }  
 //--------------------------------------------------------
if(OrderType()== OP_SELL) { // если открыта селл-позиция 
 if( вот здесь вставляй свои условия закрытия)    {
   OrderClose(OrderTicket(),OrderLots(),Ask,3,Yellow); // закрываем позицию
                     }       
                   }  
 //-------------------------------------------------------                       
    }  // Symbol()  
  } // select
 } //total
//------------конец блока закрытия позиций-----------------

This block must be inserted inside the START function, maybe at the very beginning, right after calculation of Ema_1,Ema_2,Ema_3.
And, apparently, it is necessary to make advisor work by PRICES OPEN, otherwise MA crossing will constantly close the open positions on almost every tick.

And the way you have done - it would not work correctly online, because EA will close all positions, even those opened by another EA or manual ones.

But I have already written how to make it even simpler. Instead of NumberOfPositions(NULL,OP_BUY,Magic) and instead of NumberOfPositions(NULL,OP_SELL,Magic) when opening positions, just set

NumberOfPositions(NULL,-1,Magic)

and then there will be no more than one position in the market all the time. Without any closing blocks.

Reason: