Hello,
Im trying to do a tidy little MA script with the 10 21 23e 50 65e all in one study. However, on recent IPOs there isnt enough data for most of these and if the average() returns nothing, it removes my plots of the averages that do return data. Ive tried all kinds of if statements but they seem to execute both sides of the statement and it then invalidates the plots again. Sorry if this has been asked before, but I tried to search and may have not used the right filter words.
Example of script:
Im trying to do a tidy little MA script with the 10 21 23e 50 65e all in one study. However, on recent IPOs there isnt enough data for most of these and if the average() returns nothing, it removes my plots of the averages that do return data. Ive tried all kinds of if statements but they seem to execute both sides of the statement and it then invalidates the plots again. Sorry if this has been asked before, but I tried to search and may have not used the right filter words.
Example of script:
Code:
#Establish the 10sma and query whether it is a daily or weekly chart
plot short_SMA10;
def SMA10;
if barNumber() > 10 {
if GetAggregationPeriod() > AggregationPeriod.DAY {
SMA10 = Average(price, 2);
} else {
SMA10 = Average(price, 10);
}
short_SMA10 = if show_sma10 then SMA10 else double.nan;
} else {
SMA10 = double.nan;
short_SMA10 = double.nan;
}
short_SMA10.SetDefaultColor(Color.GREEN);
#Establish the 21sma and query whether it is a daily or weekly chart
def sma21 = average(price,21);
def blah = double.nan;
def graphme;
if barNumber() < 21 {
graphme = blah;
} else {
graphme = sma21 ;
}
plot short_SMA21 = graphme;
short_SMA21.SetDefaultColor(Color.CYAN);