//+------------------------------------------------------------------+ //| R-TYPE_ZigZag.mq4 | //| Copyright 2014, Rondo | //| http://fx-dollaryen.seesaa.net | //+------------------------------------------------------------------+ #property copyright "Rondo" #property link "http://fx-dollaryen.seesaa.net/" #property version "1.1" #property description "1時間足限定のインジケーター" #property strict #property indicator_chart_window #property indicator_buffers 1 #property indicator_color1 clrYellow #property indicator_width1 2 #define PERIOD_24HR 24 //---- indicator buffers double ZigzagBuffer[]; //+------------------------------------------------------------------+ //| Custom indicator initialization function | //+------------------------------------------------------------------+ int OnInit(){ IndicatorBuffers(1); SetIndexStyle(0, DRAW_SECTION); SetIndexBuffer(0, ZigzagBuffer, INDICATOR_DATA); ArraySetAsSeries(ZigzagBuffer, true); ArrayInitialize(ZigzagBuffer, EMPTY_VALUE); //---- indicator short name IndicatorShortName("R-TYPE_ZigZag"); //---- initialization done return(INIT_SUCCEEDED); } //+------------------------------------------------------------------+ //| Custor indicator deinitialization function | //+------------------------------------------------------------------+ int deinit(){ //---- //---- return(0); } //+------------------------------------------------------------------+ //| Custom indicator iteration function | //+------------------------------------------------------------------+ int OnCalculate(const int rates_total, const int prev_calculated, const datetime& time[], const double& open[], const double& high[], const double& low[], const double& close[], const long& tick_volume[], const long& volume[], const int& spread[]){ if(_Period != 60) return(0); int counted_bars = prev_calculated; int limit = rates_total - counted_bars; if(limit>0) limit = rates_total - PERIOD_24HR -1; else limit = 0; int flag = 1; int index = rates_total - 1; for(int i=limit; i>=0; i--){ ZigzagBuffer[i] = EMPTY_VALUE; double upBand = iBands(NULL, 0, PERIOD_24HR, 1, 0, PRICE_HIGH, MODE_UPPER, i); double lowBand = iBands(NULL, 0, PERIOD_24HR, 1, 0, PRICE_LOW, MODE_LOWER, i); if(lowBand > low[i] && upBand < high[i]) continue; if(flag > 0 && lowBand > low[i]){ index = iHighest(NULL, 0, MODE_HIGH, index-i, i); ZigzagBuffer[index] = high[index]; flag = -1; } if(flag < 0 && upBand < high[i]){ index = iLowest(NULL, 0, MODE_LOW, index-i, i); ZigzagBuffer[index] = low[index]; flag = 1; } } return(0); }