planetcycles
Download scriptOverview of the PlanetCycles Indicator
The PlanetCycles script is a specialized analytical tool designed for the MetaTrader 5 platform. It translates complex astronomical movements into a visual data point on your trading charts, allowing users to track cyclical patterns based on planetary positions. By monitoring the relative distance between two different celestial bodies, the tool helps identify recurring cycles that may influence market trends.
Core Logic and Functionality
The primary purpose of this script is to calculate the angular distance—or "aspect"—between two planets (a "fast" planet and a "slow" planet) over time. Here is how the logic processes your data:
1. Celestial Selection The script allows you to define which celestial bodies to track. For example, it can compare the Moon (a fast-moving body) against the Sun (a slower-moving body). These choices dictate the frequency and nature of the cycles displayed on the chart.
2. Perspective Modes The tool offers two different viewing perspectives:
- Geocentric: This is the standard view, observing the planets as they appear from the center of the Earth.
- Heliocentric: If toggled, the script shifts the perspective to the Sun as the central point of the calculation.
3. Dynamic Cycle Calculation As the script moves across your price history, it performs a continuous calculation of the distance between the two chosen planets. The logic handles these distances in two distinct ways depending on which planets you select:
- Inner Planet Dynamics: When tracking specific inner planets (like Mercury or Venus) in relation to the Sun, the logic focuses on their position relative to the Sun's "side." It performs a series of adjustments to ensure the data stays within a specific 180-degree range, smoothing out the perspective to show how these bodies move in and out of alignment.
- General Planetary Aspects: For all other planetary combinations, the script calculates the absolute angular distance between them. It ensures the data remains consistent by normalizing the values (e.g., converting a 350-degree difference into a 10-degree difference) to show the "shortest" path between the two bodies.
Visual Representation
The result of these calculations is plotted as a continuous line in a separate window on your platform. Instead of showing raw coordinates, it provides a visual representation of the Cycle. By observing the peaks, valleys, and recurring patterns in this line, users can attempt to identify cyclical rhythms in market behavior based on astronomical timing.
//+------------------------------------------------------------------+
//| PlanetCycles.mq5 |
//| J.S. 2012 |
//| http://www.eselstreckdich.de |
//+------------------------------------------------------------------+
#property copyright "J.S. 2012"
#property link "http://www.eselstreckdich.de"
#property version "1.00"
#property indicator_separate_window
#property indicator_buffers 1
#property indicator_plots 1
#property indicator_label1 "PlanetCycle"
#property indicator_type1 DRAW_LINE
#property indicator_color1 clrRed
#property indicator_style1 STYLE_SOLID
#property indicator_width1 1
#include <SWISSEPH.mqh>
input bool Geocentric=true; // geocentric view
input BODY fastPlanet=Moon; // planet fast
input BODY slowPlanet=Sun; // planet slow
//--- indicator buffers
double CycleBuffer[];
int flag=0;
//+------------------------------------------------------------------+
//| Custom indicator initialization function |
//+------------------------------------------------------------------+
int OnInit() {
SetIndexBuffer(0,CycleBuffer,INDICATOR_DATA);
flag=0;
if(!Geocentric) flag=SEFLG_HELCTR;
return(0);
}
//+------------------------------------------------------------------+
//| Custom indicator deinitialization function |
//+------------------------------------------------------------------+
void OnDeinit(const int reason) {
swe_close();
}
//+------------------------------------------------------------------+
//| Custom indicator iteration function |
//+------------------------------------------------------------------+
int OnCalculate(const int rates_total,
const int prev_calculated,
const datetime &time[],
const double &open[],
const double &high[],
const double &low[],
const double &close[],
const long &tick_volume[],
const long &volume[],
const int &spread[]) {
double a[6], b[6];
for( int i=prev_calculated; i<rates_total && !IsStopped(); i++) {
calculate(time[i],fastPlanet,a,flag);
calculate(time[i],slowPlanet,b,flag);
if(Geocentric &&
(slowPlanet==SE_SUN || slowPlanet==SE_MERCURY || slowPlanet==SE_VENUS) &&
(fastPlanet==SE_SUN || fastPlanet==SE_MERCURY || fastPlanet==SE_VENUS)) {
// z.B. Merkur bzw. Venus vor oder hinter der Sonne, Buch Seite 4
CycleBuffer[i]=a[0]-b[0];
while(CycleBuffer[i]>180) CycleBuffer[i]-=180;
while(CycleBuffer[i]<-180) CycleBuffer[i]+=180;
if(i>0 && CycleBuffer[i]-CycleBuffer[i-1]<-100) CycleBuffer[i]+=180;
if(i>0 && CycleBuffer[i]-CycleBuffer[i-1]>100) CycleBuffer[i]-=180;
} else {
// Aspekte 0..180°, Buch Seite 15
CycleBuffer[i]=a[0]-b[0];
if(CycleBuffer[i]>360) CycleBuffer[i]-=360;
if(CycleBuffer[i]<-360) CycleBuffer[i]+=360;
if(CycleBuffer[i]>180) CycleBuffer[i]=360-CycleBuffer[i];
if(CycleBuffer[i]<-180) CycleBuffer[i]=360+CycleBuffer[i];
CycleBuffer[i]=MathAbs(CycleBuffer[i]);
}
}
return(rates_total);
}
Comments