#TickA_SineWaveIndicator

Download script
Author: JDP
#TickA_SineWaveIndicator

This tool is designed to analyze market trends by identifying underlying cyclical patterns in price movements. Rather than simply looking at raw price changes, the logic focuses on identifying the "rhythm" of the market through mathematical wave analysis.

Core Methodology

The script functions by decomposing historical price data into a sine wave structure. It aims to determine the dominant cycle of the market by performing the following steps:

  • Cycle Identification: The system looks back over a user-defined period of time to calculate the prevailing frequency of price fluctuations. It effectively tries to find out how "fast" or "slow" the current market cycle is moving.
  • Phase Calculation: Once the cycle period is established, the logic calculates the "Phase"—essentially identifying where we currently sit within that cycle (e.g., whether the market is at a peak, a trough, or in a transitionary movement). It does this by comparing the real and imaginary components of the price data.
  • Trend Mapping: By calculating this phase, the tool generates two distinct lines:
    1. The Current Wave: Represents the instantaneous position of the market cycle.
    2. The Leading Wave: A projected line shifted forward by a specific degree offset. This is intended to provide a visual representation of where the cycle might be heading based on the current momentum and established period.

How it Works for the User

Instead of showing you price bars, this indicator appears in a separate window as a wave pattern. By observing the relationship between the red and blue lines, traders can attempt to visualize the cyclical nature of the asset:

  • The Periodicity: The tool smooths out "noise" to show the core oscillation of the market.
  • Lead Visualization: The offset logic allows you to see a projected path of the cycle, helping to identify potential turning points or continuations in the current trend before they become obvious on the main price chart.

In essence, this script treats market movement as a series of waves, providing a mathematical way to see the "pulse" of the market rather than just the historical price action.

Miscellaneous
Implements a curve of type %1
8 Views
0 Downloads
0 Favorites
#TickA_SineWaveIndicator
//+------------------------------------------------------------------+
//|                          Instantaneous Trend Line by John Ehlers |
//|                               Copyright © 2004, Poul_Trade_Forum |
//|                                                         Aborigen |
//|                                          http://forex.kbpauk.ru/ |
//+------------------------------------------------------------------+
#property copyright "JDP"
#property link      ""
#property indicator_separate_window
#property indicator_buffers 2
#property indicator_color1 Red
#property indicator_color2 Blue
//---- buffers
extern int Periods=200;
extern double PeriodPers=1.0;
extern int OffsetDegrees=45;
extern bool alert=false;
int alerttm=0;
int LastTm;
double SineWave[];
double LeadSine[];
double RealPart,ImagPart,DCPhase,Period_,tmp;
double Pi = 3.1415926535;
double Price[];
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int init()
  {
   string short_name;
   IndicatorBuffers(2);
//---- indicator line
   SetIndexStyle(0,DRAW_LINE,EMPTY,2,Red);
   SetIndexStyle(1,DRAW_LINE,EMPTY,2,Blue);
   SetIndexBuffer(0,SineWave);
   SetIndexBuffer(1,LeadSine);
   SetIndexEmptyValue(0,0);
   SetIndexEmptyValue(1,0);
//---- name for DataWindow and indicator subwindow label
   short_name="Sine Wave Indicator";
   IndicatorShortName(short_name);
   SetIndexLabel(0,short_name);
//----
   SetIndexDrawBegin(0,30);
   SetIndexDrawBegin(1,30);
//----

   return(0);
  }

int deinit(){return(0);}
int start()
  {
   int i,shift,count;
   if (LastTm < Time[0]) {
      for (i = 0;i<1000;i++) {
         SineWave[i] = SineWave[i+1];
         LeadSine[i] = LeadSine[i+1];
      }
      LastTm = Time[0];   
   }
   for (i = 1001;i>0;i--) {
      SineWave[i] = SineWave[i-1];
      LeadSine[i] = LeadSine[i-1];
   }
   i = 0;
   for (shift=i; shift>=0;shift--)
   {
      Period_ = iCustom(Symbol(),0,"#TickA_SineWavePeriods",Periods,0,shift);
      Period_ = Period_*PeriodPers;
      Period_ = NormalizeDouble(Period_,0);
      RealPart=0.0;
      ImagPart=0.0;
      for    (count = 0;count<=Period_ - 1;count++)
         { RealPart = RealPart + MathSin(360*count/Period_*Pi/180) * ((iCustom(Symbol(),0,"#TickPrice",0,(shift+count))+iCustom(Symbol(),0,"#TickPrice",1,(shift+count)))/2);//Close[shift+count];
            ImagPart = ImagPart + MathCos(360*count/Period_*Pi/180) * ((iCustom(Symbol(),0,"#TickPrice",0,(shift+count))+iCustom(Symbol(),0,"#TickPrice",1,(shift+count)))/2);//Close[shift+count];
         }  
      if (MathAbs(ImagPart) != 0) {
         DCPhase = 180/Pi*MathArctan(RealPart / ImagPart);
      } else {
         if (RealPart > 0) {
            DCPhase = (Pi / 2);
         } else {
            DCPhase = -(Pi/2);
         }
      }
   
      if (MathAbs(ImagPart) < 0) //(MathAbs(ImagPart) < 0.0001)
      {
         if (RealPart>0) {
            DCPhase = DCPhase+90;
         } else  {
            if (RealPart <0) {
               DCPhase = DCPhase-90;
            } else {
               DCPhase = 0;
            }
         }
      }
   
      DCPhase=DCPhase+90;
   
      if (ImagPart < 0) DCPhase = DCPhase + 180;//(ImagPart < 0.0001) DCPhase = DCPhase + 180;
      if (DCPhase > 360) DCPhase = DCPhase - 360;

   
      // if (Period_ > 0) Trendline = Trendline    / (Period_  + 2);
      // Value11[0] = 0.33*(Price[shift] + 0.5*(Price[shift] - Price[shift+3])) + 0.67*Value11[1];
   
      SineWave[shift]=MathSin(DCPhase*Pi/180);
      LeadSine[shift]=MathSin((DCPhase+OffsetDegrees)*Pi/180);
   }
return(0);
}



Comments