Download MetaTrader 5

How to make date comparison

To add comments, please log in or register
jthornton
70
jthornton  

I've created an EA that works very well in backtesting.  However, I have a different program that I use altogether which I use to signal GREEN/RED.  Green is when I consider the market conditions favourable to go long stocks.  Red is when I go to cash.

I would like to incorporate the two systems while running a backtest.  Basically what I want to do is create dates.  For example:

01/30/2015 Green

06/17/2015 Red

09/02/2015 Green

03/01/2016 Red

These dates are just an example, but I would like to take the dates/signals and put them into some kind of an array.  I then what to add a condition to my existing EA that ONLY buys long when GREEN and doesn't do anything when RED.

So, my questions:

1.  Can someone suggest how I can input these dates/colors into an array?  I'm not overly familiar with how arrays work in MQL4

2.  Can someone show me how to create a condition that will find out if the current date (within the backtest) is within a GREEN signal?

Carl Schreiber
7301
Carl Schreiber  

1.  Can someone suggest how I can input these dates/colors into an array?  I'm not overly familiar with how arrays work in MQL4

2.  Can someone show me how to create a condition that will find out if the current date (within the backtest) is within a GREEN signal?
  1. Read about arrays! Here and in the reference of the editor and google yourself. An array can be of any type even color or datetime.
  2. color c1, c2;
    ...
    c1 = clrRed; c2 = clrGreen;
    ...
    if (c2 == clrGreen) { ... }
    
    

Array Functions - MQL4 Reference
Array Functions - MQL4 Reference
  • docs.mql4.com
Array Functions - MQL4 Reference
whroeder1
15934
whroeder1  
Carl Schreiber: An array can be of any type even color or datetime.
And that includes an array of a structure.
struct Signal{ datetime when; color direction};
Signal signals[];
:
signals[0].when      = D'01.30.2015';
signals[0].direction = Green;
To add comments, please log in or register