Questions from Beginners MQL4 MT4 MetaTrader 4 - page 91

 
Jenya77769:

Hello! The two minus numbers q and w are compared incorrectly, when they are equal, the if operator thinks one is greater than the other.What is the error? When q = -0.0002 and w is also -0.0002, res12=false, why?

because it is a double and they are not exactly equal.

FIGURE : compare normalized values

 
Jenya77769:

Hello! The two minus numbers q and w are compared incorrectly, when they are equal, the if operator thinks one is greater than the other.What is the error? When q = -0.0002 and w is also -0.0002, res12=false, why?


Compare their difference to zero, this is more correct and works for numbers of any type.

 

People, here's a question -

There is a horizontal line, a day long.

It has a text label, a label object.

How can I make this text label always be in the middle of the line (in the middle of the day), at any zoom of the chart?

 
John Smith:

People, here's a question -

There is a horizontal line, a day long.

It has a text label, a label object.

How can I make this text label always be in the middle of the line (in the middle of the day), at any zoom of the chart?

Change the X coordinate of the label, i.e. calculate it as the middle of the line
 
Renat Akhtyamov:
Change the X coordinate of the marker, i.e. calculate it as the middle of the line

Well, that's understandable, but how do I do it?


I had a second option - with marker tied to the beginning of the day, using a text variable to insert spaces before the value of the marker, depending on the zoom of the chart.

In essence, I want the label to be on the left at close zoom, and at zoom out the label should be moved to the middle. Since the zoom levels in mt4 are standard, then for each zoom level it is not so difficult to find the right number of spaces. But here is a question - does mql4 have such a function that would determine the current chart zoom level?

Then everything will be simple, something like this: "if chartzoom = 50% then spacesnumber = 10", etc.

Where spacesnumber is string variable that defines number of spaces before label text, like __________1.23456 - there are 10 spaces with _ sign.

 
John Smith:

Well, that's understandable, but how do I do it?


I had a second option - with marker tied to the beginning of the day, using a text variable to insert spaces in front of the marker value, depending on the chart zoom.

In essence, I want the label to be on the left side at close zoom, and at zoom out the label should be moved to the middle. Since the zoom levels in mt4 are standard, then for each zoom level it is not so difficult to find the right number of spaces. But here is a question - does mql4 have such a function that would determine the current chart zoom level?

Then everything will be simple, something like this: "if chartzoom = 50% then spacesnumber = 10", etc.

Where spacesnumber is string variable that defines number of spaces before label text, like __________1.23456 - there are 10 spaces with _ sign.

Read my commentshere
 

Hi all! Need help again. Can't figure out what the error is. Trawl again. Trawl by MA. I need to trawl several orders. There may be loops. As long as there is one open order, everything is working perfectly. As soon as one more order is open, bacchanalia begins - constant modification (with one and the same parameter) of the first order (error 1 is not shown). In this case the second order is modified as it should be - when appropriate conditions are met (the first order, when conditions change, changes its parameters and continues constant modification with new ones). I cannot find the reason. Who would be able to give me a hint?

void TrailingStop()
{
   int i;
   int k          = OrdersTotal(); 
   double Ma      = iAlligator(NULL, 0, 13, 8, 8, 5, 5, 3, MODE_SMMA, PRICE_MEDIAN, MODE_GATORLIPS, 1); 
   int MinDistans = int(MarketInfo(Symbol(), MODE_STOPLEVEL));
   
   double lips1  = iAlligator(NULL, 0, 13, 8, 8, 5, 5, 3, MODE_SMMA, PRICE_MEDIAN, MODE_GATORLIPS, 1); 
   double lips2  = iAlligator(NULL, 0, 13, 8, 8, 5, 5, 3, MODE_SMMA, PRICE_MEDIAN, MODE_GATORLIPS, 2);
   double teeth1 = iAlligator(NULL, 0, 13, 8, 8, 5, 5, 3, MODE_SMMA, PRICE_MEDIAN, MODE_GATORTEETH, 1);
   double teeth2 = iAlligator(NULL, 0, 13, 8, 8, 5, 5, 3, MODE_SMMA, PRICE_MEDIAN, MODE_GATORTEETH, 2);
   double jaw1   = iAlligator(NULL, 0, 13, 8, 8, 5, 5, 3, MODE_SMMA, PRICE_MEDIAN, MODE_GATORJAW , 1);
   double jaw2   = iAlligator(NULL, 0, 13, 8, 8, 5, 5, 3, MODE_SMMA, PRICE_MEDIAN, MODE_GATORJAW , 2);
   
   for (i = 0; i < k; i++)
   {
      if(OrderSelect(i, SELECT_BY_POS, MODE_TRADES))
      {
         if(OrderSymbol() == Symbol() && OrderMagicNumber() == Magic)
         {
            if(OrderType() == OP_BUY)
            {
               if(lips2 < teeth2 && teeth2 < jaw2 && lips1 < teeth1 && teeth1 < jaw1)
                  break;
               
               if(lips2 > teeth2 && teeth2 > jaw2 && lips1 > teeth1 && teeth1 > jaw1)
               {   
                  if((OrderStopLoss() + TrailingStep*Point) < Ma)
                  {
                     double Sl = NormalizeDouble(Ma, Digits);                 
                     
                     if((Bid - MinDistans) > Sl && (OrderStopLoss() + TrailingStep*Point) < Sl)
                     { 
                        OrderModifyX(OrderTicket(), OrderOpenPrice(), Sl, OrderTakeProfit(), OrderExpiration(), 0);
                     }
                  }
               }
            }
         }
      }     
 
      if(OrderSelect(i, SELECT_BY_POS, MODE_TRADES))  
      {
         if(OrderSymbol() == Symbol() && OrderMagicNumber() == Magic)
         {
            if(OrderType() == OP_SELL)
            {
               if(lips2 > teeth2 && teeth2 > jaw2 && lips1 > teeth1 && teeth1 > jaw1)
                  break;
                  
               if(lips2 < teeth2 && teeth2 < jaw2 && lips1 < teeth1 && teeth1 < jaw1)
               {
                  if(MathAbs(OrderStopLoss() - TrailingOpen*Point) > Ma)
                  {
                     double Sl = NormalizeDouble(Ma, Digits);
                 
                     if((Ask + MinDistans) < Sl && (OrderStopLoss() - TrailingStep*Point) > Sl)
                     {
                        OrderModifyX(OrderTicket(), OrderOpenPrice(), Sl, OrderTakeProfit(), OrderExpiration(), 0);
                     }
                  }
               }
            }
         }
      }
   }
}



 
Youri Lazurenko:

Hi all! Need help again. Can't figure out what the error is. Trawl again. Trawl by MA. I need to trawl several orders. There may be loops. As long as there is one open order, everything is working perfectly. As soon as one more order is open, bacchanalia begins - constant modification (with one and the same parameter) of the first order (error 1 is not shown). In this case the second order is modified as it should be - when appropriate conditions are met (the first order, when conditions change, changes its parameters and continues constant modification with new ones). I cannot find the reason. Who can help me?


1. The cycle should be reversed.

2. What's the break for?

 
Artyom Trishkin:

1. The cycle must be reversed.

2. what is break for?


Hello.

1 - "The loop must be inverse" - do you mean for(i = k; i > 0; i--)?

2. "What's the break for?" - To exit. Generally, in the beginning, after selecting the order type and if it is against the trend break. Then we select the order type again and if it is trending, we modify it.

This variant of breaking helped me before. When you suggested a solution to trawl by MA. If, for example, on a buy trade, the stop was above the MA, I got error 1 until the MA was above the stop, after which the error disappeared. When I introduced the condition that if the stop is above the MA, then break, everything went back to normal.

 
Youri Lazurenko:

Hello.

1 - "The loop must be reversed" - do you mean for(i = k; i > 0; i--)?

2. "What's the break for?" - To exit. Generally, in the beginning, after selecting the order type and if it is against the trend break. Then we select the order type again and if it is trending, we modify it.

This variant of breaking helped me before. When you suggested a solution to trawl by MA. If, for example, on a buy trade, the stop was above the MA, I got error 1 until the MA was above the stop, after which the error disappeared. When I set the condition that if the stop is above the MA, all has normalized.

break completely completes the loop. What about the rest of the positions then?
Check where the stop is relative to its new level.
The reverse loop from OrdersTotal()-1 to >=0
Reason: