RSI Trend lines drawing problem ! - page 2

 
Documentation on MQL5: Custom Indicators / Indicator Styles in Examples / DRAW_LINE
Documentation on MQL5: Custom Indicators / Indicator Styles in Examples / DRAW_LINE
  • www.mql5.com
//|                                                    DRAW_LINE.mq5 | //|                        Copyright 2011, MetaQuotes Software Corp. | //|                                              https://www.mql5.com | //| Custom indicator initialization function                         |...
 
pls keep me posted :)
 
Yes, I know how to build indicators and objects, this is not the problem. I think you may have misunderstood me in the beginning- I posted my code and the result of the code - the lines drawn were wrong for some reason, I posted a pic. I simply don’t know why it works this way
 

It depends on how you draw these lines / objects.

Indicators count up from zero.

In a loop you could also count down.

This has its effect on the objects because you swap the beginning and the end points of these objects, so you have to know up front increments or decrements, and start point / end points of these objects.

You only have to swap values until it plots correctly.

 
Stanislav Ivanov:
Yes, I know how to build indicators and objects, this is not the problem. I think you may have misunderstood me in the beginning- I posted my code and the result of the code - the lines drawn were wrong for some reason, I posted a pic. I simply don’t know why it works this way

Populate the RSI buffer first, then use a different loop to analyse it.

//+------------------------------------------------------------------+
//| 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[])
  {
//---
   if(rates_total<RSIPeriod+RSIDirectionPeriod)
      return(0);
   datetime time1,time2;
   double point1,point2;
//---
   int limit=!prev_calculated?rates_total-RSIPeriod-1:rates_total-prev_calculated;
//---
   for(int i=limit; i>=0; i--)
      ExtRsiBuffer[i]=iRSI(NULL,0,RSIPeriod,PRICE_TYPICAL,i);
//---
   limit=!prev_calculated?rates_total-RSIPeriod-RSIDirectionPeriod-2:rates_total-prev_calculated+1;
//---
   for(int i=limit; i>0; i--)
     { 
      double highest=ExtRsiBuffer[ArrayMaximum(ExtRsiBuffer,RSIDirectionPeriod,i)];
      double lowest=ExtRsiBuffer[ArrayMinimum(ExtRsiBuffer,RSIDirectionPeriod,i)];
      //----------------------------------------------------------------------------------------------------+
 
Ernst Van Der Merwe:

Populate the RSI buffer first, then use a different loop to analyse it.

Thanks
 
How is your project going ?
 
siemsons:
How is your project going ?

 I had problems with the array indices, however i have found another way to calculate what i need, its just i didnt have the time to set it up the last few day, when i do and if eventually works as desired, ill post an update

 

Hey. I'm investigating RSI Trendlines, too. I'm coding my indicator and strategy in a different technology (TradingView's PineScript). And I feel like I'm getting somewhere (see screenshot).

RSI Trendlines

But I'm seeing gaps in the conceptual phase, so I'm looking to discuss with folks around here.

So is anyone interested in discussing progress and ideas in RSI Trendlines? Maybe @Stanislav Ivanov ?

 
Marco vd Heijden:

Of course you can do that, it was designed to do that.

Just add more buffers.

Here is a quick and simple Donchian Channel example with 3 Buffers:

Hey, I was wondering if you don't mind changing this indicator into a mq4? I tried to do it myself however im a beginner coder, this would be very much appreciated! thank you in advance :)

//+------------------------------------------------------------------+
//|                                            Donchian-reversed.mq5 |
//|        Copyright 2018,Marco vd Heijden,MetaQuotes Software Corp. |
//|                                             https://www.mql5.com |
//+------------------------------------------------------------------+
#property copyright "Copyright 2018,Marco vd Heijden,MetaQuotes Software Corp."
#property link      "https://www.mql5.com"
#property version   "1.00"
#property indicator_chart_window
#property indicator_buffers 3
#property indicator_plots   3
//--- plot High
#property indicator_label1  "High"
#property indicator_type1   DRAW_LINE
#property indicator_color1  clrAliceBlue
#property indicator_style1  STYLE_SOLID
#property indicator_width1  1
//--- plot Center
#property indicator_label2  "Center"
#property indicator_type2   DRAW_LINE
#property indicator_color2  clrYellow
#property indicator_style2  STYLE_SOLID
#property indicator_width2  1
//--- plot Low
#property indicator_label3  "Low"
#property indicator_type3   DRAW_LINE
#property indicator_color3  clrAliceBlue
#property indicator_style3  STYLE_SOLID
#property indicator_width3  1
//--- input parameters
input int      period=20;// Period
//--- indicator buffers
double         HighBuffer[];
double         CenterBuffer[];
double         LowBuffer[];
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int OnInit()
  {
//--- indicator buffers mapping
   SetIndexBuffer(0,HighBuffer,INDICATOR_DATA);
   SetIndexBuffer(1,CenterBuffer,INDICATOR_DATA);
   SetIndexBuffer(2,LowBuffer,INDICATOR_DATA);

//---
   return(INIT_SUCCEEDED);
  }
//+------------------------------------------------------------------+
//| 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[])
  {
//---
   int limit;
   if(prev_calculated==0)
     {
      limit=0;
     }
   else
     {
      limit=prev_calculated-1;
     }
//--- calculate values
   for(int i=limit;i<rates_total && !IsStopped();i++)
     {
      //--- high   
      HighBuffer[i]=high[ArrayMaximum(high,i,period)];

      //--- low
      LowBuffer[i]=low[ArrayMinimum(low,i,period)];

      //--- center
      CenterBuffer[i]=(HighBuffer[i]+LowBuffer[i])/2;
     } 
//--- return value of prev_calculated for next call
   return(rates_total);
  }
//+------------------------------------------------------------------+