Indicators Used
0
Views
0
Downloads
0
Favorites
schaff_Plot_dcec
//+------------------------------------------------------------------+
//| Plot.mq4 |
//| mladen |
//+------------------------------------------------------------------+
//2009fxtsd mod extern colors rg colorscheme
#property copyright "mladen"
#property link "mladenfx@gmail.com"
#property indicator_separate_window
#property indicator_buffers 1
#property indicator_color1 Red
#property indicator_minimum -5
#property indicator_maximum 105
#property indicator_level1 85
#property indicator_level2 15
#property indicator_levelcolor DarkSlateGray
//
//
//
//
//
extern string _ = "parameters";
extern int STCPeriod = 10;
extern int FastMAPeriod = 23;
extern int SlowMAPeriod = 50;
extern int MaxBarsToCount = 500;
extern bool externColors =false;
extern color color1 = ForestGreen;
extern color color2 = Red;
extern int width_ = 2;
//
//
//
//
//
double stcBuffer[];
double macdBuffer[];
double fastKBuffer[];
double fastDBuffer[];
double fastKKBuffer[];
//
//
//
//
//
string IndicatorFileName;
bool calculating=false;
int Window;
#define shortName "Schaff trend cycle - ploted"
#define leftEnd "stc"
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
//
//
//
//
//
int init()
{
if (_ == "calculateSCHAF")
{
calculating = true;
IndicatorBuffers(5);
SetIndexBuffer(0,stcBuffer);
SetIndexBuffer(1,macdBuffer);
SetIndexBuffer(2,fastKBuffer);
SetIndexBuffer(3,fastDBuffer);
SetIndexBuffer(4,fastKKBuffer);
return(0);
}
//
//
//
//
//
IndicatorShortName(shortName);
IndicatorFileName = WindowExpertName();
return(0);
}
//
//
//
//
//
int deinit()
{
deleteAll(); return(0);
}
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
//
//
//
//
//
int start()
{
int counted_bars=IndicatorCounted();
int limit,i;
if(counted_bars<0) return(-1);
if(counted_bars>0) counted_bars--;
//
//
//
//
//
if (calculating)
{
limit = Bars-counted_bars;
for(i = limit; i >= 0; i--)
{
macdBuffer[i] = iMA(NULL,0,FastMAPeriod,0,MODE_EMA,PRICE_CLOSE,i)-
iMA(NULL,0,SlowMAPeriod,0,MODE_EMA,PRICE_CLOSE,i);
//
//
//
//
//
double lowMacd = minValue(macdBuffer,i);
double highMacd = maxValue(macdBuffer,i)-lowMacd;
if (highMacd > 0)
fastKBuffer[i] = 100*((macdBuffer[i]-lowMacd)/highMacd);
else fastKBuffer[i] = fastKBuffer[i+1];
fastDBuffer[i] = fastDBuffer[i+1]+0.5*(fastKBuffer[i]-fastDBuffer[i+1]);
//
//
//
//
//
double lowStoch = minValue(fastDBuffer,i);
double highStoch = maxValue(fastDBuffer,i)-lowStoch;
if (highStoch > 0)
fastKKBuffer[i] = 100*((fastDBuffer[i]-lowStoch)/highStoch);
else fastKKBuffer[i] = fastKKBuffer[i+1];
stcBuffer[i] = stcBuffer[i+1]+0.5*(fastKKBuffer[i]-stcBuffer[i+1]);
}
return(0);
}
//
//
//
//
//
limit = MathMin(Bars,MaxBarsToCount);
Window = WindowFind(shortName);
plot.setBack(false);
deleteAll();
//
//
//
//
//
for(i = limit; i >= 0; i--)
{
double prevSTC = iCustom(NULL,0,IndicatorFileName,"calculateSCHAF",STCPeriod,FastMAPeriod,SlowMAPeriod,0,i+1);
double currSTC = iCustom(NULL,0,IndicatorFileName,"calculateSCHAF",STCPeriod,FastMAPeriod,SlowMAPeriod,0,i);
//
//
//
//
//
color theColor = ObjectGet(leftEnd+Time[i+1],OBJPROP_COLOR);
if (externColors)
{
if (currSTC>prevSTC) theColor = color1;
if (currSTC<prevSTC) theColor = color2;
}
else {
if (currSTC>prevSTC) theColor = rgb(0,101+MathRound(currSTC*1.5),0); //greenup .mod
if (currSTC<prevSTC) theColor = rgb(154+MathRound(currSTC*1.5),0,0); //redUp
}
// if (currSTC>prevSTC) theColor = rgb(0,100+MathRound(currSTC*1.5),150); //aqua
// if (currSTC<prevSTC) theColor = rgb(255-MathRound(currSTC*1.5),0,150); //magenta
plot(leftEnd,currSTC,prevSTC,i,i+1,theColor);
}
return(0);
}
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
//
//
//
//
//
bool plot.back=true;
//
//
//
//
//
void plot.setBack(bool isBack)
{
plot.back = isBack;
}
//
//
//
//
//
void plot(string namex,double valueA, double valueB, int shiftA, int shiftB, color theColor, int width=0,int style=STYLE_SOLID)
{
string name = namex+Time[shiftA];
width=width_;
//
//
//
//
//
if (ObjectFind(name) == -1)
{
ObjectCreate(name,OBJ_TREND,Window,Time[shiftA],valueA,Time[shiftB],valueB);
ObjectSet(name,OBJPROP_RAY,false);
ObjectSet(name,OBJPROP_BACK,plot.back);
ObjectSet(name,OBJPROP_STYLE,style);
ObjectSet(name,OBJPROP_WIDTH,width);
}
ObjectSet(name,OBJPROP_COLOR,theColor);
ObjectSet(name,OBJPROP_PRICE1,valueA);
ObjectSet(name,OBJPROP_PRICE2,valueB);
}
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
//
//
//
//
//
double minValue(double& array[],int shift)
{
double minValue = array[shift];
for (int i=1; i<STCPeriod; i++) minValue = MathMin(minValue,array[shift+i]);
return(minValue);
}
double maxValue(double& array[],int shift)
{
double maxValue = array[shift];
for (int i=1; i<STCPeriod; i++) maxValue = MathMax(maxValue,array[shift+i]);
return(maxValue);
}
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
//
//
//
//
//
void deleteAll()
{
for(int i=ObjectsTotal(); i>=0; i--)
{
string name = ObjectName(i);
if (StringSubstr(name,0,3)==leftEnd) ObjectDelete(name);
}
}
//
//
//
//
//
color rgb(int red,int green,int blue)
{
red = MathMax(MathMin(red ,255),0);
green = MathMax(MathMin(green,255),0);
blue = MathMax(MathMin(blue ,255),0);
return(red+(green<<8)+(blue<<16));
}
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
---