Any rookie question, so as not to clutter up the forum. Professionals, don't pass by. Nowhere without you - 6. - page 661

 

This is basically all the code:

//------- Внешние параметры советника -----------------------------------------+
extern string _P_Expert = "---------- Параметры советника";
extern int      Magic      = 777;                 // Магический номер позиций
extern double   SL=10;                            // Размер лося
extern double   TP=10000;                           // Размер профита 
extern string     ____= "Параметры блока MoneyManagement";
extern bool      MoneyManagement=false;
extern double    Lots          = 0.01;  
extern int       MarginPercent=3;
//------- Параметры трала -----------------------------------------------------+
extern string     ______= "Параметры блока TrallingStop";
extern bool      TralSimple=true;
//------- Характкристики баров ------------------------------------------------+

//------- Подключение внешних модулей -----------------------------------------+
#include <stdlib.mqh>
#include <stderror.mqh>

int start()
{

   total=OrdersTotal();
   Comment( LotsCounting() );
//+=================================================================================+
  // Проверка средств
   if(AccountFreeMargin()<(1000*Lots)){
      Print("We have no money. Free Margin = ", AccountFreeMargin());   
      return(0);  
   }
//===========================  Открытие позиций  ===================================+ 
//==========================================================================================+
//=============================   Center_array      ========================================+
      double Center_array[50];
      int    h,limit=ArraySize(Center_array);
      ArraySetAsSeries(Center_array,true);
      for(h=0; h<limit; h++)
         Center_array[h]=iRSI(NULL,0,14,0,h);
      double MA_1 =iMAOnArray(Center_array,0,14,0,MODE_SMA,1);
      double rs_1 = iRSI(NULL,0,14,0,1);
      
      if (Last_Max1!=Max1){
      if (Close[1]>Close[2] && rs_1<MA_1){
               lots=LotsCounting();
               OrderSend(Symbol(),OP_BUYSTOP,lots,(Max1),0,SL_buy,TP_buy, "Покупаем ",Magic,Expiration,Blue);
               Last_Max1=Max1;
               PlaySound("ok.wav");
               {
               Print ("При открытии произошла ошибка ", GetLastError());
               return;
               }
            }
         }
       }

//==========================================================================================+
      if (delet) DeleteOppositeOrders("",-1,Magic);
//==========================================================================================+
//=======================================TrallingStop=======================================+
      for ( int v = OrdersTotal() - 1; v >= 0; v -- ){       
         if (OrderSelect(v, SELECT_BY_POS, MODE_TRADES)){           
            if (OrderSymbol()==Symbol() && OrderMagicNumber()==Magic){ 
               //+=================================================================================+
               ///+================================Обычный трал ====================================+
               if (TralSimple){
                  //+=================================================================================+
                  if(OrderType() == OP_BUY){
                     if((Bid-OrderOpenPrice()) > (Point*TrailingStop)){
                        if(OrderStopLoss() < Bid-Point*TrailingStop || (OrderStopLoss()==0)){
                           OrderModify(OrderTicket(),OrderOpenPrice(),Bid-Point*TrailingStop,OrderTakeProfit(),0,Blue);  
                        }
                     }
                  }
               }                                   
            }  // Symbol()  
         } // select
      } //total 
        //============================== Конец блока закрытия ==============================+
 return(0);
}
//==========================================================================================+

If Center_errey is removed, the test takes less than a minute. If this condition is still included in the code, the test runs for 2 hours

 
berezhnuy:

This is basically all the code:

If Center_errey is removed, the test takes less than a minute. If this condition is still included in the code, the test runs for 2 hours


Didn't you try to make an indicator?
 

have a variable A, which can take the values 0,1,2.

Will these comparisons be equivalent?

if(A=0 || A=1){do} and if(A != 2){do}

 
evillive:

have a variable A, which can take the values 0,1,2.

Will these comparisons be equivalent?

if(A=0 || A=1){do} and if(A != 2){do}

If the variable is of enum type, the expressions are identical.
 
evillive:

have a variable A that can take values 0,1,2.

Will these comparisons be equal?

if(A=0 || A=1){do} and if(A != 2){do}

No, because neither "A=0" nor "A=1" is a comparison.

But the comparison is "A == 0" and "A == 1".

 
simpleton:

No, because neither "A=0" nor "A=1" is a comparison.

But "A == 0" and "A == 1" are comparisons.

+1! :)
 
berezhnuy:

This is basically all the code:

If Center_errey is removed, the test takes less than a minute. If this condition is still included in the code, the test takes about 2 hours.

By the terms, recalculations and checks are not relevant on every tick, but only when a new bar appears.

That's why it makes sense to apply a corresponding function, like this one:

bool NevBar(){
   static int PrevTime=0;
   if (PrevTime==Time[0]) return(false);
   PrevTime=Time[0];
   return(true);}

and run Center_errey only when it appears.

You may also throw out all sorts of "trash". But it won't essentially affect the speed.

There is also a gross error in your code - if there is no margin, you cancel the entire code. What about trawl? Although... perhaps it's because it's only part of the code, as I understand from the comments.

 
simpleton:

No, because neither "A=0" nor "A=1" is a comparison.

But "A == 0" and "A == 1" are comparisons.


Credit ))))


Only I wrote it not in MQL, but formally, that's the trouble (:

 
evillive:

Score ))))


Only I didn't write in MQL, but formally, that's the problem (:

Not technically, because there may be NULL
 
Well, does anyone already have an RSI iMAOnArray ready to use?
Reason: