Miscellaneous
0
Views
0
Downloads
0
Favorites
MoonPhases
//+------------------------------------------------------------------+
//| MoonPhases.mq4 |
//+------------------------------------------------------------------+
//
// Calculation taken from:
// http://individual.utoronto.ca/kalendis/lunar/index.htm
//
// Coded by: Ben Letto, sbgtrading@yahoo.com
//+------------------------------------------------------------------+
//+------------------------------------------------------------------+
#property copyright "Ben L."
#include <stdlib.mqh>
#property indicator_chart_window
extern bool DrawFullMoon=true;
extern color FullMoonLineColor=White;
extern bool DrawNewMoon=false;
extern color NewMoonLineColor=DimGray;
extern datetime StartDate= D'2006.01.01 00:00';
extern datetime EndDate= D'2008.01.01 00:00';
//extern string OutFileName="FullMoonDates_out.csv";
extern int ChartTimeMinusGMTInMinutes = 120;
int OutputHandle,i;
datetime FullMoonTime,NewMoonTime;
string LineName;
//+------------------------------------------------------------------+
//| Custom indicator initialization function |
//+------------------------------------------------------------------+
int init()
{
//---- indicators
if(StartDate<Time[Bars-1]) StartDate=Time[Bars-1];
//----
return(0);
}
//+------------------------------------------------------------------+
//| Custom indicator deinitialization function |
//+------------------------------------------------------------------+
int deinit()
{
//----
//----
return(0);
}
//+------------------------------------------------------------------+
//| Custom indicator iteration function |
//+------------------------------------------------------------------+
int start()
{
//----
int total=300;
for(i=total;i>0;i--)
{ LineName=StringConcatenate("Full_",DoubleToStr(i,0));
ObjectDelete(LineName);
LineName=StringConcatenate("New_",DoubleToStr(i,0));
ObjectDelete(LineName);
}
i=1;
int errCount=0;
FullMoonTime=0;
NewMoonTime=0;
int BarsForOpenLine=10*24*60/Period();
double SecondsPerDay=60*60*24;
while(FullMoonTime < EndDate)
{ if(DrawFullMoon) FullMoonTime=StrToTime("2000.01.01 00:00")+MathRound(SecondsPerDay*(20.362954+29.5305888531*i+0.00000000010219*i*i)+ChartTimeMinusGMTInMinutes*60);
else FullMoonTime=-1;
if(FullMoonTime>StartDate)
{ LineName=StringConcatenate("Full_",DoubleToStr(i,0));
if(!ObjectCreate(LineName,OBJ_VLINE,0,FullMoonTime,0,0,0)) {HandleError(errCount, "Problem creating "+LineName+" "+TimeToStr(FullMoonTime,TIME_DATE));}
else {ObjectSet(LineName,OBJPROP_COLOR,FullMoonLineColor);ObjectSet(LineName,OBJPROP_WIDTH,2);}
}
if(DrawNewMoon) NewMoonTime=StrToTime("2000.01.01 00:00")+MathRound(SecondsPerDay*(5.597661+29.5305888610*i+0.00000000010219*i*i)+ChartTimeMinusGMTInMinutes*60);
else NewMoonTime=-1;
if(NewMoonTime > StartDate)
{ LineName=StringConcatenate("New_",DoubleToStr(i,0));
if(!ObjectCreate(LineName,OBJ_VLINE,0,NewMoonTime,0,0,0)) {HandleError(errCount, "Problem creating "+LineName+" "+TimeToStr(NewMoonTime,TIME_DATE));}
else {ObjectSet(LineName,OBJPROP_COLOR,NewMoonLineColor);ObjectSet(LineName,OBJPROP_WIDTH,2);}
}
// HandleError(errCount,LineName);
// FileWrite(OutputHandle,TimeToStr(TheDates[i],TIME_DATE||TIME_MINUTES),DoubleToStr(Open[iBarShift(Symbol(),0,TheDates[i],false)],Digits));
i++;
}
// FileClose(InputHandle);
// FileClose(OutputHandle);
//----
return(0);
}
void HandleError(int& errCount, string estr)
{ int err=GetLastError();
if(err>1)
{ errCount++;
if(errCount==1) Alert("New errors start here!");
}
if (err>0) Alert("Error: ",err," ",ErrorDescription(err)," e: ",estr);
}
Comments
Markdown Formatting Guide
# H1
## H2
### H3
**bold text**
*italicized text*
[title](https://www.example.com)

`code`
```
code block
```
> blockquote
- Item 1
- Item 2
1. First item
2. Second item
---