I need help with this script Iget an error
input aggregationPeriod = AggregationPeriod.DAY;
input showVolume = yes;
input showOpenInterest = yes;
def o = open;
def h = high;
def l = low;
def c = close;
def v = volume;
def oi = open_interest;
def isPeriodRolled = CompoundValue(1, (GetAggregationPeriod() <> GetAggregationPeriod()[1]), yes);
def volumeSum;
def oiSum;
if (isPeriodRolled) {
volumeSum = v;
oiSum = oi;
} else {
volumeSum = volumeSum[1] + v;
oiSum = oiSum[1] + oi;
}
def label = "OI: " + oiSum + "\n";
label = label + "P/C: " + Round((PutVolume() / CallVolume()) * 100, 0) + "%\n";
label = label + "Vol: " + volumeSum;
AddLabel(yes, label, Color.WHITE);
plot openInterest = showOpenInterest;
openInterest.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
openInterest.SetDefaultColor(Color.ORANGE);
def pcRatio = showVolume(PutVolume() / CallVolume())/
Double.NaN;
def volume = showVolume; (volumesum); Double.NaN;
AddCloud(volume, pcRatio, Color.GREEN, Color.RED);
reply to post62
you didn't explain what you are trying to do with this study, and almost every line is wrong, so i'm not going to guess at its purpose, and create a new study.
i will guess that you want a put call ratio thing, and show you this link, that might have something relevent.
https://usethinkscript.com/threads/put-call-ratio-pcr-indicator-for-thinkorswim.606/
-------------------------
i'll repeat this again, it is highly unlikely that chatgpt will create a working thinkscript study. it just doesn't know the language.
-------------------
when i load your study, it shows just 1 error, with this line,
def volume = showVolume; (volumesum); Double.NaN;
but there are many errors. thinkscript is funny that way, sometimes it only shows 1 or 2 errors at a time. when they get fixed, more errors will show up.
i'm guessing it should be a if then statement, like this,
def volume = if showVolume then volumesum else Double.NaN;
after fixing that one, there are 5+ errors.
def isPeriodRolled = CompoundValue(1, (GetAggregationPeriod() <> GetAggregationPeriod()[1]), yes);
several things wrong here,
..don't use offset on GetAggregationPeriod()[1]
..the agg period isn't going to change, so comparing it to itself on a previous bar will be the same.
....i'm guessing this was supposed to determine a new day?
these 3 lines are wrong.
def label = "OI: " + oiSum + "\n";
label = label + "P/C: " + Round((PutVolume() / CallVolume()) * 100, 0) + "%\n";
label = label + "Vol: " + volumeSum;
AddLabel(yes, label, Color.WHITE);
can't assign text with a def.
can't create a text string and assign to a variable. have to use the text formula within addlabel().
can't use the same variable more than once.
can't use \n within a label. doesn't do anything. labels are all on one line. if \n is used in a bubble, then it starts a new line.
here are those lines as 3 labels,
AddLabel(yes, "OI: " + oiSum , Color.WHITE);
AddLabel(yes, "P/C: " + Round((PutVolume() / CallVolume()) * 100, 0) + "%", Color.WHITE);
AddLabel(yes, "Vol: " + volumeSum, Color.WHITE);
but one line still has an error because PutVolume() and CallVolume() are not valid.
they are not built in functions, they are not defined as a script, or not defined as variables.
so i can't create a working study.
this is wrong and probably should be a if then
def pcRatio = showVolume(PutVolume() / CallVolume()) / Double.NaN;
def pcRatio = if showVolume then (PutVolume / CallVolume) else Double.NaN;
but it has errors because PutVolume() and CallVolume() are not valid.
too many unknowns and errors to fix.