caterpillar

Download script
Author: Copyright � 2005, MetaQuotes Software Corp.
caterpillar

This script is designed as a technical analysis tool for trading platforms, specifically used to generate visual data on a price chart. Its primary purpose is to take raw market price information and transform it into two distinct, smoothed trend lines that help traders identify the direction of price movement.

How the Logic Works

1. Data Collection The script begins by looking at the most recent historical candles on the chart. Instead of just looking at the closing price, it calculates a specific "midpoint" for each candle by taking the average between the highest and lowest prices reached during that period. This provides a balanced foundation for the analysis.

2. Processing via Singular Value Decomposition (SVD) The core "intelligence" of this script relies on a mathematical process called Singular Value Decomposition (SVD). While this is a complex engineering concept, you can think of it as a sophisticated filter. It takes the "noisy" and jagged movements of the market and extracts the underlying structure. It separates the meaningful trend from the random fluctuations or "jitter" that often distract traders.

3. Dual-Layer Analysis The script performs this mathematical smoothing twice using two different sets of internal parameters:

  • The First Line: Uses a slightly larger window of data to capture a broader, more stable trend. This acts as a primary guide for the general direction of the market.
  • The Second Line: Uses a smaller, more concentrated window of data. This reacts more quickly to price changes, allowing it to highlight shorter-term shifts in momentum.

4. Visual Output Finally, the script converts these two mathematical results into visible lines on your trading chart—one colored yellow and the other blue. By observing how these two lines move in relation to each other and the current price, traders can better visualize market momentum and potential trend changes.

Miscellaneous
Implements a curve of type %1
2 Views
0 Downloads
0 Favorites
caterpillar
//+------------------------------------------------------------------+
//|                                                     Ãóñåíèöà.mq4 |
//|                      Copyright © 2005, MetaQuotes Software Corp. |
//|                                        http://www.metaquotes.net |
//+------------------------------------------------------------------+
#property copyright "Copyright © 2005, MetaQuotes Software Corp."
#property link      "http://www.metaquotes.net"

#property indicator_chart_window
#property indicator_buffers 2
#property indicator_color1 Yellow
#property indicator_color2 Blue
//---- buffers
//---- indicator buffers
double ExtBuffer1[];
double ExtBuffer2[];

//300 - êîëè÷åñòâî áàðîâ
double X[300]; //ìàññèâ, â êîòîðûé çàïèñûâàþòñÿ êîòèðîâêè è îí ïåðåäàåòñÿ êàê äàííûå äëÿ ðàññ÷åòà Ãóñåíèöå
double Y1[300];//â ýòîì ìàññèâå õðàíÿòñÿ çíà÷åíèÿ Ãóñåíèöû ñ 1ûì íàáîðîì ïàðàìåòðîâ
double Y2[300];//â ýòîì ìàññèâå õðàíÿòñÿ çíà÷åíèÿ Ãóñåíèöû ñî 2ûì íàáîðîì ïàðàìåòðîâ

//èìïîðò ôóíêöèè Ãóñåíèöà èç áèáëèîòåêè
#import "ExpertSample.dll"
 void    fastsingular(double a[],int,int,int,double b[]);
  

//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int init()
  {
   IndicatorBuffers(2);
   SetIndexBuffer(0, ExtBuffer1);
   SetIndexBuffer(1, ExtBuffer2);
   SetIndexStyle(0,DRAW_LINE, EMPTY, 2);
   SetIndexStyle(1,DRAW_LINE, EMPTY, 2);
   IndicatorDigits(6);
   SetIndexDrawBegin(0,0);
   IndicatorShortName("Gus");
   return(0);
  }
int start()
  {
   //Èíèöèàëèçàöèÿ ìàññèâîâ íóëÿìè
   ArrayInitialize(X,0);
   ArrayInitialize(Y1,0);
   ArrayInitialize(Y2,0);
   
   //n - äëèíà ìàññèâà äàííûõ, ïåðåäàâàåìûõ ãóñåíèöå (ìàêñèìóì 4000, íî ëó÷øå áðàòü íåìíîãî...)
   //l1, l2 - äëèíû ëàãîâ (ìàêñèìóì 20)
   //s1, s2 - ÷èñëî ñîáñòâåííûõ êîìïîíåíò. åñëè èñïîëüçîâàòü òîëüêî äëÿ ñãëàæèâàíèÿ, òî = 1
   int i, n, l1, s1;
   n = 300; l1 = 7; s1 = 1;
   
    
   int l2, s2;
   l2 = 5; s2 = 1;
   
   //çàïîëíåíèå ìàññèâà öåíàìè
   
   for(i=299; i>=0; i--)
   {
      X[i] = Low[i] + (High[i]-Low[i])/2;
      //Print("--", X[i]);
   } 
   
   //ArrayCopy(X, Close, 0, 0, n);
   
   fastsingular(X, n, l1, s1, Y1); //âûçîâ ãóñåíèöû ñ 1ûì íàáîðîì ïàðàìåòðîâ
   fastsingular(X, n, l2, s2, Y2); //âûçîâ ãóñåíèöû ñî 2ûì íàáîðîì ïàðàìåòðîâ
   
   
   ArrayCopy(ExtBuffer1, Y1);
   ArrayCopy(ExtBuffer2, Y2);
   
   return(0);
  }
//+------------------------------------------------------------------+

Comments