Multi timeframe should be Visible while Ltp Touch

Dear Tomosz & Senior Experts

i have setup multi time frame MA indi in my chart , have so many Lines ,it's annoying to read/seen the chart on lower time frame ( 1min)..

i can do using "if (intervel () > .. or < ) to overcome while change the time frame 1min to 5 min, 10min, 15 min,& hourly
but in 1 min time frame i need all Multi time frame MA
so my idea is it's visible only while LTP (close) touch the indicator /cross the indicator then that indicator should be visible in screen

if close price not touch or cross the indicator then that indicator should be invisible

Please help to get it

example code :

TimeFrameSet( in15Minute ); // switch now to 15 minute data

ma5 = EMA( Open, 5 ); // 5 bar moving average of OPEN from 15 minute data 

TimeFrameRestore(); // restore time frame to original 

Plot( Close, "Price", colorWhite, styleCandle ); 

// plot expanded average 
Plot( TimeFrameExpand( ma5, in15Minute), "5 bar moving average from 15 min bars", colorRed );

sample picture
MA%20visible

You can check that and enclose it in a condition like this

m200 = MA( C, 200 ); 
pc_m200 = abs( m200/C - 1)*100;  // % diff
tmax = 5;	// Max Percentage difference

check1 = LastValue( pc_m200 ) <= tmax;

if( check1 ) {
    // Plot()
}

then choose a maximum threshold tmax that you want to limit the plot to.

1 Like

Dear Travick, pls i can't understand properly..
in your code i am not able to understand why using max percentage difference and tmax
pls provide one example code properly, i will learn ..

Thanks

Different Tickers will have different values, some maybe 10 and some maybe 10,000 as I see in your case so instead of hardcoding a value say 100-200 points etc, if you use % then it'll be appropriate most (if not all) of the time.

So, here, we will check "How Near" the MA is to the Last price.

You will need a variable for each of the MAs that you are plotting, in this case I'm using MA-200

For 200ma, pc_m200 will be the % difference from Close.
tmax, will be what you set, so if tmax is 5, that means 5%.

So +/-5% 10800 (Last price) is +/-540. Therefore, only if the MA is within a specific % defined by you, the Plot() will be called else skipped.

Another way, is to NULL large values, but I don't think this is efficient, where you can NULL individual values of the Array and prevent them from plotting.
In some cases, you may get broken lines etc but it is possible to remove noise.

m200 = MA( C, 200); 
pc_m200 = abs( m200/C - 1)*100 <= 5; // tmax=5
pma = IIf( pc_m200, m200, Null );
Plot( pma, "m200", colorDarkBlue, styleLine );
// I wont prefer this method though.
1 Like

Dear Travick,

Thanks for prompt reply asap..

But don't mistaken me, please read my question /or view my sample picture again once,..

your code is right to my query then i am wrong to ask my query clearly..

my query is :

in my picture i plotted 4 Multi time frame MA like 5 min, 15min, hourly, daily with 5 bar moving average..

those 4 lines plotted in chart , here i need if LTP cross 5min yellow line then then this yellow line should be appear in chart otherwise disappear ,like that all other MA's

so if (LTP cross MA of 5 bar in 15min time frame ),visibel( yellow line)

maybe i ask correctly ?

I got your question but I was suggesting a more appropriate way to deal with it.

In English, this sounds good but mathematically it isn't. How is touch expressed in maths? hence, I suggested a percentage threshold instead.
And Cross() is actually a function in AB, an impulse not a state, so this is even more ambiguous so you have to clarify this.

Also, you are dealing with large value Moving averages, they will tend to "Lag" and skew the plotting scale unlike tights bands around the price. so more affirmative logic and requirement should be considered as to what is really needed :slight_smile:

If it is a scalar, we can say touch/overlap in a more precise way, but these are Arrays, one end may be 5% away and the other overlapping the price, so which should be considered? I hope you get the point.

1 Like

thanks for detailed explanation dear..

" Also, you are dealing with large value Moving averages, they will tend to "Lag" and skew the plotting scale unlike tights bands around the price "

so that i asked the MA visible/invisible

so better thing is using % via plot it...!

1 Like