This script is designed to create a dynamic, animated visual effect on your trading chart. It automatically generates two main visual elements: a moving text label and a rotating trend line that interact with each other in real-time.
How the Logic Works
Initial Setup When you run the script, it first establishes the starting positions for its components. It identifies a specific point in your price history to place a piece of text and a specialized "angle" line.
The Animation Loop Once active, the script enters a continuous loop where it performs several actions every half-second:
- Movement: The text label moves horizontally across your chart as the script progresses through different time intervals on the history bars.
- Rotation and Scaling: The script continuously calculates new angles. It rotates the trend line and adjusts its thickness based on these calculations. Simultaneously, it manages a "pulsing" effect for the text, where the font size grows and shrinks automatically to create visual movement.
- Dynamic Geometry: The script monitors the angle of the line. If the line reaches specific vertical orientations (like 90 or 270 degrees), it adjusts the height of the line's endpoint to ensure it remains visible and properly oriented on the screen.
- Reset Mechanism: To keep the animation going indefinitely, the script includes logic to "flip" the angle once it completes a full 360-degree rotation, allowing the cycle to start over.
Interaction and Triggers The script also features a proximity detection system. It constantly compares the current price of the moving text against the value of the trend line at that same position. If the text and the line get sufficiently close to one another:
- The text content instantly changes to "REMOVED".
- The font size jumps to its maximum setting.
- The script pauses for five seconds before continuing its cycle.
In summary, this tool provides a choreographed visual display where elements move, rotate, and change size autonomously, reacting to the price history while providing a specific visual alert when certain spatial conditions are met.
//+------------------------------------------------------------------+
//| rotate_text.mq4 |
//| Copyright © 2004, MetaQuotes Software Corp. |
//| http://www.metaquotes.net/ |
//+------------------------------------------------------------------+
#property copyright "Copyright © 2004, MetaQuotes Software Corp."
#property link "http://www.metaquotes.net/"
#include <stdlib.mqh>
string line_name="rotating_line";
string object_name1="rotating_text";
void init()
{
Print("point = ", Point," bars=",Bars);
}
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
void deinit()
{
ObjectDelete(line_name);
ObjectDelete(object_name1);
ObjectsRedraw();
}
//+------------------------------------------------------------------+
//| script program start function |
//+------------------------------------------------------------------+
int start()
{
int time2;
int error,index,fontsize=10;
double price,price1,price2;
double angle=0.0;
//----
price2=High[10]+Point*10;
ObjectCreate(line_name, OBJ_TRENDBYANGLE, 0, Time[10], price2);
index=20;
ObjectCreate(object_name1, OBJ_TEXT, 0, Time[index], Low[index]-Point*100);
ObjectSetText(object_name1, "rotating_text", fontsize);
while(IsStopped()==false)
{
index++;
price=ObjectGet(object_name1, OBJPROP_PRICE1)+Point;
error=GetLastError();
if(error!=0)
{
Print(object_name1," : ",ErrorDescription(error));
break;
}
ObjectMove(object_name1, 0, Time[index], price);
ObjectSet(object_name1, OBJPROP_ANGLE, angle*2);
ObjectSet(object_name1, OBJPROP_FONTSIZE, fontsize);
ObjectSet(line_name, OBJPROP_WIDTH, angle/18.0);
double line_angle=360.0-angle;
if(line_angle==90.0) ObjectSet(line_name, OBJPROP_PRICE2, price2+Point*50);
if(line_angle==270.0) ObjectSet(line_name, OBJPROP_PRICE2, price2-Point*50);
time2=ObjectGet(line_name,OBJPROP_TIME2);
if(line_angle>90.0 && line_angle<270.0) time2=Time[index+10];
else time2=Time[0];
ObjectSet(line_name, OBJPROP_TIME2, time2);
ObjectSet(line_name, OBJPROP_ANGLE, line_angle);
ObjectsRedraw();
angle+=3.0;
if(angle>=360.0) angle=360.0-angle;
fontsize++;
if(fontsize>48) fontsize=6;
Sleep(500);
price1=ObjectGetValueByShift(line_name, index);
if(GetLastError()==0)
{
if(MathAbs(price1-price) < Point*50)
{
Print("price=",price," price1=", price1);
ObjectSetText(object_name1, "REMOVED", 48, "Arial", RGB(255,215,0));
ObjectsRedraw();
Sleep(5000);
// ObjectDelete(object_name1);
}
}
}
return(0);
}
//+------------------------------------------------------------------+
Comments