# Time intervel based plot function

`````` if (interval() < 61)
{
e20 = EMA(open,20);
Plot (e20,"",colorLightBlue,styleNoLabel

}

if (interval() >60 )
{
e40 = EMA(open,40);
Plot (e3,"",colorred,styleNoLabel);
}

if (interval() >120 )

e52 = EMA(open,52);
Plot (e52,"",colorred,styleNoLabel);

}

``````

the above code notwork proper...
if i plot 1 min chart and 2min chart ( <61 & >60 works well ) works properly
if i plot >120 interval then chart displays both ema 40 and ema 52 plot simultaneously

but i need >120 is plat ema 52 only..

@madhan, you will need to add some variables to your code, and move your Plot statements out of the If statements for the EMA Calculations.

Here is an UNTESTED example:

``````// do EMA Calculations outside of the IF statements
if (interval()<61)
{
flag61 = true;
}
if( interval > 60)
{
flag60 = true;
}
if (interval>120)
{
flag61 = false;
flag60 = false;
flag120 = true;
}

if (flag61)
{
plot (...ema desired);
}
if(flag60)
plot(...ema desired);
}

``````

Sorry, not complete code, but just what I have time for right now. Should lead you to what you want.

1 Like

no flags required

``````period = 0;	color = -1;
if( interval() < 61 )
{
period = 20;    color = colorLightBlue;
}

if( interval() > 60 AND Interval() <= 120 )
{
period = 40;    color = colorOrange;
}

if( interval() > 120 )
{
period = 52;    color = colorRed;
}

if ( period > 0 )
Plot( EMA(O, period), "", color, styleNoLabel );
``````

Or simply

``````if( interval() < 61 )
{
period = 20;    color = colorLightBlue;
}
else if( interval() > 60 AND Interval() <= 120 )
{
period = 40;    color = colorOrange;
}
else // > 120
{
period = 52;    color = colorRed;
}

Plot( EMA(O, period), "", color, styleNoLabel );
``````
1 Like

Dera Fxshart , Always prove you are gem to novice trader & code learner..

S,its work well i realised my error in code..

Thanks & apologies for delay reply due to internet issues due to covid19..

Dear Snoopy.pa30..
Really i am happy to your quick Reply ..even your code work with little tweak..Thanks for your effort and helping mind..win the market & Earn from market.