• Get $30 off VIP with code SUMMER30. Ends July 27. Happy trading!

Convert MT5 Indicator to ThinkorSwim

ryan

New member
2019 Donor
Wondering anyone can help the following mt5 indicator to tos?

Thanks!

Code:
input int      inpPeriod        = 15;            // Period
input int      inpT3Period      = 5;             // T3 period
input double   inpT3Hot         = 0.7;           // T3 hot
input enT3Type inpT3Type        = t3_fulksmat;   // T3 type
input double   inpLevels        = 100;           // Levels at +- (nnn)


int OnCalculate(const int rates_total,
                const int prev_calculated,
                const datetime &time[],
                const double &open[],
                const double &high[],
                const double &low[],
                const double &close[],
                const long &tick_volume[],
                const long &volume[],
                const int &spread[])
  {
   if(Bars(_Symbol,_Period) lt rates_total) return(prev_calculated);
   //
   //---
   //
   int i=(int)MathMax(prev_calculated-1,0); for(; i lt rates_total && !_StopFlag; i++)
     {
         int _start  = MathMax(i-inpPeriod,0);
         double HighestHighRecent = high;
         double HighestHighOlder  = high[ArrayMaximum(high,_start,inpPeriod)];
         double LowestLowRecent   = low ;
         double LowestLowOlder    = low [ArrayMinimum(low ,_start,inpPeriod)];
     
         double BuyPower  = HighestHighRecent - LowestLowOlder;
         double SellPower = HighestHighOlder  - LowestLowRecent;
         double ttf = (BuyPower+SellPower!=0) ? 100*(BuyPower-SellPower)/(0.5*(BuyPower+SellPower)) : 0;
         val = iT3(ttf,inpT3Period,inpT3Hot,inpT3Type==t3_tillson,i,rates_total);    
         valc = (val gt inpLevels) ? 1 : (val lt -inpLevels) ? 2 : 0;
         lev  = (val gt 0) ? inpLevels : (val lt 0) ? -inpLevels : 0;
         fup  =  val;
         fdn  = (val gt 0) ? MathMin(val,inpLevels) : MathMax(val,-inpLevels);
     }
   return(i);
  }

//+------------------------------------------------------------------+
//| Custom functions                                                 |
//+------------------------------------------------------------------+
#define _t3Instances     1
#define _t3InstancesSize 6
double workT3[][_t3Instances*_t3InstancesSize];
double workT3Coeffs[][6];
#define _period 0
#define _c1     1
#define _c2     2
#define _c3     3
#define _c4     4
#define _alpha  5
//
//
//
//
//

double iT3(double price,double period,double hot,bool original,int r,int bars,int instanceNo=0)
  {
   if(ArrayRange(workT3,0)!=bars) ArrayResize(workT3,bars);
   if(ArrayRange(workT3Coeffs,0) lt (instanceNo+1)) ArrayResize(workT3Coeffs,instanceNo+1);
   if(workT3Coeffs[instanceNo][_period]!=period)
     {
      workT3Coeffs[instanceNo][_period]=period;
      workT3Coeffs[instanceNo][_c1] = -hot*hot*hot;
      workT3Coeffs[instanceNo][_c2] = 3*hot*hot+3*hot*hot*hot;
      workT3Coeffs[instanceNo][_c3] = -6*hot*hot-3*hot-3*hot*hot*hot;
      workT3Coeffs[instanceNo][_c4] = 1+3*hot+hot*hot*hot+3*hot*hot;
      if(original)
         workT3Coeffs[instanceNo][_alpha] = 2.0/(1.0 + period);
      else workT3Coeffs[instanceNo][_alpha] = 2.0/(2.0 + (period-1.0)/2.0);
     }

//
//
//
//
//

   int buffer=instanceNo*_t3InstancesSize; for(int k=0; k lt 6; k++) workT3[r][k+buffer]=(r gt 0) ? workT3[r-1][k+buffer]: price;
   if(r gt 0 && period gt 1)
     {
      workT3[r][0+buffer] = workT3[r-1][0+buffer]+workT3Coeffs[instanceNo][_alpha]*(price              -workT3[r-1][0+buffer]);
      workT3[r][1+buffer] = workT3[r-1][1+buffer]+workT3Coeffs[instanceNo][_alpha]*(workT3[r][0+buffer]-workT3[r-1][1+buffer]);
      workT3[r][2+buffer] = workT3[r-1][2+buffer]+workT3Coeffs[instanceNo][_alpha]*(workT3[r][1+buffer]-workT3[r-1][2+buffer]);
      workT3[r][3+buffer] = workT3[r-1][3+buffer]+workT3Coeffs[instanceNo][_alpha]*(workT3[r][2+buffer]-workT3[r-1][3+buffer]);
      workT3[r][4+buffer] = workT3[r-1][4+buffer]+workT3Coeffs[instanceNo][_alpha]*(workT3[r][3+buffer]-workT3[r-1][4+buffer]);
      workT3[r][5+buffer] = workT3[r-1][5+buffer]+workT3Coeffs[instanceNo][_alpha]*(workT3[r][4+buffer]-workT3[r-1][5+buffer]);
     }
   return(workT3Coeffs[instanceNo][_c1]*workT3[r][5+buffer] +
          workT3Coeffs[instanceNo][_c2]*workT3[r][4+buffer]+
          workT3Coeffs[instanceNo][_c3]*workT3[r][3+buffer]+
          workT3Coeffs[instanceNo][_c4]*workT3[r][2+buffer]);
  }
//+------------------------------------------------------------------+
 
Last edited by a moderator:

Billions

Active member
2019 Donor
VIP
Does anyone have a price channel indicator:

SCMQ3va.png
 
Last edited by a moderator:

horserider

Well-known member
VIP
ToS has a price channel. Start there.

Code:
input displace = 0;
input length = 20;

plot LowerBand = Lowest(low[-displace + 1], length);
LowerBand.SetDefaultColor(GetColor(8));

plot UpperBand = Highest(high[-displace + 1], length);
UpperBand.SetDefaultColor(GetColor(1));

AddCloud(LowerBand, UpperBand, Color.lIGHT_GRAY, Color.light_gray);
 

Dupre

New member
VIP
No clue what Metatrader has, but that last chart you uploaded looks similar to Donchian Channels. The indicator spec pic is too blurry for me to read.
 

Similar threads

Top