#OTCFX_MA_PRICEv1
Download scriptThis script is designed as a visual dashboard for MetaTrader users who want to monitor moving average trends and price relationships in real-time without cluttering their main trading charts. Instead of drawing lines across your candles, it calculates specific data points and displays them as clean, readable text labels in a separate window.
Core Logic and Functionality
1. Smart Environment Adaptation The script begins by identifying which asset you are trading (such as Gold, EURUSD, or GBPJPY). It automatically adjusts its internal precision settings to match the specific decimal requirements of those currencies. It also intelligently manages timeframes, ensuring that if you select a timeframe higher than what is currently visible on your screen, it scales correctly to provide accurate data.
2. Dual Trend Analysis The logic focuses on two primary types of moving average calculations to give you a complete picture of market momentum:
- Movement Direction (Convergence/Divergence): The script compares the current value of a long-term moving average against its previous value. If the value is rising, the indicator highlights this in Green; if it is falling, it turns Crimson. This helps you instantly see if the broader trend is gaining or losing steam.
- Price Position Relative to Trend: The script calculates the distance between a fast-moving average (which reacts quickly to price changes) and a slower moving average. It then compares this result against the current market price.
- If the price relationship suggests a bullish bias, it displays in Green.
- If the relationship suggests a bearish bias, it displays in Crimson.
3. Visual Dashboard Output Rather than forcing you to interpret complex lines, the script creates an organized information display containing:
- Timeframe Identification: Clearly labels which timeframe the data is currently pulling from.
- Trend Value: Displays the exact numerical value of the primary moving average with dynamic color coding (Green for up, Crimson for down).
- Price Deviation: Shows the calculated "MA-Price" variance, providing a specific metric on how far the current price has deviated from the established trend averages.
Summary for the User
In simple terms, this tool acts as a "Status Board." It does the heavy lifting of calculating complex moving average math in the background and summarizes the results into a color-coded text dashboard. It tells you at a glance: "Is the trend going up or down?" and "Where is the current price sitting in relation to that trend?"
//+------------------------------------------------------------------+
//| #OTCFX_MA_INFO
//| Copyright © 2008, "OTCFX"
//|
//|
//|
//+------------------------------------------------------------------+
#property copyright "Copyright © 2004, MetaQuotes Software Corp."
#property link "http://www.metaquotes.net/"
//---- indicator settings
#property indicator_separate_window
//---- indicator parameters
extern int MAPeriod = 200;
extern int MAMethod=0;
extern int MAPrice=0;
extern int TimeFrame = 0;
int nDigits; int FastEMA=1;
//double SignalBuffer[];
//double MA0[];
//+------------------------------------------------------------------+
//| Custom indicator initialization function |
//+------------------------------------------------------------------+
int init()
{
IndicatorShortName("OTFX");
if(Symbol()=="GBPJPY" || Symbol()=="EURJPY" || Symbol()=="USDJPY" || Symbol()=="GOLD" || Symbol()=="USDMXN") nDigits = 2;
if(Symbol()=="GBPUSD" || Symbol()=="EURUSD" || Symbol()=="NZDUSD" || Symbol()=="USDCHF" ||
Symbol()=="USDCAD" || Symbol()=="AUDUSD" || Symbol()=="EURUSD" || Symbol()=="EURCHF" || Symbol()=="EURGBP"
|| Symbol()=="EURCAD" || Symbol()=="EURAUD" || Symbol()=="AUDNZD")nDigits = 4;
switch(TimeFrame)
{
case 1 : string TimeFrameStr="M1" ; break; //"MAMethod: 0=SMA,1=EMA,2=SMMA,3=LWMA";
case 5 : TimeFrameStr= "M5" ; break;
case 15 : TimeFrameStr= "M15"; break; // "MAPrice: 0=C,1=O,2=H,3=L,4=M,5=T,6=W";
case 30 : TimeFrameStr= "M30"; break;
case 60 : TimeFrameStr= "H1" ; break;
case 240 : TimeFrameStr= "H4" ; break;
case 1440 : TimeFrameStr= "D1" ; break;
case 10080 : TimeFrameStr= "W1" ; break;
case 43200 : TimeFrameStr= "MN1"; break;
default : TimeFrameStr= "CurrTF";
}
if (TimeFrame<Period()) TimeFrame=Period();
//---- initialization done
return(0);
}
//+------------------------------------------------------------------+
//| Moving Averages Convergence/Divergence |
//+------------------------------------------------------------------+
int start()
{
int limit;string Text="";
int i=0;
double MA1=iMA(Symbol(),TimeFrame,FastEMA,0,MODE_EMA,PRICE_CLOSE,0)-iMA(Symbol(), TimeFrame,MAPeriod,0,MAMethod,MAPrice,0)-Point ;
double MA3 =iMA(Symbol(), TimeFrame,MAPeriod,0,MAMethod,MAPrice,0);
double MA31 =iMA(Symbol(), TimeFrame,MAPeriod,0,MAMethod,MAPrice,1);
color ColorCOV ;
if( MA3 > MA31 ) { ColorCOV = Green ; } else { ColorCOV = Crimson ; }
color ColorCOR ;
if( MA1 >=0) { ColorCOR = Green ; } else { ColorCOR = Crimson ; }
Comment(Text);
string P=Period();
ObjectCreate("OT1", OBJ_LABEL, WindowFind("OTFX"), 0, 0);
ObjectSetText("OT1",StringSubstr((P),0),11, "Verdana", CornflowerBlue);
ObjectSet("OT1", OBJPROP_CORNER, 0);
ObjectSet("OT1", OBJPROP_XDISTANCE, 33);
ObjectSet("OT1", OBJPROP_YDISTANCE, 2);
ObjectCreate("OT2", OBJ_LABEL, WindowFind("OTFX"), 0, 0);
ObjectSetText("OT2",StringSubstr("~MA>PRICE CALC~",0),12, "Verdana", CornflowerBlue);
ObjectSet("OT2", OBJPROP_CORNER, 0);
ObjectSet("OT2", OBJPROP_XDISTANCE, 70);
ObjectSet("OT2", OBJPROP_YDISTANCE, 2);
ObjectCreate("OT3", OBJ_LABEL, WindowFind("OTFX"), 0, 0);
ObjectSetText("OT3",DoubleToStr( MA3,Digits), 12, "Arial Bold",ColorCOV);
ObjectSet("OT3", OBJPROP_CORNER, 0);
ObjectSet("OT3", OBJPROP_XDISTANCE, 250);
ObjectSet("OT3", OBJPROP_YDISTANCE,20 );
ObjectCreate("OT4", OBJ_LABEL, WindowFind("OTFX"), 0, 0);
ObjectSetText("OT4","MA-Price", 11, "Arial ", LightSteelBlue);
ObjectSet("OT4", OBJPROP_CORNER, 0);
ObjectSet("OT4", OBJPROP_XDISTANCE, 170);
ObjectSet("OT4", OBJPROP_YDISTANCE, 20);
ObjectCreate("OT5", OBJ_LABEL, WindowFind("OTFX"), 0, 0);
ObjectSetText("OT5",DoubleToStr( MA1,Digits), 12, "Arial Bold",ColorCOR);
ObjectSet("OT5", OBJPROP_CORNER, 0);
ObjectSet("OT5", OBJPROP_XDISTANCE, 380);
ObjectSet("OT5", OBJPROP_YDISTANCE,20 );
ObjectCreate("OT6", OBJ_LABEL, WindowFind("OTFX"), 0, 0);
ObjectSetText("OT6","MA>CL+/-", 9, "Arial ", LightSteelBlue);
ObjectSet("OT6", OBJPROP_CORNER, 0);
ObjectSet("OT6", OBJPROP_XDISTANCE, 310);
ObjectSet("OT6", OBJPROP_YDISTANCE, 20);
return(0);
}
Comments