Unrequited Conversion Requests To ThinkOrSwim

vandell001

New member
2019 Donor
Hey Gang, There is an interesting MT4 indicator out there called 3 level ZZ semafor. There is one site that has it converted to TOS, they call it 3 Level Zigzag. The site patternsmart.com requires a VIP sign up (one month trial $30.00) and then an additional $99 for the indicator. I have the MT4 code. Is there anyone who can/would be interested in converting it.
 

syedfahim

New member
VIP
@BenTen hi i need a code coverted to TOS . the code written in Pinescript Please Help Me out Here
This is a kind of supply demand indicator . The fresh zones will be of green and red line colors and the tested zone lines are grey in color.
Code:
study("Engulfing Detector", overlay=true, max_bars_back=500)

maxBarsBack = 500

previousRange = open[1] - close[1]

line bullEngulfOpen = na
line bullEngulfLow = na

line bearEngulfOpen = na
line bearEngulfHigh = na

isBullEngulf = previousRange > 0 and close > open[1]
isBearEngulf = previousRange < 0 and close < open[1]

if isBullEngulf
    bullEngulfOpen := line.new(bar_index - 1, open[1], bar_index, open[1], extend=extend.right, color=color.green)
    bullEngulfLow := line.new(bar_index - 1, low < low[1] ? low : low[1], bar_index, low < low[1] ? low : low[1], extend=extend.right, color=color.red)

if isBearEngulf
    bearEngulfOpen := line.new(bar_index - 1, open[1], bar_index, open[1], extend=extend.right, color=color.green)
    bearEngulfHigh := line.new(bar_index - 1, high > high[1] ? high : high[1], bar_index, high > high[1] ? high : high[1], extend=extend.right, color=color.red)


var maxNumberOfEngulfings = 10
bullEngulfingCount = 0
for i = 1 to maxBarsBack
    if not na(bullEngulfOpen[i])
        if low < line.get_y1(bullEngulfLow[i])
            line.delete(bullEngulfOpen[i])
            line.delete(bullEngulfLow[i])
            continue
        if low < line.get_y1(bullEngulfOpen[i])
            //line.set_x2(bullEngulfOpen[i], bar_index)
            line.set_color(bullEngulfOpen[i], color.gray)
            //line.set_extend(bullEngulfOpen[i], extend.none)
            //line.set_x2(bullEngulfLow[i], bar_index)
            line.set_color(bullEngulfLow[i], color.gray)
            //line.set_extend(bullEngulfLow[i], extend.none)
          
        bullEngulfingCount := bullEngulfingCount + 1
        if bullEngulfingCount > maxNumberOfEngulfings
            line.delete(bullEngulfOpen[i])
            line.delete(bullEngulfLow[i])
          
bearEngulfingCount = 0
for i = 1 to maxBarsBack 
    if not na(bearEngulfOpen[i])
        if high > line.get_y1(bearEngulfHigh[i])
            line.delete(bearEngulfOpen[i])
            line.delete(bearEngulfHigh[i])
            continue
      
        if high > line.get_y1(bearEngulfOpen[i])
            //line.set_x2(bearEngulfOpen[i], bar_index)
            line.set_color(bearEngulfOpen[i], color.gray)
            //line.set_extend(bearEngulfOpen[i], extend.none)
            //line.set_x2(bearEngulfHigh[i], bar_index)
            line.set_color(bearEngulfHigh[i], color.gray)
            //line.set_extend(bearEngulfHigh[i], extend.none)
          
        bearEngulfingCount := bearEngulfingCount + 1
        if bearEngulfingCount > maxNumberOfEngulfings
            line.delete(bearEngulfOpen[i])
            line.delete(bearEngulfHigh[i])
 
Last edited:
I added this to SPX 1D 5Min with no other studies - and the engulfing candles are not engulfing - Please see screenshot

Thanks for any guidance

4YLUWxg.png
 

dharmesh

New member
PLEASE HELP TO CONVERT THESE MT4 SCRIPT IN TO TOS(THINK AND SWIM PLEASE)

Code:
// + ----------------------------------------------- ------------------- +
// | SPECIFIC PARAMETERS
// + ----------------------------------------------- ------------------- +
#property copyright ""; //Authorship
#property link ""; // Link to the developer's site
#property version ""; // Indicator version
#property description ""; // Indicator description
#property strict // Strict compilation mode
#property indicator_chart_window // Display the indicator in the chart window
#property indicator_buffers 5 // Number of buffers for indicator calculations
// + ----------------------------------------------- ------------------- +
// | SPECIFIC PARAMETERS
// + ----------------------------------------------- ------------------- +
// + ----------------------------------------------- ------------------- +
// | CUSTOM TRANSFERS
// + ----------------------------------------------- ------------------- +
// Enumeration of constants for the price type
enum PriceTypeInt
  {
   PRICE_CLOSE_1 = 0, // Closing price
   PRICE_OPEN_1 = 1, // Opening price
   PRICE_HIGH_1 = 2, // Maximum price for the period
   PRICE_LOW_1 = 3, // Lowest price for the period
   PRICE_MEDIAN_1 = 4, // Median price, (high + low) / 2
   PRICE_TYPICAL_1 = 5, // Typical price, (high + low + close) / 3
   PRICE_WEIGHTED_1 = 6 // Weighted closing price, (high + low + close + close) / 4
  };
/// Enumeration of constants instead of true / false
enum BoolInt
  {
   Yes = 0, // Yes
   No = 1 // No
  };
// Enumeration of line style constants
enum StyleLineInt
  {
   STYLE_SOLID_1 = 0, // Solid line
   STYLE_DASH_1 = 1, // Dashed line
   STYLE_DOT_1 = 2, // Dotted line
   STYLE_DASHDOT_1 = 3, // Dash-dotted line
   STYLE_DASHDOTDOT_1 = 4 // Dash-dotted line with double dots
  };
// Enumeration of constants for symbols
enum StyleArrowInt
  {
   STYLE_ARROW_1 = 217, // Symbol - upward fractal arrow
   STYLE_ARROW_2 = 218, // Symbol - downward fractal arrow
   STYLE_ARROW_3 = 221, // Symbol - an upward arrow in a circle
   STYLE_ARROW_4 = 222, // Symbol - an arrow in a circle down
   STYLE_ARROW_5 = 221, // Symbol - thin up arrow
   STYLE_ARROW_6 = 222, // Symbol - thin arrow down
   STYLE_ARROW_7 = 233, // Symbol - thick up arrow
   STYLE_ARROW_8 = 234, // Symbol - thick down arrow
   STYLE_ARROW_9 = 83, // Symbol is a drop
   STYLE_ARROW_10 = 84, // Symbol - snowflake
   STYLE_ARROW_11 = 251, // Symbol - cross
   STYLE_ARROW_12 = 252, // Symbol - check mark
   STYLE_ARROW_13 = 89, // Symbol - pintogram
   STYLE_ARROW_14 = 91, // Symbol - yyang
   STYLE_ARROW_15 = 161, // Symbol - circle
   STYLE_ARROW_16 = 164, // Symbol - a circle with a dot
   STYLE_ARROW_17 = 108, // Symbol is a big dot
   STYLE_ARROW_18 = 159, // Symbol - small dot
   STYLE_ARROW_19 = 110, // Symbol is a big square
   STYLE_ARROW_20 = 167, // Symbol is a small square
   STYLE_ARROW_21 = 117, // Symbol - big diamond
   STYLE_ARROW_22 = 119, // Symbol is a small diamond
   STYLE_ARROW_23 = 171, // Symbol is a star
   STYLE_ARROW_24 = 181 // Symbol - a star in a circle
  };
// + ----------------------------------------------- ------------------- +
// | CUSTOM TRANSFERS
// + ----------------------------------------------- ------------------- +
// + ----------------------------------------------- ------------------- +
// | INPUT SETTINGS
// + ----------------------------------------------- ------------------- +
extern ENUM_TIMEFRAMES TimeFrame = PERIOD_CURRENT; // Timeframe for building the channel
extern int HalfLength = 55; //Period
extern PriceTypeInt Price = PRICE_WEIGHTED_1; // Price type
extern double BandsDeviations = 1.618; // Expand the channel
extern BoolInt Interpolate = No; // Smooth the channel
extern int History = 750; // Limit history in bars
extern BoolInt alertsOn = No; // Allow alerts
extern BoolInt alertsOnCurrent = No; // Notifications "Yes" - on the current bar "No" - on the previous
extern BoolInt alertsOnHighLow = No; // Notifications of channel breakout "Yes" - High / Low "No" - Close
extern BoolInt alertsMessage = No; // Alert in the terminal
extern BoolInt alertsPush = No; // Push notification
extern BoolInt alertsEmail = No; // Email alert
extern string ChannelSetting = "Channel autobuilding settings"; // Autobuild channel settings
extern BoolInt UseAutoChannel = No; // Use automatic channel settings
extern ENUM_TIMEFRAMES TimeM1 = PERIOD_M5; //
//+------------------------------------------------------------------+ //| SPETSIFICHESKIYe PARAMETRY //+------------------------------------------------------------------+ #property copyright ""; //Avtorstvo #property link ""; //Sylka na sayt razrabotchika #property version ""; //Versiya indikatora #property description ""; //Opisaniye indikatora #property strict //Strogiy rezhim kompilyatsii #property indicator_chart_window //Vyvod indikatora v okne grafika #property indicator_buffers 5 //Kolichestvo buferov dlya raschetov indikatora //+------------------------------------------------------------------+ //| SPETSIFICHESKIYe PARAMETRY //+------------------------------------------------------------------+ //+------------------------------------------------------------------+ //| KASTOMNYYe PERECHISLENIYA //+------------------------------------------------------------------+ //Perchisleniye konstant dlya tipa tsen enum PriceTypeInt { PRICE_CLOSE_1 = 0, //Tsena zakrytiya PRICE_OPEN_1 = 1, //Tsena otkrytiya PRICE_HIGH_1 = 2, //Maksimal'naya za period tsena PRICE_LOW_1 = 3, //Minimal'naya za period tsena PRICE_MEDIAN_1 = 4, //Mediannaya tsena, (high+low)/2 PRICE_TYPICAL_1 = 5, //Tipichnaya tsena, (high+low+close)/3 PRICE_WEIGHTED_1 = 6 //Vzveshennaya tsena zakrytiya, (high+low+close+close)/4 }; ///Perechisleniye konstant vmesto true/false enum BoolInt { Yes = 0, //Da No = 1 //Net }; //Perechisleniye konstant dlya stilya liniy enum StyleLineInt { STYLE_SOLID_1 = 0, //Sploshnaya liniya STYLE_DASH_1 = 1, //Shtrikhovaya liniya STYLE_DOT_1 = 2, //Punktirnaya liniya STYLE_DASHDOT_1 = 3, //Shtrikh-punktirnaya liniya STYLE_DASHDOTDOT_1 = 4 //Shtrikh-punktirnaya liniya s dvoynymi tochkami }; //Perechisleniya konstant dlya simvolov enum StyleArrowInt { STYLE_ARROW_1 = 217, //Simvol - strelka fraktala vverkh STYLE_ARROW_2 = 218, //Simvol - strelka fraktala vniz STYLE_ARROW_3 = 221, //Simvol - strelka v kruge vverkh STYLE_ARROW_4 = 222, //Simvol - strelka v kruge vniz STYLE_ARROW_5 = 221, //Simvol - tonkaya strelka vverkh STYLE_ARROW_6 = 222, //Simvol - tonkaya strelka vniz STYLE_ARROW_7 = 233, //Simvol - tolstaya strelka vverkh STYLE_ARROW_8 = 234, //Simvol - tolstaya strelka vniz STYLE_ARROW_9 = 83, //Simvol - kaplya STYLE_ARROW_10 = 84, //Simvol - snezhinka STYLE_ARROW_11 = 251, //Simvol - krestik STYLE_ARROW_12 = 252, //Simvol - galochka STYLE_ARROW_13 = 89, //Simvol - pintogramma STYLE_ARROW_14 = 91, //Simvol - in'yan' STYLE_ARROW_15 = 161, //Simvol - krug STYLE_ARROW_16 = 164, //Simvol - krug s tochkoy STYLE_ARROW_17 = 108, //Simvol - bol'shaya tochka STYLE_ARROW_18 = 159, //Simvol - malen'kaya tochka STYLE_ARROW_19 = 110, //Simvol - bol'shoy kvadrat STYLE_ARROW_20 = 167, //Simvol - malen'kiy kvadrat STYLE_ARROW_21 = 117, //Simvol - bol'shoy romb STYLE_ARROW_22 = 119, //Simvol - malen'kiy romb STYLE_ARROW_23 = 171, //Simvol - zvezda STYLE_ARROW_24 = 181 //Simvol - zvezda v kruge }; //+------------------------------------------------------------------+ //| KASTOMNYYe PERECHISLENIYA //+------------------------------------------------------------------+ //+------------------------------------------------------------------+ //| VKHODNYYe NASTROYKI //+------------------------------------------------------------------+ extern ENUM_TIMEFRAMES TimeFrame = PERIOD_CURRENT; //Taymfreym dlya postroyeniya kanala extern int HalfLength = 55; //Period extern PriceTypeInt Price = PRICE_WEIGHTED_1; //Tip tseny extern double BandsDeviations = 1.618; //Rasshireniye kanala extern BoolInt Interpolate = No; //Sglazhivaniye kanala extern int History = 750; //Ogranicheniye istorii v barakh extern BoolInt alertsOn = No; //Razreshit' opoveshcheniya extern BoolInt alertsOnCurrent = No; //Opoveshcheniya "Da" - na tekushchem bare "Net" - na predydushchem extern BoolInt alertsOnHighLow = No; //Opoveshcheniya probitiya kanala "Da" - High/Low "Net" - Close extern BoolInt alertsMessage = No; //Opoveshcheniye v terminale extern BoolInt alertsPush = No; //Opoveshcheniye Push extern BoolInt alertsEmail = No; //Opoveshcheniye na elektronnuyu pochtu extern string ChannelSetting = "Nastroyki avtopostroyeniya kanala"; //Nastroyki avtopostroyeniya kanala extern BoolInt UseAutoChannel = No; //Ispol'zovaniye avtomaticheskikh nastroyek kanala extern ENUM_TIMEFRAMES TimeM1 = PERIOD_M5; //
 

XeoNoX

Well-known member
VIP
this is like asking someone to build a mansion with no blue prints or thorough explanation of how they want the mansion layout to be implemented, with no blueprint there is nothing to convert.
 

nowhmar

New member
found this mt5 script need help converting it.

Code:
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[])
  {
   MqlRates _rates[]; int _ratesCopied=CopyRates(_Symbol,inpTimeFrame,1,inpAtrPeriod+1,_rates);
   if(_ratesCopied != inpAtrPeriod+1) return(prev_calculated);

   double _atr    = 0; for(int k=0;k lt inpAtrPeriod; k++) _atr += MathMax(_rates[k+1].high,_rates[k].close)-MathMin(_rates[k+1].low,_rates[k].close); _atr /= inpAtrPeriod;
   double _pclose = _rates[inpAtrPeriod].close;
   string _tf     = timeFrameToString(inpTimeFrame);
   datetime _time = time[rates_total-1]+PeriodSeconds(_Period)*inpLabelsShift;
   _createLine("res3",_pclose+_atr,_time,inpUp,inpUp,_tf+" probability band R3 ("+DoubleToString(_pclose+_atr,_Digits)+")");
   _createLine("res2",_pclose+_atr*0.75,_time,inpUp,inpUp,_tf+" probability band R2 ("+DoubleToString(_pclose+_atr*0.75,_Digits)+")");
   _createLine("res1",_pclose+_atr*0.50,_time,inpUp,inpUp,_tf+" probability band R1 ("+DoubleToString(_pclose+_atr*0.50,_Digits)+")");
   _createLine("sup1",_pclose-_atr*0.50,_time,inpDn,inpDn,_tf+" probability band S1 ("+DoubleToString(_pclose-_atr*0.50,_Digits)+")");
   _createLine("sup2",_pclose-_atr*0.75,_time,inpDn,inpDn,_tf+" probability band S2 ("+DoubleToString(_pclose-_atr*0.75,_Digits)+")");
   _createLine("sup3",_pclose-_atr,_time,inpDn,inpDn,_tf+" probability band S3 ("+DoubleToString(_pclose-_atr,_Digits)+")");
   ChartRedraw();
   return (rates_total);
  }
//+------------------------------------------------------------------+
//| Custom function(s)                                               |
//+------------------------------------------------------------------+
void _createLine(string _add,double _price,datetime _time,color _color,color _textColor,string _text,int _style=STYLE_DOT)
  {
   string _name=inpUniqueID+":"+_add;
   ObjectCreate(0,_name,OBJ_HLINE,0,0,0);
   ObjectSetInteger(0,_name,OBJPROP_COLOR,_color);
   ObjectSetInteger(0,_name,OBJPROP_STYLE,_style);
   ObjectSetDouble(0,_name,OBJPROP_PRICE,0,_price);
   _name=inpUniqueID+":label:"+_add;
   ObjectCreate(0,_name,OBJ_TEXT,0,0,0);
   ObjectSetInteger(0,_name,OBJPROP_COLOR,_textColor);
   ObjectSetInteger(0,_name,OBJPROP_TIME,0,_time);
   ObjectSetInteger(0,_name,OBJPROP_FONTSIZE,8);
   ObjectSetDouble(0,_name,OBJPROP_PRICE,0,_price);
   ObjectSetString(0,_name,OBJPROP_FONT,"Arial");
   ObjectSetString(0,_name,OBJPROP_TEXT,_text);
  }
//------------------ 
int    _tfsPer[]={PERIOD_M1,PERIOD_M2,PERIOD_M3,PERIOD_M4,PERIOD_M5,PERIOD_M6,PERIOD_M10,PERIOD_M12,PERIOD_M15,PERIOD_M20,PERIOD_M30,PERIOD_H1,PERIOD_H2,PERIOD_H3,PERIOD_H4,PERIOD_H6,PERIOD_H8,PERIOD_H12,PERIOD_D1,PERIOD_W1,PERIOD_MN1};
string _tfsStr[]={"1 minute","2 minutes","3 minutes","4 minutes","5 minutes","6 minutes","10 minutes","12 minutes","15 minutes","20 minutes","30 minutes","1 hour","2 hours","3 hours","4 hours","6 hours","8 hours","12 hours","daily","weekly","monthly"};
//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
string timeFrameToString(int period)
  {
   if(period==PERIOD_CURRENT)
      period=_Period;
   int i; for(i=0;i lt ArraySize(_tfsPer);i++) if(period==_tfsPer[i]) break;
   return(_tfsStr[i]);
  }
//+------------------------------------------------------------------+
 

nowhmar

New member
@nowhmar You neglected to post a link to the original script and didn't post an image of the resulting chart... We don't generally just convert code for a single request but if you're willing to learn Thinkscript we're more than willing to help you along... Expecting others to do all of your coding for you should be considered poor forum etiquette... These forums are meant for learning... If you've spent any amount of time in these forums you should realize that a lot more requests get posted than get converted... There's good reason for that...
so sorry, didn't realize it was poor etiquette. I am new to this forum. this is the mt5 chart by the way.
cb-1__9.png
 

cherif

Member
VIP
Below is a code named QQE Signal From Trading view. Any chance anyone could convert it to TOS so we can test it. thank you in advance



RSI_Period = input(14, title='RSI Length')
SF = input(5, title='RSI Smoothing')
QQE = input(4.238, title='Fast QQE Factor')
ThreshHold = input(10, title="Thresh-hold")

src = close
Wilders_Period = RSI_Period * 2 - 1

Rsi = rsi(src, RSI_Period)
RsiMa = ema(Rsi, SF)
AtrRsi = abs(RsiMa[1] - RsiMa)
MaAtrRsi = ema(AtrRsi, Wilders_Period)
dar = ema(MaAtrRsi, Wilders_Period) * QQE

longband = 0.0
shortband = 0.0
trend = 0

DeltaFastAtrRsi = dar
RSIndex = RsiMa
newshortband = RSIndex + DeltaFastAtrRsi
newlongband = RSIndex - DeltaFastAtrRsi
longband := RSIndex[1] > longband[1] and RSIndex > longband[1] ? max(longband[1], newlongband) : newlongband
shortband := RSIndex[1] < shortband[1] and RSIndex < shortband[1] ? min(shortband[1], newshortband) : newshortband
cross_1 = cross(longband[1], RSIndex)
trend := cross(RSIndex, shortband[1]) ? 1 : cross_1 ? -1 : nz(trend[1], 1)
FastAtrRsiTL = trend == 1 ? longband : shortband

// Find all the QQE Crosses

QQExlong = 0
QQExlong := nz(QQExlong[1])
QQExshort = 0
QQExshort := nz(QQExshort[1])
QQExlong := FastAtrRsiTL < RSIndex ? QQExlong + 1 : 0
QQExshort := FastAtrRsiTL > RSIndex ? QQExshort + 1 : 0

//Conditions

qqeLong = QQExlong == 1 ? FastAtrRsiTL[1] - 50 : na
qqeShort = QQExshort == 1 ? FastAtrRsiTL[1] - 50 : na

// Plotting

plotshape(qqeLong, title="QQE long", text="Long", textcolor=color.white, style=shape.labelup, location=location.belowbar, color=color.green, transp=0, size=size.tiny)
plotshape(qqeShort, title="QQE short", text="Short", textcolor=color.white, style=shape.labeldown, location=location.abovebar, color=color.red, transp=0, size=size.tiny)

// Alerts

alertcondition(qqeLong, title="Long", message="Long")
alertcondition(qqeShort, title="Short", message="Short")
 

Hapme

New member
Hi guys i need some help please

this is a good ATR trailer stop by Hpotter for tradeview can anyone convert the code to Think or swim

Ruby:
// This indicator is modified or developed by [DM] D.Martinez, Twitter = @didacjo

// Copyright by HPotter v2.0 10/02/2021

// Original autor HPotter and Sylvain Vervoort

// Security function by CheatCountry "Franklin Moormann"

// Average True Range Trailing Stops, Mod By [DM]

// The related article is copyrighted material from Stocks & Commodities Jun 2009

// @version=4

//############################################################################//

study(title="Average True Range Trailing Stops", shorttitle="Atr Stop", overlay = true)

f_security(_symbol, _res, _src, _repaint) =>

    security(_symbol, _res, _src[_repaint ? 0 : barstate.isrealtime ? 1 : 0])[_repaint ? 0 : barstate.isrealtime ? 0 : 1]

/// Inputs ///

Rep         = input(defval=true,    title="Allow Repainting",       type=input.bool)

Bar         = input(defval=false,   title="Allow Bar Color Change", type=input.bool)

Res         = input(defval="",      title="Resolution",             type=input.resolution)

nATRPeriod  = input(defval=5,       title="ATR Period",             type=input.integer, minval=1,       maxval=100, step=1)

nATRMultip  = input(defval=1.5,     title="ATR Multiplier",         type=input.float,   minval=0.01,    maxval=100, step=0.1)

/// Source ///

Cls = f_security(syminfo.tickerid,  Res,    close,  Rep)

Opn = f_security(syminfo.tickerid,  Res,    open,   Rep)

Hgh = f_security(syminfo.tickerid,  Res,    high,   Rep)

Low = f_security(syminfo.tickerid,  Res,    low,    Rep)

/// Brain///

f_atr(length) =>

    trueRange = na(Hgh[1])? Hgh-Low : max(max(Hgh - Low, abs(Hgh - Cls[1])), abs(Low - Cls[1]))

    rma(trueRange, length)

xATR        = f_atr(nATRPeriod)

nLoss       = nATRMultip * xATR

xATRTrailingStop = 0.0

xATRTrailingStop :=iff(Cls > nz(xATRTrailingStop[1], 0) and Cls[1] > nz(xATRTrailingStop[1], 0), max(nz(xATRTrailingStop[1]), Cls - nLoss),

                     iff(Cls < nz(xATRTrailingStop[1], 0) and Cls[1] < nz(xATRTrailingStop[1], 0), min(nz(xATRTrailingStop[1]), Cls + nLoss),

                      iff(Cls > nz(xATRTrailingStop[1], 0), Cls - nLoss, Cls + nLoss)))

/// Color ///

Col_G       = color.new(color.green,    00)

Col_R       = color.new(color.red,      00)

Col_Atr     = Cls > xATRTrailingStop[1] ? Col_G : Col_R

/// Bar Color ///

barcolor(Bar ? Col_Atr : na)

/// Plot ///

plot(xATRTrailingStop[1],   title="ATR Trailing Stop",  color=Col_Atr,   linewidth=1,    style=plot.style_line,  editable=true,  display=display.all)

/// Alerts ///

alertcondition(crossover(Cls, xATRTrailingStop[1]),   "Buy Signal",   "Bullish Change Detected")

alertcondition(crossunder(Cls,xATRTrailingStop[1]),   "Sell Signal",  "Bearish Change Detected")

/// End Of The Code ///
 
Last edited by a moderator:

astro_phx

Member
Hello, I am looking for a similar indicator to this script in tradingview. Do you have any recommendations? Thank you very much in advance.

Here is the image of how it looks in the tradingview.




//@version=4
study(title="ADX Volatility Moving Average", shorttitle="ADXVMA", overlay=true)
adxvma_period = input(3, minval=1, title = "ADXMA Period")
atrFlag = input(title="ATR", defval=false, group="ATR Settings")
length = input(title="ATR Period", defval=14, minval=1)
smoothing = input(title="Smoothing", defval="RMA", options=["RMA", "SMA", "EMA", "WMA"])

ups=0.0
downs=0.0
index=0.0
adxvma=0.0
trend=0
up=0.0
down=0.0

k=1.0/adxvma_period

volatility = atr(200)

currentUp=max(close[0] - close[1], 0)
currentDown=max(close[1] - close[0], 0)

up:=(1-k)*nz(up[1]) + k*currentUp[0]
down:=(1-k)*nz(down[1]) + k*currentDown[0]

sum = up[0] + down[0]

fractionUp=0.0
fractionDown=0.0

if sum > 0.0
fractionUp := up[0]/sum
fractionDown := down[0]/sum

ups:=(1-k)*nz(ups[1])+k*fractionUp
downs:=(1-k)*nz(downs[1])+k*fractionDown

normDiff = abs(ups[0] - downs[0])
normSum = ups[0] + downs[0]


normFraction=if normSum > 0.0
normDiff/normSum

index:=(1-k)*nz(index[1]) + k*normFraction
ups:=(1-k)*nz(ups[1]) + k*fractionUp
downs:=(1-k)*nz(downs[1]) + k*fractionDown

epsilon = 0.1 * nz(volatility[1])
hhp = highest(index,adxvma_period)[1]
llp = lowest(index,adxvma_period)[1]

hhv = max(index[0],hhp)
llv = min(index[0],llp)

vIndex=0.0

if (hhv-llv)>0.0
vIndex:=(index[0]-llv)/(hhv-llv)

adxvma:=(1 - k*vIndex)*nz(adxvma[1]) + k*vIndex*close[0]

lcolor=color.black

if (nz(trend[1])>-1 and adxvma[0]> nz(adxvma[1]))
trend:=1
lcolor:=color.green
else
if (nz(trend[1])<1 and adxvma[0]<nz(adxvma[1]))
trend:=-1
lcolor:=color.red
else
trend:=0
lcolor:=color.yellow




plot( adxvma, color= lcolor, linewidth=1)

ma_function(source, length) =>
if smoothing == "RMA"
rma(source, length)
else
if smoothing == "SMA"
sma(source, length)
else
if smoothing == "EMA"
ema(source, length)
else
wma(source, length)


shortSL = close + (ma_function(tr(true), length))
longSL = close - (ma_function(tr(true), length))
plot(atrFlag?shortSL:na, title = "shortATR", color=color.red)
plot(atrFlag?longSL:na, title = "longATR", color=color.lime)

ichimokuFlag = input(title="ichimoku", defval=false,group="ichimoku Settings")

conversionPeriods = input(5, minval=1, title="Conversion Line Length")
basePeriods = input(34, minval=1, title="Base Line Length")
laggingSpan2Periods = input(52, minval=1, title="Lagging Span 2 Length")
displacement = input(26, minval=1, title="Displacement")
donchian(len) => avg(lowest(len), highest(len))
conversionLine = donchian(conversionPeriods)
baseLine = donchian(basePeriods)
leadLine1 = avg(conversionLine, baseLine)
leadLine2 = donchian(laggingSpan2Periods)
p1 = plot(ichimokuFlag?leadLine1:na, offset = displacement - 1, color=color.blue,
title="Lead 1")
p2 = plot(ichimokuFlag?leadLine2:na, offset = displacement - 1, color=color.yellow,
title="Lead 2")
fill(p1, p2, color = leadLine1 > leadLine2 ? color.blue : color.yellow)


vwapFlag = input(title="VWAP", defval=false, group="VWAP Settings")
hideonDWM = input(false, title="Hide VWAP on 1D or Above", group="VWAP Settings")
var anchor = input(defval = "Session", title="Anchor Period", type=input.string,
options=["Session", "Week", "Month", "Quarter", "Year", "Decade", "Century", "Earnings", "Dividends", "Splits"], group="VWAP Settings")
src = input(title = "Source", type = input.source, defval = hl2, group="VWAP Settings")
offset = input(0, title="Offset", group="VWAP Settings")

showBands = input(false, title="Calculate Bands", group="Standard Deviation Bands Settings")
stdevMult = input(1.0, title="Bands Multiplier", group="Standard Deviation Bands Settings")

computeVWAP(src, isNewPeriod, stDevMultiplier) =>
var float sumSrcVol = na
var float sumVol = na
var float sumSrcSrcVol = na

sumSrcVol := isNewPeriod ? src * volume : src * volume + sumSrcVol[1]
sumVol := isNewPeriod ? volume : volume + sumVol[1]
// sumSrcSrcVol calculates the dividend of the equation that is later used to calculate the standard deviation
sumSrcSrcVol := isNewPeriod ? volume * pow(src, 2) : volume * pow(src, 2) + sumSrcSrcVol[1]

_vwap = sumSrcVol / sumVol
variance = sumSrcSrcVol / sumVol - pow(_vwap, 2)
variance := variance < 0 ? 0 : variance
stDev = sqrt(variance)

lowerBand = _vwap - stDev * stDevMultiplier
upperBand = _vwap + stDev * stDevMultiplier

[_vwap, lowerBand, upperBand]

timeChange(period) =>
change(time(period))

new_earnings = earnings(syminfo.tickerid, earnings.actual, barmerge.gaps_on, barmerge.lookahead_on)
new_dividends = dividends(syminfo.tickerid, dividends.gross, barmerge.gaps_on, barmerge.lookahead_on)
new_split = splits(syminfo.tickerid, splits.denominator, barmerge.gaps_on, barmerge.lookahead_on)

isNewPeriod = anchor == "Earnings" ? new_earnings :
anchor == "Dividends" ? new_dividends :
anchor == "Splits" ? new_split :
na(src[1]) ? true :
anchor == "Session" ? timeChange("D") :
anchor == "Week" ? timeChange("W") :
anchor == "Month" ? timeChange("M") :
anchor == "Quarter" ? timeChange("3M") :
anchor == "Year" ? timeChange("12M") :
anchor == "Decade" ? timeChange("12M") and year % 10 == 0 :
anchor == "Century" ? timeChange("12M") and year % 100 == 0 :
false

float vwapValue = na
float std = na
float upperBandValue = na
float lowerBandValue = na

if not (hideonDWM and timeframe.isdwm)
[_vwap, bottom, top] = computeVWAP(src, isNewPeriod, stdevMult)
vwapValue := _vwap
upperBandValue := showBands ? top : na
lowerBandValue := showBands ? bottom : na

vwapValueColor = vwapValue>vwapValue[1]?color.green:vwapValue<vwapValue[1]?color.red:color.yellow

plot(vwapFlag?vwapValue:na, title="VWAP",color=vwapValueColor, offset=offset)

upperBand = plot(upperBandValue, title="Upper Band", color=color.white, offset=offset)
lowerBand = plot(lowerBandValue, title="Lower Band", color=color.white, offset=offset)

fill(upperBand, lowerBand, title="Bands Fill", color= showBands ? color.new(color.white, 95) : na)


srLineCount = input(title="Number of Gann Levels", type=input.integer, minval=1, maxval=24, defval=8)

supportLineColor = input(color.aqua, "Support", input.color, group = "SETTINGS", inline = "COLOR")
resistanceLineColor = input(color.orange, "Resistance", input.color, group = "SETTINGS", inline = "COLOR")
posX_label = input(1, title="Pos. Label x-axis", minval=0, group = "SETTINGS")

// Milliseconds in a day
msec_day = 1000 * 60 * 60 * 24

t = time("1440", session.regular)
is_first = na(t[1]) and not na(t) or t[1] < t

// Truncates a given number to a certain number of decimals
truncate(number, decimals) =>
factor = pow(10, decimals)
int(number * factor) / factor

// Decimal approximation
dec(number) =>
var int decLen = 0
if number <= 10
decLen := 5
else if number <= 999
decLen := 2
else if number <= 9999
decLen := 1
else
decLen := 0

// Variable declaration
var line refLine = na

var line supportLine = na
var label supportLabel = na

var line resistanceLine = na
var label resistanceLabel = na

var lineArray = array.new_line()
var labelArray = array.new_label()

// Plot only for TODAY
if (timenow - time <= msec_day)

// Opening bar of the day
if is_first

// Delete previous lines
lineArraySize = array.size(lineArray)
for i = 0 to lineArraySize
if array.size(lineArray) > 0
ln = array.shift(lineArray)
line.delete(ln)
array.clear(lineArray)

// Delete previous labels
labelArraySize = array.size(labelArray)
for i = 0 to labelArraySize
if array.size(labelArray) > 0
lbl = array.shift(labelArray)
label.delete(lbl)
array.clear(labelArray)

// Calculate Gann circle intraday levels on confirmation of the opening bar
if barstate.isconfirmed

supportLevel = 0.0
resistanceLevel = 0.0
firstSupport = 0.0
firstResistance = 0.0

// Decimal length to be displayed
decimalLength = dec(low)

// Handle smaller prices
var int div = 1
if low <= 10
div := 10000
else
div := 1

// High and Low of the opening bar
refLine := line.new(x1=bar_index[1], y1=high, x2=bar_index, y2=high, style=line.style_dashed, extend=extend.right, color=color.blue)
array.push(lineArray, refLine)

refLine := line.new(x1=bar_index[1], y1=low, x2=bar_index, y2=low, style=line.style_dashed, extend=extend.right, color=color.blue)
array.push(lineArray, refLine)

// Calculate Gann Circle Intraday levels
sqrt_low = sqrt(low * div)
sqrt_high = sqrt(high * div)

for i = 1 to srLineCount

supportLevel := ((sqrt_high - 0.25) * (sqrt_high - 0.25)) / div
resistanceLevel := ((sqrt_low + 0.25) * (sqrt_low + 0.25)) / div

// Keep track of the support and resistance levels generated in the first iteration of the loop
if i == 1
firstSupport := supportLevel
firstResistance := resistanceLevel

// Plot only those support levels which are lower than the first resistance level
if supportLevel < firstResistance
supportLine := line.new(x1=bar_index[1], y1=supportLevel, x2=bar_index, y2=supportLevel, style=line.style_dotted, extend=extend.right, color=supportLineColor)
array.push(lineArray, supportLine)
supportLabel := label.new(time + (time-time[1])*posX_label, supportLevel, xloc=xloc.bar_time, text="(" + tostring(truncate(supportLevel, decimalLength)) + ")", style=label.style_none, textcolor=color.white)
array.push(labelArray, supportLabel)

// Plot only those resistance levels which are higher than the first support level
if resistanceLevel > firstSupport
resistanceLine := line.new(x1=bar_index[1], y1=resistanceLevel, x2=bar_index, y2=resistanceLevel, style=line.style_dotted, extend=extend.right, color=resistanceLineColor)
array.push(lineArray, resistanceLine)
resistanceLabel := label.new(time + (time-time[1])*posX_label, resistanceLevel, xloc=xloc.bar_time, text="(" + tostring(truncate(resistanceLevel, decimalLength)) + ")", style=label.style_none, textcolor=color.white)
array.push(labelArray, resistanceLabel)

sqrt_high := sqrt(supportLevel * div)
sqrt_low := sqrt(resistanceLevel * div)
// END
 

Similar threads

Top