Questions from Beginners MQL5 MT5 MetaTrader 5 - page 905

 
bij:

if(iTime(NULL,PERIOD_D1,i+1)!=iTime(NULL,PERIOD_D1,i)&& how do I write this? )

You need to extract date from time[i] and compare it with time[i+1]. If they are not equal, then extract time from time[i] and compare with given time. If they are the same, put in a line.

How all this is extracted - I have shown in the script. All that remains is to think about it.

 
Artyom Trishkin:

You need to extract the date from time[i] and compare it with time[i+1]. If not equal, extract the time from time[i] and compare it with the given time. If they are the same, draw a line.

How it's all extracted - I've shown in the script. All that's left to do is think about it.

Friday night, thinking badly) Nothing builds. Why?

   datetime date1=time[i]; 
   datetime date2=time[i+1];
 
   MqlDateTime str1,str2; 
   TimeToStruct(date1,str1); 
   TimeToStruct(date2,str2); 
  if(str1.day!=str2.day&&str1.mon!=str2.mon&&str1.year!=str2.year&&str2.hour==17&&str2.min==30){
  
   if(!TrendCreate(0,"closek"+time[i],0,iTime(NULL,PERIOD_D1,i+1),iClose(i+1,NULL,PERIOD_M30),iTime(NULL,PERIOD_D1,i),0,clrLime,STYLE_SOLID,2,false,false,false,false,0))
        {
         continue;
        }
        }
 
Artyom Trishkin:

then extract the time from time[i] and compare it with the set time.

Probably time[i+1], I need to put the line to the previous day after the close of the day.

 

Hello.

Stupid question but still, please help)

I entered a trade at some price, I always long) And I compare the price of the trade with the current bid, if we increased by 0.5% I close.Cursed at bid(((

   if(MA1_buf[1]>Close_buf[1] && MA1_buf[0]<Close_buf[0])          //если значение индикатора были выше цены закрытия и стали ниже
     {
      if(m_Position.Select(my_symbol))                             //если уже существует позиция по этому символу
        {
         if((m_Position.PositionType()==POSITION_TYPE_BUY) && (fabs(DEAL_PRICE-Bid[0])/DEAL_PRICE)>= 0.005) m_Trade.PositionClose(my_symbol);   //и тип этой позиции Buy, то закрываем ее
          return;                            
        }
      m_Trade.Buy(0.1,my_symbol);                                 //если дошли сюда, значит позиции нет, открываем ее
     }
 
ISL:

I entered a trade at some price, I am always longing)And I compare the price of the trade with the current bid, if we went up by 0.5% I close.It swears at bid(((

Probably because this is MQL5. There is no "bid" here butSymbolInfoDouble(_Symbol, SYMBOL_BID)


 
ISL:

Hello.

Stupid question but still, please help)

I entered the trade at some price, I always long) And I compare the price of the trade with the current bid, if we rose by 0.5% I close.It swears at bid(((

You're right to swear. There is no such array with Bid prices in MQL5.

Replace it with

m_symbol.Bid()

and before the cycle do not forget to update the prices:

   if(!RefreshRates())
      return;
 
Vladimir Karputov:

And he is right to swear. There is no such array with Bid prices in MQL5.

Replace it with

and before the loop do not forget to update the prices:

I have done it in two different ways:

1) Expert Advisor works, but unfortunately it does not give me the idea. It is simple, I buy when the previous candle closed below and the next one closed above. And I close only if the price rose by 0.5%.

It makes strange deals(((

   if(MA1_buf[1]>Close_buf[1] && MA1_buf[0]<Close_buf[0])          //если значение индикатора были выше цены закрытия и стали ниже
     {
      if(m_Position.Select(my_symbol))                             //если уже существует позиция по этому символу
        {
         if((m_Position.PositionType()==POSITION_TYPE_BUY) && (SymbolInfoDouble(_Symbol,SYMBOL_BID)-DEAL_PRICE)/DEAL_PRICE>= 0.005) m_Trade.PositionClose(my_symbol);   //и тип этой позиции Buy, то закрываем ее
          return;                            
        }
      m_Trade.Buy(0.1,my_symbol);                                 //если дошли сюда, значит позиции нет, открываем ее
     }

2) My method is as follows:

if(!RefreshRates())
      return; 
   if(MA1_buf[1]>Close_buf[1] && MA1_buf[0]<Close_buf[0])          //если значение индикатора были выше цены закрытия и стали ниже
     {
      if(m_Position.Select(my_symbol))                             //если уже существует позиция по этому символу
        {
         if((m_Position.PositionType()==POSITION_TYPE_BUY) && (m_symbol.Bid())-DEAL_PRICE)/DEAL_PRICE>= 0.005) m_Trade.PositionClose(my_symbol);   //и тип этой позиции Buy, то закрываем ее
          return;                            
        }
      m_Trade.Buy(0.1,my_symbol);                                 //если дошли сюда, значит позиции нет, открываем ее
     }

I think I messed up(((.

It generates an error:


 
ISL:

Did it in two different ways:

1) The Expert Advisor works, but unfortunately it does not implement the idea. It is simple, I buy when the previous candle closed lower and the next one closed higher. And I close only if the price went up 0.5%.

It makes strange deals(((

2) My method is as follows:

I think I messed up(((.

It gives out an error:


Open any of my code and there you will see both m_symbol and RefreshRates.

 
Vladimir Karputov:

Open any of my code and you will see both m_symbol and RefreshRates there.

Thank you. I've read it and done it.

Now I can't figure out why the algorithm doesn't work.

      if(!RefreshRates())
         return;
1)   if(MA1_buf[1]>Close_buf[1] && MA1_buf[0]<Close_buf[0])          //если значение индикатора были выше цены закрытия и стали ниже
     {
2)      if(m_Position.Select(Symbol()))                             //если уже существует позиция по этому символу
        {
         
          return;                            
        }
2*)    m_Trade.Buy(0.1,Symbol());                                 //если дошли сюда, значит позиции нет, открываем ее
     }
3)  if 
   ((m_Position.PositionType()==POSITION_TYPE_BUY) && (((m_symbol.Bid()-DEAL_PRICE)/DEAL_PRICE)>= 0.1))
       {
         m_Trade.PositionClose(Symbol());   //и тип этой позиции Buy, то закрываем ее
      }


What happens is the following: the purchase is made under the condition

1) If the condition is fulfilled;

2) I check whether there is already an open position, if there is, I go to point 3), if not, I open a 2*)

3) If the position is buy, and the condition is fulfilled that the price has increased by 10% from the entry price, then I close it.

In the test, the following happens, position opens and closes, not on conditions (( Again, please help!

 
ISL:

Thank you. I've done the reading.

Now I can't figure out why the algorithm doesn't work.


What happens is the following: the purchase is made under the condition

1) If the condition is fulfilled;

2) I check whether there is already an open position, if there is, I go to point 3), if not, I open a 2*)

3) If the position is buy, and the condition is fulfilled that the price has increased by 10% from the entry price, then I close it.

When testing the following happens, position opens and closes, not on conditions (( Again, please help!

I propose the following algorithm:

   if(!RefreshRates())
      return;
   if(MA1_buf[1]>Close_buf[1] && MA1_buf[0]<Close_buf[0]) //если значение индикатора были выше цены закрытия и стали ниже
     {
      if(m_Position.Select(Symbol())) //если уже существует позиция по этому символу
        {
         if(m_Position.PositionType()==POSITION_TYPE_BUY && (m_symbol.Bid()-m_Position.PriceOpen())/m_Position.PriceOpen()>=0.1)
           {
            m_Trade.PositionClose(Symbol());   //и тип этой позиции Buy, то закрываем ее
            return;
           }
        }
      else
         m_Trade.Buy(0.1,Symbol()); //если дошли сюда, значит позиции нет, открываем ее
     }

Pay attention to m_Position.PriceOpen()

Reason: