Backtest n days before month end or after month begins

Back to topics list To post a new topic, please log in or register
avatar
71
coiler 2015.02.25 13:53
 

Hi all,

could you help me with this approach, i need to code a signal that opens a trade n days before the end of the month or n first days of new month. Could you help my with pseudocode please?.

Best. 

avatar
13008
WHRoeder 2015.02.25 14:35 #
 
coiler: , i need to code a signal that opens a trade n days before the end of the month or n first days of new month. Could you help my with pseudocode please?.
  1. You have only three choices: Search for it, learn to code it, or pay someone. We're not going to code it FOR you. We are willing to HELP you when you post your attempt (using SRC) and the nature of your problem.
  2. First n days of new month is easy TimeDay(when) <= n
  3. Last n is slightly harder
    enum eMonth {JANUARY=1, FEBRUARY, MARCH, APRIL, MAY, JUNE, JULY, AUGUST,
                 SEPTEMBER, OCTOBER, NOVEMBER, DECEMBER };
    int   DaysOfMonth(datetime when){
                            // Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec
       static int     dpm[] =  {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 };
       eMonth         mo = TimeMonth(when);
       return dpm[mo - JANUARY] + (mo != FEBRUARY ? 0 : (int)IsLeapYear(when) );
    }
    bool  IsLeapYear(dateime when){
       int year = TimeYear(when); return year%4==0 && (year%100!=0 || year%400==0);}
    :
    if(DaysOfMonth(when) - TimeDay(when) > n)
    From my code
avatar
Moderator
3206
angevoyageur 2015.02.28 21:08 #
 
WHRoeder:
  1. You have only three choices: Search for it, learn to code it, or pay someone. We're not going to code it FOR you. We are willing to HELP you when you post your attempt (using SRC) and the nature of your problem.
  2. First n days of new month is easy TimeDay(when) <= n
  3. Last n is slightly harderFrom my code
Can you explain why you are still coding on 80 columns in 2015 ?
avatar
13008
WHRoeder 2015.02.28 21:42 #
 
angevoyageur: Can you explain why you are still coding on 80 columns in 2015 ?
Are your books one column but two feet wide? No because that is unreadable. They are 6 inches, sometimes two columns, so you can read it easily. So should be your code. I'm not going to go scrolling (or moving my eyes) back and forth trying to read it.

avatar
Moderator
3206
angevoyageur 2015.03.01 13:00 #
 
WHRoeder:
angevoyageur: Can you explain why you are still coding on 80 columns in 2015 ?
Are your books one column but two feet wide? No because that is unreadable. They are 6 inches, sometimes two columns, so you can read it easily. So should be your code. I'm not going to go scrolling (or moving my eyes) back and forth trying to read it.

Are you coding in columns ?

I don't code on a book, I code on a computer, any screen can easily contains 130 characters on a line and still being perfectly readable (on  my 13 inches and with my glasses).

Anyway that's all a matter of taste, personally I always find your code unreadable, being so compact.

Fortunately, this does not stop me from learning. No offense.

enum eMonth 
  {
   JANUARY=1,FEBRUARY,MARCH,APRIL,MAY,JUNE,JULY,AUGUST,SEPTEMBER,OCTOBER,NOVEMBER,DECEMBER 
  };

int DaysOfMonth(datetime when)
  {
                        // Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec
   static int     dpm[] = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 };
   eMonth         mo    = TimeMonth(when);
//---
   return(dpm[mo - JANUARY] + (mo != FEBRUARY ? 0 : (int)IsLeapYear(when) ));
  }

bool IsLeapYear(dateime when)
  {
   int year=TimeYear(when); 
//---
   return(year%4==0 && (year%100!=0 || year%400==0));
  }
   :
if(DaysOfMonth(when)-TimeDay(when)>n)


avatar
13008
WHRoeder 2015.03.01 14:20 #
 
angevoyageur:

Are you coding in columns?

I don't code on a book, I code on a computer, any screen can easily contains 130 characters on a line and still being perfectly readable (on  my 13 inches and with my glasses).

Anyway that's all a matter of taste, personally I always find your code unreadable, being so compact.

Fortunately, this does not stop me from learning. No offence.

Yes
int      pips2points;                  // slippage  3 pips  3=points 30=points  
double   pips2dbl;                     // Stoploss 15 pips  0.0015   0.00150    
int      digits_pips;                  // DoubleToStr(dbl/pips2dbl, digits_pips)
Your eMonth is only 102 characters wide, if you add proper English spacing yet this post is already becoming unreadable (depending on browser/font size.)

Also, since we must adapt to non-English (ur) and English (Correct brackets/bracers) I just extend that to sight impaired as well.
   JANUARY=1, FEBRUARY, MARCH, APRIL, MAY, JUNE, JULY, AUGUST, SEPTEMBER, OCTOBER, NOVEMBER, DECEMBER
I find the current formatting looses paragraph information that white space should convey.
void OnFirstTick(){
    if(Digits % 2 == 1){   // DE30=1/JPY=3/EURUSD=5 forum.mql4.com/43064#515262
            pips2dbl = Point*10;    pips2points = 10;    digits_pips = 1;
   } else { pips2dbl = Point;       pips2points =  1;    digits_pips = 0;     }
   // OrderSend(... Slippage_Pips * pips2points, Bid - StopLossPips * pips2dbl
//---- These are adjusted for 5 digit brokers.
                                                                              
   mi_minlot   = MI(MODE_MINLOT);
   mi_minlot   = MI(MODE_MINLOT);
   mi_maxlot   = MI(MODE_MAXLOT);
   mi_lotstep  = MI(MODE_LOTSTEP);
                                                                              
   lotDigits   = 0;  double   lotStep  = mi_lotstep;
   while(lotStep - int(lotStep) > 1.E-8){ ++lotDights;   lotStep *= 10.0;  }
                                                                              
   for(eTimeScale ts=TS_FIRST; ts < TS_COUNT; ++ts)   if(IsTsOk(ts) )
      DownloadHistory(ts);
Never stop learning.
No offense taken.

avatar
Moderator
3206
angevoyageur 2015.03.01 16:03 #
 
WHRoeder:

No offense taken.

Fixed. Thank you
Back to topics list  

To add comments, please log in or register