how to implement PivotPointUniversal in EA?

 

Hi, i want to create a EA which uses the pivot point universal indicator (https://www.mql5.com/en/code/102), with a strategy that buys and sells when price is near the pivot point calculated by the indicator.

 

How can i get the handle of that indicator in MQL5? Or how can i access to the price levels (pivot point, S1, R1, ...) calculated?

 

i'm sorry if it's a newbie question

 

thanks 

PivotPointUniversal
  • votes: 17
  • 2010.04.26
  • Dmitry | English Russian Spanish Portuguese
  • www.mql5.com
The indicator plots Pivot levels for all available history. There are 5 variants of Pivot levels is supported: Classic, Fibonacci, Demark, Camarilla, Woodies. There are 3 calculation periods: daily, weekly, monthly. For the daily pivot levels it's possible to specify the GMT time shift.
 
wavetrader:

How can i get the handle of that indicator in MQL5? Or how can i access to the price levels (pivot point, S1, R1, ...) calculated?

Use iCustom() to get handle, and CopyBuffer() to get the indicator data (see example)
Files:
PPU_EA.mq5  3 kb
 

Thank you, that helped me a lot

When i run this code

void OnNewBar()
  {
   int hPvtInd;
   hPvtInd=iCustom(_Symbol,PERIOD_CURRENT,"pivotpointuniversal");
   if(hPvtInd==INVALID_HANDLE)
     {
      Print("Error in creating pivotpointuniversal");
     }
   double bufferP[1];
   double bufferS1[1];
   double bufferR1[1];
   
   CopyBuffer(hPvtInd,0,0,1,bufferP);
   CopyBuffer(hPvtInd,1,0,1,bufferS1);
   CopyBuffer(hPvtInd,2,0,1,bufferR1);
   
   bufferP[0]=NormalizeDouble(bufferP[0],_Digits);
   bufferS1[0]=NormalizeDouble(bufferS1[0],_Digits);
   bufferR1[0]=NormalizeDouble(bufferR1[0],_Digits);
   
   Print("pivot = ",bufferP[0]," || S1 = ",bufferS1[0]," || R1 = ",bufferR1[0]);
  }


 

 in debug mode, it works (the print function correctly shows the values of pivot, S1 and R1.

 But when i use the strategy tester, in the journal the print function prints

2012.01.16 21:10:50 Core 1 2010.11.25 20:00:00   pivot = 0.0 || S1 = 0.0 || R1 = 0.0

 

 ALL zeros as values of pivot, S1 and R1! I dont know why. PS: the function OnNewBar has been implemented with the help of https://www.mql5.com/en/articles/159

 

 


	          
"New Bar" Event Handler
  • 2010.10.11
  • Konstantin Gruzdev
  • www.mql5.com
MQL5 programming language is capable of solving problems on a brand new level. Even those tasks, that already have such solutions, thanks to object oriented programming can rise to a higher level. In this article we take a specially simple example of checking new bar on a chart, that was transformed into rather powerful and versatile tool. What tool? Find out in this article.
 

i've never came up with a solution. 

Anyway, i use this code now:

MqlRates rates[1];
double P,S1,R1,S2,R2,S3,R3;


   if(CopyRates(Symbol(),PERIOD_D1,1,1,rates)<0)
     {
      Alert("Error copying rates buffer - error: ",GetLastError());
      return;
     }
   P=(rates[0].high+rates[0].low+rates[0].close)/3;
   S1=P*2-rates[0].high;
   R1=P*2-rates[0].low;
   S2=P-rates[0].high+rates[0].low;
   R2=P+rates[0].high-rates[0].low;
   S3=rates[0].low-2*(rates[0].high-P);
   R3=rates[0].high+2*(P-rates[0].low);
   P=NormalizeDouble(P,_Digits);
   S1=NormalizeDouble(S1,_Digits);
   R1=NormalizeDouble(R1,_Digits);
   S2=NormalizeDouble(S2,_Digits);
   R2=NormalizeDouble(R2,_Digits);
   S3=NormalizeDouble(S3,_Digits);
   R3=NormalizeDouble(R3,_Digits);
   Print("P = ",P," || S1 = ",S1," || R1 = ",R1," || S2 = ",S2," || R2 = ",R2," || S3 = ",S3," || R3 = ",R3);

 it gets the daily pivot points