Write your trigger at begin of start function. Sample for triggering EA one time per bar
static datetime prevtime=0; ... if(prevtime == Time[0]) return(0); prevtime = Time[0];
For every minute this code may be changed to:
static datetime prevtime=0; ... datetime minute=iTime(NULL,PERIOD_M1,0); if(prevtime == minute) return(0); prevtime = minute;
Thanks, but I don't quite understand....
I'm going to try some endless loop to bypass tick trigger.
And another question please: when I try another code, "Symbol()" seems to be weird.
I'm going to try some endless loop to bypass tick trigger.
And another question please: when I try another code, "Symbol()" seems to be weird.
...... string sym=Symbol(); Print(sym);
nothing happened.
I wrote a code, which causes DEADLOCK:
#property copyright "Copyright ?2006, MetaQuotes Software Corp." #property link "http://www.metaquotes.net" #property indicator_chart_window int init() { return(0); } int deinit() { return(0); } static int prev=0; int start() { int i=ObjectsTotal(); int lastbar=WindowFirstVisibleBar()-WindowBarsPerChart(); int j,handle; while (1>0) { if(lastbar != prev) { handle=FileOpen("mydata.csv",FILE_CSV|FILE_WRITE,','); for (j=i-1; j>=0; j--) if(ObjectType(ObjectName(j))==OBJ_ARROW && handle>0) { FileWrite(handle, ObjectGet(ObjectName(j),OBJPROP_ARROWCODE), ObjectGet(ObjectName(j),OBJPROP_PRICE1) ); } FileClose(handle); prev=lastbar; } } //---- return(0); } //+------------------------------------------------------------------+
Why?
endless loop
while (1>0)
while (1>0)
Thanks.
Have a good weekend !
Have a good weekend !
I've done quite some learning and trial......Guess I'm just one step from success now.
I got the following script, which will work also in weekdays .
The last things I don't know :
1, Why the .CSV file always shows:0,0,0,0 (in two row), or empty, even if I press F12 and draw new arrow again and again?
2, I used an Array to include each arrow's time and name. But should I define the Array as "datetime" or "string"?
I got the following script, which will work also in weekdays .
The last things I don't know :
1, Why the .CSV file always shows:0,0,0,0 (in two row), or empty, even if I press F12 and draw new arrow again and again?
2, I used an Array to include each arrow's time and name. But should I define the Array as "datetime" or "string"?
int start() { int prev=0; int prevarrow=0,arrowtotal; // drawn on the chart int lastvisiblebar; // index of it int i,j,handle; string namearray[][2]; //will sort arrowname by time,in case arrows change orders but indexes do not while (1>0) // endless loop, thanks to Sleep().... { lastvisiblebar=WindowFirstVisibleBar()-WindowBarsPerChart(); //======= if press F12 then ============================= if(lastvisiblebar != prev) { i=ObjectsTotal(); arrowtotal=0; //reset to 0 after write file //---- make arrows an Array ------ for (j=0; j<i; j++) if(ObjectType(ObjectName(j))==OBJ_ARROW) // rule out trendlines, etc. { namearray[j][0]=ObjectGet(ObjectName(j),OBJPROP_TIME1); // sort namearray[j][1]=ObjectName(j); arrowtotal++; } Comment("prevarrow=" +prevarrow +" arrowtotal=" +arrowtotal +" lastvisbar=" +lastvisiblebar); //---- if new arrows added then -------------------- if(arrowtotal!=prevarrow) { ArraySort(namearray); // sort by time handle=FileOpen("mydata.csv",FILE_CSV|FILE_WRITE,';'); if(handle>1) // write arrows to a file, in time order { for (j=0;j<ArrayRange(namearray,1);j++) FileWrite(handle, ObjectGet(namearray[j,1],OBJPROP_ARROWCODE), ObjectGet(namearray[j,1],OBJPROP_PRICE1)); FileClose(handle); } prevarrow=arrowtotal; } //------------------------------------------------- prev=lastvisiblebar; } //===================================================== Sleep(4000); } return(0); }

You are missing trading opportunities:
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
Registration
Log in
You agree to website policy and terms of use
If you do not have an account, please register
"int start()" works when new tick arrives. But I want to do this: in WEEKEND, (so no tick arrives), I'll use MT4's history function, say, go back to 2005-1-1, and press "F12" again and again, to do some exercise. In the middle of it, I'll draw some arrows on chart...... Now I need a block of code to process these arrows. The tough part is at what time the code could tell new arrow added.
In this case, I need to bypass tick triggering. Maybe "run the code every one minute" or something ?
Any good idea?