MT5 iSAR bar shift?

 

Hello,

I am working on an EA that uses information from the parabolic sar.

On the MT4 I can reference a previous bar of psar information using the following code:

double   psar_step      =  0.02; //Parabolic step
double   psar_maximum   =  0.2;  //Parabolic maximum
int      psar_barshift  = 2; //bar shift

double   temp_psar   =  iSAR(Symbol(),PERIOD_CURRENT,psar_step,psar_maximum,psar_barsift); 


HOWEVER.... I have been trying to do something similar on MT5, and I am completely lost and I do not understand how it works.


The documentation for iSar on MT5 provides the following:

int  iSAR(
   string           symbol,      // symbol name
   ENUM_TIMEFRAMES  period,      // period
   double           step,        // price increment step - acceleration factor
   double           maximum      // maximum value of step
   );

As you can see, it doesn't support bar shift.

My question is simple, how do I use iSAR to reference a previous candle on the MT5 platform?

Thank you for your time and assistance,

- David

 
whroeder1:
Of course it doesn't have shift. Perhaps you should read the manual, especially the example. Technical Indicators / iSAR - Reference on algorithmic/automated trading language for MetaTrader 5
iSar (like iCustom) returns a handle. You use the handle, shift and count to get the data. Timeseries and Indicators Access / CopyBuffer - Reference on algorithmic/automated trading language for MetaTrader 5
See my example for encapsulating calls Detailed explanation of iCustom - MQL4 and MetaTrader 4 - MQL4 programming forum

I'm sorry if I appeared to be unwilling to read the documentation, but I am having problems fully understanding it due to my physical brain damage.

I had a stroke recently due to a blood clot in my brain which has left me with a permanent disability that I will never fully recover from.

It is very hard for me to ask for help from people, because I do not wish to be a burden on others.

I learned MQL4 before my stroke, so I have most of that knowledge still,

but it is very hard for me to learn new things sometimes, and MQL5 is so vastly different from MQL4 I am struggling with it.

I appreciate the links that you provided me.

I will read over them, and keep trying.

Thank for your assistance,

- David

 
whroeder1:
Of course it doesn't have shift. Perhaps you should read the manual, especially the example. Technical Indicators / iSAR - Reference on algorithmic/automated trading language for MetaTrader 5
iSar (like iCustom) returns a handle. You use the handle, shift and count to get the data. Timeseries and Indicators Access / CopyBuffer - Reference on algorithmic/automated trading language for MetaTrader 5
See my example for encapsulating calls Detailed explanation of iCustom - MQL4 and MetaTrader 4 - MQL4 programming forum


I have built this code which I thought should be returning the psar of the bar 2,

but for some reason I cannot understand, it is simply returning the HIGH of the bar and not the psar value as intended.


   ResetLastError();
   int handle = iCustom(Symbol(),30,"Examples\\ParabolicSAR",0.02,0.2);
   double temp_buffer[];
   int copy=CopyBuffer(handle,1,2,1,temp_buffer);
   Print("psar = ",(double)temp_buffer[0]," copy = ",copy);

Here is a screenshot to show bar 2 data.


And here is the screenshot of the psar data.

And here is the output from the terminal experts window.


I do not understand why it is returning the HIGH value and not the PSAR value.

Suggestions to resolve this?

Thank you for your assistance,

- David

 

Here is what the entire EA looks like.

As you can see, I am just trying to print out the psar value.

#property copyright "psar_testing"
#property link      "psar_testing"
#property version   "1.00"

int OnInit(){return(INIT_SUCCEEDED);}

void OnDeinit(const int reason){}

void OnTick(){
   ResetLastError();
   int handle = iCustom(_Symbol,30,"Examples\\ParabolicSAR");
   double temp_buffer[];
   int copy=CopyBuffer(handle,1,2,1,temp_buffer);
   Print("psar = ",(double)temp_buffer[0]," copy = ",copy);
}

Thank you for your assistance,

- David

 

I figured it out finally.

I had this, which returns the high value.

int copy=CopyBuffer(handle,1,2,1,temp_buffer);

I changed it to this and it returns the psar value

int copy=CopyBuffer(handle,0,2,1,temp_buffer);

I believe this is due to the individual index[0] buffer of the psar indicator that was called. Is this correct?

Thank you for your assistance

- David

 
MrDavidForex: I believe this is due to the individual index[0] buffer of the psar indicator that was called. Is this correct?
Yes and you would have known that if you had followed my suggestion about encapsulating the call.
 
whroeder1:

Yes and you would have known that if you had followed my suggestion about encapsulating the call.

On a personal level, please understand that I have brain damage from a blood clot that caused a stroke, it is very hard for me to comprehend a lot of this information, but I am doing the best I can.

Clearly I read the information, or I wouldn't have figured out how to do it.

Again, thank you for the information

Reason: