I'm looking for developer on thinkorswim and python
Budget: $30 – $250 USD
I’m using the THINKORSWIM (TOS) Exponen<al Standard Devia<on (ESD) Bands as part of a
strategy and am trying to replicate in PYTHON using the HULL moving average type. In the past
we have not been able to replicate the hull moving average in Python that mimics the TOS
strategy.
I need to be able to run both a TOS and PYTHON in parallel that give me the same results. I
need to be able to change the variables (lookback and standard devia<on) for both and s<ll get
the same results.
My first choice would be to get PYTHON code that replicates the TOS code.
My second choice would be to get PYTHON and TOS code that match the results and are very
close to the original code.
TOS CODE:
Exponen<al Standard Devia<on (ESD)
input length = 20;
input numDevDn = -2.0;
input numDevUp = 2.0;
input averageType = AverageType.HULL;
def avg = MovingAverage(averageType, close);
def expDev = ExpAverage(AbsValue(avg - close), length);
plot UpperBand = avg + numDevUp * expDev;
plot MidLine = avg;
plot LowerBand = avg + numDevDn * expDev;
ExpAverage
ExpAverage ( IDataHolder data, int length);
Default values:
length: 12
Descrip<on
Returns the exponen<al moving average (EMA) of data with length.
The formula for the calcula<on of the exponen<al moving average is recursively defined as
follows:
EMA1 = price1;
EMA2 = α*price2 + (1 - α)*EMA1;
EMA3 = α*price3 + (1 - α)*EMA2;
EMAN = α*priceN + (1 - α)*EMAN-1;
where α is a smoothing coefficient equal to 2/(length + 1).
Note that in thinkScript®, exponen<al moving averages use prefetch, see the Past Offset and
Prefetch ar<cle for details.
Input parameters
Parameter Default value Descrip1on
data - Defines data for which the average is found.
length 12 Defines period on which the average is found.
Example
input price = close;
input length = 12;
plot ExpAvg = ExpAverage(price, length);
The example plots an exponen<al moving average of a security's Close price.
MovingAverage
MovingAverage ( int averageType, IDataHolder data, int length);
Default values:
averageType: AverageType.Simplelength: 12
Descrip<on
Returns the average value of specified type and length for a data set. Available average types
are: Simple, Exponen<al, Weighted, Wilder's, and Hull. Each type can be defined
using AverageType constants.
Input parameters
Parameter Default value Descrip1on
averageType AverageType.Simple Defines type of average to be applied. This parameter
accepts AverageType constants as value.
data - Defines data for which the average is found.
length 12 Defines period on which the average value is found.
Example
input price = FundamentalType.CLOSE;
input aggrega<onPeriod = Aggrega<onPeriod.DAY;
input length = 12;
input averageType = AverageType.SIMPLE;
plot MovAvg = MovingAverage(averageType, Fundamental(price, period = aggrega<onPeriod),
length);
This example script plots a moving average of specified type and length for specified fundamental data.
strategy and am trying to replicate in PYTHON using the HULL moving average type. In the past
we have not been able to replicate the hull moving average in Python that mimics the TOS
strategy.
I need to be able to run both a TOS and PYTHON in parallel that give me the same results. I
need to be able to change the variables (lookback and standard devia<on) for both and s<ll get
the same results.
My first choice would be to get PYTHON code that replicates the TOS code.
My second choice would be to get PYTHON and TOS code that match the results and are very
close to the original code.
TOS CODE:
Exponen<al Standard Devia<on (ESD)
input length = 20;
input numDevDn = -2.0;
input numDevUp = 2.0;
input averageType = AverageType.HULL;
def avg = MovingAverage(averageType, close);
def expDev = ExpAverage(AbsValue(avg - close), length);
plot UpperBand = avg + numDevUp * expDev;
plot MidLine = avg;
plot LowerBand = avg + numDevDn * expDev;
ExpAverage
ExpAverage ( IDataHolder data, int length);
Default values:
length: 12
Descrip<on
Returns the exponen<al moving average (EMA) of data with length.
The formula for the calcula<on of the exponen<al moving average is recursively defined as
follows:
EMA1 = price1;
EMA2 = α*price2 + (1 - α)*EMA1;
EMA3 = α*price3 + (1 - α)*EMA2;
EMAN = α*priceN + (1 - α)*EMAN-1;
where α is a smoothing coefficient equal to 2/(length + 1).
Note that in thinkScript®, exponen<al moving averages use prefetch, see the Past Offset and
Prefetch ar<cle for details.
Input parameters
Parameter Default value Descrip1on
data - Defines data for which the average is found.
length 12 Defines period on which the average is found.
Example
input price = close;
input length = 12;
plot ExpAvg = ExpAverage(price, length);
The example plots an exponen<al moving average of a security's Close price.
MovingAverage
MovingAverage ( int averageType, IDataHolder data, int length);
Default values:
averageType: AverageType.Simplelength: 12
Descrip<on
Returns the average value of specified type and length for a data set. Available average types
are: Simple, Exponen<al, Weighted, Wilder's, and Hull. Each type can be defined
using AverageType constants.
Input parameters
Parameter Default value Descrip1on
averageType AverageType.Simple Defines type of average to be applied. This parameter
accepts AverageType constants as value.
data - Defines data for which the average is found.
length 12 Defines period on which the average value is found.
Example
input price = FundamentalType.CLOSE;
input aggrega<onPeriod = Aggrega<onPeriod.DAY;
input length = 12;
input averageType = AverageType.SIMPLE;
plot MovAvg = MovingAverage(averageType, Fundamental(price, period = aggrega<onPeriod),
length);
This example script plots a moving average of specified type and length for specified fundamental data.