U
USptcom
Guest
Script in question is one I compiled back in 2015 and since then have forgotten the little I learned about scripting (took a break from TDA/TOS). I'm hoping someone can find the reason for its creating a 35% increase in CPU load or maybe even offer a more efficient way of scripting.
Thanks!
Script provides in-chart labels for futures index trend tracking.
Thanks!
Script provides in-chart labels for futures index trend tracking.
input length1 = 140;
input length2 = 100;
input length3 = 60;
input length4 = 30;
input length5 = 10;
def ESclose = close ("/ES", period = AggregationPeriod.DAY);
def NQclose = close ("/NQ", period = AggregationPeriod.DAY);
def YMclose = close ("/YM", period = AggregationPeriod.DAY);
def ESchange = ESclose - ESclose[1];
def NQchange = NQclose - NQclose[1];
def YMchange = YMclose - YMclose[1];
def EScloseMin = close ("/ES", period = AggregationPeriod.MIN);
def NQcloseMin = close ("/NQ", period = AggregationPeriod.MIN);
def YMcloseMin = close ("/YM", period = AggregationPeriod.MIN);
def ESchangePct = (ESclose - ESclose[1]) / ESclose[1] * 100;
def NQchangePct = (NQclose - NQclose[1]) / NQclose[1] * 100;
def YMchangePct = (YMclose - YMclose[1]) / YMclose[1] * 100;
def EScloseMin1 = if EScloseMin >= EScloseMin[length1] then 1 else 0;
def EScloseMin2 = if EScloseMin >= EScloseMin[length2] then 1 else 0;
def EScloseMin3 = if EScloseMin >= EScloseMin[length3] then 1 else 0;
def EScloseMin4 = if EScloseMin >= EScloseMin[length4] then 1 else 0;
def EScloseMin5 = if EScloseMin >= EScloseMin[length5] then 1 else 0;
def NQcloseMin1 = if NQcloseMin >= NQcloseMin[length1] then 1 else 0;
def NQcloseMin2 = if NQcloseMin >= NQcloseMin[length2] then 1 else 0;
def NQcloseMin3 = if NQcloseMin >= NQcloseMin[length3] then 1 else 0;
def NQcloseMin4 = if NQcloseMin >= NQcloseMin[length4] then 1 else 0;
def NQcloseMin5 = if NQcloseMin >= NQcloseMin[length5] then 1 else 0;
def YMcloseMin1 = if YMcloseMin >= YMcloseMin[length1] then 1 else 0;
def YMcloseMin2 = if YMcloseMin >= YMcloseMin[length2] then 1 else 0;
def YMcloseMin3 = if YMcloseMin >= YMcloseMin[length3] then 1 else 0;
def YMcloseMin4 = if YMcloseMin >= YMcloseMin[length4] then 1 else 0;
def YMcloseMin5 = if YMcloseMin >= YMcloseMin[length5] then 1 else 0;
AddLabel (1, (" ES " + Round(ESchange, 0)), if ESchange <= -.5 then Color.DARK_RED else if ESchange >= .5 then Color.DARK_GREEN else Color.BLACK);
AddLabel (1, AsText(ESchangePct, NumberFormat.TWO_DECIMAL_PLACES) + "%", if ESchangePct < 0 then Color.DARK_RED else if ESchangePct > 0 then Color.DARK_GREEN else Color.BLACK);
AddLabel (1, if EScloseMin1 then " " else " ", if EScloseMin1 then Color.GREEN else Color.RED);
AddLabel (1, if EScloseMin2 then " " else " ", if EScloseMin2 then Color.GREEN else Color.RED);
AddLabel (1, if EScloseMin3 then " " else " ", if EScloseMin3 then Color.GREEN else Color.RED);
AddLabel (1, if EScloseMin4 then " " else " ", if EScloseMin4 then Color.GREEN else Color.RED);
AddLabel (1, if EScloseMin5 then " " else " ", if EScloseMin5 then Color.GREEN else Color.RED);
AddLabel (1, " NQ " + Round(NQchange, 0), if NQchange <= -.5 then Color.DARK_RED else if NQchange >= .5 then Color.DARK_GREEN else Color.BLACK);
AddLabel (1, AsText(NQchangePct, NumberFormat.TWO_DECIMAL_PLACES) + "%", if NQchangePct < 0 then Color.DARK_RED else if NQchangePct > 0 then Color.DARK_GREEN else Color.BLACK);
AddLabel (1, if NQcloseMin1 then " " else " ", if NQcloseMin1 then Color.GREEN else Color.RED);
AddLabel (1, if NQcloseMin2 then " " else " ", if NQcloseMin2 then Color.GREEN else Color.RED);
AddLabel (1, if NQcloseMin3 then " " else " ", if NQcloseMin3 then Color.GREEN else Color.RED);
AddLabel (1, if NQcloseMin4 then " " else " ", if NQcloseMin4 then Color.GREEN else Color.RED);
AddLabel (1, if NQcloseMin5 then " " else " ", if NQcloseMin5 then Color.GREEN else Color.RED);
AddLabel (1, " YM " + Round(YMchange, 0), if YMchange <= -.5 then Color.DARK_RED else if YMchange >= .5 then Color.DARK_GREEN else Color.BLACK);
AddLabel (1, AsText(YMchangePct, NumberFormat.TWO_DECIMAL_PLACES) + "%", if YMchangePct < 0 then Color.DARK_RED else if YMchangePct > 0 then Color.DARK_GREEN else Color.BLACK);
AddLabel (1, if YMcloseMin1 then " " else " ", if YMcloseMin1 then Color.GREEN else Color.RED);
AddLabel (1, if YMcloseMin2 then " " else " ", if YMcloseMin2 then Color.GREEN else Color.RED);
AddLabel (1, if YMcloseMin3 then " " else " ", if YMcloseMin3 then Color.GREEN else Color.RED);
AddLabel (1, if YMcloseMin4 then " " else " ", if YMcloseMin4 then Color.GREEN else Color.RED);
AddLabel (1, if YMcloseMin5 then " " else " ", if YMcloseMin5 then Color.GREEN else Color.RED);