1

I am a beginner to coding world let alone pinescript. I have this indicator I want to use but it is not inbuilt in tradingview.

I have a script written for that indicator in "TradeStation Language" which I cannot write successfully in pinescript. I am dropping the link below for reference: https://onlinelibrary.wiley.com/doi/pdf/10.1002/9781118531877.app3

Someone has written it in pinescript in the year 2017 which has multiple indicator in one script but it is not working properly. The author said so himself. I am dropping the link below for reference https://www.tradingview.com/script/XH5AbqhG-Topfinder-Bottomfinder-pivot-matcher-Midas-jayy/

**I need to write the blockquote part of the code. I am having trouble with 2 things:

  1. writing a condition which will run in a loop till one of the condition is true.
  2. writing a condition which, if true the code runs in a loop and if false, the code ends**
if e > 0 then begin //temporary copy of "e" eT = e;  //used for
iteration iterate backwards until the cumulative  //displaced volume
is greater than or equal to "e" j = -1;

while eT > 0 begin j = j + 1; eT = eT - MyVolume[j]; end;

Here is the whole TradeStation script:

//Input Volume ("D" from Levine’s formula)
Input: Vol_D(0), 
//Bar Price to use; suggest "L" for TopFinder and "H" for BottomFinder; 
//Alternatively, "(H+L+C)/3" may be used for an average price
TBF_Price(L),
//Bar Volume information to use; suggest "Ticks", or "1" if no volume 
//information "Ticks" yields total volume, and "Volume" yields only up volume 
//on intraday charts
MyVolume(Ticks),
//Start Date in TradeStation date format: YYYMMDD, where YYY is years since 1900
//Example date is January 1, 2012 
StartingDate(1120101),
//Start Time in military time with no punctuation; example time is 3:30 pm
StartingTime(1530), 
//Color of TBF curve will start with
//StartColor and end with EndColor  and changes according to % D completion
StartColor(Yellow), 
EndColor(Red); 

//variable information
Vars: running(false), //whether or not TBF calculation has started and not ended
//cumulative price ∗ volume
pv(0), 
//cumulative volume
vol(0), 
//variable that holds input volume, D
_D(0), 
//interpolated pv
pvInt(0),
//loop iterator
j(0),
//same as Levine’s "e" variable
e(0), 
//temporary copy of "e" used for iteration
eT(0), 
//current calculated price of TBF curve
tbf(0), 
//percent completion of TBF curve
pct_D(0); 
//begin at user specified date and time
if (date = StartingDate and time = StartingTime) or running then begin


running = true;


//add current bar’s price ∗ volume to cumulative total
pv = pv + TBF_Price ∗ MyVolume; 
//running total of volume begin calculation of TBF price
vol = vol + (MyVolume); 


> if Vol_D <> 0 then begin //store copy of input volume
> _D = Vol_D;  //calculate "e" per Levine’s formula if "e" greater than zero,  //continue to calculate TBF price otherwise, TBF is completed e
> = vol ∗ (1 - vol / _D); 
> 
> 
> if e > 0 then begin //temporary copy of "e" eT = e;  //used for
> iteration iterate backwards until the cumulative  //displaced volume
> is greater than or equal to "e" j = -1;
> 
> 
> while eT > 0 begin j = j + 1; eT = eT - MyVolume[j]; end;
> 
> //If displaced volume is greater than "e" (nearly always),  //an
> interpolated pv amount is calculated for "j" bars ago using only 
> //that part of "j" bar’s volume needed to make cumulative //displaced
> volume equal to "e". Note that at this point, "eT" is negative //and
> contains the partial volume of "j" bars ago that should be excluded.
> if eT < 0 then pvInt = TBF_Price[j] ∗ (MyVolume[j] + eT) else pvInt =
> 0;
> 
> //calculate TBF curve price for this bar tbf = (pv - pv[j] + pvInt) /
> e; 
> 
> //calculate percent TBF completion pct_D = vol / _D ∗ 100;

plot1(tbf, "TBF");
//Set Plot Color based on gradient between two Input colors
SetPlotColor(1, GradientColor(pct_D, 0, 100,
//StartColor, EndColor));
end
//TBF curve is completed; do not run anymore
else running = false; 
end;
end

0 Answers0