How to start with MQL5 - page 37

 
Kutluhan Yesilkaya # :

hi Vladimir I added macd feature to my robot. but it is not working. no eror. The feature I want is to close the position if the difference between the macd line and the signal line is 0.05. My robot is attached. can you check it? thanks

Okay, I'll take a look tonight.

 
Kutluhan Yesilkaya # :

hi Vladimir I added macd feature to my robot. but it is not working. no eror. The feature I want is to close the position if the difference between the macd line and the signal line is 0.05. My robot is attached. can you check it? thanks

You need to use iMACD Difference Close All code. If you have questions about the code - you can ask your questions in a special thread .

 

Hi. I have an Grid E.A that takes Buy or Sell positions at for example10 pips range with some conditions. May be there are buy or sell positions and conditions will disappear for a while and after a transition, it will be able to open other positions.

My question is : How it can not open anymore position near another positions with less than 10 pips distance? The logical solution, is to have all PiceOpens and prevent take new positions at a distance of 10 pips from top and bottom of them.But I did not reach result. Please help.

.
.
.
.
   PositionSelectByTicket(PositionGetTicket(PositionsTotal()-1));
   if(m_position.Symbol()==m_symbol.Name() && m_position.Magic()==MAGICMA)
     {
      Price_Open = m_position.PriceOpen();
     }
.
.
.
.
bool IsOutOfRange()
  {
   bool   out_of_range = false;
//---
   for(int i=PositionsTotal()-1; i>=0; i--)
      if(m_position.SelectByIndex(i))
         if(m_position.Symbol()==Symbol() && m_position.Magic()==MAGICMA)
           {
            if(m_position.PositionType()==POSITION_TYPE_BUY)
              {
               double up_B    = Price_Open + Distance;
               double down_B  = Price_Open - Distance;
               if(m_symbol.Ask() > up_B || m_symbol.Ask() < down_B)
                 {
                  out_of_range = 1;
                 }
              }
            if(m_position.PositionType()==POSITION_TYPE_SELL)
              {
               double up_S    = Price_Open + Distance;
               double down_S  = Price_Open - Distance;
               if(m_symbol.Bid() > up_S || m_symbol.Bid() < down_S)
                 {
                  out_of_range = 1;
                 }
              }
           }
   return(out_of_range);
  }
Files:
1.jpg  105 kb
2.jpg  98 kb
 
RZAMK # :

Hi. I have an Grid E.A that takes Buy or Sell positions at for example10 pips range with some conditions. May be there are buy or sell positions and conditions will disappear for a while and after a transition, it will be able to open other positions.

My question is : How it can not open anymore position near another positions with less than 10 pips distance? The logical solution, is to have all PiceOpens and prevent take new positions at a distance of 10 pips from top and bottom of them.But I did not reach result. Please help.

Describe your rules in detail ( please select the correct option ):

  • 'BUY' positions are opened only ( up or down ),
  • 'SELL' positions open only ( up or down ) ?
 
RZAMK # :


If I open positions like this: each next 'BUY' position should be higher and higher, each next 'SELL' position should be lower and lower - then I use this function:

//+------------------------------------------------------------------+
//| Calculate all positions                                          |
//+------------------------------------------------------------------+
void CalculateAllPositions_HighestBuyHighestSell(double &price_highest_buy,double &price_lowest_sell)
  {
//--- auxiliary variables
   double price_highest_buy   = DBL_MIN;
   double price_lowest_sell   = DBL_MAX;
//---
   for(int i=PositionsTotal()-1; i>=0; i--)
      if(m_position.SelectByIndex(i)) // selects the position by index for further access to its properties
         if(m_position.Symbol()==m_symbol.Name() && m_position.Magic()==InpMagic)
           {
            if(m_position.PositionType()==POSITION_TYPE_BUY)
              {
               if(m_position.PriceOpen()>price_highest_buy) // the highest position of "BUY" is found
                  price_highest_buy=m_position.PriceOpen();
               continue;
              }
            else
               if(m_position.PositionType()==POSITION_TYPE_SELL)
                 {
                  if(m_position.PriceOpen()<price_lowest_sell) // the lowest position of "SELL" is found
                     price_lowest_sell=m_position.PriceOpen();
                 }
           }
  }


If I open positions like this: each next 'BUY' position should be lower and lower , each next 'SELL' position should be higher and higher - then I use this function:

//+------------------------------------------------------------------+
//| Calculate all positions                                          |
//+------------------------------------------------------------------+
void CalculateAllPositions_LowestBuyLowestSell(double &price_highest_buy,double &price_lowest_sell)
  {
//--- auxiliary variables
   double price_lowest_buy    = DBL_MAX;
   double price_highest_sell  = DBL_MIN;
//---
   for(int i=PositionsTotal()-1; i>=0; i--)
      if(m_position.SelectByIndex(i)) // selects the position by index for further access to its properties
         if(m_position.Symbol()==m_symbol.Name() && m_position.Magic()==InpMagic)
           {
            if(m_position.PositionType()==POSITION_TYPE_BUY)
              {
               if(m_position.PriceOpen()<price_lowest_buy) // the lowest position of "BUY" is found
                  price_lowest_buy=m_position.PriceOpen();
               continue;
              }
            else
               if(m_position.PositionType()==POSITION_TYPE_SELL)
                 {
                  if(m_position.PriceOpen()>price_highest_sell) // the highest position of "SELL" is found
                     price_highest_sell=m_position.PriceOpen();
                 }
           }
  }
 
Vladimir Karputov #:

If I open positions like this: each next 'BUY' position should be higher and higher, each next 'SELL' position should be lower and lower - then I use this function:


If I open positions like this: each next 'BUY' position should be lower and lower , each next 'SELL' position should be higher and higher - then I use this function:

thank you. I have learned a lot from your contents.

In fact, no " ...each next 'BUY' position should be higher and higher ..."  and no " ...each next 'BUY' position should be lower and lower..." they do not happen.

As an example, I have prepared 4 sequences of price going (of course, I have increased amount of Tr_SL).
  • In first image, sell positions are created with price drops.
  • In second image, a buy position is created by changing the conditions and increasing the price .
  • In third image, the price has dropped again and the conditions for creating three sell positions have been provided.
  • In fourth image, as the price rises, a buy position is created that is lower than the first "buy"position.
Files:
sequence_1.jpg  102 kb
sequence_2.jpg  98 kb
sequence_3.jpg  130 kb
sequence_4.jpg  130 kb
 

You can search for the nearest position:

//+------------------------------------------------------------------+
//| Nearest Position                                                 |
//+------------------------------------------------------------------+
double NearestPosition(double const price)
  {
   double nearest=DBL_MAX;
   for(int i=PositionsTotal()-1; i>=0; i--)
      if(m_position.SelectByIndex(i)) // selects the position by index for further access to its properties
         if(m_position.Symbol()==m_symbol.Name() && m_position.Magic()==InpMagic)
           {
            double shift=MathAbs(m_position.PriceOpen()-price);
            if(nearest==DBL_MAX)
               nearest=shift;
            else
               if(shift<nearest)
                  nearest=shift;
           }
//---
   return(nearest);
  }
 
Vladimir Karputov #:

You can search for the nearest position:

Thank you very much, Sir.
 
Vladimir Karputov # :

iMACD Farkı Tümünü Kapatmanız gerekir . Kodla ilgili olabilecek - özel bir özellikta sorabilirsiniz .

I already used that code. I integrated those codes into my own robot. but it is not working efficiently. I don't get eror. but I didn't get what I wanted. Can you help me?

 
Kutluhan Yesilkaya # :

I already used that code. I integrated those codes into my own robot. but it is not working efficiently. I don't get eror. but I didn't get what I wanted. Can you help me?

Attach your code, describe what exactly the code should do. Describe what exactly doesn't work.

Reason: