Why not called? Excelent called and fine works! Your corrected source is this
Run it and view log.
//+------------------------------------------------------------------+ //| CheckiLowest.mq4 | //| Copyright © 2007, MetaQuotes Software Corp. | //| https://www.metaquotes.net/ | //+------------------------------------------------------------------+ #property indicator_separate_window //#property indicator_minimum 0 #property indicator_buffers 1 #property indicator_color1 Orange double Buffer[]; int init() { SetIndexStyle(0,DRAW_HISTOGRAM,STYLE_SOLID,3); SetIndexBuffer(0,Buffer); IndicatorDigits(2); IndicatorShortName("SpreadMove (spread="+DoubleToStr(MarketInfo(Symbol(),MODE_SPREAD),0)+")"); return(0); } int start() { int limit; if (Point==0) return(-1); int counted_bars=IndicatorCounted(); if(counted_bars<0) return(-1); if(counted_bars>0) counted_bars--; limit=Bars-counted_bars; double spread=MarketInfo(Symbol(),MODE_SPREAD); double lowest=Close[iLowest(Symbol(),Period(),MODE_CLOSE,WindowBarsPerChart(),WindowFirstVisibleBar()-WindowBarsPerChart())]; for(int c=0;c<limit;c++) { Buffer[c]=MathFloor((Close[c]-lowest)/(spread*Point))+1; Print("c=",c," Close[",c,"]=",Close[c]," lowest=",lowest," WindowFirstVisibleBar=",WindowFirstVisibleBar()," WindowBarsPerChart()=",WindowBarsPerChart()); } return(0); }
Run it and view log.
Because if you scroll back the indicator window you will see that some bars are
less than zero, which would not happen if start() was called again for the bars
currently in view. If I change the period the bars are properly redrawn (untill
I scroll again).
Yes, you are right, it is necessary to know about this feature. I have made an
example which shows it.
//+------------------------------------------------------------------+ //| CheckiLow.mq4 | //| Copyright © 2007, MetaQuotes Software Corp. | //| https://www.metaquotes.net/ | //+------------------------------------------------------------------+ #property copyright "Copyright © 2007, MetaQuotes Software Corp." #property link "https://www.metaquotes.net/" //+------------------------------------------------------------------+ //| script program start function | //+------------------------------------------------------------------+ int start() { //---- int c,limit,index,range; limit=WindowFirstVisibleBar()-WindowBarsPerChart(); double lowest; range=WindowBarsPerChart(); Print(" WindowFirstVisibleBar=",WindowFirstVisibleBar()," WindowBarsPerChart()=",WindowBarsPerChart()," limit=",limit); c=limit; while(c!=0) { index=iLowest(Symbol(),Period(),MODE_CLOSE,WindowBarsPerChart(),c); lowest=Close[index]; Print("c=",c," index=",index," Close[",c,"]=",Close[c]," lowest=",lowest); if (c>0) c--; if (c<0) c++; } Print("iLowest[0]=",iLowest(Symbol(),Period(),MODE_CLOSE,range,0)); //---- return(0); } //+------------------------------------------------------------------+
Thank you.
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
I am trying to write a indicator that shows the movement of the price in spreads (i.e 1 point of the histogram is one spread) .
I have this problem. start() is not called upon scroll of the window. I do something like this:
to get the lowest visible close price, but when I scroll the window start() is not called again or even if it is WindowFirstVisibleBar() returns the same value, so I always get the lowest price of the most recent bars. ..
Here is the whole code:
I have to comment this /*,WindowBarsPerChart(),WindowFirstVisibleBar()-WindowBarsPerChart()*/ , because otherwise I get negative values, but I want the lowest value on the chart to be zero...
Please help me if you have experience with indicators.