[ARCHIVE] Any rookie question, so as not to clutter up the forum. Professionals, don't pass by. Nowhere without you - 3. - page 368

 

Good afternoon!

I have a task, it seems easy at first glance, but it doesn't work. There is an array in which the values are always in a row (in some cases the values may go in ascending order, in other cases - in descending order). There is some level (red in the picture). You need to find the two array values that are closest to the red line level. In figure a) these will be array values with indexes 0 and 1. In figure b) these will be array values with indexes 2 and 1. In figures c) and f) these will be array values with indexes 0 and 0. In figures d) and e) these will be array values with indexes 2 and 2.

Please tell me how to solve this problem. Thank you in advance.

 
Roman.:

Then don't bother at all - just move the code of the indicator to the Expert Advisor as it is to fulfil trading criteria and that's it - then in the board using these transferred trading conditions from this indicator you open positions through the Expert Advisor and that's it...
Thanks, I'm working on it :)
 
skyjet:
Thanks, I'm sorting it out :)

You're welcome... Everyone's been through it. :-)
 
drknn:

Today is Saturday - day off. You start EA, initialization happens, but since it's day off and there is no tick, the start function is not started (i.e. Trade() is not called.). To check if it works correctly, you need to stick the call of this function in the initialization block, or test it in the tester.

After substituting this function in Init() and adding the check code Print(DayOfWeek()) it turned out that the time was taken from the server, and the server's time was Friday...

Replaced

if(DayOfWeek()==0 || DayOfWeek()==6)

to

  if(TimeDayOfWeek(TimeLocal())==0 || TimeDayOfWeek(TimeLocal())==6)

and it worked as intended.

Thank you.

 

Hello, comrades!

Faced an unexpected problem.

The day before yesterday the tester was working as it should. Since yesterday evening, any version of the strategy in the tester opens one trade and after a second, or a few minutes/hours of history, the tester stops working. No errors, nothing.

Anybody have a problem with it? Please advise

 

Hello.

Please help me find the error.

Below is the problematic section in its entirety, excerpted from the EA.

extern int      MAGIC= 1; 

int start()
  {
//----
  int tt = 0;
  double SchBuyLots     = SchBuyLots_b(MAGIC);
  double SchSellLots    = SchSellLots_b(MAGIC);
  double SchBuyLots100  = SchBuyLots100_b();
  double SchSellLots100 = SchSellLots100_b();
  double SchBuyLimitLots    = SchBuyLimitLots_b(MAGIC);
  double SchSellLimitLots   = SchSellLimitLots_b(MAGIC);
  double SchBuyStopLots100  = SchBuyStopLots100_b();
  double SchSellStopLots100 = SchSellStopLots100_b();

  double dy=0;
  double dx=SchBuyLots+SchBuyLots100-SchSellLots-SchSellLots100;
  if (dx!=0) dy=MathAbs(dx);

  double zx=SchBuyLimitLots-SchSellLimitLots;

  if (dx>0 && dy+zx!=SchSellStopLots100)tt=1; else tt=2;
 
  Alert (dy+zx,"---",SchSellStopLots100,"---",tt);
   
//----
   return(0);
  }
//+------------------------------------------------------------------+
// ----------------- SchBuyLots() ---------------------------------------------
//  Функция возвращает суммарный лот Бай-ордеров для Магика
//----------------------------------------------------------------
double SchBuyLots_b(int MAGIC) {
  double SchBuyLots=0;
  int i;
  string SMB=Symbol();
  for (i=OrdersTotal()-1;i>=0;i--) {//Начало цикла
    if (!OrderSelect(i, SELECT_BY_POS, MODE_TRADES)) {}
    else{//начало работы с выбранным ордером
      if(OrderSymbol()== SMB && OrderMagicNumber()== MAGIC){ 
      if(OrderType()==OP_BUY) {
        SchBuyLots=SchBuyLots+OrderLots();
       }
      }
    }//конец работы с выбранным ордером
  }//Конец цикла
  return(SchBuyLots);
}
// ----------------------------------------------------------------------------

// ----------------- SchSellLots() ---------------------------------------------
//  Функция возвращает суммарный лот Сейл-ордеров для Магика
//-----------------------------------------------------------------
double SchSellLots_b(int MAGIC) {
  double SchSellLots=0;
  int i;
  string SMB=Symbol();
  for (i=OrdersTotal()-1;i>=0;i--) {//Начало цикла
    if (!OrderSelect(i, SELECT_BY_POS, MODE_TRADES)) {}
    else{//начало работы с выбранным ордером
      if(OrderSymbol()== SMB && OrderMagicNumber()== MAGIC) {
      if(OrderType()==OP_SELL) {
        SchSellLots=SchSellLots+OrderLots();
       }  
      }  
    }//конец работы с выбранным ордером
  }//Конец цикла
  return(SchSellLots);
}
// -------------------------------------------------------------------------------

// ----------------- SchBuyLots100() ---------------------------------------------
//  Функция возвращает суммарный лот Бай-ордеров для Магика 100
//--------------------------------------------------------------------------------
double SchBuyLots100_b() {
  double SchBuyLots100=0;
  int i;
  string SMB=Symbol();
  for (i=OrdersTotal()-1;i>=0;i--) {//Начало цикла
    if (!OrderSelect(i, SELECT_BY_POS, MODE_TRADES)) {}
    else{//начало работы с выбранным ордером
      if(OrderSymbol()== SMB && OrderMagicNumber()==100) {
      if(OrderType()==OP_BUY) {
        SchBuyLots100=SchBuyLots100+OrderLots();
       }
      }
    }//конец работы с выбранным ордером
  }//Конец цикла
  return(SchBuyLots100);
}
// --------------------------------------------------------------------------------

// ----------------- SchSellLots100() ---------------------------------------------
//  Функция возвращает суммарный лот Сейл-ордеров для Магика 100
//---------------------------------------------------------------------------------
double SchSellLots100_b() {
  double SchSellLots100=0;
  int i;
  string SMB=Symbol();
  for (i=OrdersTotal()-1;i>=0;i--) {//Начало цикла
    if (!OrderSelect(i, SELECT_BY_POS, MODE_TRADES)) {}
    else{//начало работы с выбранным ордером
      if(OrderSymbol()== SMB && OrderMagicNumber()==100) {
      if(OrderType()==OP_SELL) {
        SchSellLots100=SchSellLots100+OrderLots();
       }  
      }  
    }//конец работы с выбранным ордером
  }//Конец цикла
  return(SchSellLots100);
}
// ----------------------------------------------------------------------------
// ----------------- SchBuyLimitLots() ------------------------------------------
//  Функция возвращает суммарный лот BuyLimit-ордеров для Магика
//------------------------------------------------------------------------------
double SchBuyLimitLots_b(int MAGIC) {
  double SchBuyLimitLots=0;
  int i;
  string SMB=Symbol();
  for (i=OrdersTotal()-1;i>=0;i--) {//Начало цикла
    if (!OrderSelect(i, SELECT_BY_POS, MODE_TRADES)) {}
    else{//начало работы с выбранным ордером
      if(OrderSymbol()== SMB && OrderMagicNumber()== MAGIC){ 
      if(OrderType()==OP_BUYLIMIT) {
        SchBuyLimitLots=SchBuyLimitLots+OrderLots();
       }
      }
    }//конец работы с выбранным ордером
  }//Конец цикла
  return(SchBuyLimitLots);
}
// ----------------------------------------------------------------------------

// ----------------- SchSellLimitLots() ----------------------------------------
//  Функция возвращает суммарный лот SellLimit-ордеров для Магика
//-----------------------------------------------------------------------------
double SchSellLimitLots_b(int MAGIC) {
  double SchSellLimitLots=0;
  int i;
  string SMB=Symbol();
  for (i=OrdersTotal()-1;i>=0;i--) {//Начало цикла
    if (!OrderSelect(i, SELECT_BY_POS, MODE_TRADES)) {}
    else{//начало работы с выбранным ордером
      if(OrderSymbol()== SMB && OrderMagicNumber()== MAGIC) {
      if(OrderType()==OP_SELLLIMIT) {
        SchSellLimitLots=SchSellLimitLots+OrderLots();
       }  
      }  
    }//конец работы с выбранным ордером
  }//Конец цикла
  return(SchSellLimitLots);
}
// -------------------------------------------------------------------------------
// ----------------- SchBuyStopLots100() -----------------------------------------
//  Функция возвращает суммарный лот BuyStop-ордеров для Магика 100
//--------------------------------------------------------------------------------
double SchBuyStopLots100_b() {
  double SchBuyStopLots100=0;
  int i;
  string SMB=Symbol();
  for (i=OrdersTotal()-1;i>=0;i--) {//Начало цикла
    if (!OrderSelect(i, SELECT_BY_POS, MODE_TRADES)) {}
    else{//начало работы с выбранным ордером
      if(OrderSymbol()== SMB && OrderMagicNumber()==100) {
      if(OrderType()==OP_BUYSTOP) {
        SchBuyStopLots100=SchBuyStopLots100+OrderLots();
       }
      }
    }//конец работы с выбранным ордером
  }//Конец цикла
  return(SchBuyStopLots100);
}
// --------------------------------------------------------------------------------

// ----------------- SchSellStopLots100() -----------------------------------------
//  Функция возвращает суммарный лот SellStop-ордеров для Магика 100
//---------------------------------------------------------------------------------
double SchSellStopLots100_b() {
  double SchSellStopLots100=0;
  int i;
  string SMB=Symbol();
  for (i=OrdersTotal()-1;i>=0;i--) {//Начало цикла
    if (!OrderSelect(i, SELECT_BY_POS, MODE_TRADES)) {}
    else{//начало работы с выбранным ордером
      if(OrderSymbol()== SMB && OrderMagicNumber()==100) {
      if(OrderType()==OP_SELLSTOP) {
        SchSellStopLots100=SchSellStopLots100+OrderLots();
       }  
      }  
    }//конец работы с выбранным ордером
  }//Конец цикла
  return(SchSellStopLots100);
}
// --------------------------------------------------------------------------------

Please pay attention to the line (almost at the very beginning):

 if (dx>0 && dy+zx!=SchSellStopLots100)tt=1; else tt=2;

For some reason, when dy+zx and SchSellStopLots100 values are equal separately (I checked with allerts) in this expression they are no longer equal to each other, and the variable tt takes value 1 instead of 2.

I ask you to help me find the flaw.

Thank you in advance.

 
Trading conditions from the server have changed over the weekend... You should test on a separate terminal not connected to a broker/network, using a special utility to set the right spread. Better search for articles on testing EAs and how to do it properly.
 
nemo811:

(checked with allerts)

It is better to check via ND or modulo difference less than some delta.
 
splxgf:
Better check via ND or differences modulo less than some delta.

For some reason, adding dy and zx gives a number 0.3 (in my particular test of the current market situation) when compared to this number does not equal it. That is, I add dy+zx and get 0.3. I compare dy+zx with 0.3 - they are not equal.

Comparing dy and zx with numbers they return - equals work as they should.

Riddle.

Please help.

 
ramirez17:

Hello, comrades!

Faced an unexpected problem.

The day before yesterday the tester was working as it should. Since yesterday evening, any version of the strategy in the tester opens one trade and after a second, or a few minutes/hours of history, the tester stops working. No errors, nothing.

Anybody have a problem with it? Please advise

The tester has a magazine. Everything is written there. There are no telepaths here to read your tester's logs from a distance.