|
|||||||
| Register in Forex TSD! | |
|
Trading Systems Leaders in this forum (automated trading systems) are winning more than 3000 pips in a month (30000$ investing one lot every time). Click here to register and get more information |
|
![]() |
|
|
LinkBack | Thread Tools | Display Modes |
|
|||
|
Best way to add MaxBarsToCount (History) to the limit?
Dear Admin, would be great if we didn't merge this thread and leave it separate -
question (problem) very common and specific thread much easier for Search (plus this question allready in general thread, but no answer...) -------------------------------------------------------------------- When we limit MaxBarsToCount (History) sometimes it require to add Correction, etc is the best (safest, easiest, universal) way exist? (rule of tumb? dirty triks?) ---------------------- like here we have light fisher 4 stoch smothing: ---------- int start() { int counted_bars=IndicatorCounted(); //---- check for possible errors if(counted_bars<0) return(-1); int limit=Bars-counted_bars; if(limit>maxbars)limit=maxbars; if (limit>Bars-lenth-1)limit=Bars-lenth-1; //---- for (int shift = limit; shift>=0;shift--) { AuxBuffer[shift]=(iStochastic(NULL,0,lenth,2,1,MODE_SMA,0,MODE_MAI N,shift)/100-0.5) +0.5*AuxBuffer[shift+1]; FishBuffer[shift]= 0.25* MathLog((1+AuxBuffer[shift])/(1-AuxBuffer[shift]))+ 0.5*FishBuffer[shift+1]; SignalBuffer[shift]=FishBuffer[shift+1]; } //---- return(0); } ------------------------ for fisher limit f-la: int limit; int counted_bars=IndicatorCounted(); if(counted_bars>0) counted_bars--; limit=Bars-counted_bars; for(int i=limit; i>=0; i--) { .... for Stoch: int start() { int i,k; int counted_bars=IndicatorCounted(); double price; //---- if(Bars<=draw_begin2) return(0); //---- initial zero if(counted_bars<1) { for(i=1;i<=draw_begin1;i++) MainBuffer[Bars-i]=0; for(i=1;i<=draw_begin2;i++) SignalBuffer[Bars-i]=0; } //---- minimums counting i=Bars-KPeriod; if(counted_bars>KPeriod) i=Bars-counted_bars-1; while(i>=0) { double min=1000000; k=i+KPeriod-1; while(k>=i) { price=Low[k]; if(min>price) min=price; k--; } LowesBuffer[i]=min; i--; } .... p.s. in attached indicator, based on clean fisher transform and Stoch; MaxBars (tail) needs to be straighten-up a bit... (when MaxBars out - no problem) pps. same thing with many others; try to add maxBars to regular (stoc) macd and look on the tail... Last edited by fxbs : 01-23-2008 at 10:58 PM. |
|
|||
|
thank you everybody who helped!
here it is: when we have no arrays - works basic formula: limit = MathMin(limit, MaxBarsToCount); but when we have 4ex. MAonArray - we need more bars (MA period) to count first MaonArray bar: MaxBarsToCount + MA period macd limit test3.gif so, two ways possible- count more or draw less: - draw MaxBarsToCount but count more limit = MathMin(limit, MaxBarsToCount)+ MA period - or count the same but draw less SetIndexDrawBegin(i,Bars-MaxBarsToCount+MA period); _____ in all cases SetIndexDrawBegin in "int start()" not at "init()" section for (i=0;i<indicator_buffers;i++) SetIndexDrawBegin(i,Bars-MaxBarsToCount + MA period); return(0); } |
|
|||
|
________
whole thing 4 MAGD: PHP Code:
Last edited by fxbs : 03-01-2008 at 05:22 PM. |
|
|||
|
another way - but that's - dirty trick:
simple macd; only "-SignalSMA" added - that's it //---- signal line counted in the 2-nd buffer for(i=0; i<limit-SignalSMA; i++) before: PHP Code:
PHP Code:
not cleanest solution, but .... (as been mentioned- dirty trick; and TRO can use it for his book...) : - ))))))))) ____________ P.S. whoops - people say this slaking approach no good: limit-SignalSMA can be negative - not refreshing, etc, etc... whoopsy daisy ... what to do? ![]() ____________ gets trickier and trickier... MaxBarsToCount instead of limit - should take care of it? for(i=0; i<MaxBarsToCount -SignalSMA; i++) instead of for(i=0; i<limit-SignalSMA; i++) -sure, but we sacrificing our beloved limit.... well, gets even more trickier: PHP Code:
so: for(int i=0; i<limit+SignalSMA; i++) they wouldn't call it "dirty trick" for nothing... to do it right - everybody can; - try to do it ... different.... : )))) new update: now - even more less dirtier (setting limit4 each buffer): PHP Code:
... 2. limit = MathMin(limit, MaxBarsToCount-SignalSMA); !nobody messes with our Limit!! : (((( Last edited by fxbs : 03-01-2008 at 08:14 PM. |
|
|||
|
There is no ONE best solution.
It depends of what you want to do: for example, some indics must run at every tick of bar 0, but some other needs to run only once at the open of the bar, it's stupid to let them run at each tick; some cannot run the last "x" bars of the history because they need the datas, some run from the past to the present and some others no, and so on. The best solution is the one YOU understand ! I must admit that sometime it's very tricky... I such cases, in order to test how it works, I suggest you to add a command inside the "for" loop to print or comment the bar number, for example : for(int i = limitblablabla...) { Print(i + " " + Bars + " " + IndicatorCounted()); In a generic case, if you only want to add a MaxBars count at a working indic , the easiest way is to add at the first line of the "for" loop this line : for(int i = limitblablabla...) //original command , no need to understand it { if(i > MaxBars) continue; .... |
|
|||
|
Quote:
- that's how we learn, day by day |
|
|||
|
Hey, Michel!
how to use this line: if(i > MaxBars) continue; i tryed - no go... but if put like this: if(i < MaxBarsToCount) - works (MACD): PHP Code:
|
|
|||
|
Quote:
"if(i < MaxBarsToCount) MacdBuffer[i]=iMA(NULL,0,FastEMA... ;" is only one command ( there is only one ";" ) so the for loop doesn't need any brackets. Now, the use "if(i >MaxBarsToCount) continue;" means one more command in the for loop, so you have to use brackets to group them together. so : for(int i=0; i<limit; i++) if(i > MaxBarsToCount) continue; does'nt work because there is only one command, the if test line, which does nothing. but for(int i=0; i<limit; i++) { if(i > MaxBarsToCount) continue; MacdBuffer[i]=iMA(NULL,0,FastEMA,0,MODE blabla ; blahblahblah...; } works. I a general case, the for loop use brackets, thus "if(i > MaxBarsToCount) continue;" is ready to use (you do not need to add other brakets or modify the code) Last edited by Michel : 03-01-2008 at 07:42 AM. |
|
|||
|
Thank you, Michel! well, i did as you sayed - PHP Code:
works good but when onArray - old story - steping on tail (maybe should have use more braskets: ) macd maxbars limit.gif well, 4 onArray buffer : if(i > MaxBarsToCount - SignalSMA) continue; and that's it! : )))))))) PHP Code:
|