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

 
gyfto:


I have the following question. There is a block in init(), which hangs the terminal (that's what I want to transfer to dll). Naturally, the log cannot be viewed - the terminal is only closed by Ctrl+Alt+Delete. Unprinting in order to trace (and to measure transit time of loops coming into block) doesn't help - printer doesn't write anything, logging is not even created. I try to use FileOpen/FileWrite with the same purpose - file is just created (0 Kb), and silence. I put FileWrite after FileOpen, on the next line - no effect. Which way should I dig?

Try to use this. If it doesn't help, to search for errors, you can temporarily put mentioned initialization block into start for one-time start via flag and try to "pull" logs from it.
 
gyfto:


The topic was closed... Bad man.

I have the following question. There is a block in init(), which hangs the terminal (that's what I want to transfer to dll). Naturally, the log cannot be viewed - the terminal is only closed by Ctrl+Alt+Delete. Unprinting in order to trace (and to measure lapse time of loops coming into block) doesn't help - printer doesn't write anything, logging is not even created. I try to use FileOpen/FileWrite with the same purpose - file is just created (0 Kb), and silence. I put FileWrite after FileOpen, on the next line - no effect. What is the direction to dig?


Look, there is no hidden in the attributes?


It's not hidden.
 
TarasBY:
Try using this. If that doesn't help, to search for errors, you can temporarily take the initialisation block mentioned into the start for a one-off start via a flag and try to 'pull' the logs from it.


Neither one-time startup in start nor ininit works - neither Print nor FileWrite. I'm attaching this piece of code (I don't see another way out), I'm not going to post it here, because it's too long. I have removed all buffer declarations and described all calls of built-in technical indicators there. I've already thought about memory overflow with arrays, I've calculated that the biggest array plus all other arrays is fifty and a half meters. Well, if it doesn't print even on the very first line, when entering the block... - that's what's bothering me. Attached version is true with FileWrite.
Files:
eflfcaj.mq4  10 kb
 
gyfto:

Neither one-time launching in startup nor ininit works - neither Print nor FileWrite. I'm attaching this piece of code (I don't see another way out), I'm not pasting it here because it's too long. I have removed all buffer declarations and described all calls of built-in technical indicators there. I've already thought about memory overflow with arrays, I've calculated that the biggest array plus all other arrays is fifty and a half meters. Well, if it doesn't print even on the very first line, when entering the block... - that's what's bothering me. Attached version is true with FileWrite.

The style of the code does not dispose of it. No spaces, brackets at different levels, several operations in a row, no comments... Nightmare! :-))

Do you understand it yourself?

 
Help solve a problem with MT4. When calling up a custom indicator, its input parameters and colours in the window are not displayed (blinks quickly and disappears). How to fix it? Reinstalled MT4, didn't help.
 
gyfto:


He closed the subject... Not a good man.


= :)
 
gyfto:

Neither one-time startup nor ininitial startup works - neither Print, nor FileWrite. I'm attaching this piece of code (I don't see another way out), I'm not pasting it here because it's too long. I have removed all buffer declarations and described all calls of built-in technical indicators there. I've already thought about memory overflow with arrays, I've calculated that the biggest array plus all other arrays is fifty and a half meters. Well, if it doesn't print even on the very first line, when entering the block... - that's what's bothering me. Attached version is true with FileWrite.

I agree with Vadim - the code is hard to read. Try to decompose this code into functional blocks, in each block print or write to file. And run it in a structure that "slows down" the code execution, for example, like this:

void SteppingThrough()
{
    int  li_Time = TimeLocal(), li_N = 0;
    bool lb_work = true, lb_break = false;
    while (IsStopped() == false)
    {
        if (lb_work)
        {
            switch (li_N)
            {
                case 0:
                    //---- Block 1
                    lb_work = false;
                    li_N++;
                    break;
                case 1:
                    //---- Block 2
                    lb_work = false;
                    li_N++;
                    break;
                case N:
                    //---- Block N
                    lb_break = true;
                    li_N++;
                    break;
            }
            if (lb_break) break;
        }
        if (TimeLocal() > li_Time) {li_Time = TimeLocal(); lb_work = true;}
    }
}

Delay the execution of the next block by 1 sec. - The terminal should have enough time to print the log.

 
 

There are 2 very similar functions in Kim's "last position close flag by STOP" and the other by TAKE.

here is the code

//+----------------------------------------------------------------------------+
//|  Автор    : Ким Игорь В. aka KimIV,  http://www.kimiv.ru                   |
//+----------------------------------------------------------------------------+
//|  Версия   : 19.05.2008                                                     |
//|  Описание : Возвращает флаг закрытия последней позиции по стопу.           |
//+----------------------------------------------------------------------------+
//|  Параметры:                                                                |
//|    sy - наименование инструмента   (""   - любой символ,                   |
//|                                     NULL - текущий символ)                 |
//|    op - операция                   (-1   - любая позиция)                  |
//|    mn - MagicNumber                (-1   - любой магик)                    |
//+----------------------------------------------------------------------------+
bool isCloseLastPosByStop(string sy="", int op=-1, int mn=-1) {
  datetime t;
  double   ocp, osl;
  int      dg, i, j=-1, k=OrdersHistoryTotal();

  if (sy=="0") sy=Symbol();
  for (i=0; i<k; i++) {
    if (OrderSelect(i, SELECT_BY_POS, MODE_HISTORY)) {
      if (OrderSymbol()==sy || sy=="") {
        if (OrderType()==OP_BUY || OrderType()==OP_SELL) {
          if (op<0 || OrderType()==op) {
            if (mn<0 || OrderMagicNumber()==mn) {
              if (t<OrderCloseTime()) {
                t=OrderCloseTime();
                j=i;
              }
            }
          }
        }
      }
    }
  }
  if (OrderSelect(j, SELECT_BY_POS, MODE_HISTORY)) {
    dg=MarketInfo(OrderSymbol(), MODE_DIGITS);
    if (dg==0) if (StringFind(OrderSymbol(), "JPY")<0) dg=4; else dg=2;
    ocp=NormalizeDouble(OrderClosePrice(), dg);
    osl=NormalizeDouble(OrderStopLoss(), dg);
    if (ocp==osl) return(True);
  }
  return(False);
}
//+----------------------------------------------------------------------------+
//|  Автор    : Ким Игорь В. aka KimIV,  http://www.kimiv.ru                   |
//+----------------------------------------------------------------------------+
//|  Версия   : 19.05.2008                                                     |
//|  Описание : Возвращает флаг закрытия последней позиции по тейку.           |
//+----------------------------------------------------------------------------+
//|  Параметры:                                                                |
//|    sy - наименование инструмента   (""   - любой символ,                   |
//|                                     NULL - текущий символ)                 |
//|    op - операция                   (-1   - любая позиция)                  |
//|    mn - MagicNumber                (-1   - любой магик)                    |
//+----------------------------------------------------------------------------+
bool isCloseLastPosByTake(string sy="", int op=-1, int mn=-1) {
  datetime t;
  double   ocp, otp;
  int      dg, i, j=-1, k=OrdersHistoryTotal();

  if (sy=="0") sy=Symbol();
  for (i=0; i<k; i++) {
    if (OrderSelect(i, SELECT_BY_POS, MODE_HISTORY)) {
      if (OrderSymbol()==sy || sy=="") {
        if (OrderType()==OP_BUY || OrderType()==OP_SELL) {
          if (op<0 || OrderType()==op) {
            if (mn<0 || OrderMagicNumber()==mn) {
              if (t<OrderCloseTime()) {
                t=OrderCloseTime();
                j=i;
              }
            }
          }
        }
      }
    }
  }
  if (OrderSelect(j, SELECT_BY_POS, MODE_HISTORY)) {
    dg=MarketInfo(OrderSymbol(), MODE_DIGITS);
    if (dg==0) if (StringFind(OrderSymbol(), "JPY")<0) dg=4; else dg=2;
    ocp=NormalizeDouble(OrderClosePrice(), dg);
    otp=NormalizeDouble(OrderTakeProfit(), dg);
    if (ocp==otp) return(True);
  }
  return(False);
}

As you can see they are very similar.

But for some reason, only closing by STOP works for me.

SL=  isCloseLastPosByStop("", -1, -1);
TP=  isCloseLastPosByTake("", -1, -1);

Print(SL,"_",TP); 

It works, but my Expert Advisor does not print UNIT, but keeps printing NULL.

But the close at STOP prints correctly: if stop = 1, if not stop =0....

help me out please....

 
lottamer:

There are 2 very similar functions in Kim's "last position close flag by STOP" and the other by TAKE.

here is the code

As you can see they are very similar.

But for some reason, only closing by STOP works for me.

I open position manually, put short TAKE. it works - but EA does not print UNIT, but continues to print NULL.

But the close at STOP prints correctly: if stop = 1, if not stop =0....

help me understand this please....


Look carefully at what price the stop order had in the open position and at what price it exactly closed. Igor's function compares these exact prices but does not take slippage into account.
Reason: