[Archive!] Any rookie question, so as not to clutter up the forum. Professionals, don't pass it by. Couldn't go anywhere without you - 2. - page 513

 

Pro tips on how to make it optimise for opening prices in the auto-optimiser:

https://forum.mql4.com/ru/42125

 
Hello, I am a beginner trying to understand how to write an EA
advise how to write "if a previously closed order was a buy order and closed with a stop loss then sell 0.1 lot with a stop loss 50 take profit 50" please)
 

Specialists! Help! How can this be implemented?


int start() 
{
 bool OPEN=false;

 условие1=х;//вычисление условия1
 условие2=y;//вычисление условия2
 
 if(условие1==х)OPEN=true;
 
 if(условие2==y&&OPEN==true)
 OrderSend;

We need to fix OPEN=true until the
condition2. Condition1 may change during this time.

Thanks in advance!

 

take it out for the start

 bool OPEN=false;
 
sergeev:

take it out for the start


Thank you so much! As they say everything is brilliantly simple! And I've been racking my brains all day.
 

Please tell me what I'm doing wrong when calculating the number of first bars ( Quant_Bars ) that correspond to the condition only above or below the buffer. I.e. as soon as the indicator is drawn BEFORE the closed bar (1), I should count previous bars with the indicator BELOW the bars (except for those which don't conform to the condition) and vice versa, in the opposite direction of movement. My variant gives wrong values.

Who knows how to do it?

#property indicator_chart_window     
#property indicator_buffers 1
#property indicator_color1 Green
double step = 0.1;
double max = 0.2;

int n = 1;
double S;
double barA;
double barB;
double Bufer[];
int k,k1;
//---------------------------------
int init()
{
   SetIndexStyle(0, DRAW_ARROW,EMPTY,0,Green); 
   SetIndexArrow(0, 159); 
   SetIndexBuffer(0, Bufer);
   return (0);
}
//---------------------------------
int deinit() 
{
   return (0);
}
//----------------------------------
int start()
{

 k1=k;
 for(int i=Bars-2; i>=0; i--)  
    {
     if(i == Bars-2)
       {
         Bufer[i] = Low[i] - 10.0 * Point;
         n = 1;
         S = step;
         barA = High[i];
         barB = Low[i];
       }
    else
       {
         if(Close[i] > barA)
           {
             barA = Close[i];
               if (n==1 && S <= max - step)
                  { S = S + step; }
             k=1;
           }          
         if(Close[i] < barB)
           {
            barB = Close[i];
              if (n == -1 && S <= max - step)
                 { S = S + step;}
            k=2;
           }
        if (n == 1)
           { Bufer[i] = Bufer[i + 1] + S * (barA - (Bufer[i + 1]));}
       else
           { Bufer[i] = Bufer[i + 1] + S * (barB - (Bufer[i + 1]));}
      
       if ((Bufer[i+1] < Close[i + 1] && Bufer[i] > Close[i]) || (Bufer[i + 1] > Close[i + 1] && Bufer[i] < Close[i]))
          {
           S = step;
             if (n == 1)
                {Bufer[i] = barA;}
             else
                {Bufer[i] = barB;}
           barB = Close[i];
           barA = Close[i];
           n = -1 * n;
          }
       }
   }
    
//--------------------------Подсчитать бары:
   int num1 = 2;  // бар  
   int counted_bars = IndicatorCounted(); 
 //-----СЕЛЛ
if(Bufer[2]<Close[2] && Bufer[1]>Close[1])    
   {
     for( i=num1; i<=Bars; i++ )
        { 
          if(Bufer[i]<Close[i])
                                 
             {int Quant_Bars = Quant_Bars+i;}
          if(Bufer[i]>Close[i] && Bufer[i-1]<Close[i-1]) 
          break;
         }
     Alert("Число баров= ",Quant_Bars, "  counted_bars= ",counted_bars," бары= ", Bars );    
    }
    
 //-----БАЙ  
if(Bufer[2]>Close[2] && Bufer[1]<Close[1])     
   {
     for( i=num1; i<=Bars; i++ )
        { 
          if(Bufer[i]<Close[i])                     
            {Quant_Bars = Quant_Bars+i;}
          if(Bufer[i]>Close[i] && Bufer[i-1]<Close[i-1]) 
          break;
         }
     Alert("Число баров= ",Quant_Bars, "  counted_bars= ",counted_bars," бары= ", Bars );    
    }  

   return (0);
}
 

question,

Why, when my Expert Advisor neatly drains the entire deposit and practically all trades are losing, then when I change the "polarity" of the signals, the deposit does not increase as rapidly, but already? )))) the points are the same, the error is in the order opening direction only, or there is something else?

 
Maxaxa:

question,

Why, when my Expert Advisor neatly drains the entire deposit and practically all trades are losing, then when I change the "polarity" of the signals, the deposit does not increase as rapidly, but already? )))) the points are the same, the error is in the order opening direction only, or there is something else?

This is a trading philosophy.
 
Maxaxa:


there is something else
 
Solree:

Good afternoon.

There are 4 orders, 2 sells and 2 buys. Seals are created, figuratively speaking, when the price goes up and buy when it goes down. The sells are deleted when a buy is created and vice versa. When a ticket is created, the 1st sell or buy is stored in the variable pos. All 4 have the same comment - "Aelit". So, there is a code:

The order is selected normally by the ticket, but very often the comment comparison fails. For interest, I made else Alert(OrderComment()); and the log showed "Alert: Aelit[sl]". What is [sl]? Is it because all orders have the same comment? Then why was the same [sl] when I made a comment that didn't match the others for the test? If you remove the comment check, there is a ticket error in the log for OrderModify. At first I thought this condition was reached before any order was created, but no, at that time the order is already there, and the ticket is the same in case of condition triggering and not triggering. How do we understand it?

It is not a miracle that your brokerage company added to your comment - the order has closed when StopLoss was reached.

You have not correctly organized the order selection on the ticket. When making such a selection, first of all, MODE_TRADES is unnecessary - it is omitted in the OrderSelect() function,

Secondly, after the successful selection of the order, you don't check whether the order is selected from the array of orders according to the ticket - from the market ones or from the closed ones.

To do this, after the order is selected, check its close time and if it is equal to zero, then only then the order is a market one, otherwise - it is selected from the orders already closed (hence the addition to your comment)