this was my try but there are still errors... dont be irritated because here is dayClose instead of open... the idea is the same ... I want to use this for diferent tests...
#property strict #property indicator_separate_window //show "Hit" in separate window #property indicator_minimum 0 #property indicator_maximum 1 #property indicator_buffers 1 #property indicator_plots 1 #property indicator_label1 "Hit" #property indicator_type1 DRAW_HISTOGRAM #property indicator_color1 clrMediumBlue #property indicator_style1 STYLE_SOLID #property indicator_width1 1 #property indicator_chart_window //show "Today Close" in chart window #property indicator_label2 "DayClose" #property indicator_buffers 1 #property indicator_color1 Blue #property indicator_style1 4 #property indicator_width1 1 //--- input parameters double findagainvalue[]; input int Startstunde[]=8; input double Findagainstarttime=16; input double Findagainendtime=26; input int Testperiode=1000; extern double TimeZoneOfData=0; datetime Valuetime; bool ExtParameters=false; //--- indicator buffers int Hit[]; double TodayCloseBuffer[]; //+------------------------------------------------------------------+ //| Custom indicator initialization function | //+------------------------------------------------------------------+ int OnInit() { //--- indicator buffers mapping SetIndexBuffer(0,Hit); SetIndexStyle(0,DRAW_HISTOGRAM); SetIndexLabel(0,"Hit"); SetIndexEmptyValue(0,0); // } // { SetIndexStyle(1,DRAW_LINE); SetIndexBuffer(1,TodayCloseBuffer); SetIndexLabel(1,"DayClose"); SetIndexEmptyValue(1,0.0); return(0); // } //--- if(Testperiode<=1) { Print("Wrong input parameters"); ExtParameters=false; return(INIT_FAILED); } else ExtParameters=true; //--- initialization done return(INIT_SUCCEEDED); } //+------------------------------------------------------------------+ //| 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[]) { int counted_bars=IndicatorCounted(); if(counted_bars < 0) return(-1); if(counted_bars>0) counted_bars--; int lastbar=Bars-counted_bars; if(counted_bars==0) lastbar-=1+1; DailyClose(1,lastbar); return (0); } //+------------------------------------------------------------------+ //| DailyClose | //+------------------------------------------------------------------+ int DailyClose(int offset,int lastbar) { int shift; int tzdiffsec=TimeZoneOfData*3600; bool ShowDailyCloseLevel=True; for(shift=lastbar;shift>=offset;shift--) { TodayCloseBuffer[shift]=0; if(ShowDailyCloseLevel) { if(TimeDay(Time[shift]-tzdiffsec)!=TimeDay(Time[shift-1]-tzdiffsec)) { // day change TodayCloseBuffer[shift]=Close[shift]; //Initialisierung Buffer TodayCloseBuffer[shift+1]=0; //Deinitialisierung verhindert Stufen Startstunde[shift]=Time[shift]; findagainvalue[shift]=Close[shift]; } else { TodayCloseBuffer[shift]=TodayCloseBuffer[shift+1]; } } } return(0); } int countHit(int offset,int lastbar) { int shift; for(shift=lastbar;shift>=offset;shift--) { Hit[shift]=0; if (Time[0]>Startstunde[0]+Findagainstarttime*3600 && Time[0]<Startstunde[0]+Findagainendtime*3600) Hit[shift]=1; else Hit[shift]=0; } return(Hit); } //+------------------------------------------------------------------+

You are missing trading opportunities:
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
Registration
Log in
You agree to website policy and terms of use
If you do not have an account, please register
hello,
i try for hours to build an easy custom indicator... in mt4 ....but i am new in indicator programming.
what i want to have is very easy in my opinion:
i want a simple 1 or 0 in case the price returns in a specific time window back to a certain level.
For example: open at 8 a.m. Does the price come back to this value in the time between 1 p.m. (Start time after 5 hours) same day and 7 a.m. the day after the next day (End time after 47 hours)? if so=1 else =0 / shown in histogram (perhaps with MA of the hits)
under the open should be the histogram with 0 (without hit) or 1 (with hit). So at first it is a 0... then the time window comes and perhaps price reaches the same level and it changes to a 1.
Can s.o. help me with the code for this?