
You are missing trading opportunities:
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
Registration
Log in
You agree to website policy and terms of use
If you do not have an account, please register
Well guys, the first part is done ( reading all pairs rates ).
Now i need use the rates of all paris copied with the function ArrayCopyRates to pot some graphic indicators like an RSI... as i draw in the image below:
In my initial question i intend know how to do this... and not about reading rates. I do not think i will need to copy rates before to draw it, but was good to know how to do... now i just need to discover a way to split the indicator area to plot all pairs...
There is no way to split the indicator area. Everything must be drawn separately, no buffers, no auto scaling. See
Did you see such a picture? (MetaQuotes Software Corp.) - MQL4 forum - Page 12
Did you see such a picture? (MetaQuotes Software Corp.) - MQL4 forum - Page 14
Did you see such a picture? (MetaQuotes Software Corp.) - MQL4 forum - Page 36
There is no way to split the indicator area. Everything must be drawn separately, no buffers, no auto scaling. See
Did you see such a picture? (MetaQuotes Software Corp.) - MQL4 forum - Page 12
Did you see such a picture? (MetaQuotes Software Corp.) - MQL4 forum - Page 14
Did you see such a picture? (MetaQuotes Software Corp.) - MQL4 forum - Page 36
This is a Indicator I picked up somewhere, I never tried to decipher it. I shows a representation of 3 timeframes of the current chart. The crazy thing is the candles are drawn with Histograms. Pretty neat but not what I am into right now.
Best Wishes
An update to those following this thread!
I have been helping the OP via PM fix his code as he has difficulty with English and we both speak Portuguese. In our testing we came across another "funny" that is happening with the "ArrayCopyRates()" function. When using an MqlRates array with "ArrayCopyRates()" in an EA, the data array is a virtual one that always reports the current status of things, so data is always fresh.
However, in an Indicator, this does not seem to be the case. The array is not a virtual copy but instead a static copy set in time at the moment that the "ArrayCopyRates()" was called. The data does not update when the Symbol is different to the chart symbol. When it is the same symbol as the chart, then the array data is "live" and updates as expected, but when it is of another symbol, it is a static copy.
So, in order for it to work in an Indicator, one must call the"ArrayCopyRates()" function on every call to OnCalculate() event if fresh data is needed.
Just to expand your findings Fernando - even if symbol is the same as chart symbol, if the timeframe is different then the array is static.
So in order to have a virtual copy, in an indicator, it must be the same symbol AND the same timeframe. Anything else is static.
Assuming it is mid week to find the high and low of previous day I simply use:
Lo = iLow(NULL, PERIOD_D1, 1);
That's fine, but now I need to find on the previous day what time was the high and the low. I decided to aproximate the time to the 1h candle at high and low using iHighest and iLowest. And that's when the problems begun.
PrevDayEnd = iBarShift(NULL, PERIOD_H1, iTime(NULL, PERIOD_D1, 0)-1);
PrevDayBegin--;
MqlRates mqlrates_array_d1[];
MqlRates mqlrates_array_h1[];
MqlRates mqlrates_array[];
ArrayCopyRates(mqlrates_array_d1,NULL,PERIOD_D1);
ArrayCopyRates(mqlrates_array_h1,NULL,PERIOD_H1);
ArrayCopyRates(mqlrates_array,NULL,0);
OnInit();
:
isHistoryLoading = true;
:
OnCalculate( ... )
:
MqlRates mqlrates_array_d1[];
MqlRates mqlrates_array_h1[];
MqlRates mqlrates_array[];
if(isHistoryLoading)
{
ResetLastError();
if(ArrayCopyRates(mqlrates_array_d1,NULL,PERIOD_D1)>0)
{
if(GetLastError() == 0)
{
if((iTime(NULL,PERIOD_D1,0) > 0) && (iTime(NULL,PERIOD_D1,1) > 0))
{
ResetLastError();
if(ArrayCopyRates(mqlrates_array_h1,NULL,PERIOD_H1)>0)
{
if(GetLastError() == 0)
{
if((iTime(NULL,PERIOD_H1,0) > 0) && (iTime(NULL,PERIOD_H1,1) > 0))
{
ResetLastError();
if(ArrayCopyRates(mqlrates_array,NULL,0)>0)
{
if(GetLastError() == 0)
{
if((iTime(NULL,0,0) > 0) && (iTime(NULL,0,1) > 0))
{
isHistoryLoading = false;
if(DebugLog)
Print("Chart up-to-date!");
}
}
}
}
}
}
}
}
}
}
if(isHistoryLoading)
{
if(DebugLog)
Print("Waiting for chart to update!");
return(rates_total);
}
:
:
if(ObjectFind(Trend2Name) != -1) // Check whether mid range line exists
{
if((TimeDay(ObjectGetInteger(0,Trend2Name,OBJPROP_TIME,0))==TimeDay(TimeCurrent()))
&& (TimeMonth(ObjectGetInteger(0,Trend2Name,OBJPROP_TIME,0))==TimeMonth(TimeCurrent()))
&& (TimeYear(ObjectGetInteger(0,Trend2Name,OBJPROP_TIME,0))==TimeYear(TimeCurrent()))) // Indicator has already been ploted today
{
return(rates_total);
}
else // Indicator exists but in a past date, so delete it and plot it on current day
{
if(DebugLog)
Print("Indicator in a past date! Deleting it and creating it today!");
if(ObjectFind(FibName) != -1)
FiboLevelsDelete(0,FibName);
// Indicator will be created by the OnChartEvent() when it detects the fib was deleted.
}
}
else // Indicator doesn't exist, so create it
{
if(DebugLog)
Print("Indicator doesn't exist! Creating it.");
CreateIndicator();
}
:
After a few ticks the data is partially loaded and the piece of code above will detect that the lines have been plotted on a previous day, delete the fib and trigger a recalculation of the ranges and redraw of the objects (i.e. fib, trendlines, etc).
CurrDayBegin = iTime(NULL, PERIOD_D1, 0);
while(TimeDayOfWeek(iTime(NULL, PERIOD_H1, iBarShift(NULL, PERIOD_H1, CurrDayBegin))) != TimeDayOfWeek(TimeCurrent()))
// If iBarShift can't find the 0am candle and returns the 11pm candle of prev day.
CurrDayBegin = CurrDayBegin + 3600; // Move 1h until you find the 1st candle of today.These are screenshots of the indicator:
(1) Calculated using incomplete history (please notice the horizontal lines don't start at the beginning of the day)
(2) Recalculated using the complete history (horizontal lines starting at the beginning of the day)