[WARNING CLOSED!] Any newbie question, so as not to clutter up the forum. Professionals, don't go by. Can't go anywhere without you. - page 386

 
splxgf писал(а) >>

Probably something like this, because infinite loops take a very long time on modern hardware.

:)

 
Rita >>:

Добрый день.

В индикатоте есть ф-я IndicatorShortName("iC_C_mod, ..... ");

Мне, однако, нужно, кроме этой надписи, - чтобя я могла вставить коммент с динамично изменяющейся переменной в окно индикатора.

Типа ф-и Comment();

Но только, именно, в окно индикатора, а вовсе не на сам график.

Пож. подскажите ?


#property copyright "Copyright © 2009, :-)"
#property link      "----"

#property indicator_separate_window

int start()
{
   string info = "Bid= "+DoubleToStr(Bid,5);
   IndicatorShortName( info);
//----
   return(0);
}

so it will output to the window you want

 
Rita >>:

Добрый день.

В индикатоте есть ф-я IndicatorShortName("iC_C_mod, ..... ");

Мне, однако, нужно, кроме этой надписи, - чтобя я могла вставить коммент с динамично изменяющейся переменной в окно индикатора.

Типа ф-и Comment();

Но только, именно, в окно индикатора, а вовсе не на сам график.

Пож. подскажите ?


You can create a label and change the text


   string ID  = "MyLabelName";


   if(ObjectCreate( ID, OBJ_LABEL, 0, 20, 20))
     {
       ObjectSet( ID, OBJPROP_XDISTANCE, 35);
       ObjectSet( ID, OBJPROP_YDISTANCE, 35);
     }
 
   //отображение на экране значения переменной txt 
   string txt = "Belissimo";
   ObjectSetText( ID, txt , 18, "Arial Black", Green);
The code may be wrong, but it works.
 
Don't leave it unattended
 
Thank you, xeon and splxgf!
 
My friends, good afternoon.

It will be interesting to listen to you on the following question:

There is an opinion that the quotation of a currency pair is influenced by many other financial instruments:
movement of leading stock indices, futures, options, etc.


1) Do you think it is possible to trace this influence
(and therefore constructively used in a trading strategy)???

2) Have you noticed any persistent correlations between the relevant currency pairs and the quotes of other financial instruments?

3) Have you used indicators to demonstrate such correlations?


(I'm waiting for your comments in the thematic branch of this forum with the same name: https://forum.mql4.com/ru/28930 )

 

splxgf писал

void CheckSell()
{
if((NormalizeDouble(Price,Digits) < NormalizeDouble(MA10,Digits)))
Sell();
}

Probably something like this, because infinite loops take a very long time on modern hardware.


But then the program will just check the condition and if it is fulfilled, it will sell it. And if it doesn't, what will it do? It is supposed to wait for the condition to be fulfilled in this very code fragment.



Vinin wrote


Why did you make a loop? If there is no condition, the program should just exit and not wait for the signal to appear.

That is why I made the loop, because it is in this code fragment where the program should wait for the condition to appear. You cannot exit to the beginning of the loop. What is the correct way to implement the wait for a condition?


And this is my design:

void CheckSell()
{
while(!(NormalizeDouble(Price,Digits) < NormalizeDouble(MA10,Digits)))
{
Sleep(5);
RefreshRates();
}
Sell();
}


- Is it working and just hangs the tester? Or it does not work at all? Very much want to understand how to properly wait for a condition to be fulfilled without exiting the given function.


Thanks for the answers!

 
Jahspear >>:


Но ведь тогда программа просто проверит условие и если оно выполняется, продаст. А если не выполняется, что она будет делать? По задумке, должна ждать выполнения условия именно в этом месте кода.


Вот поэтому и сделал цикл, что именно в этом месте кода программа должна ждать выполнения условия. Выйти в начало нельзя. Как правильно реализовать цикл ожидания условия?


- она рабочая и просто тестер вешает? Или не работает в принципе? Очень хочется понять, как правильно ожидать выполнения условия, не выходя из заданной функции.

The program is most likely to work, and it is wrong to wait for the condition without exiting the function, at least the tester will not give a new tick until the procedure has been executed.

If the condition is not fulfilled, you should terminate the program and give control to the tester. Programs used to be linear and therefore looped themselves and waited for signals from above. Now the program is event-driven, when event occurs, for example, a new tick and the handler of this event is call start() after all necessary work on processing of a new tick is finished, the function must terminate, instead of being a dispatcher.

It is correct to check the condition in the start(), the condition has come, do your business, if not, finish your work and wait for the next tick. We already adjust our logic to this.

 

There is also a question.

The indicator displays the MA lines of two currency pairs in a separate window. It works fine.

But when I insert a condition in the code:

"If on one of the symbols a bar is missed, then on the second symbol - this present bar is skipped (not considered)", like this:

int start()
  {
     int limit;
     int counted_bars=IndicatorCounted();
  //---- проверка на возможные ошибки
     if( counted_bars<0) return(-1);
  //---- последний посчитанный бар будет пересчитан
     if( counted_bars>0) counted_bars-=10;
     limit=Bars- counted_bars;
  //---- основной цикл
ВОТ Я СТАВЛЮ ЭТО УСЛОВИЕ  :
    for( k = 0; k < iBars( Symbol_1,Period()); k++)   {  
    int symb2Shift = iBarShift( Symbol_2,Period(),iTime( Symbol_1,Period(), k),true);
    if( symb2Shift != -1)                            { 
//---------------------------------
    for( k=0; k< limit; k++)
       {
       Symbol1[ k]=     (iMA( Symbol_1,..... k)  ;
       Symbol2[ k]=     (iMA( Symbol_2,..... k)  ;           
       } 
                        }
                       }
//----
    return(0);
  }

Then mt4 hangs for a minute and a half to two minutes. Then the indicator starts working, but it uses 35-45% of RAM.

What can be the reason, please advise?

 

Good afternoon!

Can you please tell me how to write a simple indicator that would highlight a certain bar (should be set in the options), for example at 12.30 with a vertical line and sign the days of the week on the chart (say somewhere above the hay of each day)?

Thank you!

Reason: