Any questions from newcomers on MQL4 and MQL5, help and discussion on algorithms and codes - page 1594

 
законопослушный гражданин:

thanks

But in this function: double GetProfitFromStart()

yellow is just the name of the function, am I right?

and in principle it can be anything?

Yes, I called it that to make it clear Get Profit FromStart
 
MakarFX:
Yes, I named it that way to make it clear Get Profit FromStart

Thank you.

In Expert tick function

void OnTick() - it turns out that the code line : if(CountOrders()==0&ObjectGetInteger(0, "lab_Button",OBJPROP_STATE)) is not only the first order trigger when the EA is initially started

but also each run after the order has been closed according to a condition:

if(GetProfitFromStart()>CountProfit || GetProfitFromStart()<CountLoss*-1)
     {
      if (IsTesting())
        {
         CloseOrder(); ObjectSetInteger(0,"lab_Button",OBJPROP_STATE,false);
        }
      else
        {
         CloseOrder();
}
}

do I understand it correctly?

 
MakarFX:

the amount of loss on all losing orders

I must have misunderstood again

or the amount of loss on each losing order

or the cumulative loss on all losing orders...


If you need only a single print, you'd better do it as a script

You don't have to, you can do it like this

Your code helped, now the same messages are not shown 100 times but only 4-10 times. Perhaps the else operator should be added.
 
Petronet:
Your code helped, now the same messages are not shown 100 times but only 4-10 times. Perhaps the else operator needs to be added.
How and where is the code written?
 
законопослушный гражданин:

Thank you.

In Expert tick function

void OnTick() - it turns out that the code line : if(CountOrders()==0&ObjectGetInteger (0, "lab_Button",OBJPROP_STATE)) is not only the first order trigger when the EA is initially started

but also each run after the order has been closed according to a condition:

do I understand it correctly?

These are the conditions for running the EA, if( if) (CountOrders()==0( no order )&&ObjectGetInteger(0, "lab_Button",OBJPROP_STATE))( and the button is pressed), then we can trade

 
MakarFX:
How and where is the code written?
The code is inserted in the body of the int start() function of the EA. I added else operator, which screws up an empty variable, duplication of data has stopped, but when two consecutive minus profits, duplication of data occurs on 10 and 2-3 times. Commented out my original loop, which gave the same information 100 times. Your working one.
int start()
  {
  
  //for (int trade = OrdersHistoryTotal() - 1; trade >= 0; trade--) 
  //{
     //if ( OrderSelect(trade, SELECT_BY_POS,MODE_HISTORY)) 
     //{
         //old_order_type = OrderType();
         //if ( OrderProfit()<0 ) //последний закрытый советником ордер был убыточным, значит, следующий ордер открываем в направлении, противоположном закрытому с убытком
         //{
                //Print("Закрылись с минусом:", OrderProfit());
                //break; //прекращаем поиск
         //}
         
     //}
     //break;
  //}
  
  for(int pos=0; pos<OrdersHistoryTotal(); pos++)
     {
      if(OrderSelect(pos, SELECT_BY_POS, MODE_HISTORY))
        {
         if(OrderSymbol()==_Symbol)
           {
            if(OrderCloseTime()>=TimeStart)
              {
               if(OrderProfit()<0) {cnt=OrderProfit();
               Print("ордера с минусом", cnt); TimeStart=TimeCurrent(); cnt=0;}
               else gg=gg+1;
              }
           }
        }
     }
 
Petronet:
The code is inserted in the body of int start() function of the EA. I added else operator, which screws empty variable, duplication of data has stopped, but when two consecutive losing profits, duplication of data occurs 10 and 2-3 times. Commented out my original loop, which gave the same information 100 times. Your working one.
// это в глобальные переменные
datetime TimeStart; 

// это в init()

TimeStart=Time[0];

Will print once when there is a loss trade

 
Hi all, I have inserted a function to close positions on Friday at 8:30pm

But the advisor doesn't see that it's Friday and closes positions every day

it looks like this

input bool     UseTimeLimitClose           = true;     // -- Funktion ein/ausschalten --
enum daysOfWeek 
   { 
     Monday = 1, 
     Tuesday = 2, 
     Wednesday = 3, 
     Thursday = 4, 
     Friday = 5
   };
input  daysOfWeek closday          =    5;            // -- Handel bis Tag --
input int    Close_Hour            =   20;            // -- Handel bis Uhrzeit Std.--
input int    Close_min             =   30;



void OnTick() 

 if(UseTimeLimitClose)
     {
      MqlDateTime TimeNow;
      TimeToStruct(TimeCurrent(),TimeNow);
      if  ( TimeNow.day_of_week >= closday  && TimeNow.hour >= Close_Hour && TimeNow.min >= Close_min  ) 
       {
          CloseAllPositions();
       }     

 
Eugen8519:
Hi all, I have inserted a function to close positions on Friday at 8:30pm

But the advisor doesn't see that it's Friday and closes positions every day

stands like this

void OnTick() 

 if(UseTimeLimitClose)
     {
      if  (TimeDayOfWeek(TimeCurrent())==closday  && TimeHour(TimeCurrent())>= Close_Hour && TimeMinute(TimeCurrent()) >= Close_min  ) 
       {
          CloseAllPositions();
       }     
 

Please tell me how to output this to an external variable

double levelss[7] = {0,0.236,0.382,0.5,0.618,1,1.618}; // Уровни Fibo