vol22
Luna

 
Уровень 3


Группа "Стол заказов MQL"

Рейтинг 2081



РЕКОМЕНДУЮ



индикатор

добры вечер! исправьте пожалуйста индикатор чтобы можно было выбирать таймфрейм старших интервалов! например кинуть на м5 график индикатор и чтоб он показывал уровни старших таймфреймов!
вот код его

#property indicator_chart_window
#property indicator_buffers 1
#property indicator_color1 Red // zig zag color

// •——————————————————————————————————————————————————————————————————————————————————————————————•
// | INPUTS |
// •——————————————————————————————————————————————————————————————————————————————————————————————•
extern int TimeFrame = 0;
extern string TimeString = «0=Current, 60=H1, 240=H4, 1440=Day, 10080=Week, 43200=Month»;
extern bool draw_zones = true; // should be set to FALSE if the idicator is called from an expert advisor
extern int BackLimit = 1000; //количество баров с истории котировок для поиска

extern string ZIGZAG_INPUTS = "—————————————————————————";

extern int
ExtDepth = 12,
ExtDeviation = 5,
ExtBackstep = 3;

extern bool
show_ZigZag = true;

extern string INDICATOR_INPUTS = "—————————————————————————";

extern int
show_breached_zones = 1,
false_breach = 0; // if nonzero, tail-breaches less than this are ignored, 0 — only Close[] price counts
// this value is also used to move the base of the zone
extern double
price_out = 1.0; // 1, 2, 3 соотношение для нахождения зон. Например локальная свеча (потенциальный источник)
// равен 20 пунктов при price_out = 2 зона находится и наносится после ухда цены на расстояние 40 пунктов
extern int
space_zone = 0, // В пунктах. Нанесение зон с отступом в пунктах (там где Stop Loss должен быть)
extend_zone = 0, // расширение зон в процентах. Если «0» отклёчено
max_extend = 0, // максимально допустимое расширение в пунктах.
min_width = 10, // если “0” то выключено. Минимальная ширина зоны в пунктах, если больше “0” (например 10 пунктов свеча локальная) то наносить зону по Default width
default_width = 20, // ширина зоны по умолчанию в пунктах. Работает, если Min width больше “0”
max_width = 50, // если “0” то выключено. Максимальная ширина зоны в пунктах. Если больше “0” то переходим
// ступенчато на ТФ ниже текущего для нахождение зон (Если switch_to_lower_tf =1).
// Если зону удовлетворяющую нас не была найдена на меньшем ТФ то зона ссужается в % от размера свечи того самого меньшего ТФ (max_width_percentage)

switch_to_lower_tf = 1,// Переключатель для поиска зон на меньших ТФ. Если «1» то широкие зоны ссужаются на текущем графике в % от размера той самой широкой свечи (max_width_percentage=50)
max_width_percentage = 50; // (в процентах). Если switch_to_lower_tf =0 то поиск и сужение широких зон происходит на текущем ТФ в % от ширины свечи

extern string NOTIFICATIONS = "—————————————————————————";

extern bool show_alert = false;
extern bool play_sound = false;
extern bool send_mail = false;

extern string APPEARANCE = "—————————————————————————";

extern bool show_zone_info = false; // demand or supply, tf, number of breaches
extern int text_size = 9;
extern color text_color = Black;
extern bool show_price_labels = false; // показывать ценовые метки зон
extern int price_label_size = 1;

extern color
virgin_demand_color = C'84 ,141,212', // Light Blue
virgin_supply_color = C'255,121,121', // Light Red
demand_color = C'0 ,112,192', // Blue
supply_color = C'255, 0, 0', // Red
breached_color = C'113,113,113'; // Gray

// •——————————————————————————————————————————————————————————————————————————————————————————————•
// | GLOBAL VARIABLES |
// •——————————————————————————————————————————————————————————————————————————————————————————————•

// ziggy buffers
double ZigzagBuffer[];
double HighMapBuffer[];
double LowMapBuffer[];

// buffers for borders' values

double resist_up[];
double resist_dn[];
double support_up[];
double support_dn[];
double zone_type[]; // 1 — Virgin, 2 — Tested, 3 — Broken (once). Twice broken zones are deleted and they don't count

bool downloadhistory = false; // ziggy variable
int
level = 3, // ziggy variable
left_shift = 1; // zones' left borders are shifted to the left by this number of bars

double offset, max_ext, max_wid, min_wid, def_wid, false_br, mindiff,
percentage, second_check, third_check, extend_ratio;

int tfs[9] = {1, 5, 15, 30, 60, 240, 1440, 10080, 43200};
int dividers[9] = {0, 5, 3, 2, 2, 4, 6, 5, 4};
int chart_tf, seconds_in_bar, text_time, label_time, number_of_zones;
string spaces[30];
string symbol;
string name_info[1000]; // this array keeps the names of info-texts
bool is_visual, is_not_testing;
// •——————————————————————————————————————————————————————————————————————————————————————————————•
// | INIT |
// •——————————————————————————————————————————————————————————————————————————————————————————————•

void init()
{
// we'll need some predefined spaces-strings to adjust the horizontal position of zone info
int i, j;
for(i=25; i<30; i++){
for(j=0; j<i; j++){
spaces[i] = StringConcatenate(spaces[i]," ");
}
spaces[i] = StringConcatenate(spaces[i]," ");
}
// — IndicatorBuffers(8);
SetIndexDrawBegin(0, Bars — BackLimit — 3*ExtDepth);
SetIndexDrawBegin(0, Bars — BackLimit — 3*ExtDepth);
SetIndexDrawBegin(0, Bars — BackLimit — 3*ExtDepth);
if(show_ZigZag) {SetIndexStyle(0, DRAW_SECTION);} // sections between nonzero values
else {SetIndexStyle(0, DRAW_NONE );}
SetIndexBuffer(0, ZigzagBuffer);
SetIndexBuffer(1, HighMapBuffer);
SetIndexBuffer(2, LowMapBuffer);
SetIndexBuffer(3, support_dn);
SetIndexBuffer(4, support_up);
SetIndexBuffer(5, resist_dn);
SetIndexBuffer(6, resist_up);
SetIndexBuffer(7, zone_type);
SetIndexEmptyValue(0, 0.0);
SetIndexEmptyValue(1, 0.0);
SetIndexEmptyValue(2, 0.0);
SetIndexEmptyValue(3, 0.0);
SetIndexEmptyValue(4, 0.0);
SetIndexEmptyValue(5, 0.0);
SetIndexEmptyValue(6, 0.0);
SetIndexEmptyValue(7, 0.0);
IndicatorShortName(" Demand and Supply on ZigZag("+ExtDepth+","+ExtDeviation+","+ExtBackstep+")");
// 5-digit amendments
if(Digits == 3 || Digits == 5){
ExtDeviation *= 10;
space_zone *= 10;
max_extend *= 10;
min_width *= 10;
default_width *= 10;
max_width *= 10;
false_breach *= 10;
}
// the following values must be calculated only once, so we don't have to calculate them on every tick
extend_ratio = 1.0 + extend_zone / 100.0;
second_check = 1.5 * Point;
third_check = 2.5 * Point;
mindiff = 0.1*Point;
percentage = max_width_percentage / 100.0;
symbol = Symbol();
chart_tf = Period();
seconds_in_bar = chart_tf*60;
offset = NormalizeDouble(space_zone * Point, Digits);
max_ext = NormalizeDouble(max_extend * Point, Digits);
max_wid = NormalizeDouble(max_width * Point, Digits);
min_wid = NormalizeDouble(min_width * Point, Digits);
def_wid = NormalizeDouble(default_width * Point, Digits);
false_br = NormalizeDouble(false_breach * Point, Digits);
//Comment("\n",WindowExpertName());
}

// •——————————————————————————————————————————————————————————————————————————————————————————————•
// | DEINIT |
// •——————————————————————————————————————————————————————————————————————————————————————————————•

void deinit()
{
if(draw_zones){
int bar;
for(bar = 0; bar < BackLimit; bar ++){
Delete(StringConcatenate(Time[bar],«pit» ));
Delete(StringConcatenate(Time[bar],«peak»));
}
Comment("");
}
}
// •——————————————————————————————————————————————————————————————————————————————————————————————•
// | START |
// •——————————————————————————————————————————————————————————————————————————————————————————————•

void start()
{
// text adjustment is better to be executed on every tick
if(draw_zones){
if(show_zone_info){
int i, text_bar = WindowFirstVisibleBar()-WindowBarsPerChart();
if(text_bar < 0){
text_time = Time[0]-text_bar * seconds_in_bar;}
else{
text_time = Time[0] + seconds_in_bar;}

for(i = number_of_zones; i > 0; i--){
ObjectSet(name_info[i],OBJPROP_TIME1,text_time);
}
}
}
// ——————————————————————————————————————————————————————————————

static int last_ot = 0;
if(last_ot == Time[0]) {return;}
last_ot = Time[0];

DeleteOldZones(BackLimit, BackLimit+3);
if(show_price_labels){
label_time = Time[0] + seconds_in_bar;
}
number_of_zones = 0;
// empty arrays
ArrayInitialize(support_up,0.0);
ArrayInitialize(support_dn,0.0);
ArrayInitialize(resist_up,0.0);
ArrayInitialize(resist_dn,0.0);
ArrayInitialize(zone_type,0.0);
/*
ArrayInitialize(br_support_up,0.0);
ArrayInitialize(br_support_dn,0.0);
ArrayInitialize(br_resist_up,0.0);
ArrayInitialize(br_resist_dn,0.0);
*/
Ziggy();
int bar, time, tf, breaches, pr_out_time, touches;
double high, low, height;
int limit = MathMin(BackLimit-1, Bars-1);
for(bar = limit; bar > 0; bar --){
if(ZigzagBuffer[bar] == 0.0){ // not a peak/pit
if(draw_zones){
Delete(StringConcatenate(Time[bar], «peak»));
Delete(StringConcatenate(Time[bar], «pit»));
}
continue;
}
high = High[bar];
low = Low [bar];
height = high — low;
tf = chart_tf;
time = Time[bar];
pr_out_time = 0;

if(max_width > 0){
if(height > max_wid){
if(switch_to_lower_tf == 1){
FindLowerTF(ZigzagBuffer[bar], tf, time, height, high, low);
// all values are passed by reference, so they may be changed
if(height > max_wid){
height *= percentage;
}
}
else{
height *= percentage;
}
}
}
if(min_width > 0){
if(height < min_wid){
height = def_wid;
}
}
// PEAKs ————————————————————————————————————————————————————————————————————————————————————————
if(HighMapBuffer[bar] > 0.0){
if(switch_to_lower_tf == 1){
if(PriceOutForPeaks(tf, time, height, high, pr_out_time) == false) {continue;} // price_out requirement isn't met
}
else{
if(PriceOutForPeaksCurrTF(bar, height, high, pr_out_time) == false) {continue;} // price_out requirement isn't met
}

high += offset; // adjust the upper border
height += offset;
touches = 0;
breaches = PeakBreaches(bar-1, height, high, pr_out_time, touches);

if(breaches > 1){
if(draw_zones){
Delete(StringConcatenate(Time[bar], «peak»));
}
continue;
}
if(breaches == 1){
if(show_breached_zones == 1){
if(TouchingOlderPeak(height, high)){
if(draw_zones){
Delete(StringConcatenate(Time[bar], «peak»));
}
continue;
}
// remember to arrays
number_of_zones ++;
resist_up[number_of_zones] = high;
resist_dn[number_of_zones] = high-height;
zone_type[number_of_zones] = 3; // broken
if(draw_zones){
CreateBreached(StringConcatenate(Time[bar], «peak»), breached_color,
StringConcatenate(«Broken Supply, »,TFName(tf),", Test = ",touches),
Time[bar+left_shift], high,
Time[0], high-height);
if(Close[0]<=high){
if(Close[0] >= high-height){
Alerts(StringConcatenate(symbol,", ",TFName(chart_tf),": цена коснулась зоны сопротивления"));
}
}
}
}
else{ // if(show_breached_zones == 0)
if(draw_zones){
Delete(StringConcatenate(Time[bar], «peak»));
}
}
continue;
}
if(TouchingOlderPeak(height, high)){
if(draw_zones){
Delete(StringConcatenate(Time[bar], «peak»));
}
continue;
}
if(touches > 0){
// remember to arrays
number_of_zones++;
resist_up[number_of_zones] = high;
resist_dn[number_of_zones] = high-height;
zone_type[number_of_zones] = 2; // tested
if(draw_zones){
CreateBreached(StringConcatenate(Time[bar], «peak»), supply_color,
StringConcatenate(«Tested Supply, »,TFName(tf),", Test = ",touches),
Time[bar+left_shift], high,
Time[0], high-height );
if(Close[0]<=high){
if(Close[0] >= high-height){
Alerts(StringConcatenate(symbol,", ",TFName(chart_tf),": цена коснулась зоны сопротивления"));
}
}
}
}
else{
// remember to arrays
number_of_zones++;
resist_up[number_of_zones] = high;
resist_dn[number_of_zones] = high-height;
zone_type[number_of_zones] = 1; // virgin
if(draw_zones){
CreateVirgin(StringConcatenate(Time[bar], «peak»), virgin_supply_color,
StringConcatenate(«Virgin Supply, »,TFName(tf),", Test = ",touches),
Time[bar+left_shift], high,
Time[0], high-height );
if(Close[0]<=high){
if(Close[0] >= high-height){
Alerts(StringConcatenate(symbol,", ",TFName(chart_tf),": цена коснулась зоны сопротивления"));
}
}
}
}
}
// PITs ====================================================================================
else{ // implying LowMapBuffer[bar] != 0.0
if(switch_to_lower_tf == 1){
if(PriceOutForPits(tf, time, height, low, pr_out_time) == false) {continue;} // price_out requirement isn't met
}
else{
if(PriceOutForPitsCurrTF(bar, height, low, pr_out_time) == false){continue;} // price_out requirement isn't met
}
low -= offset; // adjust the lower border
height += offset;
touches = 0;
breaches = PitBreaches(bar-1, height, low, pr_out_time, touches);

if(breaches > 1){
if(draw_zones){
Delete(StringConcatenate(Time[bar],«pit»));
}
continue;}
if(breaches == 1){
if(show_breached_zones == 1){
if(TouchingOlderPit(height, low)){
if(draw_zones){
Delete(StringConcatenate(Time[bar],«pit»));
}
continue;
}
// remember to arrays
number_of_zones++;
support_dn[number_of_zones] = low;
support_up[number_of_zones] = low + height;
zone_type[number_of_zones] = 3; // broken
if(draw_zones){
CreateBreached(StringConcatenate(Time[bar],«pit»), breached_color,
StringConcatenate(«Broken Demand, »,TFName(tf),", Test = ",touches),
Time[bar+left_shift], low+height,
Time[0], low);
if(Close[0]>=low){
if(Close[0] <= low+height){
Alerts(StringConcatenate(symbol,", ",TFName(chart_tf),": цена коснулась зоны поддержки"));
}
}
}
}
else{ // if(show_breached_zones == 0)
if(draw_zones){
Delete(StringConcatenate(Time[bar],«pit»));
}
}
continue;
}
if(TouchingOlderPit(height, low)){
if(draw_zones){
Delete(StringConcatenate(Time[bar],«pit»));
}
continue;
}
if(touches > 0){
// remember to arrays
number_of_zones++;
support_dn[number_of_zones] = low;
support_up[number_of_zones] = low + height;
zone_type[number_of_zones] = 2; // tested
if(draw_zones){
CreateBreached(StringConcatenate(Time[bar],«pit»), demand_color,
StringConcatenate(«Tested Demand, »,TFName(tf),", Test = ",touches),
Time[bar+left_shift], low+height,
Time[0], low);
if(Close[0]>=low){
if(Close[0] <= low+height){
Alerts(StringConcatenate(symbol,", ",TFName(chart_tf),": цена коснулась зоны поддержки"));
}
}
}
}
else{
// remember to arrays
number_of_zones++;
support_dn[number_of_zones] = low;
support_up[number_of_zones] = low + height;
zone_type[number_of_zones] = 1; // virgin
if(draw_zones){
CreateVirgin(StringConcatenate(Time[bar],«pit»), virgin_demand_color,
StringConcatenate(«Virgin Demand, »,TFName(tf),", Test = ",touches),
Time[bar+left_shift], low+height,
Time[0], low );
if(Close[0]>=low){
if(Close[0] <= low+height){
Alerts(StringConcatenate(symbol,", ",TFName(chart_tf),": цена коснулась зоны поддержки"));
}
}
}
}
}
}// end of bar loop
zone_type[0] = number_of_zones;
}// end of start

// •——————————————————————————————————————————————————————————————————————————————————————————————•
// | USER |
// •——————————————————————————————————————————————————————————————————————————————————————————————•
void DeleteOldZones(int start_bar, int end_bar)
{
if(draw_zones){
int bar;
for(bar = start_bar; bar < end_bar; bar ++){
Delete(StringConcatenate(Time[bar],«pit» ));
Delete(StringConcatenate(Time[bar],«peak»));
}
}
}
// •——————————————————————————————————————————————————————————————————————————————————————————————•
bool PriceOutForPitsCurrTF(int bar, double height, double start_point, int& prout_time)
{
double end_point = start_point + (price_out + 1) * height;

for(bar--; bar > -1; bar --){
if(High[bar] >= end_point){
prout_time = Time[bar];
return(true);
}
}
return(false);
}
// •——————————————————————————————————————————————————————————————————————————————————————————————•
bool PriceOutForPeaksCurrTF(int bar, double height, double start_point, int& prout_time)
{
double end_point = start_point — (price_out + 1) * height;
for(bar--; bar > -1; bar --){
if(Low[bar] <= end_point){
prout_time = Time[bar];
return(true);
}
}
return(false);
}
// •——————————————————————————————————————————————————————————————————————————————————————————————•
bool PriceOutForPits(int tf, int time, double height, double start_point, int& prout_time)
{
double end_point = start_point + (price_out + 1) * height;
int bar = iBarShift(NULL, tf, time, true) — 1;
for(; bar > -1; bar --){
if(iHigh(NULL, tf, bar) >= end_point){
prout_time = iTime(NULL, tf, bar);
return(true);
}
}
return(false);
}
// •——————————————————————————————————————————————————————————————————————————————————————————————•
bool PriceOutForPeaks(int tf, int time, double height, double start_point, int& prout_time)
{
double end_point = start_point — (price_out + 1) * height;
int bar = iBarShift(NULL, tf, time, true) — 1;
for(; bar > -1; bar --){
if(iLow(NULL, tf, bar) <= end_point){
prout_time = iTime(NULL, tf, bar);
return(true);
}
}
return(false);
}
// •——————————————————————————————————————————————————————————————————————————————————————————————•
void Alerts(string text)
{
if(play_sound){
PlaySound(«alert.wav»);}
if(show_alert){
Alert(text);}
if(send_mail){
SendMail(«Demand and Supply indicator»,text);}
}
// •——————————————————————————————————————————————————————————————————————————————————————————————•
void CreateVirgin(string name_prefix, color Color, string text

,int time1, double price1
,int time2, double price2)
// corners are given as follows: upper_left, lower_right
// visually parameters of the function correspond to the corners

{
//-----------------------------------------------------------------------
string
name_back = StringConcatenate(name_prefix,«back»);

if(ObjectFind(name_back) != 0){
ObjectCreate(name_back, OBJ_RECTANGLE, 0, time1, price1, time2, price2);
ObjectSet(name_back, OBJPROP_COLOR, Color);
}

else{
ObjectMove(name_back,0,time1,price1);
ObjectMove(name_back,1,time2,price2);
}
//-----------------------------------------------------------------------
if(show_zone_info){

text = StringConcatenate(text, spaces[StringLen(text)]);
double price = price1 — 0.25 * (price1 — price2);
name_info[number_of_zones] = StringConcatenate(name_prefix,«info»);
if(ObjectFind(name_info[number_of_zones]) != 0){
ObjectCreate(name_info[number_of_zones],OBJ_TEXT,0, text_time, price);
ObjectSetText(name_info[number_of_zones],text, text_size,«Courier New»,text_color);
}
else{
ObjectMove(name_info[number_of_zones],0,text_time,price);
ObjectSetText(name_info[number_of_zones],text, text_size,«Courier New»,text_color);
}
}
//-----------------------------------------------------------------------
if(!show_price_labels){return;}
string
name_uppr = StringConcatenate(name_prefix,«uppr»),
name_dnpr = StringConcatenate(name_prefix,«dnpr»);
//-----------------------------------------------------------------------
if(ObjectFind(name_uppr) != 0){
ObjectCreate(name_uppr,OBJ_ARROW,0,label_time, price1);
ObjectSet(name_uppr,OBJPROP_ARROWCODE,SYMBOL_RIGHTPRICE);
ObjectSet(name_uppr,OBJPROP_COLOR,Color);
ObjectSet(name_uppr,OBJPROP_WIDTH,price_label_size);
}
else{
ObjectMove(name_uppr,0,label_time,price1);
}
//-----------------------------------------------------------------------
if(ObjectFind(name_dnpr) != 0){
ObjectCreate(name_dnpr,OBJ_ARROW,0,label_time,price2);
ObjectSet(name_dnpr,OBJPROP_ARROWCODE,SYMBOL_RIGHTPRICE);
ObjectSet(name_dnpr,OBJPROP_COLOR,Color);
ObjectSet(name_dnpr,OBJPROP_WIDTH,price_label_size);
}
else{
ObjectMove(name_dnpr,0,label_time,price2);
}
}
// •——————————————————————————————————————————————————————————————————————————————————————————————•
// the only difference of CreateBreached from CreateVirgin is that it can change the color of an existing zone
// CreateVirgin is supposed to work a little bit faster
void CreateBreached(string name_prefix, color Color, string text

,int time1, double price1
,int time2, double price2)
// corners are given as follows: upper_left, lower_right
// visually parameters of the function correspond to the corners

{
//-----------------------------------------------------------------------
string name_back = StringConcatenate(name_prefix,«back»);

if(ObjectFind(name_back) != 0){
ObjectCreate(name_back, OBJ_RECTANGLE, 0, time1, price1, time2, price2);
ObjectSet(name_back, OBJPROP_COLOR, Color);
}

else{
if(ObjectGet(name_back, OBJPROP_COLOR) != Color){
ObjectSet(name_back, OBJPROP_COLOR, Color);
}
ObjectMove(name_back,0,time1,price1);
ObjectMove(name_back,1,time2,price2);
}
//-----------------------------------------------------------------------
if(show_zone_info){

text = StringConcatenate(text, spaces[StringLen(text)]);
double price = price1 — 0.25 * (price1 — price2);
name_info[number_of_zones] = StringConcatenate(name_prefix,«info»);
if(ObjectFind(name_info[number_of_zones]) != 0){
ObjectCreate(name_info[number_of_zones],OBJ_TEXT,0, text_time, price);
ObjectSetText(name_info[number_of_zones],text, text_size,«Courier New»,text_color);
}
else{
ObjectMove(name_info[number_of_zones],0,text_time,price);
ObjectSetText(name_info[number_of_zones],text, text_size,«Courier New»,text_color);
}
}
//-----------------------------------------------------------------------
if(!show_price_labels){return;}
string
name_uppr = StringConcatenate(name_prefix,«uppr»),
name_dnpr = StringConcatenate(name_prefix,«dnpr»);
//-----------------------------------------------------------------------
if(ObjectFind(name_uppr) != 0){
ObjectCreate(name_uppr,OBJ_ARROW,0,label_time,price1);
ObjectSet(name_uppr,OBJPROP_ARROWCODE,SYMBOL_RIGHTPRICE);
ObjectSet(name_uppr,OBJPROP_COLOR,Color);
ObjectSet(name_uppr,OBJPROP_WIDTH,price_label_size);
}
else{
ObjectMove(name_uppr,0,label_time,price1);
}
//-----------------------------------------------------------------------
if(ObjectFind(name_dnpr) != 0){
ObjectCreate(name_dnpr,OBJ_ARROW,0,label_time,price2);
ObjectSet(name_dnpr,OBJPROP_ARROWCODE,SYMBOL_RIGHTPRICE);
ObjectSet(name_dnpr,OBJPROP_COLOR,Color);
ObjectSet(name_dnpr,OBJPROP_WIDTH,price_label_size);
}
else{
ObjectMove(name_dnpr,0,label_time,price2);
}
}
// •——————————————————————————————————————————————————————————————————————————————————————————————•
double PrevPeakFor(int bar)
{
for(; bar < Bars; bar++){
if(ZigzagBuffer[bar]>0.0){
if(HighMapBuffer[bar] > 0.0){
return(HighMapBuffer[bar]);
}
}
}
}
// •——————————————————————————————————————————————————————————————————————————————————————————————•
double PrevPitFor(int bar)
{
for(; bar < Bars; bar++){
if(ZigzagBuffer[bar]>0.0){
if(LowMapBuffer[bar] > 0.0){
return(LowMapBuffer[bar]);
}
}
}
}
// •——————————————————————————————————————————————————————————————————————————————————————————————•
int PitBreaches(int start_bar, double& height, double& lower_border, int prout_time, int& touches)
{
int bar, barr, cross_up, cross_dn;
double prev_peak;

for(bar = start_bar; bar > -1; bar --){
if(Close[bar] < lower_border){
cross_dn = 1;
}
else{
// touch extention
if(extend_zone > 0){
if(ZigzagBuffer[bar]>0.0){
if(LowMapBuffer[bar] > 0.0){
if(Low[bar] <= lower_border + height){
touches++;
if(Time[bar] > prout_time){
if(Low[bar] >= lower_border){
prev_peak = PrevPeakFor(bar+1);
for(barr = bar-1; barr >-1; barr--){
if(High[barr] >= prev_peak){
height *= extend_ratio;
height = MathMin(height, max_ext);
break;
}
}
}
}
}
}
}
}
else{
if(Low[bar] <= lower_border + height){
if(ZigzagBuffer[bar]>0.0){
if(LowMapBuffer[bar] > 0.0){
touches++;}}}
}

// first breach
if(false_breach > 0){
if(Low[bar] < lower_border — false_br){
cross_dn = 1;
}
// false_break extention
else{
if(cross_dn < 1){
if(Low[bar] < lower_border){
height += MathAbs(Low[bar] — lower_border);
lower_border = Low[bar];
}
}
}
}
// if once breached, look for the second breach
if(cross_dn == 1){
if(Close[bar] > lower_border + height){
cross_up = 1;
}
else{
if(false_breach > 0){
if(High[bar] > lower_border + height + false_br){
cross_up = 1;
}
}
}
}
} // end of else
if(cross_up == 1){ if(cross_dn == 1){ return(2);}}
}
return(cross_up + cross_dn);
}
// •——————————————————————————————————————————————————————————————————————————————————————————————•
int PeakBreaches(int start_bar, double& height, double& upper_border, int prout_time, int& touches)
{
int bar, barr, cross_up, cross_dn;
double prev_pit;

for(bar = start_bar; bar > -1; bar --){
if(Close[bar] > upper_border){
cross_up = 1;
}
else{
// touch extention
if(extend_zone > 0){
if(ZigzagBuffer[bar]>0.0){
if(HighMapBuffer[bar] > 0.0){
if(High[bar] >= upper_border — height){
touches++;
if(Time[bar] > prout_time){
if(High[bar] <= upper_border){
prev_pit = PrevPitFor(bar+1);
for(barr = bar-1; barr >-1; barr--){
if(Low[barr] <= prev_pit){
height *= extend_ratio;
height = MathMin(height, max_ext);
break;
}
}
}
}
}
}
}
}
else{
if(High[bar] >= upper_border — height){
if(ZigzagBuffer[bar]>0.0){
if(HighMapBuffer[bar] > 0.0){
touches++;}}}
}
// first breach
if(false_breach > 0){
if(High[bar] > upper_border + false_br){
cross_up = 1;
}
// false_break extention
else{
if(cross_up < 1){
if(High[bar] > upper_border){
height += MathAbs(High[bar] — upper_border);
upper_border = High[bar];
}
}
}
}
// if once breached, look for the second breach
if(cross_up == 1){
if(Close[bar] < upper_border — height){
cross_dn = 1;
}
else{
if(false_breach > 0){
if(Low[bar] < upper_border — height — false_br){
cross_dn = 1;
}
}
}
}
}// end of else
if(cross_up == 1){ if(cross_dn == 1){ return(2);}}
}
return(cross_up + cross_dn);
}

// •——————————————————————————————————————————————————————————————————————————————————————————————•
bool TouchingOlderPeak(double height, double high)
{
int i = number_of_zones;
for(; i > 0; i--){
if(resist_up[i] > 0.25){
if(high > resist_dn[i]){
if(high — height < resist_up[i]){
return(true);
}
}
}
}
return(false);
}
// •——————————————————————————————————————————————————————————————————————————————————————————————•
bool TouchingOlderPit(double height, double low)
{
int i = number_of_zones;
for(; i > 0; i--){
if(support_up[i] > 0.25){
if(low < support_up[i]){
if(low + height > support_dn[i]){
return(true);
}
}
}
}
return(false);
}
// •——————————————————————————————————————————————————————————————————————————————————————————————•

void Delete(string name_prefix)
{
string
name_back = StringConcatenate(name_prefix,«back»),
name_info = StringConcatenate(name_prefix,«info»),
name_uppr = StringConcatenate(name_prefix,«uppr»),
name_dnpr = StringConcatenate(name_prefix,«dnpr»);
if(ObjectFind(name_back) == 0){
ObjectDelete(name_back);}
if(ObjectFind(name_info) == 0){
ObjectDelete(name_info);}
if(ObjectFind(name_uppr) == 0){
ObjectDelete(name_uppr);}
if(ObjectFind(name_dnpr) == 0){
ObjectDelete(name_dnpr);}
}
// •——————————————————————————————————————————————————————————————————————————————————————————————•
void FindLowerTF(double peak_value, int& new_tf, int& new_time, double& new_height, double& new_high, double& new_low)
{
int bar, new_bar, j, limit,
time = new_time,
i = ArrayBsearch(tfs, new_tf),
i_limit = i-2;

if(new_tf == 10080){time += 86400;} // weeks start from Sunday

bool peak_found;
while(i>i_limit){
new_tf = tfs[i-1]; // take tf one step smaller than current
new_bar = iBarShift(NULL, new_tf, time, true);

if(new_bar > -1){
// find the bar right under the peak (or above the pit)
// dividers is the number of minor-TF bars in one major-TF bar
limit = new_bar — dividers[i]; // here we keep the last minor TF bar's successor
peak_found = false;
for(bar = new_bar ;bar > limit; bar--){
if(iCustom(NULL, new_tf, «ZigZag», ExtDepth, ExtDeviation, ExtBackstep, 0, bar) == peak_value){
peak_found = true;
break;}}
// first amendment
if(peak_found == false){
for(bar = new_bar ;bar > limit; bar--){
if(iHigh(NULL, new_tf, bar) == peak_value){
peak_found = true;
break;}
else{if(iLow(NULL, new_tf, bar) == peak_value){
peak_found = true;
break;}}}}
// second amendment
if(peak_found == false){
for(bar = new_bar ;bar > limit; bar--){
if(MathAbs(iHigh(NULL, new_tf, bar) — peak_value) < second_check){
peak_found = true;
break;}
else{if(MathAbs(iLow(NULL, new_tf, bar)- peak_value) < second_check){
peak_found = true;
break;}}}}
// third amendmend
if(peak_found == false){
for(bar = new_bar ;bar > limit; bar--){
if(MathAbs(iHigh(NULL, new_tf, bar) — peak_value) < third_check){
peak_found = true;
break;}
else{
if(MathAbs(iLow(NULL, new_tf, bar)- peak_value) < third_check){
peak_found = true;
break;}}}}
// check height
new_high = iHigh(NULL, new_tf, bar);
new_low = iLow (NULL, new_tf, bar);
new_height = new_high — new_low;
new_time = iTime(NULL, new_tf, bar);
if(new_height <= max_wid){
return;
}
else{
time = iTime(NULL, new_tf, bar);
i--; // try even smaller tf

}
}
else{ // if new_bar == -1
new_tf = tfs[i];
new_time = time;
// other data has not been changed by the previous iteration
Print(«Время », TimeToStr(new_time),": нужный бар на М ", tfs[i-1], " не найден — возврат на М ",new_tf);
return;
}
}
}
// •——————————————————————————————————————————————————————————————————————————————————————————————•
string TFName(int period = 0)
{

// •——————————————————————————————————————————————————————————————————————————————————————————————•
void Ziggy()
{
int i, counted_bars = IndicatorCounted();
int limit,counterZ,whatlookfor;
int shift,back,lasthighpos,lastlowpos;
double val,res;
double curlow,curhigh,lasthigh,lastlow;

if (counted_bars==0 && downloadhistory) // history was downloaded
{
ArrayInitialize(ZigzagBuffer,0.0);
ArrayInitialize(HighMapBuffer,0.0);
ArrayInitialize(LowMapBuffer,0.0);
}
if (counted_bars==0)
{
limit=Bars-ExtDepth;
downloadhistory=true;
}
if (counted_bars>0)
{
while (counterZ<level && i<100)
{
res=ZigzagBuffer[i];
if (res!=0) counterZ++;
i++;
}
i--;
limit=i;
if (LowMapBuffer[i]!=0)
{
curlow=LowMapBuffer[i];
whatlookfor=1;
}
else
{
curhigh=HighMapBuffer[i];
whatlookfor=-1;
}
for (i=limit-1;i>=0;i--)
{
ZigzagBuffer[i]=0.0;
LowMapBuffer[i]=0.0;
HighMapBuffer[i]=0.0;
}
}
for(shift=limit; shift>=0; shift--)
{
val=Low[iLowest(NULL,0,MODE_LOW,ExtDepth,shift)];
if(val==lastlow) val=0.0;
else
{
lastlow=val;
if((Low[shift]-val)>(ExtDeviation*Point)) val=0.0;
else
{
for(back=1; back<=ExtBackstep; back++)
{
res=LowMapBuffer[shift+back];
if((res!=0)&&(res>val)) LowMapBuffer[shift+back]=0.0;
}
}
}
if (Low[shift]==val) LowMapBuffer[shift]=val; else LowMapBuffer[shift]=0.0;
//--- high
val=High[iHighest(NULL,0,MODE_HIGH,ExtDepth,shift)];
if(val==lasthigh) val=0.0;
else
{
lasthigh=val;
if((val-High[shift])>(ExtDeviation*Point)) val=0.0;
else
{
for(back=1; back<=ExtBackstep; back++)
{
res=HighMapBuffer[shift+back];
if((res!=0)&&(res<val)) HighMapBuffer[shift+back]=0.0;
}
}
}
if (High[shift]==val) HighMapBuffer[shift]=val; else HighMapBuffer[shift]=0.0;
}

// final cutting
if (whatlookfor==0)
{
lastlow=0;
lasthigh=0;
}
else
{
lastlow=curlow;
lasthigh=curhigh;
}
for (shift=limit;shift>=0;shift--)
{
res=0.0;
switch(whatlookfor)
{
case 0: // look for peak or lawn
if (lastlow==0 && lasthigh==0)
{
if (HighMapBuffer[shift]!=0)
{
lasthigh=High[shift];
lasthighpos=shift;
whatlookfor=-1;
ZigzagBuffer[shift]=lasthigh;
res=1;
}
if (LowMapBuffer[shift]!=0)
{
lastlow=Low[shift];
lastlowpos=shift;
whatlookfor=1;
ZigzagBuffer[shift]=lastlow;
res=1;
}
}
break;
case 1: // look for peak
if (LowMapBuffer[shift]!=0.0 && LowMapBuffer[shift]<lastlow && HighMapBuffer[shift]==0.0)
{
ZigzagBuffer[lastlowpos]=0.0;
lastlowpos=shift;
lastlow=LowMapBuffer[shift];
ZigzagBuffer[shift]=lastlow;
res=1;
}
if (HighMapBuffer[shift]!=0.0 && LowMapBuffer[shift]==0.0)
{
lasthigh=HighMapBuffer[shift];
lasthighpos=shift;
ZigzagBuffer[shift]=lasthigh;
whatlookfor=-1;
res=1;
}
break;
case -1: // look for lawn
if (HighMapBuffer[shift]!=0.0 && HighMapBuffer[shift]>lasthigh && LowMapBuffer[shift]==0.0)
{
ZigzagBuffer[lasthighpos]=0.0;
lasthighpos=shift;
lasthigh=HighMapBuffer[shift];
ZigzagBuffer[shift]=lasthigh;
}
if (LowMapBuffer[shift]!=0.0 && HighMapBuffer[shift]==0.0)
{
lastlow=LowMapBuffer[shift];
lastlowpos=shift;
ZigzagBuffer[shift]=lastlow;
whatlookfor=1;
}
break;
default: return;
}
}
}
  • 0
  • Просмотров: 891
  • 5 июля 2020, 14:48
  • vol22
Понравилcя материал? Не забудьте поставить плюс и поделиться в социальной сети!

Вступите в группу "Стол заказов MQL", чтобы следить за обновлениями
ПРИСОЕДИНИТЬСЯ К ГРУППЕ
присоединиться
  Предыдущая запись в группе
Усреднитель на основе дивергенции по RSI
Следующая запись в группе  
индикатор
04 июля 2020
05 июля 2020

Комментарии (2)

+
+1
cкиньте файлом
avatar

  34  AM2 Сообщений: 15871 - Андрей

  • 5 июля 2020, 16:27
+
0
а как?
avatar

  3  vol22 Автор Сообщений: 8 - Luna

  • 5 июля 2020, 16:52

Зарегистрируйтесь или авторизуйтесь, чтобы оставить комментарий
Начать торговлю с Альпари