Script that runs when a new bar is created in all timeframe - page 2

 
GlobalVariable

isn't reliable

 
qjol:

isn't reliable

Yep. Using a GV means the script can run on only one chart. Multiple charts would conflict with each other.

and unnecessary.

and dates are NOT int's.

Correct
Broken
int init(){}
int deinit(){}

int run_once_perbar_function()
{
datetime cur_bartime = Time[0];         
static datetime prev_bartime;
if (cur_bartime = prev_barTime) return; 
prev_bartime = cur_bartime;

//code below this point will run once each new bar
Alert("whatever...");
int init(){}
int deinit(){}

int run_once_perbar_function()
{
int cur_bartime;
int prev_bartime;

cur_bartime=Time[0];
prev_bartime=GlobalVariableGet("prev_bartime");

if(prev_bartime==0) {
   GlobalVariableSet("prev_bartime",cur_bartime); 
   return(0);}

if(cur_bartime==prev_bartime) return(0);
GlobalVariableSet("prev_bartime",cur_bartime);

//code below this point will run once each new bar
Alert("whatever...");

 
Ickyrus:
Wow! smoknfx finally answered a question! (:->


yes, isnt that amazing. i answered a question.

i have been known to do things like that from time to time.

would you be surprised to learn that this isnt my first rodeo?

it isnt.

happy trading,

zero/.

 
WHRoeder:

Yep. Using a GV means the script can run on only one chart. Multiple charts would conflict with each other.

and unnecessary.

and dates are NOT int's.

Correct
Broken

i cant remember the exact syntax off the top of my head, it has been a while... but let me just take a stab at writing some pseudo code...

string variablename=Symbol()+"_"+"timer";

int t=TimeCurrent();

GlobalVariableSet(variablename,t);

and yes, i understand that TimeCurrent() is documented to use a datetime value as the return value, but an int works just fine and i like it.

dig me?

you may feel free to keep pushing me, if you insist, mr whroeder, but i can play fiddle faddle with an old man like you until the sun goes down.

especially in the coding department.

the truth is, mr whroeder, that i am continually being pleasant and nice while you are continually being rude and nasty.

it is your decision.

oh yes, one more issue, i was not present here last month, so that is why i forgot to wish you a happy birthday.

happy birthday!

zero/.