Please help me find a method to minimize amount of code required to check the distance of a price bar to an EMA, 21 in this case. I'm checking the "closeness" of the High to the EMA in case I'm below it, then the Low if I'm above it, then the Close if my High and Lows are straddling the EMA, then checking which one is the least amount of distance to the EMA. (If I understand correctly, Math.Min only allows checking of two parameters)
[FONT=Courier New][SIZE=2][COLOR=#008000][FONT=Courier New][SIZE=2][COLOR=#008000] [SIZE=2][FONT=Courier New][COLOR=#008000]//distanceTo21a = Math.Round(Math.Abs(High[0] - EMA(21)[0])*10);[/COLOR][/FONT][/SIZE] [SIZE=2][FONT=Courier New][COLOR=#008000]// distanceTo21b = Math.Round(Math.Abs(Low[0] - EMA(21)[0])*10);[/COLOR][/FONT][/SIZE] [SIZE=2][FONT=Courier New][COLOR=#008000]// distanceTo21c = Math.Round(Math.Abs(Close[0] - EMA(21)[0])*10);[/COLOR][/FONT][/SIZE] [SIZE=2][FONT=Courier New][COLOR=#008000]// distanceTo21MinAB = Math.Min(distanceTo21a,distanceTo21b);[/COLOR][/FONT][/SIZE] [SIZE=2][FONT=Courier New][COLOR=#008000]// distanceTo21Min = Math.Min(distanceTo21MinAB,distanceTo21c);[/COLOR][/FONT][/SIZE] [/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT]
Kirk
Comment