Price Data Components
Indicators Used
0
Views
0
Downloads
0
Favorites
Multi pair Laguerre RSI mtf
//+------------------------------------------------------------------+
//| Multi pair laguerre RSI.mq4 |
//| mladen |
//+------------------------------------------------------------------+
#property copyright "mladen"
#property link "mladenfx@gmail.com"
#property indicator_separate_window
#property indicator_buffers 4
#property indicator_color1 DarkOrange
#property indicator_color2 Lime
#property indicator_color3 DimGray
#property indicator_color4 DimGray
#property indicator_minimum -0.1
#property indicator_maximum 1.1
#property indicator_style3 STYLE_DOT
#property indicator_style4 STYLE_DOT
//
//
//
//
//
extern string _ = "parameters";
extern int AppliedPrice = PRICE_CLOSE;
extern double Gama1 = 0.6;
extern double Gama2 = 0.8;
extern int barsPerPair = 70;
extern string TimeFrame = "Current time frame";
extern string pairs = "EURUSD;GBPUSD;USDCAD";
extern double levelUp = 0.85;
extern double levelDown = 0.15;
extern string text = "color";
extern color textColor = Silver;
extern color backColor = C'48,48,48';
extern int separatorWidth = 6;
//
//
//
//
//
double ind_buffer1[];
double ind_buffer2[];
double ind_buffer3[];
double ind_buffer4[];
double L0[];
double L1[];
double L2[];
double L3[];
//
//
//
//
//
string aPairs[];
string shortName;
int window;
bool calculating=false;
string IndicatorFileName;
int timeFrame;
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
//
//
//
//
//
int init()
{
SetIndexBuffer(0,ind_buffer1);
if (_=="calculateLaguerre")
{
IndicatorBuffers(5);
SetIndexBuffer(1,L0); SetIndexEmptyValue(1,0);
SetIndexBuffer(2,L1); SetIndexEmptyValue(2,0);
SetIndexBuffer(3,L2); SetIndexEmptyValue(3,0);
SetIndexBuffer(4,L3); SetIndexEmptyValue(4,0);
calculating = true;
return(0);
}
//
//
//
//
//
SetIndexBuffer(1,ind_buffer2);
SetIndexBuffer(2,ind_buffer3);
SetIndexBuffer(3,ind_buffer4);
SetIndexLabel(0,"Laguerre RSI"+DoubleToStr(Gama1,2));
SetIndexLabel(1,"Laguerre RSI"+DoubleToStr(Gama1,2));
SetIndexLabel(2,NULL);
SetIndexLabel(3,NULL);
//
//
//
//
//
pairs = StringUpperCase(StringTrimLeft(StringTrimRight(pairs)));
if (StringSubstr(pairs,StringLen(pairs),1) != ";")
pairs = StringConcatenate(pairs,";");
//
//
//
//
//
string addition="";
if (IsMini()) addition="m";
if (IsDoubleDotted()) addition="..";
else if (IsDotted()) addition=".";
int s = 0;
int i = StringFind(pairs,";",s);
string current;
string temp;
while (i > 0)
{
current = StringSubstr(pairs,s,i-s)+addition;
if (iClose(current,0,0) > 0)
{
ArrayResize(aPairs,ArraySize(aPairs)+1);
aPairs[ArraySize(aPairs)-1] = current;
if (current == Symbol())
{
temp = aPairs[0];
aPairs[0] = current;
aPairs[ArraySize(aPairs)-1] = temp;
}
}
s = i + 1;
i = StringFind(pairs,";",s);
}
//
//
//
//
//
separatorWidth = MathMax(separatorWidth,4);
shortName = MakeUniqueName("Multi laguerre RSI "," ("+DoubleToStr(Gama1,2)+","+DoubleToStr(Gama2,2)+")");
IndicatorShortName(shortName);
timeFrame = stringToTimeFrame(TimeFrame);
IndicatorFileName = WindowExpertName();
//
//
//
//
//
return(0);
}
int deinit()
{
for (int i = 0; i < ArraySize(aPairs); i++) {
ObjectDelete(shortName+i);
ObjectDelete(shortName+i+i);
}
return(0);
}
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
//
//
//
//
//
int start()
{
int limit = ArraySize(aPairs);
int i,k;
//
//
//
//
//
if (calculating) { CalculateLaguerre(); return(0); }
window = WindowFind(shortName);
for(i=0,k=0; i<limit; i++) calculateLaguerreRSI(aPairs[i],barsPerPair,k,i);
//
//
//
//
//
for (i=0;i<indicator_buffers;i++) SetIndexDrawBegin(i,Bars-k);
return(0);
}
//+------------------------------------------------------------------+
//+ +
//+------------------------------------------------------------------+
//
//
//
//
//
int calculateLaguerreRSI(string symbol,int limit,int& shift,int element)
{
int i;
//
//
//
//
//
for(i=0; i<limit; i++) {
int y=iBarShift(NULL,timeFrame,Time[i]);
if (Gama1!=0) ind_buffer1[shift+i]=iCustom(symbol,timeFrame,IndicatorFileName,"calculateLaguerre",AppliedPrice,Gama1,0,y);
if (Gama2!=0) ind_buffer2[shift+i]=iCustom(symbol,timeFrame,IndicatorFileName,"calculateLaguerre",AppliedPrice,Gama2,0,y);
ind_buffer3[shift+i]=levelUp;
ind_buffer4[shift+i]=levelDown;
}
//
//
//
//
//
for (i=0;i<separatorWidth;i++) {
ind_buffer1[shift+limit+i] = EMPTY_VALUE;
ind_buffer2[shift+limit+i] = EMPTY_VALUE;
ind_buffer3[shift+limit+i] = EMPTY_VALUE;
ind_buffer4[shift+limit+i] = EMPTY_VALUE;
}
//
//
//
//
//
createLabel(symbol,element,shift+limit+separatorWidth-2,isSignalCrossing(shift));
shift += limit+separatorWidth-1;
}
//
//
//
//
//
bool isSignalCrossing(int shift)
{
double res = (ind_buffer1[shift] - ind_buffer2[shift])*
(ind_buffer1[shift+1] - ind_buffer2[shift+1]);
return(res<=0);
}
//+------------------------------------------------------------------+
//+ +
//+------------------------------------------------------------------+
//
//
//
//
//
void CalculateLaguerre()
{
int counted_bars=IndicatorCounted();
int i,limit;
if(counted_bars<0) return(-1);
if(counted_bars>0) counted_bars--;
limit=Bars-counted_bars;
//
//
//
//
//
for (i=limit; i>=0; i--)
{
double Price = iMA(NULL,0,1,0,MODE_SMA,AppliedPrice,i);
double RSI = 0.00;
double CU = 0.00;
double CD = 0.00;
L0[i] = (1.0 - Gama1)*Price + Gama1*L0[i+1];
L1[i] = -Gama1*L0[i] + L0[i+1] + Gama1*L1[i+1];
L2[i] = -Gama1*L1[i] + L1[i+1] + Gama1*L2[i+1];
L3[i] = -Gama1*L2[i] + L2[i+1] + Gama1*L3[i+1];
//
//
//
//
//
if (L0[i] >= L1[i])
CU = L0[i] - L1[i];
else CD = L1[i] - L0[i];
if (L1[i] >= L2[i])
CU = CU + L1[i] - L2[i];
else CD = CD + L2[i] - L1[i];
if (L2[i] >= L3[i])
CU = CU + L2[i] - L3[i];
else CD = CD + L3[i] - L2[i];
if (CU + CD != 0)
RSI = CU / (CU + CD) ;
ind_buffer1[i] = RSI;
}
}
//+------------------------------------------------------------------+
//+ +
//+------------------------------------------------------------------+
//
//
//
//
//
void createLabel(string symbol,int element, int shift, bool signalCrossing)
{
string name = shortName+element;
double price1 = 1.1;
double price2 = -0.1;
//
//
//
//
//
if (ObjectFind(name) == -1)
{
ObjectCreate(name,OBJ_TEXT,window,0,0);
ObjectSet(name,OBJPROP_ANGLE,90);
ObjectSetText(name,symbol);
}
ObjectSet(name,OBJPROP_TIME1 ,Time[shift]);
ObjectSet(name,OBJPROP_PRICE1,(price1+price2)/2);
if (signalCrossing)
ObjectSet(name,OBJPROP_COLOR,Gold);
else ObjectSet(name,OBJPROP_COLOR,textColor);
//
//
//
//
//
name = shortName+element+element;
if (ObjectFind(name) == -1)
{
ObjectCreate(name,OBJ_RECTANGLE,window,0,0,0,0);
ObjectSet(name,OBJPROP_COLOR,backColor);
}
ObjectSet(name,OBJPROP_TIME1,Time[shift]);
ObjectSet(name,OBJPROP_PRICE1,price1);
ObjectSet(name,OBJPROP_TIME2,Time[shift-(separatorWidth-2)]);
ObjectSet(name,OBJPROP_PRICE2,price2);
}
//+------------------------------------------------------------------+
//+ +
//+------------------------------------------------------------------+
//
//
//
//
//
string StringUpperCase(string str)
{
string s = str;
int lenght = StringLen(str) - 1;
int char;
while(lenght >= 0)
{
char = StringGetChar(s, lenght);
//
//
//
//
//
if((char > 96 && char < 123) || (char > 223 && char < 256))
s = StringSetChar(s, lenght, char - 32);
else
if(char > -33 && char < 0)
s = StringSetChar(s, lenght, char + 224);
lenght--;
}
//
//
//
//
//
return(s);
}
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
//
//
//
//
//
string MakeUniqueName(string first, string rest)
{
string result = first+(MathRand()%1001)+rest;
while (WindowFind(result)> 0)
result = first+(MathRand()%1001)+rest;
return(result);
}
bool IsMini() { return(StringFind(Symbol(),"m") > -1); }
bool IsDoubleDotted() { return(StringFind(Symbol(),"..") > -1); }
bool IsDotted() { return(StringFind(Symbol(),".") > -1); }
//
//
//
//
//
int stringToTimeFrame(string tfs)
{
for(int l = StringLen(tfs)-1; l >= 0; l--)
{
int char = StringGetChar(tfs,l);
if((char > 96 && char < 123) || (char > 223 && char < 256))
tfs = StringSetChar(tfs, l, char - 32);
else
if(char > -33 && char < 0)
tfs = StringSetChar(tfs, l, char + 224);
}
//
//
//
//
//
int tf=0;
if (tfs=="M1" || tfs=="1") tf=PERIOD_M1;
if (tfs=="M5" || tfs=="5") tf=PERIOD_M5;
if (tfs=="M15"|| tfs=="15") tf=PERIOD_M15;
if (tfs=="M30"|| tfs=="30") tf=PERIOD_M30;
if (tfs=="H1" || tfs=="60") tf=PERIOD_H1;
if (tfs=="H4" || tfs=="240") tf=PERIOD_H4;
if (tfs=="D1" || tfs=="1440") tf=PERIOD_D1;
if (tfs=="W1" || tfs=="10080") tf=PERIOD_W1;
if (tfs=="MN" || tfs=="43200") tf=PERIOD_MN1;
if (tf<Period() && tf!=0) tf=Period();
return(tf);
}
Comments
Markdown Formatting Guide
# H1
## H2
### H3
**bold text**
*italicized text*
[title](https://www.example.com)

`code`
```
code block
```
> blockquote
- Item 1
- Item 2
1. First item
2. Second item
---