Almost there, as last question - I made all changes…and seens to be working .
Only issue is related to Current Max that is being printed correctly. However Line of Current Max is following the bid price. …Thereby, I have tried change the the function from SYMBOL_BID to LASTHIGH or ASKHIGH. it did not work!
Also, bool if not working - even set to false. it keeps showing the line. np so far…
Any Idea ?
//+------------------------------------------------------------------+
//| TesteMaxlow.mq5 |
//| Copyright 2017, MetaQuotes Software Corp. |
//| https://www.mql5.com |
//+------------------------------------------------------------------+
#property copyright "Copyright 2017, MetaQuotes Software Corp."
#property link "https://www.mql5.com"
#property version "1.00"
#property indicator_chart_window
#property indicator_plots 0
sinput string _0_="***********************"; // Max and Min (Intraday)
input bool maxA=true; // Max (Intraday)
input color cormaxA=clrBlueViolet; // Select Color
input ENUM_LINE_STYLE eslinemaxA=STYLE_DASH; // Style
input int larguramaxA=1; // Width
input bool minA=true; // Min (Intraday)
input color corminA=clrBlueViolet; // Select Color
input ENUM_LINE_STYLE eslineminA=STYLE_DASH; // Style
input int larguraminA=1; // Width
sinput string _1_="***********************";// Previous Max and Min - ----
input bool maxD=true; // Previous Max
input color cormaxD=clrRed; // Color
input ENUM_LINE_STYLE eslinemaxD=STYLE_SOLID; // Style
input int larguramaxD=1; // Width
input bool minD=true; // Previous Min
input color corminD=clrRed; // Color
input ENUM_LINE_STYLE eslineminD=STYLE_SOLID; // Style
input int larguraminD=1; // Width
double maxAtual;
double minAtual;
double maxAnterior;
double minAnterior;
double highh[],loww[];
string strmaxant = "Previous Max";
string strminant = "Previous Min";
string strmaxatual = "Current Max";
string strminatual = "Current Min";
double m_adjusted_point;
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
int OnInit()
{
int digits_adjust=1;
if(Digits()==3 || Digits()==5)
digits_adjust=10;
m_adjusted_point=Point()*digits_adjust;
//
if(maxD)
if(ObjectFind(0,strmaxant)<0)
HLineCreate(0,strmaxant,0,0.0,cormaxD,eslinemaxD,larguramaxD);
if(minD)
if(ObjectFind(0,strminant)<0)
HLineCreate(0,strminant,0,0.0,corminD,eslineminD,larguraminD);
if(maxA)
if(ObjectFind(0,strmaxatual)<0)
HLineCreate(0,strmaxatual,0,0.0,cormaxA,eslinemaxA,larguramaxA);
if(minA)
if(ObjectFind(0,strminatual)<0)
HLineCreate(0,strminatual,0,0.0,corminA,eslineminA,larguraminA);
// Previous Max
double mAnterior=CopyHigh(_Symbol,PERIOD_D1,0,2,highh);
if(mAnterior>0) Print("Precos Max Anterior atualizado");
// Previous Min
double minPassada=CopyLow(_Symbol,PERIOD_D1,0,2,loww);
if(minPassada>0) Print("Precos Minima Anterior atualizado");
//
return(INIT_SUCCEEDED);
}
//+------------------------------------------------------------------+
//| Indicator deinitialization function |
//+------------------------------------------------------------------+
void OnDeinit(const int reason)
{
//---
Print(__FUNCTION__,", ",reason);
if(reason==1) // REASON_REMOVE
{
HLineDelete(0,strmaxant);
HLineDelete(0,strminant);
HLineDelete(0,strmaxatual);
HLineDelete(0,strminatual);
}
}
//+------------------------------------------------------------------+
//| 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[])
{
// Previous Max
maxAnterior=highh[0];
Print(" Maxima Anterior = ",maxAnterior);
if(ObjectFind(0,strmaxant)<0)
HLineCreate(0,strmaxant,0,0.0,cormaxD,eslinemaxD,larguramaxD);
HLineMove(0,strmaxant,maxAnterior);
// Previous Min
minAnterior=loww[0];
Print("Minima Anterior = ",minAnterior);
if(ObjectFind(0,strminant)<0)
HLineCreate(0,strminant,0,0.0,corminD,eslineminD,larguraminD);
HLineMove(0,strminant,minAnterior);
// Current Max - Intraday
double maxima[];
ArraySetAsSeries(maxima,true);
CopyHigh(_Symbol,PERIOD_D1,0,1,maxima);
int maxT=ArrayMaximum(maxima, 0, 0);
maxAtual=maxima[maxT];
if(maxAtual>0) Print("Maxima atual = ",maxAtual);
if(ObjectFind(0,strmaxatual)<0)
HLineCreate(0,strmaxatual,0,0.0,cormaxA,eslinemaxA,larguramaxA);
HLineMove(0,strmaxatual,maxAtual);
/* Function for ArrayMaximum
double HighestHigh(string pSymbol, ENUM_TIMEFRAMES pPeriod, int pBars, int pStart = 0)
{
double high[];
ArraySetAsSeries(high,true);
int copied = CopyHigh(pSymbol,pPeriod,pStart,pBars,high);
if(copied == -1) return(copied);
int maxIdx = ArrayMaximum(high);
double maxAtual = high[maxIdx];
return(highest);
*/
// Current Min - Intraday
double lowww[];
ArraySetAsSeries(lowww,true);
CopyLow(_Symbol,PERIOD_D1,0,1,lowww);
int minIdx=ArrayMinimum(lowww,0,0);
minAtual=lowww[minIdx];
if(minAtual>0) Print("Minima Atual = ",minAtual);
if(ObjectFind(0,strmaxatual)<0)
HLineCreate(0,strminatual,0,0.0,corminA,eslineminA,larguraminA);
HLineMove(0,strmaxatual,minAtual);
/*
double LowestLow(string pSymbol, ENUM_TIMEFRAMES pPeriod, int pBars, int pStart = 0)
{
double low[];
ArraySetAsSeries(low,true);
int copied = CopyLow(pSymbol,pPeriod,pStart,pBars,low);
if(copied == -1) return(copied);
int minIdx = ArrayMinimum(low);
double lowest = low[minIdx];
return(lowest);
*/
return(rates_total);
}
//+------------------------------------------------------------------+
//| Create the horizontal line |
//+------------------------------------------------------------------+
bool HLineCreate(const long chart_ID=0, // chart's ID
const string name="HLine", // line name
const int sub_window=0, // subwindow index
double price=0, // line price
const color clr=clrRed, // line color
const ENUM_LINE_STYLE style=STYLE_SOLID, // line style
const int width=1, // line width
const bool back=false, // in the background
const bool selection=true, // highlight to move
const bool hidden=true, // hidden in the object list
const long z_order=0) // priority for mouse click
{
//--- if the price is not set, set it at the current Bid price level
if(!price)
price=SymbolInfoDouble(Symbol(),SYMBOL_BID);
//--- reset the error value
ResetLastError();
//--- create a horizontal line
if(!ObjectCreate(chart_ID,name,OBJ_HLINE,sub_window,0,price))
{
Print(__FUNCTION__,
": failed to create a horizontal line! Error code = ",GetLastError());
return(false);
}
//--- set line color
ObjectSetInteger(chart_ID,name,OBJPROP_COLOR,clr);
//--- set line display style
ObjectSetInteger(chart_ID,name,OBJPROP_STYLE,style);
//--- set line width
ObjectSetInteger(chart_ID,name,OBJPROP_WIDTH,width);
return(true);
}
//+------------------------------------------------------------------+
//| Move horizontal line |
//+------------------------------------------------------------------+
bool HLineMove(const long chart_ID=0, // chart's ID
const string name="HLine", // line name
double price=0) // line price
{
//--- if the line price is not set, move it to the current Bid price level
if(!price)
price=SymbolInfoDouble(Symbol(),SYMBOL_BID);
//--- reset the error value
ResetLastError();
//--- move a horizontal line
if(!ObjectMove(chart_ID,name,0,0,price))
{
Print(__FUNCTION__,
": failed to move the horizontal line! Error code = ",GetLastError());
return(false);
}
//--- successful execution
return(true);
}
//+------------------------------------------------------------------+
//| Delete a horizontal line |
//+------------------------------------------------------------------+
bool HLineDelete(const long chart_ID=0, // chart's ID
const string name="HLine") // line name
{
//--- reset the error value
ResetLastError();
//--- delete a horizontal line
if(!ObjectDelete(chart_ID,name))
{
Print(__FUNCTION__,
": failed to delete a horizontal line! Error code = ",GetLastError());
return(false);
}
//--- successful execution
return(true);
}
//+----------------------------------------------------------------