// Code formatted, no changes... #property indicator_separate_window #property indicator_minimum 0 #property indicator_maximum 100 #property indicator_level1 20 #property indicator_level2 80 #property indicator_buffers 1 #property indicator_color1 Turquoise //---- input parameters extern int RSI_Period=34; extern int lookback=13; extern int summing=3; //---- buffers double SwingRSI_Buffer[]; double RSI_Buffer[]; double HiRSI_Buffer[]; double LowRSI_Buffer[]; double RSILow_Buffer[]; double HiLow_Buffer[]; double ema_Buffer1[]; double ema_Buffer2[]; //+------------------------------------------------------------------+ //| Custom indicator initialization function | //+------------------------------------------------------------------+ int init() { //---- indicators IndicatorBuffers(8); SetIndexBuffer(0,SwingRSI_Buffer); SetIndexStyle(0,DRAW_LINE); SetIndexDrawBegin(0,RSI_Period+lookback); SetIndexBuffer(1,RSI_Buffer); SetIndexBuffer(2,HiRSI_Buffer); SetIndexBuffer(3,LowRSI_Buffer); SetIndexBuffer(4,RSILow_Buffer); SetIndexBuffer(5,HiLow_Buffer); SetIndexBuffer(6,ema_Buffer1); SetIndexBuffer(7,ema_Buffer2); //---- name for data Window and indicator subwindow label IndicatorShortName("RSI Swing("+RSI_Period+","+lookback+","+summing+")"); //---- Init done return(0); } //+------------------------------------------------------------------+ //| Custom indicator iteration function | //+------------------------------------------------------------------+ int start() { int i,limit; int counted_bars=IndicatorCounted(); //---- last counted bar will be recounted if(counted_bars>0) counted_bars--; limit=Bars-counted_bars; for(i=0; i<limit; i++) { RSI_Buffer[i]=iRSI(NULL,0,RSI_Period,PRICE_CLOSE,i); HiRSI_Buffer[i] = RSI_Buffer[ArrayMaximum(RSI_Buffer,lookback,i)]; LowRSI_Buffer[i] = RSI_Buffer[ArrayMinimum(RSI_Buffer,lookback,i)]; RSILow_Buffer[i] = (RSI_Buffer[i]- LowRSI_Buffer[i]); HiLow_Buffer[i] = (HiRSI_Buffer[i]-LowRSI_Buffer[i]); ema_Buffer1[i] = iMAOnArray(RSILow_Buffer,0,summing,0,MODE_SMA,i); ema_Buffer2[i] = iMAOnArray(HiLow_Buffer,0,summing,0,MODE_SMA,i); SwingRSI_Buffer[i] = ema_Buffer1[i]/(0.1+(ema_Buffer2[i]))*100; } //---- return(0); } //+------------------------------------------------------------------+
Try reversing your loop. if that doesn't do it, break things into two loops.
First one filles the array you are working with, second takes action on it.
for(i=Limit; i>=0; i--) { RSI_Buffer[i] = iRSI(NULL,0,RSI_Period,PRICE_CLOSE,i); } for(i=Limit; i>=0; i--) { HiRSI_Buffer[i] = RSI_Buffer[ArrayMaximum(RSI_Buffer,lookback,i)]; LowRSI_Buffer[i] = RSI_Buffer[ArrayMinimum(RSI_Buffer,lookback,i)]; RSILow_Buffer[i] = (RSI_Buffer[i]- LowRSI_Buffer[i]); HiLow_Buffer[i] = (HiRSI_Buffer[i]-LowRSI_Buffer[i]); ema_Buffer1[i] = iMAOnArray(RSILow_Buffer,0,summing,0,MODE_SMA,i); ema_Buffer2[i] = iMAOnArray(HiLow_Buffer,0,summing,0,MODE_SMA,i); SwingRSI_Buffer[i] = ema_Buffer1[i]/(0.1+(ema_Buffer2[i]))*100; }
Try reversing your loop. if that doesn't do it, break things into two loops.
First one filles the array you are working with, second takes action on it.
Thanks phy,
I tried your last proposition with the two loops.
But still the same problem. There is some improvement, instead of twice F5 (compile) I only need to do it once.
I hope you have some more ideas.
Many thanks in advance....
I tried now to separate all the loops and YES! this works!!!
Thanks very much for your help,
Sylvano
#property indicator_separate_window
#property indicator_minimum 0
#property indicator_maximum 100
#property indicator_level1 20
#property indicator_level2 80
#property indicator_buffers 1
#property indicator_color1 Turquoise
//---- input parameters
extern int RSI_Period=34;
extern int lookback=13;
extern int summing=3;
//---- buffers
double SwingRSI_Buffer[];
double RSI_Buffer[];
double HiRSI_Buffer[];
double LowRSI_Buffer[];
double RSILow_Buffer[];
double HiLow_Buffer[];
double ema_Buffer1[];
double ema_Buffer2[];
//+------------------------------------------------------------------+
//| Custom indicator initialization function |
//+------------------------------------------------------------------+
int init()
{
//---- indicators
IndicatorBuffers(8);
SetIndexBuffer(0,SwingRSI_Buffer);
SetIndexStyle(0,DRAW_LINE);
SetIndexDrawBegin(0,RSI_Period);
SetIndexBuffer(1,RSI_Buffer);
SetIndexBuffer(2,HiRSI_Buffer);
SetIndexBuffer(3,LowRSI_Buffer);
SetIndexBuffer(4,RSILow_Buffer);
SetIndexBuffer(5,HiLow_Buffer);
SetIndexBuffer(6,ema_Buffer1);
SetIndexBuffer(7,ema_Buffer2);
//---- name for data Window and indicator subwindow label
IndicatorShortName("RSI Swing("+RSI_Period+","+lookback+","+summing+")");
//---- Init done
return(0);
}
//+------------------------------------------------------------------+
//| Custom indicator iteration function |
//+------------------------------------------------------------------+
int start()
{
int i,limit;
int counted_bars=IndicatorCounted();
//---- last counted bar will be recounted
if(counted_bars>0) counted_bars--;
limit=Bars-counted_bars;
for(i=limit; i>=0; i--)
{
RSI_Buffer[i] = iRSI(NULL,0,RSI_Period,PRICE_CLOSE,i);
}
for(i=limit; i>=0; i--)
{
HiRSI_Buffer[i] = RSI_Buffer[ArrayMaximum(RSI_Buffer,lookback,i)];
LowRSI_Buffer[i] = RSI_Buffer[ArrayMinimum(RSI_Buffer,lookback,i)];
}
for(i=limit; i>=0; i--)
{
RSILow_Buffer[i] = (RSI_Buffer[i]- LowRSI_Buffer[i]);
HiLow_Buffer[i] = (HiRSI_Buffer[i]-LowRSI_Buffer[i]);
}
for(i=limit; i>=0; i--)
{
ema_Buffer1[i] = iMAOnArray(RSILow_Buffer,0,summing,0,MODE_SMA,i);
ema_Buffer2[i] = iMAOnArray(HiLow_Buffer,0,summing,0,MODE_SMA,i);
}
for(i=limit; i>=0; i--)
{
SwingRSI_Buffer[i] = ema_Buffer1[i]/(0.1+(ema_Buffer2[i]))*100;
}
//----
return(0);
}
//+------------------------------------------------------------------+

- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
I am completely new to MQL4. But trying to start using MQL4 for FOREX trading, I have an indicator I use in MetaStock, I call RSI-Swing.
So, I need to convert it to MQL4. Trying to gain time is there anybody who could help?
This is the MetaStock code:
peri:=Input("RSI period: ",1,100,34);
lbav:=Input("Lookback average: ",1,100,13);
suav:=Input("Summing average: ",1,50,3);
(Sum(RSI(peri)-LLV(RSI(peri),lbav),suav)/(0.1+Sum(HHV(RSI(peri),lbav)-LLV(RSI(peri),lbav),suav)))*100;
In plain language:
Input the default value for the RSI (peri).
Input a lookback period (lbav).
Input the summing period (suav).
RSI(peri): the RSI indicator
LLV(RSI(peri),lbav),suav): Lowest low value of the RSI indicator in the lookback period.
(Sum(RSI(peri)-LLV(RSI(peri),lbav),suav): Summing of the substraction result over the summing average.
HHV: Highest high value.
Many thanks in advance
It seems I have a working version now. But I keep having the problem that this indicator only appears after twice doing a compile (F5) action. When I change to a different time setting it is gone and only re-appears after twice doing a compilation again.
HELP!!!! very much appreciated...
This is the code:
#property indicator_separate_window
#property indicator_minimum 0
#property indicator_maximum 100
#property indicator_level1 20
#property indicator_level2 80
#property indicator_buffers 1
#property indicator_color1 Turquoise
//---- input parameters
extern int RSI_Period=34;
extern int lookback=13;
extern int summing=3;
//---- buffers
double SwingRSI_Buffer[];
double RSI_Buffer[];
double HiRSI_Buffer[];
double LowRSI_Buffer[];
double RSILow_Buffer[];
double HiLow_Buffer[];
double ema_Buffer1[];
double ema_Buffer2[];
//+------------------------------------------------------------------+
//| Custom indicator initialization function |
//+------------------------------------------------------------------+
int init()
{
//---- indicators
IndicatorBuffers(8);
SetIndexBuffer(0,SwingRSI_Buffer);
SetIndexStyle(0,DRAW_LINE);
SetIndexDrawBegin(0,RSI_Period+lookback);
SetIndexBuffer(1,RSI_Buffer);
SetIndexBuffer(2,HiRSI_Buffer);
SetIndexBuffer(3,LowRSI_Buffer);
SetIndexBuffer(4,RSILow_Buffer);
SetIndexBuffer(5,HiLow_Buffer);
SetIndexBuffer(6,ema_Buffer1);
SetIndexBuffer(7,ema_Buffer2);
//---- name for data Window and indicator subwindow label
IndicatorShortName("RSI Swing("+RSI_Period+","+lookback+","+summing+")");
//---- Init done
return(0);
}
//+------------------------------------------------------------------+
//| Custom indicator iteration function |
//+------------------------------------------------------------------+
int start()
{
int i,limit;
int counted_bars=IndicatorCounted();
//---- last counted bar will be recounted
if(counted_bars>0) counted_bars--;
limit=Bars-counted_bars;
for(i=0; i<limit; i++)
{
RSI_Buffer[i]=iRSI(NULL,0,RSI_Period,PRICE_CLOSE,i);
HiRSI_Buffer[i] = RSI_Buffer[ArrayMaximum(RSI_Buffer,lookback,i)];
LowRSI_Buffer[i] = RSI_Buffer[ArrayMinimum(RSI_Buffer,lookback,i)];
RSILow_Buffer[i] = (RSI_Buffer[i]- LowRSI_Buffer[i]);
HiLow_Buffer[i] = (HiRSI_Buffer[i]-LowRSI_Buffer[i]);
ema_Buffer1[i] = iMAOnArray(RSILow_Buffer,0,summing,0,MODE_SMA,i);
ema_Buffer2[i] = iMAOnArray(HiLow_Buffer,0,summing,0,MODE_SMA,i);
SwingRSI_Buffer[i] = ema_Buffer1[i]/(0.1+(ema_Buffer2[i]))*100;
}
//----
return(0);
}
//+------------------------------------------------------------------+