How to change chart time frame with code?
  #1 (permalink)  
Old 06-25-2008, 02:07 PM
Currency Trader
 
Join Date: Jan 2008
Location: Whidbey Island
Posts: 1
chaffinsjc is on a distinguished road
Default How to change chart time frame with code?

When an Expert Advisor is attached to a chart, the time frame is manually applied by clicking M1, M5, H1, etc. This time frame controls how often the EA receives a market tick which then runs all the code in the start() method.

How can I programmatically change the time frame from D1 to H4 to H1 to M30 to M15 to M5 to M1?

The underlying requirement is that the EA only wants to trade once a week at a particular time. As the weekday and clock time approaches, changing the time frame would allow waking up the start() method more and more often until the moment arrives.
Reply With Quote
  #2 (permalink)  
Old 06-28-2008, 12:21 AM
Forex Warrior
 
Join Date: Feb 2007
Posts: 264
FerruFx is on a distinguished road
Default

If the EA is attached on let say M5, it will received exactly the same amount of ticks than the D1 chart. The start() function will execute each tick regardless the TF where the EA is attached.

However, if you want to limit some part of your code, you may use something like this:

First declare this:

Quote:
datetime timeprev=0;
Then in start() function:

Quote:
if(timeprev!=iTime(Symbol(),PERIOD_D1,0))
{
...
YOUR CODE HERE
...
timeprev = iTime(Symbol(),PERIOD_D1,0);
}
Your code will be executed only once D1 bar in this example (even on a M5 chart).

Hope that helps.

FerruFx
__________________
FerruFx / www.ervent.net - Professional Coding Services (EAs/Indicators/Alerts)
Reply With Quote
Reply

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
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


Similar Threads
Thread Thread Starter Forum Replies Last Post
MT4 Time frame - 10 M chart bnf Indicator Coding 2 07-07-2011 12:07 PM
Indicators with All Time Frames on one chart SteveG Indicators 4 01-06-2011 02:24 PM
multiple time frame indicator tinybolt10 Indicators 14 03-07-2010 07:14 AM
Strategy Tester - virtual chart not active chart? joc_06 MetaTrader and ZeroCode 0 08-11-2007 04:41 PM
How Can I Change the Lot size to .10 JohnnyQuad MetaTrader and ZeroCode 2 09-07-2005 06:42 AM


All times are GMT. The time now is 10:44 AM.

Registered members gain free access to online FOREX currency trading tools, foreign exchange software, Metatrader MT4/MT5 expert advisors, MT4 indicators and EAs. Register now