Author: Integer
s_Test

This script is designed to create a dynamic visual animation on your trading platform's interface. Rather than performing financial calculations or executing trades, its primary purpose is to generate a smooth, moving graphic element—specifically an animated "smiley face" that shifts vertically on the screen.

How the Logic Works

The script operates through a continuous loop that updates the display almost instantly. Here is the step-by-step breakdown of how it achieves this:

1. The Movement Engine The script uses a mathematical function (a sine wave) to calculate movement. Because sine waves naturally fluctuate up and down in a smooth, repeating curve, the script uses this logic to determine the vertical position of the animation. It continuously increases an internal value, which tells the graphic where to be at any given millisecond.

2. The Animation Logic The program constantly checks the current "height" of the movement:

  • If the movement is within a specific range, it displays one set of characters (representing one part of a smile).
  • If the movement exceeds that range, it switches to a different character. By rapidly switching these characters based on the rising and falling wave, it creates a fluid visual transition for the user.

3. Real-Time Rendering To ensure the animation looks smooth rather than "choppy," the script includes a command to force the window to redraw itself constantly. It also includes a tiny pause (a delay of 1 millisecond) between updates, which allows the animation to flow naturally without overwhelming your computer's processor.

4. Cleanup and Management The script is programmed to be "clean." When you stop or remove the script, it includes a specific instruction to automatically delete the animated object from your chart. This ensures that no leftover graphics remain on your screen after the program is closed.

11 Views
0 Downloads
0 Favorites
s_Test
//+------------------------------------------------------------------+
//|                                                       s_Test.mq4 |
//|                                                                * |
//|                                                                * |
//+------------------------------------------------------------------+
#property copyright "Integer"
#property link      "for-good-letters@yandex.ru"

//+------------------------------------------------------------------+
//| script program start function                                    |
//+------------------------------------------------------------------+
int start()
  {
//----

   double f=0;
   double s=0.03;
   while(!IsStopped()){
      int y=MathAbs(MathSin(f))*100;
      f+=s;
         if(y<12){
            fObjLabel("Smile",25,y,StringSetChar("",0,75),2,Red,50,0,"WingDings",false);
         }
         else{
            fObjLabel("Smile",25,y,StringSetChar("",0,74),2,Red,50,0,"WingDings",false);         
         }
      WindowRedraw();
      Sleep(1);
   }
//----
   return(0);
  }
//+------------------------------------------------------------------+
int deinit(){
   ObjectDelete("Smile");
   WindowRedraw();
}
void fObjLabel(
   string aObjectName,     // 1 èìÿ
   int aX,                 // 2 õ
   int aY,                 // 3 ó
   string aText,           // 4 òåêñò
   int aCorner=0,          // 5 óãîë   0  1
                           //          2  3
   color aColor=Red,       // 6 öâåò
   int aFontSize=8,        // 7 ðàçìåð øðèôòà
   int aWindowNumber=0,    // 8 îêíî
   string aFont="Arial",   // 9 øðèôò
   bool aBack=false        // 10 ôîí
   ){     
      if(ObjectFind(aObjectName)!=aWindowNumber){
         ObjectCreate(aObjectName,OBJ_LABEL,aWindowNumber,0,0);
      }      
   ObjectSet(aObjectName,OBJPROP_XDISTANCE,aX);
   ObjectSet(aObjectName,OBJPROP_YDISTANCE,aY);   
   ObjectSetText(aObjectName,aText,aFontSize,aFont,aColor);
   ObjectSet(aObjectName,OBJPROP_BACK,aBack);
   ObjectSet(aObjectName,OBJPROP_CORNER,aCorner);   
}

Comments