arupnag
Pine Script Rookie
Pine Script Rookie
Posts: 1
Joined: December 27th, 2021
Contact: TradingView Profile

Can someone please help converting this MT4 indicator into a Tradingview one?

#property copyright "Copyright © 2021, Arup Nag"
#property link ""

#property indicator_separate_window
#property indicator_buffers 1
#property indicator_color1 Lime
#property indicator_width1 1

extern int VIX_Period = 22;

double VixBuffer[];


int init() {
string short_name;
IndicatorBuffers(1);
SetIndexStyle(0,DRAW_LINE);
SetIndexBuffer(0,VixBuffer);
//SetIndexBuffer(1,TempBuffer);
short_name="Ultimate Divergence ("+VIX_Period+")";
IndicatorShortName(short_name);
SetIndexLabel(0,short_name);

SetIndexDrawBegin(0,VIX_Period);

return(0);
}

int deinit()
{
return(0);
}

int start()
{
int i, counted_bars=IndicatorCounted();

if(Bars<=VIX_Period) return(0);

if(counted_bars<1) {
for(i=1;i<=VIX_Period;i++) {
VixBuffer[Bars-i]=0.0;
}
}

int limit=Bars-counted_bars;
if (counted_bars>0) limit++;
for(i=0; i<limit; i++)
VixBuffer=VIX(i);

return(0);
}
//+------------------------------------------------------------------+

double VIX(int shift) {
double highClose1, vix1;
highClose1 = Close[iHighest(NULL,0,MODE_CLOSE,VIX_Period,shift)];
vix1 = (Low[shift] - highClose1) / highClose1 * 100;
double highClose2, vix2;
highClose2 = Close[iLowest(NULL,0,MODE_CLOSE,VIX_Period,shift)];
vix2 = (High[shift] - highClose2) / highClose2 * 100;
return (vix1+vix2);

processingclouds
Pine Script Master
Pine Script Master
Posts: 115
Joined: January 30th, 2022

Re: Can someone please help converting this MT4 indicator into a Tradingview one?

Hey there,

Here is the pinescript version of the above function :

Code: Select all

// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © processingclouds

//@version=5
indicator("[zzz] Conversion Ultimate Divergence VIX_Period", "UDVix")

VIX_Period = input.int(defval=52)
limit = input.int(defval=12)

VIX(shift) =>
    highClose1 = ta.highest(close[shift], VIX_Period)
    vix1 = (low[shift] - highClose1) / highClose1 * 100
    highClose2 = ta.lowest(close[shift], VIX_Period)
    vix2 = (high[shift] - highClose2) / highClose2 * 100
    vix1 + vix2

vixed = VIX(limit)
plot(vixed)
plot(0)

Return to “Request Scripts”