Convert a TOS Thinkscript strategy to a C# Strategy  [SOLVED]

Questions about MultiCharts .NET and user contributed studies.
frugalmule

Convert a TOS Thinkscript strategy to a C# Strategy

Postby frugalmule » 15 Jan 2016

I have a trial copy of multi-charts and would like to see if we can convert the following TOS code to MC.

Thank you very much for any assistance you guys can provide.

Code: Select all

#RULES
#Buy to Open should occur when The fastLength MA crosses above the slowLength MA as shown
#AND #The ADX is over 20
#AND the MACDHistogram is above 0.
#Sell to Exit should ONLY occur when the MACDHistogram is below 0.

#Built-In Moving Average Cross Strategy
input price = close;
input fastLength = 20;
input slowLength = 50;
input averageType = AverageType.EXPONENTIAL;
plot FastMA = MovingAverage(averageType, price, fastLength);
plot SlowMA = MovingAverage(averageType, price, slowLength);
FastMA.SetDefaultColor(GetColor(1));
SlowMA.SetDefaultColor(GetColor(2));

#ADX Study
#To convert this to a Strategy, replace 'plot' with 'def', add the line below it, then comment out the GetColor line.
input length = 14;
input ADXaverageType = AverageType.WILDERS;
def ADX = DMI(length, ADXaverageType).ADX;
def filterLongADX = ADX > 20; #Create a filter using the variable we just defined.
#ADX.SetDefaultColor(GetColor(5));

#MACDHistogram
#To convert this to a Strategy, replace 'plot' with 'def' add the line below it, then comment out the lines that begin with 'Diff'.
#plot Diff = MACD(fastLength, slowLength, MACDLength, averageType).Diff;
input MACDfastLength = 12;
input MACDslowLength = 26;
input MACDLength = 9;
input MACDaverageType = AverageType.EXPONENTIAL;
Def Diff = MACD(MACDfastLength, MACDslowLength, MACDLength, MACDaverageType).Diff;
def filterLongMACD = Diff > 0;
def filterShortMACD = Diff < 0;
#Diff.SetDefaultColor(GetColor(5));
#Diff.SetPaintingStrategy(PaintingStrategy.HISTOGRAM);
#Diff.SetLineWeight(3);
#Diff.DefineColor("Positive and Up", Color.GREEN);
#Diff.DefineColor("Positive and Down", Color.DARK_GREEN);
#Diff.DefineColor("Negative and Down", Color.RED);
#Diff.DefineColor("Negative and Up", Color.DARK_RED);
#Diff.AssignValueColor(if Diff >= 0 then if Diff > Diff[1] then Diff.Color("Positive and Up") else Diff.Color("Positive and Down") else if Diff < Diff[1] then Diff.Color("Negative and Down") else Diff.Color("Negative and Up"));

#Moved the AddOrder syntax below so that it appears below the MACross, ADX and MACDCross inputs, plots, and definitions.
AddOrder(OrderType.BUY_TO_OPEN, FastMA crosses above SlowMA and filterLongADX is true and filterLongMACD is true, tickcolor = GetColor(1), arrowcolor = GetColor(1), name = "LE");
AddOrder(OrderType.SELL_TO_CLOSE, filterShortMACD is true, tickcolor = GetColor(1), arrowcolor = GetColor(1), name = "LX");

User avatar
JoshM
Posts: 2195
Joined: 20 May 2011
Location: The Netherlands
Has thanked: 1544 times
Been thanked: 1565 times
Contact:

Re: Convert a TOS Thinkscript strategy to a C# Strategy

Postby JoshM » 16 Jan 2016

This for sure seems possible at first glance, but before I would code a script like this I'll need to know the strategy name and its assumptions and hypotheses. Because if we create a nameless script without additional information, that won't be of much help to others and only adds to the 'noise'.

frugalmule

Re: Convert a TOS Thinkscript strategy to a C# Strategy

Postby frugalmule » 16 Jan 2016

You must not have seen all my comments in the code. It's all there. I took it from 3 studies and coverted into a single strategy. My logic as well as how we did the conversion are all in the code.

frugalmule

Re: Convert a TOS Thinkscript strategy to a C# Strategy  [SOLVED]

Postby frugalmule » 16 Jan 2016

We could call it 160116_MACross_ADX_MACDHistogram_LE/X

User avatar
JoshM
Posts: 2195
Joined: 20 May 2011
Location: The Netherlands
Has thanked: 1544 times
Been thanked: 1565 times
Contact:

Re: Convert a TOS Thinkscript strategy to a C# Strategy

Postby JoshM » 16 Jan 2016

You must not have seen all my comments in the code. It's all there. I took it from 3 studies and coverted into a single strategy. My logic as well as how we did the conversion are all in the code.
That's not what I meant from the angle that I'm coming from. Let's see who else responds in this thread.

frugalmule

Re: Convert a TOS Thinkscript strategy to a C# Strategy

Postby frugalmule » 16 Jan 2016

Obviously I don't know how to get a reply here.

User avatar
JoshM
Posts: 2195
Joined: 20 May 2011
Location: The Netherlands
Has thanked: 1544 times
Been thanked: 1565 times
Contact:

Re: Convert a TOS Thinkscript strategy to a C# Strategy

Postby JoshM » 16 Jan 2016

Obviously I don't know how to get a reply here.
Why? It's weekend so it just takes time. There's not much activity here during the weekends compared with other forums.

User avatar
Henry MultiСharts
Posts: 9165
Joined: 25 Aug 2011
Has thanked: 1264 times
Been thanked: 2957 times

Re: Convert a TOS Thinkscript strategy to a C# Strategy

Postby Henry MultiСharts » 27 Jan 2016

Hello frugalmule,

Please contact us directly if you are interested in the custom programming services.


Return to “MultiCharts .NET”