Forex
Google
New signals service!

Go Back   Forex Trading > Discussion Areas > Metatrader 4


Register in Forex TSD!
Trading Systems Leaders in this forum (automated trading systems) are winning more than 3000 pips in a month (30000$ investing one lot every time).
Click here to register and get more information

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 05-17-2007, 04:29 PM
Junior Member
 
Join Date: Dec 2006
Posts: 13
Flirrrt is on a distinguished road
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:

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
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #2 (permalink)  
Old 05-17-2007, 05:12 PM
ryanklefas's Avatar
Senior Member
 
Join Date: Apr 2006
Location: USA
Posts: 439
ryanklefas is on a distinguished road
Try putting and ending bracket " } " to finish off the function.
__________________
"Don't work harder, work smarter." -- my Java professor

Coder for Hire:
http://www.firecell-fx.com
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #3 (permalink)  
Old 05-17-2007, 05:14 PM
ryanklefas's Avatar
Senior Member
 
Join Date: Apr 2006
Location: USA
Posts: 439
ryanklefas is on a distinguished road
I noticed you have another thread with more coding questions. Try posting your entire indicator or EA so programmers can see the whole picture.
__________________
"Don't work harder, work smarter." -- my Java professor

Coder for Hire:
http://www.firecell-fx.com
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #4 (permalink)  
Old 05-17-2007, 05:32 PM
Member
 
Join Date: Apr 2006
Posts: 67
ejoi is on a distinguished road
What is m? if its for current bar... just 0 will do.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #5 (permalink)  
Old 05-17-2007, 06:30 PM
Junior Member
 
Join Date: Dec 2006
Posts: 13
Flirrrt is on a distinguished road
m is set to 0, i want the current "action".

My complete code is:
Code:
//+------------------------------------------------------------------+
//|                                                         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?
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #6 (permalink)  
Old 05-17-2007, 08:36 PM
european's Avatar
Senior Member
 
Join Date: Apr 2006
Posts: 284
european is on a distinguished road
To be able to add new records/lines to a file you need:

FileSeek(handle, 0, SEEK_END);
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #7 (permalink)  
Old 05-17-2007, 11:05 PM
ralph.ronnquist's Avatar
Senior Member
 
Join Date: Oct 2006
Posts: 280
ralph.ronnquist is on a distinguished road
... and you need to use
PHP Code:
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.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #8 (permalink)  
Old 05-18-2007, 07:57 AM
Junior Member
 
Join Date: Dec 2006
Posts: 13
Flirrrt is on a distinguished road
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???
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply

Bookmarks

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
What's the best way to check if the tick is the first tick of the new bar? blooms Metatrader 4 2 10-31-2006 06:10 AM
Problem using Variables Tick-by-Tick unltdsoul Metatrader 4 2 07-04-2006 03:36 AM
About start() The_N Indicators - Metatrader 4 1 05-21-2006 03:20 PM


All times are GMT. The time now is 06:49 PM.



Search Engine Friendly URLs by vBSEO 3.2.0 ©2008, Crawlability, Inc.