Convert Trend Magic Indicator to ThinkorSwim

tenacity11

Active member
2019 Donor
Can anyone convert this to TOS for me. I included 2 screen shots. thanks so much.

Code:
//Tradestation Version

Var:

Up(0),

Dn(0);

//do not change the inputs for CCI and ATR

UP = (LOW - AvgTrueRange(5));//plots below the bars

if CCI(50) >= 0 then begin

Plot1( UP, "TrendMagic" ,Blue) ;

Condition1 = True;

end else begin

DN = (HIGH + AvgTrueRange(5));//plots above the bars

If CCI(50) < 0 then begin

Plot1( DN, "TrendMagic" ,Red) ;

Condition2 = True;

end;end;

//Alert Conditions

Condition1 = FALSE ;

Condition2 = False;

if Condition1 then

Alert( "TrendMagicUp" ) ;

if Condition2 then

Alert( "TrendMagicDn" ) ;

secret of earning huge profit magic-trend-indicator


Juzk8v9.jpg


This was another code I found. fyi.

Code:
#property indicator_chart_window
#property indicator_buffers 2
#property indicator_color1 Blue
#property indicator_width1 2
#property indicator_color2 Red
#property indicator_width2 2
//+------------------------------------------------------------------+
extern int CCI = 50;
extern int ATR = 5;
//+------------------------------------------------------------------+
double bufferUp[];
double bufferDn[];
//+------------------------------------------------------------------+
int init()
{
   SetIndexStyle(0, DRAW_LINE, STYLE_SOLID, 2);
   SetIndexBuffer(0, bufferUp);
   SetIndexStyle(1, DRAW_LINE, STYLE_SOLID, 2);
   SetIndexBuffer(1, bufferDn);
   return (0);
}
//+------------------------------------------------------------------+
int deinit()
{
   return (0);
}
//+------------------------------------------------------------------+
int start()
{
   double thisCCI;
   double lastCCI;
   int counted_bars = IndicatorCounted();
   if (counted_bars < 0) return (-1);
   if (counted_bars > 0) counted_bars--;
   int limit = Bars - counted_bars;
   for (int shift = limit; shift >= 0; shift--)
   {
      thisCCI = iCCI(NULL, 0, CCI, PRICE_TYPICAL, shift);
      lastCCI = iCCI(NULL, 0, CCI, PRICE_TYPICAL, shift + 1);
      if (thisCCI >= 0 && lastCCI < 0) bufferUp[shift + 1] = bufferDn[shift + 1];
      if (thisCCI <= 0 && lastCCI > 0) bufferDn[shift + 1] = bufferUp[shift + 1];
      if (thisCCI >= 0)
      {
         bufferUp[shift] = Low[shift] - iATR(NULL, 0, ATR, shift);
         if (bufferUp[shift] < bufferUp[shift + 1])
            bufferUp[shift] = bufferUp[shift + 1];
      }
      else
      {
         if (thisCCI <= 0)
         {
            bufferDn[shift] = High[shift] + iATR(NULL, 0, ATR, shift);
            if (bufferDn[shift] > bufferDn[shift + 1])
               bufferDn[shift] = bufferDn[shift + 1];
         }
      }
   }
   return (0);
}
//+------------------------------------------------------------------+
//+------------------------------------------------------------------+
 

horserider

Well-known member
VIP
Indicator was shared with the chart. So it was there.

Here is the code:

Code:
input agg = AggregationPeriod.FIFTEEN_MIN;
def c = close(period = agg);
def h = high(period = agg);
def l = low(period = agg);
def pricedata = hl2(period = agg);

DefineGlobalColor("TrendUp", CreateColor(0, 254, 30));
DefineGlobalColor("TrendDown", CreateColor(255, 3, 2));


input lengthCCI = 50;
input lengthATR = 5;
input AtrFactor = 0.7;

def ATRcci = Average(TrueRange(h, c, l), lengthATR) * AtrFactor;
def price = c + l + h;
def linDev = LinDev(price, lengthCCI);
def CCI = if linDev == 0
          then 0
          else (price - Average(price, lengthCCI)) / linDev / 0.015;
def MT1 = if CCI > 0
          then Max(MT1[1], pricedata - ATRcci)
          else Min(MT1[1], pricedata + ATRcci);
plot data = MT1;
data.AssignValueColor(if c < MT1 then Color.RED else Color.GREEN);
 

San

Member
2019 Donor
@tenacity11 and BenTen team, Just i want to share my thought... I am very comfort using all these indicator in Offline i mean After the market time end , but during the market hours 9.30EST- 4PM EST, I am really scared, even if i stick with the strategy/ Instruction/Rule I experience lot of fail trade.. I don't know how to come out these situation.. BUT still i am trying to finding which strategy may fit for me during market hours.

I would like to say one thing.. This forum its give me a hope that i will definitely find a good strategy in one day.... !!!! Because in this forum i see lot of open heart people and helping tendency people... ...
 

BenTen

Administrative
Staff
VIP
@San You're definitely not alone. It's good that you're going through these indicators and backtesting them. But that does not mean you can't paper trade them during trading hours. I would suggest using the ThinkorSwim paper trade account and practice so you get confident with the strategy that you picked (you can even paper trade by jogging down the share price or contract price as if you're actually buying them). If it doesn't turn out like you expected, then you know to move on then and not lose a single dime.

And also be patient when paper trading. Nothing will yield you 100% winning rate. Just because the first trade didn't work out doesn't the mean indicator or strategy isn't working. Give it some time. The good thing about paper trading is that you're flexible with what you test (have fun with all the strategies and indicators that you think may fit your needs). I hope that helps.
 

Lukhy11

New member
2019 Donor
VIP
Code:
#Trend Magic Indicator

#Revised with Auto Aggregation and Global Colors

#Originally posted by horserider



def agg = getAggregationPeriod();

def c = close(period = agg);

def h = high(period = agg);

def l = low(period = agg);

def pricedata = hl2(period = agg);

DefineGlobalColor("TrendUp", CreateColor(0, 254, 30));

DefineGlobalColor("TrendDown", CreateColor(255, 3, 2));

input lengthCCI = 50;

input lengthATR = 5;

input AtrFactor = 0.7;

def ATRcci = Average(TrueRange(h, c, l), lengthATR) * AtrFactor;

def price = c + l + h;

def linDev = LinDev(price, lengthCCI);

def CCI = if linDev == 0

then 0

else (price - Average(price, lengthCCI)) / linDev / 0.015;

def MT1 = if CCI > 0

then Max(MT1[1], pricedata - ATRcci)

else Min(MT1[1], pricedata + ATRcci);

plot data = MT1;

data.AssignValueColor(if c < MT1 then GlobalColor("TrendDown") else GlobalColor("TrendUp"));
 

horserider

Well-known member
VIP
@Lukhy11 Thanks. Makes it simple for those that do not wish to worry about changing aggregation if they change chart time.
The advantage of being able to change aggregation is you can see the study at 10 min aggregation on a 5 minute chart. Or whatever combination that will still allow it to chart. I am now testing using a 5 minute chart with two of the studies, one at 5 minute agg and one at 15 min agg. Take a look and see if it shows you anything.
 

tenacity11

Active member
2019 Donor
Here's the code. I'm still following but so far it looks good.

Code:
#Trend Magic Indicator
#Revised with Auto Aggregation and Global Colors
#Originally posted by horserider

def agg = getAggregationPeriod();
def c = close(period = agg);
def h = high(period = agg);
def l = low(period = agg);
def pricedata = hl2(period = agg);
DefineGlobalColor("TrendUp", CreateColor(0, 254, 30));
DefineGlobalColor("TrendDown", CreateColor(255, 3, 2));
input lengthCCI = 50;
input lengthATR = 5;
input AtrFactor = 0.7;
def ATRcci = Average(TrueRange(h, c, l), lengthATR) * AtrFactor;
def price = c + l + h;
def linDev = LinDev(price, lengthCCI);
def CCI = if linDev == 0
then 0
else (price - Average(price, lengthCCI)) / linDev / 0.015;
def MT1 = if CCI > 0
then Max(MT1[1], pricedata - ATRcci)
else Min(MT1[1], pricedata + ATRcci);
plot data = MT1;
data.AssignValueColor(if c < MT1 then GlobalColor("TrendDown") else GlobalColor("TrendUp"));
 

uawgmsmco

New member
VIP
Shouldn't this script be able to function on Tick charts as well with the "getAggregationPeriod" function? I can't get this bad boy to plot on the desktop platform. It plots perfectly on the Mobile App tick charts.
 
Last edited:

RBO

New member
VIP
I have been trying this is on daily chart. The lines are too close to the price where it creates many false signals. Is default settings work or any change in ATR or CCI or ATR Factor more reliable ?
 

HighBredCloud

Well-known member
VIP
I have been trying this is on daily chart. The lines are too close to the price where it creates many false signals. Is default settings work or any change in ATR or CCI or ATR Factor more reliable ?

Just use one instance of the Trend Magic on the DAILY chart...Use these settings 20 4 0.7
 

Similar threads

Top