CosMod
Download scriptThis tool is designed as a visual aid for traders, providing a unique perspective on price action by transforming standard market data into a specialized rhythmic wave. Unlike traditional indicators that simply show the direction of the price, this script focuses on analyzing the "remainder" or the relative position of the current price compared to a moving average.
Core Logic Overview
The indicator functions by establishing a baseline using a Simple Moving Average (SMA). This baseline represents the smoothed trend of the market over a specific period defined by the user. Instead of plotting this average directly, the script calculates the difference between the current closing price and this average.
Once that difference is calculated, the logic applies a mathematical transformation known as a cosine function. In practical terms, this converts the price fluctuations into a wave-like movement.
How it Visualizes Data
By using this mathematical conversion, the indicator smooths out erratic "noise" and highlights underlying cycles. It essentially maps out the oscillation of the price relative to its average. For a trader, this means:
- Cycle Identification: It visualizes how often and how far the price deviates from its established trend.
- Relative Movement: Rather than looking at raw currency values (which can be large and distracting), it focuses on the rhythmic "pulse" of the market.
- Trend Context: It provides a separate window for analysis, allowing you to see the cyclical behavior of the asset independently from the main price chart.
Key Parameters
The primary setting provided allows users to adjust the calculation period. By changing this timeframe, you can alter the sensitivity of the moving average baseline, thereby changing how "tight" or "wide" the resulting waves appear on your screen.
//+------------------------------------------------------------------+
//| CosMod.mq4 |
//| Infinite Eith |
//| http://www.metaquotes.net |
//+------------------------------------------------------------------+
#property copyright "Infinite Eith"
#property link "http://www.metaquotes.net"
#property indicator_separate_window
#property indicator_buffers 1
#property indicator_color1 DodgerBlue
extern int KPeriod=14;
double MA;
double KBuffer[];
int init()
{
string short_name;
SetIndexStyle(0,DRAW_LINE);
SetIndexBuffer(0,KBuffer);
short_name="CosMod("+KPeriod+")";
IndicatorShortName(short_name);
SetIndexLabel(0,short_name);
SetIndexDrawBegin(0,KPeriod);
return(0);
}
int start()
{
int i,counted_bars=IndicatorCounted();
MA=iMA(NULL,0,14,0,MODE_SMA,PRICE_CLOSE,0);
if(Bars<=KPeriod) return(0);
if(counted_bars<1)
for(i=1;i<=KPeriod;i++) KBuffer[Bars-i]=0.0;
i=Bars-KPeriod-1;
if(counted_bars>=KPeriod) i=Bars-counted_bars-1;
while(i>=0)
{
KBuffer[i]=MathCos(MathMod(Close[i],MA));
i--;
}
return(0);
}
Comments