Немного переделал. Мне кажется стал более удобным, практичным
//+------------------------------------------------------------------+ //| 4D - Range Switch.mq4 | //| Copyright © 2009, Vic2008 | //| | //+------------------------------------------------------------------+ #property copyright "Copyright © 2009, Vic2008" #property link "" #property indicator_chart_window #property indicator_buffers 1 #property indicator_color1 Red extern int period=4; //---- buffers double ExtMapBuffer1[]; //+------------------------------------------------------------------+ //| Custom indicator initialization function | //+------------------------------------------------------------------+ int init() { //---- indicators SetIndexStyle(0,DRAW_LINE); SetIndexBuffer(0,ExtMapBuffer1); //---- return(0); } //+------------------------------------------------------------------+ //| Custom indicator deinitialization function | //+------------------------------------------------------------------+ int deinit() { //---- //---- return(0); } //+------------------------------------------------------------------+ //| Custom indicator iteration function | //+------------------------------------------------------------------+ int start() { int i; int Indicator_Counted=IndicatorCounted(); int limit=Bars-Indicator_Counted; if (limit>1){ limit=Bars-5; } for( i=limit; i>=0; i-- ){ double lHigh4=High[iHighest(NULL,0,MODE_HIGH,period, i+1)]; double lLow4 =Low[ iLowest( NULL,0,MODE_LOW, period, i+1)]; double lHigh3=High[iHighest(NULL,0,MODE_HIGH,period-1, i+1)]; double lLow3 =Low[ iLowest( NULL,0,MODE_LOW, period-1, i+1)]; ExtMapBuffer1[i]=ExtMapBuffer1[i+1]; if (Close[i]>lHigh4) ExtMapBuffer1[i]=lLow3; else if (Close[i]<lLow4) ExtMapBuffer1[i]=lHigh3; } return(0); } //+------------------------------------------------------------------+
По крайней мере. теперь можно в советниках использовать. Не будет на каждом тике всю историю пересчитывать
А я вот так сделал
int start() { int limit, i; int counted_bars=IndicatorCounted(); limit=Bars-counted_bars; if (limit>1){ limit=Bars-5; } for(i=limit;i>=0;i--) { if(Close[i] > iHigh(NULL,0, iHighest(NULL,0,MODE_HIGH,4,i+1) )) { ExtMapBuffer1[i]=iLow(NULL,0, iLowest(NULL,0,MODE_LOW,4,i)); } else { if(Close[i] < iLow(NULL,0, iLowest(NULL,0,MODE_LOW,4,i+1))) { ExtMapBuffer1[i]=iHigh(NULL,0, iHighest(NULL,0,MODE_HIGH,4,i)); } else { ExtMapBuffer1[i]=PREV; } } PREV=ExtMapBuffer1[i]; } return(0); }
Хотя если для стопов, правильнее наверно сделать так
ExtMapBuffer1[i]=iLow(NULL,0, iLowest(NULL,0,MODE_LOW,4,i+1)); ExtMapBuffer1[i]=iHigh(NULL,0, iHighest(NULL,0,MODE_HIGH,4,i+1));но тогда картинка меняется
Vinin:
Немного переделал. Мне кажется стал более удобным, практичным
//+------------------------------------------------------------------+ //| 4D - Range Switch.mq4 | //| Copyright © 2009, Vic2008 | //| | //+------------------------------------------------------------------+ #property copyright "Copyright © 2009, Vic2008" #property link "" #property indicator_chart_window #property indicator_buffers 1 #property indicator_color1 Red extern int period=4; //---- buffers double ExtMapBuffer1[]; //+------------------------------------------------------------------+ //| Custom indicator initialization function | //+------------------------------------------------------------------+ int init() { //---- indicators SetIndexStyle(0,DRAW_LINE); SetIndexBuffer(0,ExtMapBuffer1); //---- return(0); } //+------------------------------------------------------------------+ //| Custom indicator deinitialization function | //+------------------------------------------------------------------+ int deinit() { //---- //---- return(0); } //+------------------------------------------------------------------+ //| Custom indicator iteration function | //+------------------------------------------------------------------+ int start() { int i; int Indicator_Counted=IndicatorCounted(); int limit=Bars-Indicator_Counted; if (limit>1){ limit=Bars-5; } for( i=limit; i>=0; i-- ){ double lHigh4=High[iHighest(NULL,0,MODE_HIGH,period, i+1)]; double lLow4 =Low[ iLowest( NULL,0,MODE_LOW, period, i+1)]; double lHigh3=High[iHighest(NULL,0,MODE_HIGH,period-1, i+1)]; double lLow3 =Low[ iLowest( NULL,0,MODE_LOW, period-1, i+1)]; ExtMapBuffer1[i]=ExtMapBuffer1[i+1]; if (Close[i]>lHigh4) ExtMapBuffer1[i]=lLow3; else if (Close[i]<lLow4) ExtMapBuffer1[i]=lHigh3; } return(0); } //+------------------------------------------------------------------+
По крайней мере. теперь можно в советниках использовать. Не будет на каждом тике всю историю пересчитывать
Да, так лучше и гибче... Спасибо!
Вы упускаете торговые возможности:
- Бесплатные приложения для трейдинга
- 8 000+ сигналов для копирования
- Экономические новости для анализа финансовых рынков
Регистрация
Вход
Вы принимаете политику сайта и условия использования
Если у вас нет учетной записи, зарегистрируйтесь
Реверс по 4-м свечам:
Author: Victor