Miscellaneous
0
Views
0
Downloads
0
Favorites
_minKvad
//+------------------------------------------------------------------+
//| 3.mq4 |
//| Copyright © 2005, HexSys Software Corp. |
//| http:// |
//+------------------------------------------------------------------+
#property copyright "Copyright © 2005, HexSys Software Corp."
#property link "http://www.metaquotes.net/"
#include <stdlib.mqh>
#property indicator_chart_window
#property indicator_buffers 5
#property indicator_color1 Red
#property indicator_color2 Blue
#property indicator_color3 Yellow
#property indicator_color4 Red
#property indicator_color5 Blue
//---- indicator parameters
extern int CountBar=60;
extern int PosZnak=1000;
//extern int ExtDeviation=5;
//extern int ExtBackstep=3;
//---- indicator buffers
double ExtMapBuffer[];
double ExtMapBuffer2[];
double ExtMapBuffer3[];
double ExtMapBuffer4[];
double ExtMapBuffer5[];
//+------------------------------------------------------------------+
//| Custom indicator initialization function |
//+------------------------------------------------------------------+
int init()
{
IndicatorBuffers(5);
//---- drawing settings
SetIndexStyle(0,DRAW_ARROW);
SetIndexStyle(1,DRAW_ARROW);
SetIndexStyle(2,DRAW_SECTION);
SetIndexStyle(3,DRAW_SECTION);
SetIndexStyle(4,DRAW_SECTION);
//---- indicator buffers mapping
SetIndexBuffer(0,ExtMapBuffer);
SetIndexBuffer(1,ExtMapBuffer2);
SetIndexBuffer(2,ExtMapBuffer3);
SetIndexBuffer(3,ExtMapBuffer4);
SetIndexBuffer(4,ExtMapBuffer5);
SetIndexEmptyValue(0,0.0);
SetIndexEmptyValue(1,0.0);
SetIndexEmptyValue(2,0.0);
SetIndexEmptyValue(3,0.0);
SetIndexEmptyValue(4,0.0);
ArraySetAsSeries(ExtMapBuffer,true);
ArraySetAsSeries(ExtMapBuffer2,true);
ArraySetAsSeries(ExtMapBuffer3,true);
ArraySetAsSeries(ExtMapBuffer4,true);
ArraySetAsSeries(ExtMapBuffer5,true);
//---- indicator short name
IndicatorShortName("minKvadrat");//+ExtDepth+","+ExtDeviation+","+ExtBackstep+")");
//---- initialization done
return(0);
}
int deinit()
{
//---- TODO: add your code here
ObjectDelete(CountBar+"Kva1");
ObjectDelete(CountBar+"Kva2");
ObjectDelete(CountBar+"Kva3");
//----
return(0);
}
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
int start()
{
int i;
double Sx=0,Sy=0,Sxv2=0,Sxy=0,n=0,tekY=0,x=0;
double m=0,b=0;
double max=0,min=0,pos=0,tempY=0;
string txt;
for(i=CountBar; i>1; i--)
{
ExtMapBuffer[i-1]=0; ExtMapBuffer2[i-1]=0;
if ((High[i-2]<=High[i-1]) && (High[i]<=High[i-1])) ExtMapBuffer[i-1]=High[i-1];
if ((Low[i-2]>=Low[i-1]) && (Low[i]>=Low[i-1])) ExtMapBuffer2[i-1]=Low[i-1];
}
ExtMapBuffer3[CountBar]=0; ExtMapBuffer4[CountBar]=0; ExtMapBuffer5[CountBar]=0;
ExtMapBuffer3[2]=0; ExtMapBuffer4[2]=0; ExtMapBuffer5[2]=0; //*
for(i=CountBar; i>1; i--)
{
if (ExtMapBuffer[i]!=0 || ExtMapBuffer2[i]!=0)
{
n=n+1;
x=CountBar-i;
Sx=Sx+x;
if (ExtMapBuffer[i]!=0) tekY=ExtMapBuffer[i];
if (ExtMapBuffer2[i]!=0) tekY=ExtMapBuffer2[i];
if (ExtMapBuffer[i]!=0 && ExtMapBuffer2[i]!=0) tekY=(ExtMapBuffer[i]+ExtMapBuffer2[i])/2;
Sy=Sy+tekY;
Sxv2=Sxv2+x*x;
Sxy=Sxy+x*tekY;
}
}
m=(n*Sxy-Sx*Sy)/(n*(Sxv2)-Sx*Sx);
b=(Sy*Sxv2-Sx*Sxy)/(n*(Sxv2)-Sx*Sx);
//Print("Sx:",DoubleToStr(Sx,4)," Sy:",DoubleToStr(Sy,4)," Sxy:",DoubleToStr(Sxy,4),
// " Sxv2:",DoubleToStr(Sxv2,4)," n:",DoubleToStr(n,4),," m:",DoubleToStr(m,12),
// " b:",DoubleToStr(b,4));
ExtMapBuffer3[CountBar]=b;
ExtMapBuffer3[2]=m*(CountBar-2)+b;
//---------------------------------------------
max=0;min=1000;pos=0;
for(i=CountBar; i>1; i--)
{
if (ExtMapBuffer[i]!=0 || ExtMapBuffer2[i]!=0)
{
x=CountBar-i;
if (ExtMapBuffer[i]!=0) tekY=ExtMapBuffer[i];
if (ExtMapBuffer2[i]!=0) tekY=ExtMapBuffer2[i];
if (ExtMapBuffer[i]!=0 && ExtMapBuffer2[i]!=0) tekY=(ExtMapBuffer[i]+ExtMapBuffer2[i])/2;
tempY=tekY-(m*x+b);
if (tempY>=max) max=tempY;
if (tempY<=min) min=tempY;
//if (MathAbs(tekY-(m*x+b))>=max) { max=MathAbs(tekY-(m*x+b)); pos=i; }
}
}
ExtMapBuffer4[CountBar]=b+max;
ExtMapBuffer4[2]=m*(CountBar-2)+b+max;
ExtMapBuffer5[CountBar]=b+min;
ExtMapBuffer5[2]=m*(CountBar-2)+(b+min);
//Print("K(",CountBar,") [m]",DoubleToStr(m,9)," [min]",DoubleToStr(ExtMapBuffer5[2],4),
// " [max]",DoubleToStr(ExtMapBuffer4[2],4)," [srd]",DoubleToStr(ExtMapBuffer3[2],4),
// " [max-srd]",DoubleToStr(ExtMapBuffer4[2]-ExtMapBuffer3[2],4),
// " [srd-min]",DoubleToStr(ExtMapBuffer3[2]-ExtMapBuffer5[2],4),
// " [Bid-max]",DoubleToStr(Bid-ExtMapBuffer4[2],4),
// " [Bid-srd]",DoubleToStr(Bid-ExtMapBuffer3[2],4),
// " [Bid-min]",DoubleToStr(Bid-ExtMapBuffer5[2],4),
// );
//-------------------------------------------
txt=" ";
txt=txt+" "+DoubleToStr(m*(CountBar-2)+b,4);
txt=txt+" /"+DoubleToStr(MathArctan(m*PosZnak)*(180/3.141592653589793),2);
if(ObjectFind(CountBar+"Kva1") != 0)
{
ObjectCreate(CountBar+"Kva1", OBJ_TEXT, 0, Time[0], m*(CountBar-2)+b);
ObjectSetText(CountBar+"Kva1", txt, 10, "Arial", White);
}
else
{
ObjectSetText(CountBar+"Kva1", txt, 10, "Arial", White);
ObjectMove(CountBar+"Kva1", 0, Time[0], m*(CountBar-2)+b);
}
//-------------------------------------------
txt=" ";
txt=txt+"+"+DoubleToStr((ExtMapBuffer4[2]-ExtMapBuffer3[2]),4)+" pt";
txt=txt+" ["+DoubleToStr(Bid-ExtMapBuffer4[2],4)+"]";
if(ObjectFind(CountBar+"Kva2") != 0)
{
ObjectCreate(CountBar+"Kva2", OBJ_TEXT, 0, Time[0], m*(CountBar-2)+b+max);
ObjectSetText(CountBar+"Kva2", txt, 8, "Arial", White);
}
else
{
ObjectSetText(CountBar+"Kva2", txt, 8, "Arial", White);
ObjectMove(CountBar+"Kva2", 0, Time[0], m*(CountBar-2)+b+max);
}
//-------------------------------------------
txt=" ";
txt=txt+"-"+DoubleToStr((ExtMapBuffer3[2]-ExtMapBuffer5[2]),4)+" pt";
txt=txt+" ["+DoubleToStr(Bid-ExtMapBuffer5[2],4)+"]";
if(ObjectFind(CountBar+"Kva3") != 0)
{
ObjectCreate(CountBar+"Kva3", OBJ_TEXT, 0, Time[0], m*(CountBar-2)+b+min);
ObjectSetText(CountBar+"Kva3", txt, 8, "Arial", White);
}
else
{
ObjectSetText(CountBar+"Kva3", txt, 8, "Arial", White);
ObjectMove(CountBar+"Kva3", 0, Time[0], m*(CountBar-2)+b+min);
}
}//end
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
---