In other news: A ranger was trapped between a bull and a bear
[MT4] Changing the visible timeframes of multiple objects? 435 replies
Need EA that deletes all pending when equity below x value 6 replies
Objects removed when changing TFs on MT4 4 replies
Indicator that makes objects visible only in the Time Frame drawn 7 replies
[MT4] - Detect when price approaches arbitrary drawn objects 1 reply
int uninit_reason;
//+------------------------------------------------------------------+
//| Expert initialization function |
//+------------------------------------------------------------------+
int OnInit()
{
//---
if(uninit_reason==REASON_CHARTCHANGE) return(INIT_SUCCEEDED);
..............................................
//+------------------------------------------------------------------+
//| Expert deinitialization function |
//+------------------------------------------------------------------+
void OnDeinit(const int reason)
{
//---
uninit_reason=reason; #property copyright "GumRai"
#property link "http://www.mql5.com"
#property version "1.00"
//#property strict
#property indicator_chart_window
//--- input parameters
input int MarketOpenTime=3;
input color HighLineColour= Blue;
input color LowLineColour= Red;
input int LineWidth=1;
int uninit_reason;
//+------------------------------------------------------------------+
//| Custom indicator initialization function |
//+------------------------------------------------------------------+
int OnInit()
{
//--- indicator buffers mapping
//---
if(uninit_reason==REASON_CHARTCHANGE) return(INIT_SUCCEEDED);
}
void OnDeinit(const int reason)
{
//---
uninit_reason=reason;
for(int i=ObjectsTotal()-1;i>=0;i--)
{
string ObName= ObjectName(i);
if(StringFind(ObName,"OpenTimehigh",0) )
ObjectDelete(ObName);
if(StringFind(ObName,"OpenTimelow",0) )
ObjectDelete(ObName);
}
//---
}
//+------------------------------------------------------------------+
//| 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[])
{
//---
int limit=Bars-prev_calculated;
if(limit>Bars-10)
limit=Bars-10;
else
limit=limit+1;
for(int i=limit;i>0;i--)
{
datetime bartime=iTime(NULL,PERIOD_H1,i);
string sbartime=TimeToString(bartime,TIME_DATE||TIME_MINUTES);
if( TimeHour(bartime ) ==MarketOpenTime )
{
double MarketOpenTimehigh=iHigh(NULL,PERIOD_H1,i);
double MarketOpenTimelow=iLow(NULL,PERIOD_H1,i);
datetime bartimeplusday=bartime+(24*PERIOD_H1*60)-1;
if(ObjectFind("OpenTimehigh"+sbartime)!=0)
{
ObjectCreate("OpenTimehigh"+sbartime,OBJ_TREND,0,bartime,MarketOpenTimehigh,bartimeplusday,MarketOpenTimehigh);
ObjectSet("OpenTimehigh"+sbartime,OBJPROP_COLOR,HighLineColour);
ObjectSet("OpenTimehigh"+sbartime,OBJPROP_RAY_RIGHT,false);
ObjectSet("OpenTimehigh"+sbartime,OBJPROP_RAY_LEFT,false);
ObjectSet("OpenTimehigh"+sbartime,OBJPROP_WIDTH,LineWidth);
}
if(ObjectFind("OpenTimelow"+sbartime)!=0)
{
ObjectCreate("OpenTimelow"+sbartime,OBJ_TREND,0,bartime,MarketOpenTimelow,bartimeplusday,MarketOpenTimelow);
ObjectSet("OpenTimelow"+sbartime,OBJPROP_COLOR,LowLineColour);
ObjectSet("OpenTimelow"+sbartime,OBJPROP_RAY_RIGHT,false);
ObjectSet("OpenTimelow"+sbartime,OBJPROP_RAY_LEFT,false);
ObjectSet("OpenTimelow"+sbartime,OBJPROP_WIDTH,LineWidth);
}
}
}
//--- return value of prev_calculated for next call
return(rates_total);
}
//+------------------------------------------------------------------+ DislikedThanks MetBo, for the sample code and link. I had to comment out '#property strict' first, then inserted the code and it even compiled, no error......... (only a warning "not all control paths return a value"). But it still deletes all drawn objects. #property copyright "GumRai" #property link "http://www.mql5.com" #property version "1.00" //#property strict #property indicator_chart_window //--- input parameters input int MarketOpenTime=3; input color HighLineColour= Blue; input color LowLineColour= Red; input int LineWidth=1; int uninit_reason;...Ignored
int OnInit()
{
//--- indicator buffers mapping
//---
return(INIT_SUCCEEDED);
}
void OnDeinit(const int reason)
{
//---
for(int i=ObjectsTotal()-1;i>=0;i--)
{
string ObName= ObjectName(i);
if(StringFind(ObName,"OpenTimehigh",0)==0 )
ObjectDelete(ObName);
if(StringFind(ObName,"OpenTimelow",0)==0 )
ObjectDelete(ObName);
}
//---
}