[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 38

 
ikatsko >> :

Left (for simplicity) only what constitutes the problem in the code. Put the indicator on and see the problem, so to speak.




If I'm not mistaken, the init function is called only once, when you hang up on a chart. It would be logical to force reinitialization when tf changes - to avoid "strange things" with memory manager's work.

if( CurrentPeriod!=Period())
{
    ReInitParam();
    CurrentPeriod=Period();
}

>> Good luck.

 
ikatsko писал(а) >>

Left (for simplicity) only what constitutes the problem in the code. We put the indicator and see the problem, so to speak.



//+------------------------------------------------------------------+
//| Custom indicator initialization function |
//+------------------------------------------------------------------+
int init()
{
//...........................................................
Set_SL[History*Depth]=1.0*Level*Point;
Alert("Init:"," Set_SL[",History*Depth,"]=",Set_SL[History*Depth]);//suspended it to see: it shows (say) 0,0001
//--------------------------------------------------------------------//----
return(0);
}

You should not refer to arrays from init(). Most likely, the arrays haven't been initialized yet. It makes sense to move the problematic part to start()

 
Vinin >> :

It is enough to check the last closed transaction. But you have to provide for when there is no history yet

Which function can you use to do this?

 
xruss писал(а) >>

What function can be used to do this?

You have to write a function or look for a ready-made one.

 
VladislavVG >> :

If I'm not mistaken, the init function is only called once, when you hang up on a chart. It would be logical to force re-initialization when you change the t\f - to avoid "strange things" with memory manager operation.


Good luck.

From the tutorial:

Special init() function.
In custom indicators the special init() function is called (and executed) immediately after the client terminal start, after a change of a symbol and/or a chart period, after recompiling the programme in MetaEditor and after the change of input parameters from the custom indicator setting window.

 
ikatsko >> :

From the textbook:

Special init() function.
In custom indicators the special function init() is called (and executed) immediately after the client terminal start, after the change of symbol and/or chart period, after recompiling the program in MetaEditor and after the change of input parameters from the custom indicator setup window.

It takes five minutes at most - declare a function and transfer it there from the init attachment and call it as I wrote you.

Good luck.

SZ the max int value your function gives you is most likely EMPTY_VALUE.

Yes, one more thing: the CurrentPeriod variable must be declared as a static or global variable for the file. I usually assign a value of -1 to such variables.

 
How do I refer to the previous bar (already formed)?
 
RocketTrend >> :
How to refer to the previous bar(already formed)?

Close[1]/Open[1]/High[1]/Low[1]/.... Depending on what value is needed.

 
VladislavVG >> :

Close[1]/Open[1]/High[1]/Low[1]/.... Depending on what value is required.

Thank you

 
VladislavVG >> :

Close[1]/Open[1]/High[1]/Low[1]/.... Depending on what value is required.

Thank you

Reason: