Download MetaTrader 5

Plot Histogram

To add comments, please log in or register
NK7
10
NK7  

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

whroeder1
16278
whroeder1  
NK7: I am trying to... I would want to ... May I request your kind help to ...
  1. You're not trying to do anything, you haven't started.
  2. You want, but unwilling to learn how.
  3. Help with what? You haven't done anything. You haven't posted your code nor stated a problem
  4. You have only three choices: Search for it, learn to code it, or pay (Freelance) someone to code it. We're not going to code it for you (although it could happen if you are lucky or the problem is interesting.) We are willing to help you when you post your attempt (using SRC) and the nature of your problem.
NK7
10
NK7  
whroeder1:
  1. You're not trying to do anything, you haven't started.
  2. You want, but unwilling to learn how.
  3. Help with what? You haven't done anything. You haven't posted your code nor stated a problem
  4. You have only three choices: Search for it, learn to code it, or pay (Freelance) someone to code it. We're not going to code it for you (although it could happen if you are lucky or the problem is interesting.) We are willing to help you when you post your attempt (using SRC) and the nature of your problem.


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;

}

whroeder1
16278
whroeder1  

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.

  1. Don't paste code
    Play video
    Please edit your post.
    For large amounts of code, attach it

  2. Why did you post your MT4 question in the Root / MT5 Indicators section instead of the MQL4 section (bottom of the Root page?)
  3. int OnInit() {
       ArrayCopyRates(Period_Price,(Symbol()), PeriodCode);
    Everything below that must be done in OnCalculate.
  4. 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.
  5. Verify you actually have data for the PeriodCode you are using. See Download history in MQL4 EA - MQL4 and MetaTrader 4 - MQL4 programming forum
To add comments, please log in or register