how can i make my indicator to be calculated in testing not every tick, but once at new bar

 

Hi frds,

I have my indicator which calculates something for me at open prices to for example 60 bars past, I mean from Open[0] to Open[59] lets say. When I test my EA and I use 15 minutes bar and in one bar there are approx 70 ticks and i use it with many combinations of inputs for example 5 sets of imputs (12, 8 34) (26, 8 56) etc it takes a lot of time to calculate it but I need only to calculate it at once at the begginig of the bar. Has anyone idea how to code it to work efficiently?? thx

 

Please search its been done before thousands of times just one link below.

https://forum.mql4.com/25830

 
ladygaga:

 


Hi Ladygaga!

Put this at the beginning of your start loop...

if(IsTesting())
    {if(Volume[0] != 1)
         {return(0);}}

Try it... hope this helps.  Seems far easier to answer a question than to clutter up the forum with someones determined efforts to jerk newbies around.  I think we already know how some people feel about researching... isn't this getting to be old yet?

 
Ruptor:

Please search its been done before thousands of times just one link below.

https://forum.mql4.com/25830

Using Time[0] is a bad idea. All you need to do is switch timeframes on the chart and it gets stuffed completely. iTime would not have this problem.

 
blogzr3:

Using Time[0] is a bad idea. All you need to do is switch timeframes on the chart and it gets stuffed completely. iTime would not have this problem.


Hi blogzr3!

Yes, you are right... and some people who do that, and figure out that the problem you mention exists, usually add a safety feature to their code, to force the indicator to remain in the same timeframe, regardless of which timeframe is selected, after the indicator is dropped on the chart.

 

HI guys thank You for help

Wiley I'm not sure if I understand You in the right way...Lest assume that I have my own function which is similar to iStochastic, better, lets assume that it is stochastic oscilator- my own code and I take stochastic value from last bar so:

myownStochastic(NULL,0,120,50,20,MODE_SMA,0,MODE_MAIN,1) and lets assume that value for last bar (no current) is 46 and it should be 46 for all the ticks in current bar so it need to be calculated only once not 70 times on last 120 bars, when Volume[0]==1 we have 46 and when Volume[0]!=1 it gives me 0 so for example my trade is closed but my indicator is not equal 0 ??? Am I right Wiley?