Price Data Components
Indicators Used
Miscellaneous
0
Views
0
Downloads
0
Favorites
precentualzz_victor-mtf
//+------------------------------------------------------------------+
//| ZigZag Pointer.mq4 |
//| zigzag modified by Dr. Gaines |
//| neamtu_victor@yahoo.com |
//| neamtu victor |
//+------------------------------------------------------------------+
#property copyright "neamtu victor"
#property link "neamtu_victor@yahoo.com"
#property indicator_chart_window
#property indicator_buffers 2
#property indicator_color1 Lime
#property indicator_width1 1
#property indicator_color2 Red
#property indicator_width2 1
//---- indicator parameters
extern string _ = "parameters";
extern double Percent = 0.04;
extern string TimeFrame = "Current time frame";
//---- indicator buffers
double buyArrowsBuffer[];
double sellArrowsBuffer[];
double values[];
//
//
//
//
//
int timeFrame;
string indicatorFileName;
//+------------------------------------------------------------------+
//| Custom indicator initialization function |
//+------------------------------------------------------------------+
int init()
{
IndicatorBuffers(3);
//---- drawing settings
SetIndexStyle(0,DRAW_ARROW);
SetIndexArrow(0, 159);//233
SetIndexStyle(1,DRAW_ARROW);
SetIndexArrow(1, 159);//234
//---- indicator buffers mapping
SetIndexBuffer(0,buyArrowsBuffer);
SetIndexBuffer(1,sellArrowsBuffer);
SetIndexBuffer(2,values);
SetIndexEmptyValue(0,0.0);
IndicatorShortName("Percentual ZigZag("+Percent+")");
if (_=="calculating") return(0);
//
//
//
//
timeFrame = stringToTimeFrame(TimeFrame);
indicatorFileName = WindowExpertName();
return(0);
}
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
double barPrice(int shift){
double auxPrice=0;
auxPrice=(iOpen(Symbol(),0,shift)+iClose(Symbol(),0,shift)+iLow(Symbol(),0,shift)+iHigh(Symbol(),0,shift))/4;
return(auxPrice);
}
int start()
{
int counted_bars=IndicatorCounted();
int shift,limit;
if(counted_bars<0) return(-1);
if(counted_bars>0) counted_bars--;
limit = Bars-counted_bars;
/*
int counted_bars=IndicatorCounted();
if(counted_bars<0)
return(-1);
int limit=Bars-counted_bars-1;
*/
if (_=="calculating")
{
//
//
//
//
//
for(shift=limit; shift>=0; shift--)
{
double value = values[shift+1];
if (shift >= (Bars-2)) value=barPrice(shift);
else
{
//Print(" barPrice: ", barPrice(shift), " value+p.. ", value );
double upValue = value + (Percent/100.0)*value;
double dnValue = value - (Percent/100.0)*value;
if (barPrice(shift) > upValue)
{
buyArrowsBuffer[shift]=iLow(Symbol(),0,shift)-iATR(NULL,0,20,shift)/2.0;
sellArrowsBuffer[shift]=0;
value=upValue;
//Print("Bars ",Bars, " Shift ",shift," barPrice: ", value);
}
if (barPrice(shift) < dnValue)
{
sellArrowsBuffer[shift]=iHigh(Symbol(),0,shift)+iATR(NULL,0,20,shift)/2.0;
buyArrowsBuffer[shift]=0;
value=dnValue;
//Print("Bars ",Bars, " Shift ",shift," barPrice: ", value);
}
}
values[shift]=value;
}
return(0);
}
//
//
//
//
//
if (timeFrame!=0) limit = MathMax(limit,timeFrame/Period());
for(shift=limit; shift>=0; shift--)
{
int y = iBarShift(NULL,timeFrame,Time[shift]);
buyArrowsBuffer[shift] = iCustom(NULL,timeFrame,indicatorFileName,"calculating",Percent,0,y);
sellArrowsBuffer[shift] = iCustom(NULL,timeFrame,indicatorFileName,"calculating",Percent,1,y);
}
}
//
//
//
//
//
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);
}
//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
---