Spezifikation
Hello developers,
The purpose of this indicator is to preserve value of indicator value on one Time-frame when turn chart on different TF. The underlying condition is:
if(iMA(NULL,D1,15,0,MODE_EMA,0,d1bar_1)>=iMA(NULL,D1,15,0,MODE_EMA,0,d1bar_2)) THEN value=1, else Value=-1
I knew how to do it using 1 method, named APPROACH 1 in the code. It is a bit long, especially when it come to lag value like today (D_0), yesterday (D_1)....
I am learning method 2, named APPROACH 2 which allow me simply create a value like indicator_1[I]=indicator_0[I+1]. The problem is that on H1, the [I+1] is 1 more H1 bar even though I want to preserve D1 value which associated with D1 bar.
With the help of other member, the preservation of D1 on any TF chart is done. I want you to follow exactly the same method for H4 and H1.
I try to fill in all other information, and essentially, all you need to do is to make adjustment for H4 and H1 in the below section (If I am correct).
//---THIS SECTION IS FOR D1 CONVERISIOn------------------------------------------------------------- //-this section is to make sure that on NON_D1 chart, value of D1 still "preserve and spread" #define HR2400 86400 // 24 * 3600 = PERIOD_D1 * 60 int TimeOfDay(datetime when=0){ if(when == 0) when = TimeCurrent(); return( when % HR2400 ); } datetime DateOfDay(datetime when=0){ if(when == 0) when = TimeCurrent(); return( when - TimeOfDay(when) ); } datetime Yesterday(datetime when=0){ if(when == 0) when = TimeCurrent(); int iD1 = iBarShift(NULL, PERIOD_D1, DateOfDay(when) - 1); return( iTime(NULL, PERIOD_D1, iD1) ); } //-------------------------------------------------------------------------------------------------- //lag operation datetime now = Time[i], yest = Yesterday(now); int iYest = iBarShift(NULL,0, yest); D1new_indi_1[i]=D1new_indi[iYest];
I attached the code itself and the MA color indicator just so you can compare the result.