NK7: I am trying to... I would want to ... May I request your kind help to ...
|
|
|
Whroeder1, sorry if this came through the wrong way.
Here is the snippet of the code that I have been writing.
I am complete novice to coding, let alone MQ4 codes. Was able to plot the pivot lines etc on the charts with history as per, but stuck at the histogram.
Used some references from already existing indicators, but aint getting the desired outcome.
//+------------------------------------------------------------------+
//| Custom indicator initialization function |
//+------------------------------------------------------------------+
int OnInit()
{
//--- indicator buffers mapping
SetIndexBuffer(0,HistogramBuffer,INDICATOR_DATA);
if(Daily==true)
{
PeriodCode = 1440;
PeriodLabel = "D";
PeriodBuffer = 86400;
}
//ArrayInitialize(Period_Price,0);
ArrayCopyRates(Period_Price,(Symbol()), PeriodCode);
if(Yearly)
PeriodsToPlot = 3;
for(int i=0; i <= PeriodsToPlot; i++)
{
if(Yearly)
{
int year = Year() - (i+1);
double close,high,low=10000;
for (int x=0;x<60;x++)
{
if(TimeYear(Period_Price[x][0]) == year)
{
if(Period_Price[x][3] > high)
high = Period_Price[x][3];
if(Period_Price[x][2] < low)
low = Period_Price[x][2];
if (TimeMonth(Period_Price[x][0]) == 12)
close = Period_Price[x][4];
}
}
PreviousHigh = high;
PreviousLow = low;
PreviousClose = close;
}
else
{
PreviousHigh = Period_Price[i+1][3];
PreviousLow = Period_Price[i+1][2];
PreviousClose = Period_Price[i+1][4];
}
//****************************CALCUALATIONS
Pivot = ((PreviousHigh + PreviousLow + PreviousClose)/3);
R1 = (2*Pivot)-PreviousLow;
S1 = (2*Pivot)-PreviousHigh;
R2 = Pivot + (PreviousHigh - PreviousLow);
S2 = Pivot - (PreviousHigh - PreviousLow);
S3 = S1 - (PreviousHigh - PreviousLow);
R3 = R1 + (PreviousHigh - PreviousLow);
R4 = R3 + (R2-R1);
S4 = S3 - (S1-S2);
BC = (PreviousHigh + PreviousLow ) / 2;
TC = (Pivot - BC) + Pivot;
if (BC > TC)
{
double temp = BC;
BC = TC;
TC = temp;
}
PLT = ((TC - BC) / Pivot) * 100;
}
//+------------------------------------------------------------------+
//| 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[])
{
for(int i=0; i <= PeriodsToPlot; i++)
HistogramBuffer[i]=PLT;
}
NK7:
Here is the snippet of the code that I have been writing.
I am complete novice to coding, let alone MQ4 codes. Was able to plot the pivot lines etc on the charts with history as per, but stuck at the histogram.
-
Play videoPlease edit your post.
For large amounts of code, attach it - Why did you post your MT4 question in the
Root /
MT5 Indicators
section
instead of the
MQL4 section (bottom of
the Root page?)
int OnInit() { ArrayCopyRates(Period_Price,(Symbol()), PeriodCode);
Everything below that must be done in OnCalculate.- The ArrayCopyRates must be done in OnCalculate if you insist in using the double array as that actually copies the data. Use the MqlRates version.
- Verify you actually have data for the PeriodCode you are using. See Download history
in MQL4 EA - MQL4 and MetaTrader 4 - MQL4 programming forum

- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
Dear Coders,
I am trying to create a new indicator which plots a histogram based on the following calculation w.r.t the Pivot points, both current and past.
Pivot = ((PreviousHigh + PreviousLow + PreviousClose)/3);
BC = (PreviousHigh + PreviousLow ) / 2;
TC = (Pivot - BC) + Pivot;
if (BC > TC)
{
double temp = BC;
BC = TC;
TC = temp;
}
PLT = ((TC - BC))/PP) * 100
I would want to plot the PLT on a histrogram in a separate window at the bottom of the charts .
May I request your kind help to plot the histogram for the PLT.
Thanks
NK
P.S :
The VBA code for the following is :
#Indicator
#PARAM "UpperMarker", .75
#PARAM "LowerMarker", .25
Dim fPivotRange As Single
fPivotRange = ((FLOOR_PIV(1) - FLOOR_PIV(-1))/FLOOR_PIV(0)) * 100
PlotHIST("PRHIST", fPivotRange, .5, red, 3)
PlotLabel (UpperMarker)
PlotLabel (LowerMarker)
SetScales(0,1)
Return 0