open_position_ma

Download script
Author: reza rahmad
open_position_ma

This script is designed as a visual technical analysis tool for the MetaTrader platform. It simplifies market trend identification by calculating specific moving averages across different timeframes and displaying a real-time "signal" on your trading chart.

Core Logic and Functionality

Multi-Timeframe Analysis The tool automatically gathers data from two primary timeframes: the 1-hour (H1) and the 4-hour (H4) charts. It calculates moving averages for both of these periods to ensure that the signals are based on broader market trends rather than just short-term price fluctuations.

Visual Indicators When you activate this script, it performs several visual tasks on your chart:

  • Identification Labels: It places text labels directly on the chart to identify specific moving average levels (such as MA 5 and MA 20), allowing you to see exactly where these key price benchmarks are located.
  • Trend Lines: The script draws horizontal trend lines at the current value of the moving averages. This helps traders visualize the "support" or "resistance" zones created by these averages in real-time.
  • Dynamic Status Text: A prominent text display on your screen updates instantly to provide a clear market sentiment summary.

Signal Generation Logic The script determines the market sentiment by comparing the current closing price of the 1-hour chart against two different moving averages (a "fast" and a "slow" average). The logic branches into four distinct categories:

  • Strong Buy: Triggered when the current price is above both the fast and slow moving averages, indicating significant upward momentum.
  • Weak Buy: Triggered when the price is above the fast average but still below the slow average, suggesting a slight recovery or a less confident upward move.
  • Strong Sell: Triggered when the current price is below both the fast and slow moving averages, indicating heavy downward momentum.
  • Weak Sell: Triggered when the price is below the fast average but above the slow average, suggesting a slight dip in an overall bearish environment.
  • No Logic: If the price sits exactly on a boundary or does not meet specific criteria, the script notifies you that no clear trend signal is currently detected.

Summary for Traders

Essentially, this tool acts as a real-time "trend translator." Instead of you having to manually calculate and compare multiple moving averages across different timeframes, the script does the math for you and provides a clear, color-coded text instruction—ranging from Strong Buy to Strong Sell—to help you quickly gauge the current market direction at a glance.

Indicators Used
Moving average indicator
8 Views
0 Downloads
0 Favorites
open_position_ma
//+------------------------------------------------------------------+
//|                                             open position MA.mq4 |
//|                                                      reza rahmad |
//|                                           reiz_gamer@yahoo.co.id |
//+------------------------------------------------------------------+
#property copyright "reza rahmad"
#property link      "reiz_gamer@yahoo.co.id"
#property version   "1.00"
#property strict
#property indicator_chart_window
extern double MA_fast = 5;
extern double MA_slow = 20;
extern double MA_shift_fast = 2;
extern double MA_shift_slow = 0;

  double h15 =iMA( NULL,PERIOD_H1, MA_fast, MA_shift_fast,MODE_SMA,PRICE_CLOSE,0);
   double h120=iMA( NULL,PERIOD_H1,MA_slow, MA_shift_slow,MODE_SMA,PRICE_CLOSE,0);
   double h45=iMA( NULL,PERIOD_H4, MA_fast, MA_shift_fast,MODE_SMA,PRICE_CLOSE,0);
   double h420=iMA( NULL,PERIOD_H4, MA_shift_slow, MA_shift_slow,MODE_SMA,PRICE_CLOSE,0);
  
//---jectSet("text",OBJPROP_YDISTANCE,60);
int init(){
   

ObjectCreate("texti",OBJ_LABEL,0,0,0,0,0);
ObjectSet("texti",OBJPROP_CORNER,1);
   ObjectSet("texti",OBJPROP_XDISTANCE,50);
   ObjectSet("texti",OBJPROP_YDISTANCE,60);
   ObjectSetText("texti","TEST",24,"Times New Roman",Green);
   
   ObjectCreate("textir",OBJ_LABEL,0,0,0,0,0);
ObjectSet("textir",OBJPROP_CORNER,1);
   ObjectSet("textir",OBJPROP_XDISTANCE,50);
   ObjectSet("textir",OBJPROP_YDISTANCE,40);
   ObjectSetText("textir","created by reza rahmad",10,"Times New Roman",Green);

   ObjectCreate("text1",OBJ_TEXT,0,0,0,0,0);
   ObjectSet("text1",OBJPROP_CORNER,1);
   ObjectSet("text1",OBJPROP_TIME1,Time[0]);
   ObjectSet("text1",OBJPROP_PRICE1,h15 +5 * Point); 
    ObjectSetText("text1","MA 5",7,"Times New Roman",Magenta);
    
  ObjectCreate("text2",OBJ_TEXT,0,0,0,0,0);
   ObjectSet("text2",OBJPROP_CORNER,1);
   ObjectSet("text2",OBJPROP_TIME1,Time[0]);
   ObjectSet("text2",OBJPROP_PRICE1,h120 +5 * Point); 
    ObjectSetText("text2","MA 20",7,"Times New Roman",Magenta);
    
    
    return(0);
   }
  
 int deinit(){
  ObjectDelete("texti");
 ObjectDelete("text1");
 ObjectDelete("text2");
 ObjectDelete("h15");
  ObjectDelete("h120");
  ObjectDelete("h55");
   ObjectDelete("h420");
   return(0);
 }
 
  int start(){
 
      ObjectCreate("b1",OBJ_TREND,0,0,0,0,0);
      ObjectSet("b1",OBJPROP_PRICE1,h15);
      ObjectSet("b1",OBJPROP_PRICE2,h15);
      ObjectSet("b1",OBJPROP_TIME1,Time[0]);
      ObjectSet("b1",OBJPROP_TIME2,Time[7]);
      ObjectSet("b1",OBJPROP_RAY,false);
      ObjectSet("b1",OBJPROP_WIDTH,2);
      ObjectSet("b1",OBJPROP_COLOR,clrRed);
     
      ObjectCreate("s1",OBJ_TREND,0,0,0,0,0);
      ObjectSet("s1",OBJPROP_PRICE1,h120);
      ObjectSet("s1",OBJPROP_PRICE2,h120);
      ObjectSet("s1",OBJPROP_TIME1,Time[0]);
      ObjectSet("s1",OBJPROP_TIME2,Time[7]);
      ObjectSet("s1",OBJPROP_RAY,false);
      ObjectSet("s1",OBJPROP_WIDTH,2);
      ObjectSet("s1",OBJPROP_COLOR,clrRed);
     
/*break h4 strong       
      ObjectSet("b4",OBJPROP_PRICE1,h45);
      ObjectSet("b4",OBJPROP_PRICE2,h45);
      ObjectSet("b4",OBJPROP_TIME1,Time[0]);
      ObjectSet("b4",OBJPROP_TIME2,Time[7]);
      ObjectSet("b4",OBJPROP_RAY,false);
      ObjectSet("b4",OBJPROP_WIDTH,4);
      ObjectSet("b4",OBJPROP_COLOR,clrGreen);

      ObjectCreate("s4",OBJ_TREND,0,0,0,0,0);
      ObjectSet("s4",OBJPROP_PRICE1,h420);
      ObjectSet("s4",OBJPROP_PRICE2,h420);
      ObjectSet("s4",OBJPROP_TIME1,Time[0]);
      ObjectSet("s4",OBJPROP_TIME2,Time[7]);
      ObjectSet("s4",OBJPROP_RAY,false);
      ObjectSet("s4",OBJPROP_WIDTH,4);
      ObjectSet("s4",OBJPROP_COLOR,clrGreen);
 */
if(iClose (NULL,PERIOD_H1,0) > h15 && iClose (NULL,PERIOD_H1,0) > h120)
  {
   ObjectSetText("texti","STRONG BUY",24,"Times New Roman",Green);
  }
else if(iClose (NULL,PERIOD_H1,0) > h15 && iClose (NULL,PERIOD_H1,0) < h120)
       {
        ObjectSetText("texti","WEAK BUY",24,"Times New Roman",Green);
       }
    else if(iClose (NULL,PERIOD_H1,0) < h15 && iClose (NULL,PERIOD_H1,0) < h120)
              {
               ObjectSetText("texti","STRONG SELL",24,"Times New Roman",Red);
              }
       else if(iClose (NULL,PERIOD_H1,0) < h15 && iClose (NULL,PERIOD_H1,0) > h120)
              {
               ObjectSetText("texti","WEAK SELL",24,"Times New Roman",Red);
              }     
 
 else
     {
      ObjectSetText("texti","NO LOGIC",24,"Times New Roman",Red);
     }
   
   
 
  return(0);
 }
//+---------------------------------------------------------------+

Comments