Covert Thinkscript to NinjaScript
Budget: $30 – $250 USD
Convert thinkorswim ThinkScript indicator to NinjaScript for NinjaTrader 8. Indicator code will be provided, do not bid if you aren’t familiar with the request or have never done a similar task.
If successful this will be an ongoing project. First is the indicator programming..... this first phase is a standard deviation channel, second is a "waverider" indicator, third is the strat.
Below is the thinkscript code:
## Standard Deviation Channel------------------------------------------------------------
input DeviationAlert = 2.0;
input ShowStdDevLabel = yes;
input ShowHalfDeviations = yes;
input ShowThirdDeviationSet = yes;
input ShowFourthDeviationSet = yes;
def C = hlc3;
#Regression and Deviation Definitions
def Reg = InertiaAll(C);
def StdDev = StDevAll(C);
#Regression and Deviation Plots
plot Dev4 = if ShowFourthDeviationSet then Reg + 4 * StdDev else Double.NaN;
plot Dev4H = if ShowHalfDeviations and ShowFourthDeviationSet then Reg + 3.5 * StdDev else Double.NaN;
plot Dev3 = if ShowThirdDeviationSet then Reg + 3 * StdDev else Double.NaN;
plot Dev3H = if ShowHalfDeviations and ShowThirdDeviationSet then Reg + 2.5 * StdDev else Double.NaN;
plot Dev2 = Reg + 2 * StdDev;
plot Dev2H = if ShowHalfDeviations then Reg + 1.5 * StdDev else Double.NaN;
plot Dev1 = Reg + 1 * StdDev;
plot Dev1H = if ShowHalfDeviations then Reg + .5 * StdDev else Double.NaN;
plot Regression = Reg;
plot DevN1H = if ShowHalfDeviations then Reg - .5 * StdDev else Double.NaN;
plot DevN1 = Reg - 1 * StdDev;
plot DevN2H = if ShowHalfDeviations then Reg - 1.5 * StdDev else Double.NaN;
plot DevN2 = Reg - 2 * StdDev;
plot DevN3H = if ShowHalfDeviations and ShowThirdDeviationSet then Reg - 2.5 * StdDev else Double.NaN;
plot DevN3 = if ShowThirdDeviationSet then Reg - 3 * StdDev else Double.NaN;
plot DevN4H = if ShowHalfDeviations and ShowFourthDeviationSet then Reg - 3.5 * StdDev else Double.NaN;
plot DevN4 = if ShowFourthDeviationSet then Reg - 4 * StdDev else Double.NaN;
#Dynamic Color Line Code
Dev4.SetDefaultColor (Color.MAGENTA);
Dev4H.SetDefaultColor (Color.LIGHT_GRAY);
Dev4H.SetStyle (Curve.SHORT_DASH);
Dev3.SetDefaultColor (Color.CYAN);
Dev3H.SetDefaultColor (Color.LIGHT_GRAY);
Dev3H.SetStyle (Curve.SHORT_DASH);
Dev2.AssignValueColor(if Reg >= Reg[1] then Color.GREEN else Color.RED);
Dev2H.SetDefaultColor (Color.LIGHT_GRAY);
Dev2H.SetStyle (Curve.SHORT_DASH);
Dev1.SetDefaultColor (Color.LIGHT_ORANGE);
Dev1H.SetDefaultColor (Color.LIGHT_GRAY);
Dev1H.SetStyle (Curve.SHORT_DASH);
Regression.SetDefaultColor (Color.LIGHT_GRAY);
DevN1H.SetDefaultColor (Color.LIGHT_GRAY);
DevN1H.SetStyle (Curve.SHORT_DASH);
DevN1.SetDefaultColor (Color.LIGHT_ORANGE);
DevN2H.SetDefaultColor (Color.LIGHT_GRAY);
DevN2H.SetStyle (Curve.SHORT_DASH);
DevN2.AssignValueColor(if Reg < Reg[1] then Color.RED else Color.GREEN);
DevN3H.SetDefaultColor (Color.LIGHT_GRAY);
DevN3H.SetStyle (Curve.SHORT_DASH);
DevN3.SetDefaultColor (Color.CYAN);
DevN4H.SetDefaultColor (Color.LIGHT_GRAY);
DevN4H.SetStyle (Curve.SHORT_DASH);
DevN4.SetDefaultColor (Color.MAGENTA);
#Dev Label code
def Dev = Reg + 1 * StdDev;
def R = Reg;
#Conversion Code
def D1 = (Dev - R) / R;
def L1 = (C - R) / R;
def P1 = Round(L1 / D1, 1);
AddLabel(ShowStdDevLabel, ("Dev " + P1), if P1 < 1 and P1 > -1 then Color.LIGHT_GRAY
else if P1 >= 1 and P1 < 2 or P1 <= -1 and P1 > -2 then Color.ORANGE
else if R >= R[1] and P1 >= 2 and P1 < 3 or R >= R[1] and P1 <= -2 and P1 > -3 then Color.GREEN
else if R < R[1] and P1 >= 2 and P1 < 3 or R < R[1] and P1 <= -2 and P1 > -3 then Color.RED
else if P1 >= 3 and P1 < 4 or P1 <= -3 and P1 > -4 then Color.CYAN
else Color.MAGENTA);
#Alerts Code
#def PosDev = Reg + DeviationAlert * StdDev;
#def NegDev = Reg - DeviationAlert * StdDev;
def Alert1 = C crosses above PosDev;
def Alert2 = C crosses below NegDev;
Alert(Alert1, "Price Cross > Dev " + DeviationAlert, Alert.BAR, Sound.Ring);
Alert(Alert2, "Price Cross < Dev " + -DeviationAlert, Alert.BAR, Sound.Ring);
If successful this will be an ongoing project. First is the indicator programming..... this first phase is a standard deviation channel, second is a "waverider" indicator, third is the strat.
Below is the thinkscript code:
## Standard Deviation Channel------------------------------------------------------------
input DeviationAlert = 2.0;
input ShowStdDevLabel = yes;
input ShowHalfDeviations = yes;
input ShowThirdDeviationSet = yes;
input ShowFourthDeviationSet = yes;
def C = hlc3;
#Regression and Deviation Definitions
def Reg = InertiaAll(C);
def StdDev = StDevAll(C);
#Regression and Deviation Plots
plot Dev4 = if ShowFourthDeviationSet then Reg + 4 * StdDev else Double.NaN;
plot Dev4H = if ShowHalfDeviations and ShowFourthDeviationSet then Reg + 3.5 * StdDev else Double.NaN;
plot Dev3 = if ShowThirdDeviationSet then Reg + 3 * StdDev else Double.NaN;
plot Dev3H = if ShowHalfDeviations and ShowThirdDeviationSet then Reg + 2.5 * StdDev else Double.NaN;
plot Dev2 = Reg + 2 * StdDev;
plot Dev2H = if ShowHalfDeviations then Reg + 1.5 * StdDev else Double.NaN;
plot Dev1 = Reg + 1 * StdDev;
plot Dev1H = if ShowHalfDeviations then Reg + .5 * StdDev else Double.NaN;
plot Regression = Reg;
plot DevN1H = if ShowHalfDeviations then Reg - .5 * StdDev else Double.NaN;
plot DevN1 = Reg - 1 * StdDev;
plot DevN2H = if ShowHalfDeviations then Reg - 1.5 * StdDev else Double.NaN;
plot DevN2 = Reg - 2 * StdDev;
plot DevN3H = if ShowHalfDeviations and ShowThirdDeviationSet then Reg - 2.5 * StdDev else Double.NaN;
plot DevN3 = if ShowThirdDeviationSet then Reg - 3 * StdDev else Double.NaN;
plot DevN4H = if ShowHalfDeviations and ShowFourthDeviationSet then Reg - 3.5 * StdDev else Double.NaN;
plot DevN4 = if ShowFourthDeviationSet then Reg - 4 * StdDev else Double.NaN;
#Dynamic Color Line Code
Dev4.SetDefaultColor (Color.MAGENTA);
Dev4H.SetDefaultColor (Color.LIGHT_GRAY);
Dev4H.SetStyle (Curve.SHORT_DASH);
Dev3.SetDefaultColor (Color.CYAN);
Dev3H.SetDefaultColor (Color.LIGHT_GRAY);
Dev3H.SetStyle (Curve.SHORT_DASH);
Dev2.AssignValueColor(if Reg >= Reg[1] then Color.GREEN else Color.RED);
Dev2H.SetDefaultColor (Color.LIGHT_GRAY);
Dev2H.SetStyle (Curve.SHORT_DASH);
Dev1.SetDefaultColor (Color.LIGHT_ORANGE);
Dev1H.SetDefaultColor (Color.LIGHT_GRAY);
Dev1H.SetStyle (Curve.SHORT_DASH);
Regression.SetDefaultColor (Color.LIGHT_GRAY);
DevN1H.SetDefaultColor (Color.LIGHT_GRAY);
DevN1H.SetStyle (Curve.SHORT_DASH);
DevN1.SetDefaultColor (Color.LIGHT_ORANGE);
DevN2H.SetDefaultColor (Color.LIGHT_GRAY);
DevN2H.SetStyle (Curve.SHORT_DASH);
DevN2.AssignValueColor(if Reg < Reg[1] then Color.RED else Color.GREEN);
DevN3H.SetDefaultColor (Color.LIGHT_GRAY);
DevN3H.SetStyle (Curve.SHORT_DASH);
DevN3.SetDefaultColor (Color.CYAN);
DevN4H.SetDefaultColor (Color.LIGHT_GRAY);
DevN4H.SetStyle (Curve.SHORT_DASH);
DevN4.SetDefaultColor (Color.MAGENTA);
#Dev Label code
def Dev = Reg + 1 * StdDev;
def R = Reg;
#Conversion Code
def D1 = (Dev - R) / R;
def L1 = (C - R) / R;
def P1 = Round(L1 / D1, 1);
AddLabel(ShowStdDevLabel, ("Dev " + P1), if P1 < 1 and P1 > -1 then Color.LIGHT_GRAY
else if P1 >= 1 and P1 < 2 or P1 <= -1 and P1 > -2 then Color.ORANGE
else if R >= R[1] and P1 >= 2 and P1 < 3 or R >= R[1] and P1 <= -2 and P1 > -3 then Color.GREEN
else if R < R[1] and P1 >= 2 and P1 < 3 or R < R[1] and P1 <= -2 and P1 > -3 then Color.RED
else if P1 >= 3 and P1 < 4 or P1 <= -3 and P1 > -4 then Color.CYAN
else Color.MAGENTA);
#Alerts Code
#def PosDev = Reg + DeviationAlert * StdDev;
#def NegDev = Reg - DeviationAlert * StdDev;
def Alert1 = C crosses above PosDev;
def Alert2 = C crosses below NegDev;
Alert(Alert1, "Price Cross > Dev " + DeviationAlert, Alert.BAR, Sound.Ring);
Alert(Alert2, "Price Cross < Dev " + -DeviationAlert, Alert.BAR, Sound.Ring);