MMI and Thinkscript - Think or Swim

Posted By: chsmac85

MMI and Thinkscript - Think or Swim - 12/10/18 22:56

I'm trying to convert the lite C version of MMI into thinkscript so that I can use MMI with think or swim.

I've coded up the following but I'm not 100% sure it's doing what it's supposed to do as the iterator logic is different in thinkscript than anything I've seen. Thinkscript uses fold instead of for loops. See https://tlc.thinkorswim.com/center/reference/thinkScript/Reserved-Words/fold.html

The trickiest part was calculating nh and nl as these are iterated for each price in the lookback series.

The input mmiLength section lets the user define how far back you want to look. I choose 150 as a default value based off of a previous post from JCL that said 100-200 bars is a good compromise.

Here's my solution. Anyone see any problems with it?

input mmiLength = 150;
def m = Median(close, mmiLength);

def nh = fold i = 1 to mmiLength+1 with p = 0 do if close[i] > m and close[i] > getValue(close, i + 1) then p+1 else p+0;

def nl = fold j = 1 to mmiLength+1 with q = 0 do if close[j] < m and close[j] < getValue(close, j + 1) then q+1 else q+0;

plot mmi= 100*(nl+nh)/(mmiLength-1);
Posted By: OptimusPrime

Re: MMI and Thinkscript - Think or Swim - 12/11/18 00:45

Hi chsmac85:

This is a Zorro specific forum.. We are trying to learn and improve our use of Lite-C specifically. Did you try a similiar forum specifically for ThinkorSwim coding?
Posted By: chsmac85

Re: MMI and Thinkscript - Think or Swim - 12/11/18 02:36

sorry I didn't. I considered MMI to be a part of the zorro family and posted in the brokers section given think or swim is a platform for a very popular broker. But that's fine, I can look for help elsewhere.
© 2024 lite-C Forums