Ind_Open_Market

Author: Copyright 2018, MetaQuotes Software Corp.
Price Data Components
Series array that contains close prices for each bar
0 Views
0 Downloads
0 Favorites
Ind_Open_Market
ÿþ//+------------------------------------------------------------------+

//|                                              Ind_Open_Market.mq5 |

//|                        Copyright 2018, MetaQuotes Software Corp. |

//|                                             https://www.mql5.com |

//+------------------------------------------------------------------+

#property copyright "Copyright 2018, MetaQuotes Software Corp."

#property link      "https://www.mql5.com"

#property version   "1.00"

#property indicator_chart_window

#property indicator_plots 0

input ushort   inpSize=50;      //Main info font size

input int      InpSize1=10;     //Secondary info font size



string Panel_t1="",Panel_t2="";

double VarDir = 0;

//+------------------------------------------------------------------+

//| Custom indicator initialization function                         |

//+------------------------------------------------------------------+

int OnInit()

  {

//--- Label create

   Panel("pnl",inpSize,100,30);

   Panel("pnl1",InpSize1,100,50);

   

//---

   return(INIT_SUCCEEDED);

  }

//+------------------------------------------------------------------+

//| deinitialization function                                        |

//+------------------------------------------------------------------+

void OnDeinit(const int reason)

  {

   ObjectsDeleteAll(0,0);   // delete all objects

  }  

//+------------------------------------------------------------------+

//| Custom indicator iteration function                              |

//+------------------------------------------------------------------+

int OnCalculate(const int rates_total,

                const int prev_calculated,

                const datetime &time[],

                const double &open[],

                const double &high[],

                const double &low[],

                const double &close[],

                const long &tick_volume[],

                const long &volume[],

                const int &spread[])

  {

//---

   IsMktOpen(Symbol());   // this is the main function

//--- 

   return(rates_total);

  }





//+------------------------------------------------------------------+  

void IsMktOpen(string inpSymbol2)

{

   VarDir = 0;

   Panel_t1="Mercado fechado.";   // This is the  default message. May be " Market closed" or something else

   

   // calcule the last time

   MqlDateTime Timez; 

   TimeCurrent(Timez);   

   datetime start=StringToTime((string)Timez.year+"."+(string)Timez.mon+"."+(string)Timez.day+" 00:05");

   datetime stop=TimeCurrent();

   datetime IMK[];

   int IMpen= CopyTime(inpSymbol2,PERIOD_M1,start,stop,IMK); // search for the first candle

   if(IMpen > 0)  // yes, market is open!

   {

    double Varnow=iClose(inpSymbol2,PERIOD_D1,0);      // price now

    double Varclose=iClose(inpSymbol2,PERIOD_D1,1);    // close price from last session

    if(Varnow !=0 && Varclose !=0)

     VarDir = NormalizeDouble(((Varnow / Varclose) -1) * 100,2);

    

    // here you can put any information about the symbol you want, this is only a sample

    Panel_t1=DoubleToString(Varnow, _Digits) +"  "+ DoubleToString(VarDir,2)+" %";

    Panel_t2="Fechamento anterior: "+ DoubleToString(Varclose, _Digits);

    

    // change the color if is positive or negative

    if(VarDir > 0)

       ObjectSetInteger(0,"pnl",OBJPROP_COLOR,0,clrLime);

    else

       ObjectSetInteger(0,"pnl",OBJPROP_COLOR,0,clrRed);  

   }

   

   // print the info on chart

   ObjectSetString(0,"pnl",OBJPROP_TEXT,Panel_t1);

   ObjectSetString(0,"pnl1",OBJPROP_TEXT,Panel_t2);    

   

   return;

}     





//+------------------------------------------------------------------+

//+  graphic function  

//+------------------------------------------------------------------+

void Panel(string name,int size,int x,int y)

{

   ObjectCreate(0,name,OBJ_LABEL,0,0,0);

   ObjectSetInteger(0,name,OBJPROP_COLOR,0,clrGray);

   ObjectSetInteger(0,name,OBJPROP_FONTSIZE,size);

   ObjectSetString(0,name,OBJPROP_FONT,"Arial");

   ObjectSetInteger(0,name,OBJPROP_BACK,true);

   ObjectSetInteger(0,name,OBJPROP_ANCHOR,ANCHOR_CENTER);

   ObjectSetInteger(0,name,OBJPROP_XDISTANCE,x);

   ObjectSetInteger(0,name,OBJPROP_YDISTANCE,y);

}   

   

  

Comments