Convert this thinkscript code to pine-script

  Kiến thức lập trình

got this thinkscript code that i am trying to convert it into pine-script to use in tradingview, but pine-script does not provide the compoundvalue, so not sure how to do it. Any help will be really appericated

input Ih = high;
input Ii = low;
input N = 13;

#High Low Bands added 7/18/2019 by mc01439
#High
def Dh;
Dh = CompoundValue(1, Dh[1] + (Ih - Dh[1]) /  (N * Power((Ih / Dh[1]), 4)), Ih);
 
plot MDIh = Dh;
MDIh.SetPaintingStrategy(PaintingStrategy.LINE);
#MDIh.SetLineWeight(3);
#MDIh.SetDefaultColor(Color.White);

MDIh.DefineColor("Up", CreateColor( 0,  102, 255));
MDIh.DefineColor("Down", CreateColor( 255, 255, 0));
MDIh.SetLineWeight(2);
MDIh.AssignValueColor(if MDIh > MDIh[1] and MDIh[1] > MDIh[2] and MDIh[2] > MDIh[3] and MDIh[3] > MDIh[4] then MDIh.Color("Up") else if MDIh < MDIh[1] and MDIh[1] < MDIh[2] and MDIh[2] < MDIh[3] and MDIh[3] < MDIh[4] then MDIh.Color("Down") else Color.MAGENTA);

#Low
def Di;
Di = CompoundValue(1, Di[1] + (Ii - Di[1]) /  (N * Power((Ii / Di[1]), 4)), Ii);
 
plot MDIi = Di;
MDIi.SetPaintingStrategy(PaintingStrategy.LINE);
#MDIi.SetLineWeight(3);
#MDIi.SetDefaultColor(Color.White);

MDIi.DefineColor("Up", CreateColor( 0,  102, 255));
MDIi.DefineColor("Down", CreateColor( 255, 255, 0));
MDIi.SetLineWeight(2);
MDIi.AssignValueColor(if MDIi > MDIi[1] and MDIi[1] > MDIi[2] and MDIi[2] > MDIi[3] and MDIi[3] > MDIi[4] then MDIi.Color("Up") else if MDIi < MDIi[1] and MDIi[1] < MDIi[2] and MDIi[2] < MDIi[3] and MDIi[3] < MDIi[4] then MDIi.Color("Down") else Color.MAGENTA);

addCloud (MDIh, MDIi, Color.GRAY, Color.GRAY);

i really got stumped on how to convert the CompoundValue from thinkscript, did not know a way, as it looks its a recursive call

New contributor

jith is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.

LEAVE A COMMENT