how to draw trendline on rsi window?

 

hi

i'm trying to draw a trendline on rsi indicator window but i couldnt

i tried subwindow and subID and ind values in objectCreate function in subwindow param.

 can someone help me?

void drawTrendLine(string symbol, ENUM_TIMEFRAMES timeframe, ushort hp1, ushort hp2){
   
   long winHandle = 0;
   long chartID = ChartID();
   long subID;

   datetime time1 = iTime(symbol, timeframe, hp1);
   datetime time2 = iTime(symbol, timeframe, hp2);

   double price1 = getRSI(symbol, timeframe, hp1);
   double price2 = getRSI(symbol, timeframe, hp2);

   int subwindow;
   subwindow = ChartWindowFind(chartID, "RSI(6)");
   ChartGetInteger(chartID, CHART_WINDOW_HANDLE, 1, subID);
   int ind = ChartIndicatorGet(chartID, subwindow, "RSI(6)");

   ObjectCreate(chartID, "trendlineAD", OBJ_TREND, subwindow, time1, price1, time2, price2);
   ObjectSetInteger(chartID, "trendlineAD", OBJPROP_RAY, true);
   ObjectSetInteger(chartID,"trendlineAD", OBJPROP_STYLE, STYLE_SOLID);
   ObjectSetInteger(chartID, "trendlineAD", OBJPROP_COLOR, clrAntiqueWhite);
   ObjectSetInteger(chartID, "trendlineAD", OBJPROP_WIDTH, 1);
   
}
 
appacki:

hi

i'm trying to draw a trendline on rsi indicator window but i couldnt

i tried subwindow and subID and ind values in objectCreate function in subwindow param.

 can someone help me?

Have a look at Alain Verleyen's MACD Divergence indicator code. It contains a custom trendlines function that uses inputs to control indicator window selection:

//+------------------------------------------------------------------+
//| Draw a trend line on main chart or on indicator                  |
//+------------------------------------------------------------------+
void DrawTrendLine(ENUM_TRENDLINE_TYPE window,datetime x1,datetime x2,double y1,double y2,color lineColor,ENUM_LINE_STYLE style)
  {
   string label=OBJECT_PREFIX+"#"+IntegerToString(window)+DoubleToString(x1,0);
   int subwindow=(window==TRENDLINE_MAIN) ? 0 : ChartWindowFind();
   ObjectDelete(0,label);
   ObjectCreate(0,label,OBJ_TREND,subwindow,x1,y1,x2,y2,0,0);
   ObjectSetInteger(0,label,OBJPROP_RAY,false);
   ObjectSetInteger(0,label,OBJPROP_COLOR,lineColor);
   ObjectSetInteger(0,label,OBJPROP_STYLE,style);
  }
Files:
 
Ryan L Johnson #:

Have a look at Alain Verleyen's MACD Divergence indicator code. It contains a custom trendlines function that uses inputs to control indicator window selection:

subwindow = ChartWindowFind(chartID, "RSI(6)");

In my code, chartWindowFind returns a value of 1 and when I use the this value in the ObjectCreate function in the subwindow parameter, nothing happens.

It seems that Alain Verleyen also used the same method.

 
appacki #:

In my code, chartWindowFind returns a value of 1 and when I use the this value in the ObjectCreate function in the subwindow parameter, nothing happens.

It seems that Alain Verleyen also used the same method.

I loaded up the RSI indicator from my MT5 Indicators==>Examples folder and if you're using that indicator, you appear to have inserted a space in the indicator short name that the indicator does not have. The exact short name string is required. Try removing the space.

RSI

 
Ryan L Johnson #:

I loaded up the RSI indicator from my MT5 Indicators==>Examples folder and if you're using that indicator, you appear to have inserted a space in the indicator short name that the indicator does not have. The exact short name string is required. Try removing the space.


There is no space in the code provided by the OP.
 
I think that we need to see the greater context of the OP's code, i.e., where the custom function is called.
 
this is my code
Files:
testLine.mq5  3 kb
 
appacki #:
this is my code

Thanks for posting your complete file. Unfortunately, you're mixing indicator code with EA code.

Did you download and inspect Alain Verleyen's complete indicator code in my Post #1?

For an introduction to indicator coding, see:

Articles

Custom Indicators (Part 1): A Step-by-Step Introductory Guide to Developing Simple Custom Indicators in MQL5

Kelvin Muturi Muigua, 2024.05.02 13:26

Learn how to create custom indicators using MQL5. This introductory article will guide you through the fundamentals of building simple custom indicators and demonstrate a hands-on approach to coding different custom indicators for any MQL5 programmer new to this interesting topic.

For an introduction to EA coding, see:

Articles

Step-By-Step Guide to writing an Expert Advisor in MQL5 for Beginners

Samuel Olowoyo, 2010.06.09 11:37

The Expert Advisors programming in MQL5 is simple, and you can learn it easy. In this step by step guide, you will see the basic steps required in writing a simple Expert Advisor based on a developed trading strategy. The structure of an Expert Advisor, the use of built-in technical indicators and trading functions, the details of the Debug mode and use of the Strategy Tester are presented.

 
Ryan L Johnson #:

Thanks for posting your complete file. Unfortunately, you're mixing indicator code with EA code.

Did you download and inspect Alain Verleyen's complete indicator code in my Post #1?

For an introduction to indicator coding, see:


For an introduction to EA coding, see:


Thanks ryan
Using the links you provided and mixing the indicator with the ea and a little debugging I was able to achieve what I wanted