[ARCHIVE]Any rookie question, so as not to clutter up the forum. Professionals, don't pass it by. Can't go anywhere without you - 5. - page 231

 

I am copying it correctly into the indicator folder7

 
hoz:

There is the following situation:

I have shown a piece of code where there is a misunderstanding. All variables are declared global. In theIsObjectFound() function I get the values of the first and second price point of the object, the name, and the price value of the object on the current bar. If the object is found it should exit the function in true mode , otherwise infalse .


The function continues to execute the start function. What is this?

Never be greedy with debug output if something works wrong and try to check for more errors. Example of a working script:

//+------------------------------------------------------------------+
//|                                             Test ObjectFound.mq4 |
//|                                         Copyright © 2013, ir0407 |
//+------------------------------------------------------------------+
#property copyright "Copyright © 2013, ir0407"
#property link      ""

#include <stderror.mqh>
#include <stdlib.mqh>

string objName;
int isObj;
double objPrice1, objPrice2, objPriceCurr; 

//+------------------------------------------------------------------+
//| script program start function                                    |
//+------------------------------------------------------------------+
int start()
{
   if (!IsObjectFound())
   {
      Print("В окне отсуствуют объекты, поиск продолжается...");
      return (0);
   }
  return(0);
}
//+------------------------------------------------------------------+

//+-------------------------------------------------------------------------------------+
//| Блок поиска своих объектов                                                          |
//+-------------------------------------------------------------------------------------+
bool IsObjectFound(int ObjType = EMPTY)
{
   int Error;
   //Eсли объектов на графике нет, то и делать нам тут больше нечего
   if(ObjectsTotal(ObjType) == 0)
   {
      Print("Объекты на графике отсутствуют.");
      return(False);
   }
   for (int obj = 0; obj < ObjectsTotal(ObjType); obj++)
   {
      objName = ObjectName(obj);
      //Нужно убедиться что в переменной objName лежит имя объекта,
      //а не какая нибудь чепуха.
      Error = GetLastError();
      if(Error == ERR_NO_ERROR)
      {
        isObj = ObjectFind(objName);
        if(isObj == -1)
        {
          Print("Объект с именем \"", objName, "\" не найден.");
          Error = GetLastError();
          Print("Функция ObjectFind() вернула код ошибки #", Error);
          return(false);
        }
        objPrice1 = ObjectGet(objName, OBJPROP_PRICE1);
        objPrice2 = ObjectGet(objName, OBJPROP_PRICE2);
        objPriceCurr = ObjectGetValueByShift(objName,0);
        Print("objPrice1 = ", objPrice1);
        Print("objPrice2 = ", objPrice2);
        Print("objPriceCurr = ", objPriceCurr);
      }
      else
      {
        Print("Функция ObjectName() вернула код ошибки #", Error);
        return(false);
      }
   }
   return (True); // Объект найден!
}
 
ir0407:

Never be greedy with debug output if something works wrong and try to check for more errors. Example of a working script:



Igor, thanks for the valuable comment. You are right! I haven't worked with objects before, now I'm getting the hang of it. I've been thinking about which side to approach it from.
 
GaNDarM:


You have misunderstood. I don't want to change the value of my balance on the terminal, although it would indeed be nice:)

I need to change my lot size depending on the result of a previous trade (profit or loss). And how to prescribe change of deposit (incurred a loss or gained a profit) I don't know.

The trade result can be controlled in 2 ways (maybe there are others, I like them):
1) To remember the previous value of the deposit and compare it with the current one (AccountBalance()). But this method will need to involve the global variables of the terminal for the variable not to lose its value at reboot of the EA or terminal (or write it into a file);

2) And you can check the result of a previous trade from the history (look for the function in Kim's thread).

 
koSTRIKin:

I am copying it correctly to the indicator folder7

The correct folder is experts/indicators. Just in case, check its presence in the folder after writing.

If it is there, it will definitely appear after compiling any code in the editor.

 
      objName = ObjectName(obj);
      //Нужно убедиться что в переменной objName лежит имя объекта,
      //а не какая нибудь чепуха.
      Error = GetLastError();
      if(Error == ERR_NO_ERROR)
Why would there be nonsense if the function returns the name of the object concretely?
 

GaNDarM

(функцию поищите в ветке у Кима). 

Branch
 
TarasBY:

There are 2 ways to control trade result (there may be others, these ones suit me):
1) To remember the previous value of the deposit and compare it with the current one (AccountBalance()). But this method must involve global variables of the terminal for the variable not to lose its value when restarting the EA or the terminal (or write it in a file);

2) And you can check the result of a previous trade from the history (look for the function in Kim's thread).


Thank you, I will search
 

Why are the variables assigned zero in INIT()? What is the error or how to assign the buy and sell prices to variables outside of the start() function? I tried putting RefreshRates(); in front of them, but no change :(

int init()
  {
   .....
   //---
   UpL  =  Ask;     // Пик вверх изначально равен цене покупки
   DownL  =  Bid;     // Пик вниз изначально равен цене продажи
   
   return(0);
  }
//---end init--------------------------------------------------------
 

Greetings!

Explain how to programmatically get the value of the number of bars from last week's low to the beginning of the current week.

Reason: