How can I draw arrow on chart based on RSI cross below 50 and above 50?
How can I draw arrow on chart based on RSI cross below 50 and above 50?
Loading saved threads...
Raphael Tunji · External communityPost link
External question — Stack Overflow Stack Exchange
Author: Raphael Tunji
Original post: https://stackoverflow.com/questions/77024981
License: CC BY-SA 4.0 — https://creativecommons.org/licenses/by-sa/4.0/
Adaptation: HTML converted to plain text; contact email addresses removed.
I have tried using this code
#property indicator_chart_window
#property indicator_buffers 2
#property indicator_width1 2
#property indicator_width2 2
#property indicator_color1 clrRed
#property indicator_color2 clrGreen
double upArrow[],downArrow[];
int draw;
int OnInit(){
IndicatorSetString(INDICATOR_SHORTNAME,"Arrow");
// Arrow
PlotIndexSetInteger(0,PLOT_DRAW_TYPE,DRAW_ARROW,1);
PlotIndexSetInteger(0,PLOT_ARROW,233); // 233 159
PlotIndexSetDouble(0,PLOT_EMPTY_VALUE,0.0);
PlotIndexSetString(0,PLOT_LABEL,"Buy");
PlotIndexSetInteger(0,PLOT_DRAW_BEGIN,draw);
SetIndexBuffer(0,upArrow);
PlotIndexSetInteger(1,PLOT_DRAW_TYPE,DRAW_ARROW,1);
PlotIndexSetInteger(1,PLOT_ARROW,234); // 234 233
PlotIndexSetDouble(1,PLOT_EMPTY_VALUE,0.0);
PlotIndexSetString(1,PLOT_LABEL,"Sell");
PlotIndexSetInteger(1,PLOT_DRAW_BEGIN,draw);
SetIndexBuffer(1,downArrow);
return(INIT_SUCCEEDED);
}
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 = rates_total - prev_calculated;
double RSIArray[];
int rsi=iRSI(Symbol(),Period(),14,PRICE_CLOSE);
ArraySetAsSeries(RSIArray,true);
CopyBuffer(rsi,0,0,limit,RSIArray);
MqlRates PriceInfo[];
ArraySetAsSeries(PriceInfo,true);
int PriceData = CopyRates(Symbol(),Period(),0,limit,PriceInfo);
for(int i = limit - 2; i >= 0; i--) {
double rsi_1 = RSIArray[i];
double rsi_2 = RSIArray[i+1];
if(rsi_2 < 50 && rsi_1 >= 50){
upArrow[i]=low[i+1]-10*Point();
Print("Cross above RSI 50 on candle: ", i, ", ", PriceInfo[i].close);
}else if(rsi_2 > 50 && rsi_1 <= 50){
downArrow[i]=high[i+1]+10*Point();
Print("Cross below RSI 50 on candle: ", i, ", ", PriceInfo[i].close);
}
}
return(rates_total);
}
I am not seeing any arrow on chart when I attach the indicator, I actually don't know what I am doing wrong. please help me out. I was able to see the print statement when the conditions are met, but the arrows are not drawn. I have also confirm that code to get RSI values is correct, same with the code to get the prices.
Quote
Report
Post Reply
Quoted from Forex.com.bd-Editorial External question — Stack Overflow Stack Exchange Author: Raphael Tunji Source score (net votes, not local likes): 1 Original post: https://stackoverflow.com/questions/77024981 License: CC BY-SA 4.0 — https://creativecommons.org/licenses/by-sa/4.0/ Adaptation: HTML converted to plain text; contact email addresses removed. I have tried using this code #property indicator_chart_window #property indicator_buffers 2 #property indicator_width1 2 #property indicator_width2 2 #property indicator_color1 clrRed #property indicator_color2 clrGreen double upArrow[],downArrow[]; int draw; int OnInit(){ IndicatorSetString(INDICATOR_SHORTNAME,"Arrow"); // Arrow PlotIndexSetInteger(0,PLOT_DRAW_TYPE,DRAW_ARROW,1); PlotIndexSetInteger(0,PLOT_ARROW,233); // 233 159 PlotIndexSetDouble(0,PLOT_EMPTY_VALUE,0.0); PlotIndexSetString(0,PLOT_LABEL,"Buy"); PlotIndexSetInteger(0,PLOT_DRAW_BEGIN,draw); SetIndexBuffer(0,upArrow); PlotIndexSetInteger(1,PLOT_DRAW_TYPE,DRAW_ARROW,1); PlotIndexSetInteger(1,PLOT_ARROW,234); // 234 233 PlotIndexSetDouble(1,PLOT_EMPTY_VALUE,0.0); PlotIndexSetString(1,PLOT_LABEL,"Sell"); PlotIndexSetInteger(1,PLOT_DRAW_BEGIN,draw); SetIndexBuffer(1,downArrow); return(INIT_SUCCEEDED); } 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 = rates_total - prev_calculated; double RSIArray[]; int rsi=iRSI(Symbol(),Period(),14,PRICE_CLOSE); ArraySetAsSeries(RSIArray,true); CopyBuffer(rsi,0,0,limit,RSIArray); MqlRates PriceInfo[]; ArraySetAsSeries(PriceInfo,true); int PriceData = CopyRates(Symbol(),Period(),0,limit,PriceInfo); for(int i = limit - 2; i >= 0; i--) { double rsi_1 = RSIArray[i]; double rsi_2 = RSIArray[i+1]; if(rsi_2 < 50 && rsi_1 >= 50){ upArrow[i]=low[i+1]-10*Point(); Print("Cross above RSI 50 on candle: ", i, ", ", PriceInfo[i].close); }else if(rsi_2 > 50 && rsi_1 <= 50){ downArrow[i]=high[i+1]+10*Point(); Print("Cross below RSI 50 on candle: ", i, ", ", PriceInfo[i].close); } } return(rates_total); } I am not seeing any arrow on chart when I attach the indicator, I actually don't know what I am doing wrong. please help me out. I was able to see the print statement when the conditions are met, but the arrows are not drawn. I have also confirm that code to get RSI values is correct, same with the code to get the prices.
Checking account access…