//+------------------------------------------------------------------+ //| TrendIndicatorADX_SAR.mq5 | //| Copyright 2014, MetaQuotes Software Corp. | //| http://www.mql5.com | //+------------------------------------------------------------------+ #property copyright "Copyright 2014, gioooooo." #property link "http://www.mql5.com" #property version "2.00" //#property indicator_separate_window #property indicator_chart_window #property indicator_buffers 1 #property indicator_plots 1 //--- plot tred #property indicator_label1 "sar tf sup" #property indicator_type1 DRAW_LINE #property indicator_color1 clrRed #property indicator_style1 STYLE_SOLID #property indicator_width1 1 input int barre = 500; input double SARstep=0.02; //il passo, ovvero il punto iniziale di posizionamento dello stop input double SARMaximum=0.2;//lo spostamento massimo, che controlla il movimento del punto SAR rispetto al movimento del prezzo. int h_SAR; ENUM_TIMEFRAMES timeframeSup; int PeriodSeconds_TF2; //--- indicator buffers double tredBuffer[]; //+------------------------------------------------------------------+ //| Custom indicator initialization function | //+------------------------------------------------------------------+ int OnInit() { //--- indicator buffers mapping SetIndexBuffer(0,tredBuffer,INDICATOR_DATA); Print("Timeframe=",Period()); if( Period()== PERIOD_M1 ) timeframeSup= PERIOD_M5; else if(Period()== PERIOD_M5 ) timeframeSup= PERIOD_M15; else if(Period()== PERIOD_M15) timeframeSup= PERIOD_M30; else if(Period()== PERIOD_M30) timeframeSup= PERIOD_H1; else if(Period()== PERIOD_H1 ) timeframeSup= PERIOD_H4; else if(Period()== PERIOD_H4 ) timeframeSup= PERIOD_D1; else if(Period()== PERIOD_D1 ) timeframeSup= PERIOD_W1; else if(Period()== PERIOD_W1 ) timeframeSup= PERIOD_MN1; else timeframeSup= Period(); Print("timeframe sup=",timeframeSup); h_SAR= iSAR(NULL,timeframeSup,SARstep,SARMaximum); //iRSI(NULL,timeframeSup,14,PRICE_CLOSE); if (h_SAR== INVALID_HANDLE) Print("Errore nell'Handle dell'indicatore iSAR"); else Print("Init OK"); PeriodSeconds_TF2=PeriodSeconds(timeframeSup); //ExtExpert.Refresh(); //--- return(INIT_SUCCEEDED); } void OnDeinit(const int motivo){ IndicatorRelease(h_SAR); } //+------------------------------------------------------------------+ //| 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[]) { //--- double SAR[1]; double CLOSE[1]; datetime TIME[1]; //--- return value of prev_calculated for next call int start = PeriodSeconds_TF2; //for (int i=(int)MathMax(prev_calculated-1,start); i