Re: Trend Indicators

51
mntiwana wrote:Thu May 04, 2017 10:28 am
Too many indicators on chart is not and never cause repainting and i don't know which indi is that even,not visible ad no code even
I am sorry. Here it is on a clean chart with default settings. Mladen posted this version not long ago.
Precision Trend 2.2 (histo+alerts) Precision Trend 2.2 (histo+alerts)
Here is the code.

Code: Select all

//+------------------------------------------------------------------+
//|                                              precision trend.mq4 |
//+------------------------------------------------------------------+
#property copyright "mladen"
#property link      "mladenfx@gmail.com"

#property indicator_separate_window
#property indicator_buffers  2
#property indicator_color1   clrGreen
#property indicator_color2   clrRed
#property indicator_width1   2
#property indicator_width2   2
#property indicator_minimum  0
#property indicator_maximum  1
#property strict

//
//
//
//
//

extern ENUM_TIMEFRAMES TimeFrame         = PERIOD_CURRENT; // Time frame
extern int             avgPeriod         = 30;             // Average period
extern double          sensitivity       = 3;              // Sensitivity
extern bool            AlertsOn          = false;          // Turn alerts on?
extern bool            AlertsOnCurrent   = false;          // Alerts on still opened bar?
extern bool            AlertsMessage     = true;           // Alerts should display message?
extern bool            AlertsSound       = false;          // Alerts should play a sound?
extern bool            AlertsNotify      = false;          // Alerts should send a notification?
extern bool            AlertsEmail       = false;          // Alerts should send an email?
extern string          SoundFile         = "alert2.wav";   // Sound file

double upBuffer[],dnBuffer[],count[],trend[];
string indicatorFileName;
#define _mtfCall(_buff,_ind) iCustom(NULL,TimeFrame,indicatorFileName,0,avgPeriod,sensitivity,AlertsOn,AlertsOnCurrent,AlertsMessage,AlertsSound,AlertsNotify,AlertsEmail,SoundFile,_buff,_ind)

//------------------------------------------------------------------
//
//------------------------------------------------------------------
//
//
//
//
//

int OnInit()
{
   IndicatorBuffers(4);
   SetIndexBuffer(0,upBuffer); SetIndexStyle(0,DRAW_HISTOGRAM);
   SetIndexBuffer(1,dnBuffer); SetIndexStyle(1,DRAW_HISTOGRAM);
   SetIndexBuffer(2,count); 
   SetIndexBuffer(3,trend); 
         indicatorFileName = WindowExpertName();
         TimeFrame         = MathMax(TimeFrame,_Period);
return(INIT_SUCCEEDED);
}
void OnDeinit(const int reason) { return; }
int OnCalculate (const int       rates_total,
                 const int       prev_calculated,
                 const datetime& btime[],
                 const double&   open[],
                 const double&   high[],
                 const double&   low[],
                 const double&   close[],
                 const long&     tick_volume[],
                 const long&     volume[],
                 const int&      spread[] )
{
   int counted_bars = prev_calculated;
      if(counted_bars < 0) return(-1);
      if(counted_bars > 0) counted_bars--;
           int limit=MathMin(rates_total-counted_bars,rates_total-1); count[0] = limit;
            if (TimeFrame!=_Period)
            {
               limit = (int)MathMax(limit,MathMin(Bars-1,_mtfCall(2,0)*TimeFrame/Period()));
               for (int i=limit; i>=0; i--)
               {
                  int y = iBarShift(NULL,TimeFrame,Time[i]);
                  trend[i]    = _mtfCall(3,y);
                  upBuffer[i] = (trend[i] ==  1) ? 1 : EMPTY_VALUE;
                  dnBuffer[i] = (trend[i] == -1) ? 1 : EMPTY_VALUE;
            }
            return(0);
         }            
           

   //
   //
   //
   //
   //
            
   for(int i=limit; i>=0 && !_StopFlag; i--)
   {
      trend[i]    = iPrecisionTrend(high[i],low[i],close[i],avgPeriod,sensitivity,i,rates_total);
         upBuffer[i] = (trend[i] ==  1) ? 1 : EMPTY_VALUE;
         dnBuffer[i] = (trend[i] == -1) ? 1 : EMPTY_VALUE;
   }
   manageAlerts();
   return(rates_total);
}


//------------------------------------------------------------------
//
//------------------------------------------------------------------
//
//
//
//
//

#define _ptInstances     1
#define _ptInstancesSize 8
double  _ptWork[][_ptInstances*_ptInstancesSize];
#define __range 0
#define __trend 1
#define __avgr  2
#define __avgd  3
#define __avgu  4
#define __minc  5
#define __maxc  6
#define __close 7
double iPrecisionTrend(double _high, double _low, double _close, int _period, double _sensitivity, int i, int bars, int instanceNo=0)
{
   if (ArrayRange(_ptWork,0)!=bars) ArrayResize(_ptWork,bars); instanceNo*=_ptInstancesSize; int r=bars-i-1;
   
   //
   //
   //
   //
   //

   _ptWork[r][instanceNo+__close] = _close;
   _ptWork[r][instanceNo+__range] = _high-_low;
   _ptWork[r][instanceNo+__avgr]  = _ptWork[r][instanceNo+__range];
   int k=1; for (; k<_period && (r-k)>=0; k++) _ptWork[r][instanceNo+__avgr] += _ptWork[r-k][instanceNo+__range];
                                               _ptWork[r][instanceNo+__avgr] /= k;
                                               _ptWork[r][instanceNo+__avgr] *= _sensitivity;

      //
      //
      //
      //
      //
               
      if (r==0)
      {
         _ptWork[r][instanceNo+__trend] = 0;
         _ptWork[r][instanceNo+__avgd] = _close-_ptWork[r][instanceNo+__avgr];
         _ptWork[r][instanceNo+__avgu] = _close+_ptWork[r][instanceNo+__avgr];
         _ptWork[r][instanceNo+__minc] = _close;
         _ptWork[r][instanceNo+__maxc] = _close;
      }
      else
      {
         _ptWork[r][instanceNo+__trend] = _ptWork[r-1][instanceNo+__trend];
         _ptWork[r][instanceNo+__avgd]  = _ptWork[r-1][instanceNo+__avgd];
         _ptWork[r][instanceNo+__avgu]  = _ptWork[r-1][instanceNo+__avgu];
         _ptWork[r][instanceNo+__minc]  = _ptWork[r-1][instanceNo+__minc];
         _ptWork[r][instanceNo+__maxc]  = _ptWork[r-1][instanceNo+__maxc];
         
         //
         //
         //
         //
         //
         
         switch((int)_ptWork[r-1][instanceNo+__trend])
         {
            case 0 :
                  if (_close>_ptWork[r-1][instanceNo+__avgu])
                  {
                     _ptWork[r][instanceNo+__minc]  = _close;
                     _ptWork[r][instanceNo+__avgd]  = _close-_ptWork[r][instanceNo+__avgr];
                     _ptWork[r][instanceNo+__trend] =  1;
                  }
                  if (_close<_ptWork[r-1][instanceNo+__avgd])
                  {
                     _ptWork[r][instanceNo+__maxc]  = _close;
                     _ptWork[r][instanceNo+__avgu]  = _close+_ptWork[r][instanceNo+__avgr];
                     _ptWork[r][instanceNo+__trend] = -1;
                  }
                  break;
           case 1 :
                  _ptWork[r][instanceNo+__avgd] = _ptWork[r-1][instanceNo+__minc] - _ptWork[r][instanceNo+__avgr];
                     if (_close>_ptWork[r-1][instanceNo+__minc]) _ptWork[r][instanceNo+__minc] = _close;
                     if (_close<_ptWork[r-1][instanceNo+__avgd])
                     {
                        _ptWork[r][instanceNo+__maxc] = _close;
                        _ptWork[r][instanceNo+__avgu] = _close+_ptWork[r][instanceNo+__avgr];
                        _ptWork[r][instanceNo+__trend] = -1;
                     }
                  break;                  
            case -1 :
                  _ptWork[r][instanceNo+__avgu] = _ptWork[r-1][instanceNo+__maxc] + _ptWork[r][instanceNo+__avgr];
                     if (_close<_ptWork[r-1][instanceNo+__maxc]) _ptWork[r][instanceNo+__maxc] = _close;
                     if (_close>_ptWork[r-1][instanceNo+__avgu])
                     {
                        _ptWork[r][instanceNo+__minc]  = _close;
                        _ptWork[r][instanceNo+__avgd]  = _close-_ptWork[r][instanceNo+__avgr];
                        _ptWork[r][instanceNo+__trend] = 1;
                     }
         }
      }            
   return(_ptWork[r][instanceNo+__trend]);
}

//-------------------------------------------------------------------
//
//-------------------------------------------------------------------
//
//
//
//
//

void manageAlerts()
{
   if (AlertsOn)
   {
      int whichBar = (AlertsOnCurrent) ? 0 : 1;
      if (trend[whichBar] != trend[whichBar+1])
      {
         if (trend[whichBar] == 1) doAlert(whichBar,"up");
         if (trend[whichBar] ==-1) doAlert(whichBar,"down");
      }         
   }
}   

//
//
//
//
//

void doAlert(int forBar, string doWhat)
{
   static string   previousAlert="nothing";
   static datetime previousTime;
   string message;
   
   if (previousAlert != doWhat || previousTime != Time[forBar]) {
       previousAlert  = doWhat;
       previousTime   = Time[forBar];

       //
       //
       //
       //
       //

       message = timeFrameToString(_Period)+" "+Symbol()+" at "+TimeToStr(TimeLocal(),TIME_SECONDS)+" precision trend changed to : "+doWhat;
          if (AlertsMessage) Alert(message);
          if (AlertsNotify)  SendNotification(message);
          if (AlertsEmail)   SendMail(_Symbol+" precision trend ",message);
          if (AlertsSound)   PlaySound(SoundFile);
   }
}

//
//
//
//
//

string sTfTable[] = {"M1","M5","M15","M30","H1","H4","D1","W1","MN"};
int    iTfTable[] = {1,5,15,30,60,240,1440,10080,43200};

string timeFrameToString(int tf)
{
   for (int i=ArraySize(iTfTable)-1; i>=0; i--) 
         if (tf==iTfTable[i]) return(sTfTable[i]);
                              return("");
}


Re: Trend Indicators

52
I am sorry. Here it is on a clean chart with default settings. Mladen posted this version not long ago.

Hi scarlet
I think you are trying confuse and misleading your self,i don't see any repainting results from,i checked it for a while,may be experts can better help you.
first,you needs to adjust indicator parameters according to price,i guess you used default .
Attachments
Indicator is just a tool.

Use it only if it can benefit you. Leave it if you don't know how to use it optimally.

Re: Trend Indicators

53
mntiwana wrote:Fri May 05, 2017 3:50 am I am sorry. Here it is on a clean chart with default settings. Mladen posted this version not long ago.

Hi scarlet
I think you are trying confuse and misleading your self,i don't see any repainting results from,i checked it for a while,may be experts can better help you.
first,you needs to adjust indicator parameters according to price,i guess you used default .
Well, that's possible; I might have adjusted a setting between screenshots and forgotten I had done so.

I will continue to test on clean charts. It will be a great addition if it doesn't recalculate the past history. I am adjusting the period as determined by the dominant cycle (which in turn I determine using Goertzel browser). However I'm trying different settings to get a sense of what works for particular instruments.

If I find evidence of history bars changing is it okay to submit it here again?

Re: Trend Indicators

54
scarletPip wrote:Fri May 05, 2017 5:20 am

Well, that's possible; I might have adjusted a setting between screenshots and forgotten I had done so.

I will continue to test on clean charts. It will be a great addition if it doesn't recalculate the past history. I am adjusting the period as determined by the dominant cycle (which in turn I determine using Goertzel browser). However I'm trying different settings to get a sense of what works for particular instruments.

If I find evidence of history bars changing is it okay to submit it here again?
For sure,it help us all traders and this is the FORUM's purpose and aim :)
Indicator is just a tool.

Use it only if it can benefit you. Leave it if you don't know how to use it optimally.


Re: Trend Indicators

57
mntiwana wrote:Fri May 05, 2017 3:50 am I am sorry. Here it is on a clean chart with default settings. Mladen posted this version not long ago.

Hi scarlet
I think you are trying confuse and misleading your self,i don't see any repainting results from,i checked it for a while,may be experts can better help you.
first,you needs to adjust indicator parameters according to price,i guess you used default .
Would you mind to post the indicator in the sub-window....."advanced step rsx smoothed".

Re: Trend Indicators

59
RplusT wrote:Fri May 05, 2017 9:11 am Would you mind to post the indicator in the sub-window....."advanced step rsx smoothed".
Advanced StepRSI + smoothing + fl's + alerts + arrows
Originally it was posted here : viewtopic.php?p=1294910269#p1294910269
That is here,actually it is RSI with 6 types RSIs,so you can choice RSX from - is a smoothed version with floating levels - 20 prices - interpolated mtf - full alerts and arrows package :)
My request to experts,currently it is alerting and arrowing on step crosses simply,kindly if a choice for alerting/arrowing on RSI line (yellow in the picture) cross levels (outer-middle)
thanks
Indicator is just a tool.

Use it only if it can benefit you. Leave it if you don't know how to use it optimally.

Re: Trend Indicators

60
mntiwana wrote:Fri May 05, 2017 1:02 pm Advanced StepRSI + smoothing + fl's + alerts + arrows
Originally it was posted here : viewtopic.php?p=1294910269#p1294910269
That is here,actually it is RSI with 6 types RSIs,so you can choice RSX from - is a smoothed version with floating levels - 20 prices - interpolated mtf - full alerts and arrows package :)
My request to experts,currently it is alerting and arrowing on step crosses simply,kindly if a choice for alerting/arrowing on RSI line (yellow in the picture) cross levels (outer-middle)
thanks
Hello mntiwana ,

may I ask what that blue line is and what possible settings it has?

Thx.
D.


Who is online

Users browsing this forum: Applebot [Crawler], EVGENIY86, knsxrty459, miccaluko155, Proximic [Bot], rudiarius and 278 guests