OsMA Color xb4
Download scriptThis script functions as a visual trading tool designed to help traders identify momentum shifts and trend directions by interpreting price action data. It takes complex mathematical calculations and translates them into a simplified, color-coded histogram that shows the "strength" of the current market move.
How it Works
The logic behind this tool can be broken down into three main stages:
1. Data Processing The script begins by analyzing the relationship between two different types of moving averages (Fast and Slow). By comparing these, the tool calculates a momentum value. It specifically uses "Weighted" price data, which gives more importance to recent price movements than older ones, making the indicator more responsive to what is happening in the market right now.
2. Trend Identification Once the momentum value is calculated, the script looks at whether that value is positive or negative:
- Positive values generally indicate upward momentum.
- Negative values generally indicate downward momentum.
The script then compares the current momentum value against the previous one to determine if the move is gaining strength, losing steam, or changing direction.
3. Visual Communication Instead of showing you raw numbers, the script transforms these calculations into a color-coded visual experience:
- Long Signals (Bullish): When the data suggests upward momentum, the tool identifies this as an "OSMA LONG." It highlights these sections in a specific color (Lime) to alert the trader to potential buying interest or upward trend strength.
- Short Signals (Bearish): When the data suggests downward momentum, the tool identifies this as an "OSMA SHORT." It highlights these sections in a different color (Red) to signal potential selling pressure or a downward trend.
Summary for the User
The primary goal of this script is to eliminate the guesswork of reading raw charts. By providing a clear, colored histogram and dynamic text labels on your screen, it tells you at a glance whether the current market sentiment is leaning toward a "Long" position (buying) or a "Short" position (selling), based on the underlying speed and direction of price changes.
//+------------------------------------------------------------------+
//| OsMA.mq4 |
//| Copyright © 2004, MetaQuotes Software Corp. |
//| http://www.metaquotes.net/ |
//+------------------------------------------------------------------+
#property copyright "Copyright © 2004, MetaQuotes Software Corp."
#property link "http://www.metaquotes.net/"
//---- indicator settings
#property indicator_separate_window
#property indicator_buffers 4
#property indicator_color1 DodgerBlue
#property indicator_color2 Blue
#property indicator_color3 Red
#property indicator_color4 FireBrick
//#property indicator_level1 0.0003
//#property indicator_level2 -0.0003
//---- indicator buffers
extern int FastEMA=12;
extern int SlowEMA=26;
extern int SignalSMA=9;
double ind_buffer1[], ind_buffer1s[];
double ind_buffer2[], ind_buffer2s[];
double ind_buffer3[];
string gs_92="";
string short_name = "OSMA";
//+------------------------------------------------------------------+
//| Custom indicator initialization function |
//+------------------------------------------------------------------+
int init()
{
//---- 1 additional buffer used for counting.
IndicatorBuffers(5);
//---- drawing settings
SetIndexStyle(0,DRAW_HISTOGRAM,STYLE_SOLID,4);
SetIndexStyle(1,DRAW_HISTOGRAM,STYLE_SOLID,4);
SetIndexStyle(2,DRAW_HISTOGRAM,STYLE_SOLID,4);
SetIndexStyle(3,DRAW_HISTOGRAM,STYLE_SOLID,4);
IndicatorDigits(MarketInfo(Symbol(),MODE_DIGITS)+1);
SetIndexDrawBegin(0,34);
SetIndexDrawBegin(1,34);
SetIndexDrawBegin(3,34);
SetIndexDrawBegin(4,34);
//---- 3 indicator buffers mapping
if(!SetIndexBuffer(0,ind_buffer1) &&
!SetIndexBuffer(1,ind_buffer1s) &&
!SetIndexBuffer(2,ind_buffer2) &&
!SetIndexBuffer(3,ind_buffer2s) &&
!SetIndexBuffer(4,ind_buffer3))
Print("cannot set indicator buffers!");
IndicatorShortName(short_name);
//---- name for DataWindow and indicator subwindow label
//---- initialization done
return(0);
}
//+------------------------------------------------------------------+
//| Awesome Oscillator |
//+------------------------------------------------------------------+
int start()
{
int limit;
int counted_bars=IndicatorCounted();
double prev,current;
createalltext();
color li_104 = White;
//---- check for possible errors
if(counted_bars<0) return(-1);
//---- last counted bar will be recounted
if(counted_bars>0) counted_bars--;
limit=Bars-counted_bars;
//---- macd counted in the 1-st additional buffer
for(int i=0; i<limit; i++)
ind_buffer3[i]=iOsMA(NULL,0,FastEMA,SlowEMA,SignalSMA,PRICE_WEIGHTED,i);
//---- dispatch values between 2 buffers
bool up=true;
for(i=limit-1; i>=0; i--)
{
current=ind_buffer3[i];
prev=ind_buffer3[i+1];
if (((current<0)&&(prev>0))||(current<0))
up= false;
if (((current>0)&&(prev<0))||(current>0))
up= true;
if(!up)
{
if(current > prev)
{
ind_buffer2s[i]=current;
ind_buffer2[i]=0.0;
ind_buffer1[i]=0.0;
ind_buffer1s[i]=0.0;
gs_92 = "OSMA SHORT";
li_104 = Red;
}
else
{
ind_buffer2[i]=current;
ind_buffer2s[i]=0.0;
ind_buffer1[i]=0.0;
ind_buffer1s[i]=0.0;
gs_92 = "OSMA SHORT";
li_104 = Red;
}
}
else
{
if(current < prev)
{
ind_buffer1s[i]=current;
ind_buffer1[i]=0.0;
ind_buffer2[i]=0.0;
ind_buffer2s[i]=0.0;
gs_92 = "OSMA LONG";
li_104 = Lime;
}
else
{
ind_buffer1[i]=current;
ind_buffer1s[i]=0.0;
ind_buffer2[i]=0.0;
ind_buffer2s[i]=0.0;
gs_92 = "OSMA LONG";
li_104 = Lime;
}
}
}
settext("OSMA", gs_92, 12, li_104, 10, 100);
return(0);
}
void createalltext() {
createtext("OSMA");
settext("OSMA", "", 12, White, 10, 15);
}
void createtext(string a_name_0) {
ObjectCreate(a_name_0, OBJ_LABEL, WindowFind(short_name), 0, 0);
}
void settext(string a_name_0, string a_text_8, int a_fontsize_16, color a_color_20, int a_x_24, int a_y_28) {
ObjectSet(a_name_0, OBJPROP_XDISTANCE, a_x_24);
ObjectSet(a_name_0, OBJPROP_YDISTANCE, a_y_28);
ObjectSetText(a_name_0, a_text_8, a_fontsize_16, "Arial", a_color_20);
}
Comments