Magenta yearly season cycles

Author: Copyright � 2005, MetaQuotes Software Corp.
Magenta yearly season cycles

This script is designed to automatically visualize historical market events or seasonal cycles directly on your trading charts. Instead of manually marking dates, the tool imports external data from a file and handles the complex task of positioning visual markers accurately across different financial instruments.

How the Logic Works

1. Data Importation The script begins by searching for an external data file (specifically a CSV format). This file acts as the "memory" for the tool, containing a list of specific dates paired with descriptions. By reading from an external source, the tool allows users to update market events without needing to modify the underlying code.

2. Intelligent Asset Scaling The tool recognizes that different financial markets (such as Forex pairs like EURUSD, Gold, or S&P 500 indices) have vastly different price scales. To ensure that text labels are always visible and not overlapping with the price candles, the script automatically calculates a "buffer" zone. It adjusts this vertical spacing based on exactly which asset you are currently viewing, ensuring the layout remains clean and readable regardless of whether you are trading low-value currencies or high-value indices.

3. Automated Visual Mapping The core logic iterates through every entry in your data file:

  • Vertical Markers: For every date listed, the script draws a vertical dotted line. This provides a clear "wall" on the chart to identify exactly when a significant event occurred.
  • Text Labels: Simultaneously, it places a descriptive text label at that specific point in time.
  • Dynamic Coloring: The script distinguishes between different types of entries based on their description. If an entry is marked as "New," it applies a neutral Gray color; otherwise, it uses Magenta to highlight the event.

4. Precision Placement To ensure the markers land exactly where they should, the script performs a background calculation. It scans the history of the current chart to find the precise "bar" (time slot) that corresponds with the date in your file. Once found, it anchors both the line and the text at that exact coordinate.

5. Object Management The logic includes a "safety check" for every item it places on the screen. It checks whether a marker already exists:

  • If the marker is missing, the script creates it from scratch with the correct thickness, style, and font.
  • If the marker already exists, the script simply updates its position or properties to ensure the chart stays synchronized with your data.

Summary for the User

Essentially, this script transforms a static list of dates into a dynamic, interactive timeline. You provide the historical data in a file, and the tool automatically builds a professional-grade visual map on your charts, adjusting its spacing and labels automatically to suit whichever market you are currently trading.

Miscellaneous
Uses files from the file systemIt reads information from a file
10 Views
0 Downloads
0 Favorites
Magenta yearly season cycles
//+------------------------------------------------------------------+
//|                                                wxLunarCycles.mq4 |
//|                      Copyright © 2005, MetaQuotes Software Corp. |
//|                                        http://www.metaquotes.net |
//+------------------------------------------------------------------+
#property copyright "Copyright © 2005, MetaQuotes Software Corp."
#property link      "http://www.metaquotes.net"


//+------------------------------------------------------------------+
//| script program start function                                    |
//+------------------------------------------------------------------+
int start()
  {
//----
   
	
	string EDate, Description;
	int TimeIndex;
	color Colour;
	double Buffer;
	
	int handle;
	handle=FileOpen("yearlyseasoncycle.csv",FILE_CSV|FILE_READ,',');
	if(handle<1)
 	{
  		Print("File my_data.dat not found, the last error is ", GetLastError());
  		return(false);
 	}

   if(Symbol() == "EURUSD" || Symbol() == "GBPUSD")
      Buffer = 100*Point;
   if(Symbol() == "AUDUSD")
      Buffer = 100*Point;
   if(Symbol() == "GOLD")
      Buffer = 1000*Point;      
   if(Symbol() == "_CL")
      Buffer = 10*Point;
   if(Symbol() == "_SP500")
      Buffer = 2000*Point;
   if(Symbol() == "_DJI")
      Buffer = 2000*Point;


	while(!FileIsEnding(handle))
	{
		EDate = FileReadString(handle);
		Description = FileReadString(handle);
		//Alert(EDate, "--", Description);
		if(EDate == "") continue;
		datetime DDate = StrToTime(EDate);
		
		
		if(Description == "New") 
			Colour = Gray;
		else
			Colour = Magenta;
				
		SetObj(EDate + Description + MathRand(), OBJ_VLINE, StrToTime(EDate), 0, 1, Colour);
		
      TimeIndex=0;
      for(int j=0; j<Bars; j++)
      {
         if(Time[j]>=DDate && Time[j+1]<=DDate ) TimeIndex=j;
         if(TimeIndex != 0) break;
      }
		
		
		SetTxtObj(EDate + Description + "txt" + MathRand(), OBJ_TEXT, StrToTime(EDate), Low[TimeIndex]-Buffer, Description, 90, Colour);
	}
	
	FileClose(handle);
   
//----
   return(0);
  }
//+------------------------------------------------------------------+


int SetTxtObj(string Name, int ObjType, datetime Time1, double Price1, string ObjText, double Angle, color LColor) 
{
   if(ObjectFind(Name)<0)
   {
   //object not found create new one
      if(ObjType==OBJ_TEXT)
      {
         ObjectCreate(Name, OBJ_TEXT, 0, Time1, Price1);
         ObjectSetText(Name, ObjText, 10, "Times New Roman", LColor);
         ObjectSet(Name, OBJPROP_ANGLE, Angle);
         //ObjectSet(Name, OBJPROP_COLOR, LColor);         

      }   
   
   }
   else
   {
      if(ObjectType(Name)==OBJ_TEXT)
      {
         ObjectSet(Name, OBJPROP_TIME1, Time1);
         ObjectSet(Name, OBJPROP_PRICE1, Price1);
         ObjectSetText(Name, ObjText, 10, "Times New Roman", LColor);
         ObjectSet(Name, OBJPROP_ANGLE, Angle);
         //ObjectSet(Name, OBJPROP_COLOR, LColor);         

      }
   }
   return(0);
}

int SetObj(string Name, int ObjType, datetime Time1, double Price1, int Thickness, color LColor) 
{
   if(ObjectFind(Name)<0)
   {
   //object not found create new one
      if(ObjType==OBJ_VLINE)
      {
         ObjectCreate(Name, OBJ_VLINE, 0, Time1, Price1);
         ObjectSet(Name, OBJPROP_WIDTH, Thickness);
         ObjectSet(Name, OBJPROP_COLOR, LColor);         
         ObjectSet(Name, OBJPROP_STYLE, STYLE_DOT);
         
         
      
      	ObjectCreate(Name+"buffer", OBJ_RECTANGLE, 0, Time1-24*60*60, 0, Time1+24*60*60, 9999);
      	ObjectSet(Name+"buffer",OBJPROP_COLOR, Black);
           
      }   
   
   }
   else
   {
      if(ObjectType(Name)==OBJ_VLINE)
      {
         ObjectSet(Name, OBJPROP_TIME1, Time1);
         ObjectSet(Name, OBJPROP_PRICE1, Price1);
         
         ObjectSet(Name, OBJPROP_WIDTH, Thickness);
         ObjectSet(Name, OBJPROP_COLOR, LColor);         

      }
   }
   return(0);
}

Comments