Isn't start() supposed to run on every tick?

 

I've learned that what is placed after the start(), will run on every tick. But my code doesnt agree with me.

I'm trying to export to a file on every tick, with this code:

int start()

{

string tab = "";

int f = FileOpen(Symbol()+Period()+".csv", FILE_CSV | FILE_WRITE,',');

FileWrite(f,"Date","Open","High","Low","Close","Volume");

Print(tab, TimeToStr(iTime(NULL,0,m), TIME_DATE) ,iOpen(NULL,0,m), iHigh(NULL,0,m),

iLow(NULL,0,m) ,iClose(NULL,0,m) ,iVolume(NULL,0,m));

string sDate = TimeToStr(iTime(NULL,0,m),TIME_DATE);

sDate = StringSetChar(sDate,4,'/');

sDate = StringSetChar(sDate,7,'/');

FileWrite(f,sDate, TimeToStr(iTime(NULL,0,m),TIME_MINUTES),iOpen(NULL,0,m), iHigh(NULL,0,m),

iLow(NULL,0,m), iClose(NULL,0,m), iVolume(NULL,0,m));

FileClose(f);

I get a file, and the first line.. but it seems as it only runs once, not even when a new bar is created. I know that the m-variabel isn't used correct ehre, I just want "something" to be exported so I see it works. What can I replace m with, to always get the "latest"/current prices? 0?

(/johan

 

Try putting and ending bracket " } " to finish off the function.

 

I noticed you have another thread with more coding questions. Try posting your entire indicator or EA so programmers can see the whole picture.

 

What is m? if its for current bar... just 0 will do.

 

m is set to 0, i want the current "action".

My complete code is:

//+------------------------------------------------------------------+

//| test.mq4 |

//| |

//| |

//+------------------------------------------------------------------+

#property copyright ""

#property link ""

//---- indicator settings

#property indicator_separate_window

//+------------------------------------------------------------------+

//| Custom indicator initialization function |

//+------------------------------------------------------------------+

int init()

{

return(0);

}

//+------------------------------------------------------------------+

int start()

{

int m=0;

//---- done

string tab = "";

int f = FileOpen(Symbol()+Period()+".csv", FILE_CSV | FILE_WRITE,',');

FileWrite(f,"Date","Open","High","Low","Close","Volume");

Print(tab, TimeToStr(iTime(NULL,0,m), TIME_DATE) ,iOpen(NULL,0,m), iHigh(NULL,0,m),

iLow(NULL,0,m) ,iClose(NULL,0,m) ,iVolume(NULL,0,m));

string sDate = TimeToStr(iTime(NULL,0,m),TIME_DATE);

sDate = StringSetChar(sDate,4,'/');

sDate = StringSetChar(sDate,7,'/');

FileWrite(f,sDate, TimeToStr(iTime(NULL,0,m),TIME_MINUTES),iOpen(NULL,0,m), iHigh(NULL,0,m),

iLow(NULL,0,m), iClose(NULL,0,m), iVolume(NULL,0,m));

FileClose(f);

return(0);

}

//+------------------------------------------------------------------+

By this i get an csv-file with the first line od Date, Open, high etc.. and a second line with the values. But this is only written once, when I attach the indicator to the chart. I want it to write to the file at every new tick being made...

Ideas?

 

To be able to add new records/lines to a file you need:

FileSeek(handle, 0, SEEK_END);

 

... and you need to use

FileOpen( ..., FILE_CSV | FILE_WRITE | FILE_READ, ... )

The way you had it, the file was over-written each tick, and only the last writing remained.

 

You're right, my bad. I got it working as an indicator now, but the thing is that I want to use on my ea for extended backtesting. The exact same code doesn't give any output at all, maybe it's not possible?

When you backtest an ea, doesn't it trigger on every tick being made? I know it's just 1min data and the ticks is "made up", but shoulden't it work the same? Or maybe you can solve it with like if volume[0]>volume[1] or something, to create the trigger for the output?

If I set the output exactly as my triggerconditions for the trade, I still get no output???

Reason: