What is the PineScript equivalent of MQL4's _Point? - mql4

I am trying to convert this indicator to PineScript. Couldn't figure out how to get Point variable. Is there any way to achieve the same thing in PineScript?
_Point official definition:
The _Point variable contains the point size of the current symbol in the quote currency.
https://docs.mql4.com/predefined/_point
Updated: Added the indicator code
//| Ticks Volume Indicator |
//| Copyright В© William Blau |
//| Coded/Verified by Profitrader |
//+------------------------------------------------------------------+
#property copyright "Copyright В© 2006, Profitrader."
#property link "profitrader#inbox.ru"
//-----
#property indicator_separate_window
#property indicator_buffers 1
#property indicator_color1 Blue
//---- input parameters
extern int r=12;
extern int s=12;
extern int u=5;
//---- buffers
double TVI[];
double UpTicks[];
double DownTicks[];
double EMA_UpTicks[];
double EMA_DownTicks[];
double DEMA_UpTicks[];
double DEMA_DownTicks[];
double TVI_calculate[];
double MyPoint;
//+------------------------------------------------------------------+
//| Custom indicator initialization function |
//+------------------------------------------------------------------+
int init() {
IndicatorShortName("TVI("+r+","+s+","+u+")");
IndicatorBuffers(8);
SetIndexBuffer(0,TVI);
SetIndexBuffer(1,UpTicks);
SetIndexBuffer(2,DownTicks);
SetIndexBuffer(3,EMA_UpTicks);
SetIndexBuffer(4,EMA_DownTicks);
SetIndexBuffer(5,DEMA_UpTicks);
SetIndexBuffer(6,DEMA_DownTicks);
SetIndexBuffer(7,TVI_calculate);
SetIndexStyle(0,DRAW_LINE);
SetIndexLabel(0,"TVI");
if (Digits == 5 || (Digits == 3 && StringFind(Symbol(), "JPY") != -1))
MyPoint = Point*10;
else if (Digits == 6 || (Digits == 4 && StringFind(Symbol(), "JPY") != -1))
MyPoint = Point*100;
else
MyPoint = Point;
return(0);
}
//+------------------------------------------------------------------+
//| Custom indicator deinitialization function |
//+------------------------------------------------------------------+
int deinit() {
return(0);
}
//+------------------------------------------------------------------+
//| Ticks Volume Indicator |
//+------------------------------------------------------------------+
int start() {
int i,counted_bars=IndicatorCounted();
//---- check for possible errors
if(counted_bars<0) return(-1);
//---- last counted bar will be recounted
if(counted_bars>0) counted_bars--;
int limit=Bars-counted_bars;
//----
for(i=0; i=0; i--) {
EMA_UpTicks[i]=iMAOnArray(UpTicks,0,r,0,MODE_EMA,i);
EMA_DownTicks[i]=iMAOnArray(DownTicks,0,r,0,MODE_EMA,i);
}
for(i=limit-1; i>=0; i--) {
DEMA_UpTicks[i]=iMAOnArray(EMA_UpTicks,0,s,0,MODE_EMA,i);
DEMA_DownTicks[i]=iMAOnArray(EMA_DownTicks,0,s,0,MODE_EMA,i);
}
for(i=0; i=0; i--) {
if (iClose(NULL,0,i)==0)
TVI[i]=EMPTY_VALUE;
else
TVI[i]=iMAOnArray(TVI_calculate,0,u,0,MODE_EMA,i);
}
//----
return(0);
}
//+------------------------------------------------------------------+

Related

MQL5 Heikin Ashi RSI Oscillator: error plotting candles

I was trying to convert this indicator from TradingView to MQL5 but it badly prints the candles, as in the attached photo, and i don't understand where is the problem.
From the TradingView indicator i want to convert only the Heiken Ashi code, not RSI and Stoch lines.
Here there is the code:
//+------------------------------------------------------------------+
//| Heiken_Ashi_RSI_Oscillator.mq5 |
//| Copyright 2009-2020, MetaQuotes Software Corp. |
//| http://www.mql5.com |
//+------------------------------------------------------------------+
#property copyright "2009-2020, MetaQuotes Software Corp."
#property link "http://www.mql5.com"
//--- indicator settings
#property indicator_separate_window
#property indicator_buffers 5
#property indicator_plots 1
#property indicator_type1 DRAW_COLOR_CANDLES
#property indicator_color1 DodgerBlue, Red
#property indicator_label1 "Heiken Ashi Open;Heiken Ashi High;Heiken Ashi Low;Heiken Ashi Close"
//--- indicator buffers
double ExtOBuffer[];
double ExtHBuffer[];
double ExtLBuffer[];
double ExtCBuffer[];
double ExtColorBuffer[];
input int periodoRSI=14;
input int smoothRSI=1;
int handle_harsi_close,handle_harsi_open,handle_harsi_low,handle_harsi_high;
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
double HA_RSI_CLOSE(int shift)
{
double value[];
if(handle_harsi_close!=INVALID_HANDLE)
{
if(CopyBuffer(handle_harsi_close,0,shift,1,value)>0)
return(value[0]);
}
return(WRONG_VALUE);
}
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
double HA_RSI_OPEN(int shift)
{
double value[];
if(handle_harsi_close!=INVALID_HANDLE)
{
if(CopyBuffer(handle_harsi_open,0,shift,1,value)>0)
return(value[0]);
}
return(WRONG_VALUE);
}
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
double HA_RSI_HIGH(int shift)
{
double value[];
if(handle_harsi_close!=INVALID_HANDLE)
{
if(CopyBuffer(handle_harsi_high,0,shift,1,value)>0)
return(value[0]);
}
return(WRONG_VALUE);
}
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
double HA_RSI_LOW(int shift)
{
double value[];
if(handle_harsi_close!=INVALID_HANDLE)
{
if(CopyBuffer(handle_harsi_low,0,shift,1,value)>0)
return(value[0]);
}
return(WRONG_VALUE);
}
//+------------------------------------------------------------------+
//| Custom indicator initialization function |
//+------------------------------------------------------------------+
void OnInit()
{
handle_harsi_close=iRSI(_Symbol,PERIOD_CURRENT,periodoRSI,PRICE_CLOSE);
handle_harsi_open=iRSI(_Symbol,PERIOD_CURRENT,periodoRSI,PRICE_OPEN);
handle_harsi_high=iRSI(_Symbol,PERIOD_CURRENT,periodoRSI,PRICE_HIGH);
handle_harsi_low=iRSI(_Symbol,PERIOD_CURRENT,periodoRSI,PRICE_LOW);
//--- indicator buffers mapping
SetIndexBuffer(0,ExtOBuffer,INDICATOR_DATA);
SetIndexBuffer(1,ExtHBuffer,INDICATOR_DATA);
SetIndexBuffer(2,ExtLBuffer,INDICATOR_DATA);
SetIndexBuffer(3,ExtCBuffer,INDICATOR_DATA);
SetIndexBuffer(4,ExtColorBuffer,INDICATOR_COLOR_INDEX);
//---
IndicatorSetInteger(INDICATOR_DIGITS,_Digits);
//--- sets first bar from what index will be drawn
IndicatorSetString(INDICATOR_SHORTNAME,"Heiken Ashi RSI Oscillator");
//--- sets drawing line empty value
PlotIndexSetDouble(0,PLOT_EMPTY_VALUE,0.0);
}
//+------------------------------------------------------------------+
//| Heiken Ashi |
//+------------------------------------------------------------------+
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 start;
//--- preliminary calculations
if(prev_calculated==0)
{
ExtLBuffer[0]=low[0];
ExtHBuffer[0]=high[0];
ExtOBuffer[0]=open[0];
ExtCBuffer[0]=close[0];
start=1;
}
else
start=prev_calculated-1;
//--- the main loop of calculations
for(int i=start; i<rates_total && !IsStopped(); i++)
{
double _closeRSI = HA_RSI_CLOSE(0);
double _openRSI = HA_RSI_CLOSE(1);
double _highRSI_raw = HA_RSI_HIGH(0);
double _lowRSI_raw = HA_RSI_LOW(0);
double _highRSI = MathMax(_highRSI_raw, _lowRSI_raw);
double _lowRSI = MathMin(_highRSI_raw, _lowRSI_raw);
double _close = (_openRSI + _highRSI + _lowRSI + _closeRSI) / 4;
double _open = (_openRSI + _closeRSI) / 2;
double _high = MathMax(_highRSI, MathMax(_open, _close));
double _low = MathMin(_lowRSI, MathMin(_open, _close));
ExtLBuffer[i]=_low;
ExtHBuffer[i]=_high;
ExtOBuffer[i]=_open;
ExtCBuffer[i]=_close;
//--- set candle color
if(_open<_close)
ExtColorBuffer[i]=0.0; // set color DodgerBlue
else
ExtColorBuffer[i]=1.0; // set color Red
}
//---
return(rates_total);
}
//+------------------------------------------------------------------+
THANK YOU!

Sort ATR by hour

Hello Im wondering if there is a way I can somehow view ATR by hour, so when it calculates results in has 24 different values from 00:00 to 23:00. I would like the average to be of the ranges for that hour only in the lookback period. (for example hour 02:00 compares it range to the other 02:00 ranges in the look back period)
Original ATR Code
//| ATR.mq4 |
//| Copyright 2005-2014, MetaQuotes Software Corp. |
//| http://www.mql4.com |
//+------------------------------------------------------------------+
#property copyright "2005-2014, MetaQuotes Software Corp."
#property link "http://www.mql4.com"
#property description "Average True Range"
#property strict
//--- indicator settings
#property indicator_separate_window
#property indicator_buffers 1
#property indicator_color1 DodgerBlue
//--- input parameter
input int InpAtrPeriod=14; // ATR Period
//--- buffers
double ExtATRBuffer[];
double ExtTRBuffer[];
//+------------------------------------------------------------------+
//| Custom indicator initialization function |
//+------------------------------------------------------------------+
int OnInit(void)
{
string short_name;
//--- 1 additional buffer used for counting.
IndicatorBuffers(2);
IndicatorDigits(Digits);
//--- indicator line
SetIndexStyle(0,DRAW_LINE);
SetIndexBuffer(0,ExtATRBuffer);
SetIndexBuffer(1,ExtTRBuffer);
//--- name for DataWindow and indicator subwindow label
short_name="ATR("+IntegerToString(InpAtrPeriod)+")";
IndicatorShortName(short_name);
SetIndexLabel(0,short_name);
//--- check for input parameter
if(InpAtrPeriod<=0)
{
Print("Wrong input parameter ATR Period=",InpAtrPeriod);
return(INIT_FAILED);
}
//---
SetIndexDrawBegin(0,InpAtrPeriod);
//---
return(INIT_SUCCEEDED);
}
//+------------------------------------------------------------------+
//| Average True Range |
//+------------------------------------------------------------------+
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 i,limit;
//--- check for bars count and input parameter
if(rates_total<=InpAtrPeriod || InpAtrPeriod<=0)
return(0);
//--- counting from 0 to rates_total
ArraySetAsSeries(ExtATRBuffer,false);
ArraySetAsSeries(ExtTRBuffer,false);
ArraySetAsSeries(open,false);
ArraySetAsSeries(high,false);
ArraySetAsSeries(low,false);
ArraySetAsSeries(close,false);
//--- preliminary calculations
if(prev_calculated==0)
{
ExtTRBuffer[0]=0.0;
ExtATRBuffer[0]=0.0;
//--- filling out the array of True Range values for each period
for(i=1; i<rates_total; i++)
ExtTRBuffer[i]=MathMax(high[i],close[i-1])-MathMin(low[i],close[i-1]);
//--- first AtrPeriod values of the indicator are not calculated
double firstValue=0.0;
for(i=1; i<=InpAtrPeriod; i++)
{
ExtATRBuffer[i]=0.0;
firstValue+=ExtTRBuffer[i];
}
//--- calculating the first value of the indicator
firstValue/=InpAtrPeriod;
ExtATRBuffer[InpAtrPeriod]=firstValue;
limit=InpAtrPeriod+1;
}
else
limit=prev_calculated-1;
//--- the main loop of calculations
for(i=limit; i<rates_total; i++)
{
ExtTRBuffer[i]=MathMax(high[i],close[i-1])-MathMin(low[i],close[i-1]);
ExtATRBuffer[i]=ExtATRBuffer[i-1]+(ExtTRBuffer[i]-ExtTRBuffer[i-InpAtrPeriod])/InpAtrPeriod;
}
//--- return value of prev_calculated for next call
return(rates_total);
}
//+------------------------------------------------------------------+````

Is there a way that i can find numbers that are the nearest to each other in a array

My logic in my code right now is this
Step1. Scan for 100 candlesstick or more from the past
Step2. Collect and store the date of all 100 to find out the high of each candlestick
Step3. Go through all the candlestick high data and find the one that are near each other (Still dont know how i would do that)
Step4. Plot HLine
Now the first problem im having is how would i code it where i would be able to find which candlestick numbers are close to each other in order to plot the HLine.
extern int candleCount = 100;
int totalHigh;
int FinishingTotalHigh;
int totalLow;
int FinishingTotalLow;
//+------------------------------------------------------------------+
//| Expert initialization function |
//+------------------------------------------------------------------+
int OnInit()
{
//---
//---
return(INIT_SUCCEEDED);
}
//+------------------------------------------------------------------+
//| Expert deinitialization function |
//+------------------------------------------------------------------+
void OnDeinit(const int reason)
{
//---
}
//+------------------------------------------------------------------+
//| Expert tick function |
//+------------------------------------------------------------------+
void OnTick()
{
totalHigh = 0;
totalLow = 0;
// Initializing the variables.
double Highest = High[0];
double Lowest = Low[0];
Alert("");
Alert("");
Alert("");
Alert("");
Alert("");
// Scan the 100 candles and update the values of the highest and lowest.
for (int i = 0; i <= candleCount; i++)
{
//Alert(i+"Index Data: "+High[i]);
totalHigh = High[i] + totalHigh;
totalLow = Low[i] + totalLow;
if (High[i] > Highest) Highest = High[i];
if (Low[i] < Lowest) Lowest = Low[i];
}
FinishingTotalHigh = totalHigh/candleCount;
FinishingTotalLow = totalLow/candleCount;
// Print the result.
Alert("Highest price found is "+Highest);
Alert("Lowest price found is "+Lowest);
Alert("TotalHigh: "+FinishingTotalHigh);
Alert("TotalLow: "+FinishingTotalLow);
}
//+------------------------------------------------------------------+

How to read iExposure indicator's Profit values from iCustom() function in MQL4?

please help me on How to read iExposure indicator's Profit values from iCustom() function in MQL4?
Thanks
I am using mt4 provided iExposure.mq4 indicator. it has below buffers
SetIndexBuffer(0,ExtMapBuffer);
ExtMapBuffer[Bars-1]=-1;
I need Profit part from iCustom`()
I attached the entire indicator code for your reference.
thanks,
//+------------------------------------------------------------------+
//| iExposureSymbol.mq4 |
//| Copyright 2007-2014, MetaQuotes Software Corp. |
//| http://www.mql4.com |
//+------------------------------------------------------------------+
#property copyright "2007-2014, MetaQuotes Software Corp."
#property link "http://www.mql4.com"
#property strict
#property indicator_separate_window
#property indicator_buffers 1
#property indicator_minimum 0.0
#property indicator_maximum 0.1
#define SYMBOLS_MAX 1
#define DEALS 0
#define BUY_LOTS 1
#define BUY_PRICE 2
#define SELL_LOTS 3
#define SELL_PRICE 4
#define NET_LOTS 5
#define PROFIT 6
input color InpColor=LightSeaGreen; // Text color
string ExtName="Exposure";
string ExtSymbols[SYMBOLS_MAX];
int ExtSymbolsTotal=0;
double ExtSymbolsSummaries[SYMBOLS_MAX][7];
int ExtLines=-1;
string ExtCols[8]={"Symbol",
"Deals",
"Buy lots",
"Buy price",
"Sell lots",
"Sell price",
"Net lots",
"Profit"};
int ExtShifts[8]={ 10, 80, 130, 180, 260, 310, 390, 460 };
int ExtVertShift=14;
double ExtMapBuffer[];
//+------------------------------------------------------------------+
//| Custom indicator initialization function |
//+------------------------------------------------------------------+
void OnInit()
{
IndicatorShortName(ExtName);
SetIndexBuffer(0,ExtMapBuffer);
SetIndexStyle(0,DRAW_NONE);
IndicatorDigits(0);
SetIndexEmptyValue(0,0.0);
}
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
void OnDeinit(const int reason)
{
int windex=WindowFind(ExtName);
if(windex>0)
ObjectsDeleteAll(windex);
}
//+------------------------------------------------------------------+
//| 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[])
{
string name;
int i,col,line,windex=WindowFind(ExtName);
//----
if(windex<0)
return(rates_total);
//---- header line
if(ExtLines<0)
{
for(col=0; col<8; col++)
{
name="Head_"+string(col);
if(ObjectCreate(name,OBJ_LABEL,windex,0,0))
{
ObjectSet(name,OBJPROP_XDISTANCE,ExtShifts[col]);
ObjectSet(name,OBJPROP_YDISTANCE,ExtVertShift);
ObjectSetText(name,ExtCols[col],9,"Arial",InpColor);
}
}
ExtLines=0;
}
//----
ArrayInitialize(ExtSymbolsSummaries,0.0);
int total=Analyze();
if(total>0)
{
line=0;
for(i=0; i<ExtSymbolsTotal; i++)
{
if(ExtSymbolsSummaries[i][DEALS]<=0) continue;
line++;
//---- add line
if(line>ExtLines)
{
int y_dist=ExtVertShift*(line+1)+1;
for(col=0; col<8; col++)
{
name="Line_"+string(line)+"_"+string(col);
if(ObjectCreate(name,OBJ_LABEL,windex,0,0))
{
ObjectSet(name,OBJPROP_XDISTANCE,ExtShifts[col]);
ObjectSet(name,OBJPROP_YDISTANCE,y_dist);
}
}
ExtLines++;
}
//---- set line
int digits=(int)MarketInfo(ExtSymbols[i],MODE_DIGITS);
double buy_lots=ExtSymbolsSummaries[i][BUY_LOTS];
double sell_lots=ExtSymbolsSummaries[i][SELL_LOTS];
double buy_price=0.0;
double sell_price=0.0;
if(buy_lots!=0) buy_price=ExtSymbolsSummaries[i][BUY_PRICE]/buy_lots;
if(sell_lots!=0) sell_price=ExtSymbolsSummaries[i][SELL_PRICE]/sell_lots;
name="Line_"+string(line)+"_0";
ObjectSetText(name,ExtSymbols[i],9,"Arial",InpColor);
name="Line_"+string(line)+"_1";
ObjectSetText(name,DoubleToStr(ExtSymbolsSummaries[i][DEALS],0),9,"Arial",InpColor);
name="Line_"+string(line)+"_2";
ObjectSetText(name,DoubleToStr(buy_lots,2),9,"Arial",InpColor);
name="Line_"+string(line)+"_3";
ObjectSetText(name,DoubleToStr(buy_price,digits),9,"Arial",InpColor);
name="Line_"+string(line)+"_4";
ObjectSetText(name,DoubleToStr(sell_lots,2),9,"Arial",InpColor);
name="Line_"+string(line)+"_5";
ObjectSetText(name,DoubleToStr(sell_price,digits),9,"Arial",InpColor);
name="Line_"+string(line)+"_6";
ObjectSetText(name,DoubleToStr(buy_lots-sell_lots,2),9,"Arial",InpColor);
name="Line_"+string(line)+"_7";
ObjectSetText(name,DoubleToStr(ExtSymbolsSummaries[i][PROFIT],2),9,"Arial",InpColor);
}
}
//---- remove lines
if(total<ExtLines)
{
for(line=ExtLines; line>total; line--)
{
name="Line_"+string(line)+"_0";
ObjectSetText(name,"");
name="Line_"+string(line)+"_1";
ObjectSetText(name,"");
name="Line_"+string(line)+"_2";
ObjectSetText(name,"");
name="Line_"+string(line)+"_3";
ObjectSetText(name,"");
name="Line_"+string(line)+"_4";
ObjectSetText(name,"");
name="Line_"+string(line)+"_5";
ObjectSetText(name,"");
name="Line_"+string(line)+"_6";
ObjectSetText(name,"");
name="Line_"+string(line)+"_7";
ObjectSetText(name,"");
}
}
//---- to avoid minimum==maximum
ExtMapBuffer[Bars-1]=-1;
//----
return(rates_total);
}
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
int Analyze()
{
double profit;
int i,index,type,total=OrdersTotal();
//----
for(i=0; i<total; i++)
{
if(!OrderSelect(i,SELECT_BY_POS)) continue;
type=OrderType();
if(type!=OP_BUY && type!=OP_SELL) continue;
index=SymbolsIndex(OrderSymbol());
if(index<0 || index>=SYMBOLS_MAX) continue;
//----
ExtSymbolsSummaries[index][DEALS]++;
profit=OrderProfit()+OrderCommission()+OrderSwap();
ExtSymbolsSummaries[index][PROFIT]+=profit;
if(type==OP_BUY)
{
ExtSymbolsSummaries[index][BUY_LOTS]+=OrderLots();
ExtSymbolsSummaries[index][BUY_PRICE]+=OrderOpenPrice()*OrderLots();
}
else
{
ExtSymbolsSummaries[index][SELL_LOTS]+=OrderLots();
ExtSymbolsSummaries[index][SELL_PRICE]+=OrderOpenPrice()*OrderLots();
}
}
//----
total=0;
for(i=0; i<ExtSymbolsTotal; i++)
{
if(ExtSymbolsSummaries[i][DEALS]>0) total++;
}
//----
return(total);
}
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
int SymbolsIndex(string SymbolName)
{
bool found=false;
int i;
//----
for(i=0; i<ExtSymbolsTotal; i++)
{
if(SymbolName==ExtSymbols[i])
{
found=true;
break;
}
}
//----
if(found)
return(i);
if(ExtSymbolsTotal>=SYMBOLS_MAX)
return(-1);
//----
i=ExtSymbolsTotal;
ExtSymbolsTotal++;
ExtSymbols[i]=Symbol();
ExtSymbolsSummaries[i][DEALS]=0;
ExtSymbolsSummaries[i][BUY_LOTS]=0;
ExtSymbolsSummaries[i][BUY_PRICE]=0;
ExtSymbolsSummaries[i][SELL_LOTS]=0;
ExtSymbolsSummaries[i][SELL_PRICE]=0;
ExtSymbolsSummaries[i][NET_LOTS]=0;
ExtSymbolsSummaries[i][PROFIT]=0;
//----
return(i);
}
//+------------------------------------------------------------------+

How to find day's first candle's HIGH, LOW in current Time frame

I am new to MT4, know little basic programming for MQL4. I am trading in UTC+5:30 in Indian Stocks. I just want a small piece of code to get today's First candles HIGH and LOW in current TimeFrame. Our trading starts at 9:15 AM IST and ends at 3:30 PM IST.
e.g. if I select PERIOD_M15 (15 min chart) then I need to have day's first candle (i.e. from 9:15AM to 9:30AM) HIGH and LOW.
thanks in advance.
welcome to SOF!
you need input parameters (time of the day start):
input int InpTimeStartHour=9;
input int InpTimeStartMinute=15;
this can be as a one string but for simplicity such fields
bool getHighLowFistCandle(double &high,double &low){
//check if first candle (zero-current) is after 9:15
datetime lastCandle=iTime(Symbol(),0,1);
if(TimeHour(lastCandle)<InpTimeStartHour ||
(TimeHour(lastCandle)==InpTimeStartHour && TimeMinute(lastCandle)<InpTimeStartMinute){
return(false);
}
//looking for that time candle starting from day start
datetime todayStart=iTime(Symbol(),PERIOD_D1,0);
int shift=iBarShift(Symbol(),0,todayStart);
for(int i=shift;i>0;i--){
datetime iCandleTime=iTime(Symbol(),0,i);
if(TimeHour(iCandleTime)==InpTimeStartHour &&
TimeMinute(iCandleTime)==InpTimeStartMinute){
high=iHigh(Symbol(),0,i);
low=iLow(Symbol(),0,i);
return(true);
}
}
return(false);
}
Below is my indicator code,
//+------------------------------------------------------------------+
//| ProjectName |
//| Copyright 2018, CompanyName |
//| http://www.companyname.net |
//+------------------------------------------------------------------+
#property copyright "Copyright 2020,ANKUR SONI."
#property link "https://www.mql5.com"
#property version "1.00"
#property strict
#property indicator_buffers 1
#property indicator_chart_window
#property indicator_width1 5
#property indicator_color1 clrYellow
double engulfing[];
input int InpTimeStartHour=8;
input int InpTimeStartMinute=45;
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
int OnInit()
{
SetIndexBuffer(0, engulfing);
SetIndexStyle(0, DRAW_ARROW);
return(INIT_SUCCEEDED);
}
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
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[])
{
for(int i = (Bars - 2) ; i > 0 ; i--)
{
if(TimeHour(time[i]) == InpTimeStartHour && TimeMinute(time[i]) == InpTimeStartMinute)
{
double currentHigh = High[i];
double currentLow = Low[i];
double nextHigh = High[i-1];
double nextLow = Low[i-1];
if(nextHigh > currentHigh && nextLow < currentLow)
{
engulfing[i-1] = High[i-1] + 15;
}
}
}
return(rates_total);
}
//+------------------------------------------------------------------+

Resources