Why the default value selection doesn't work?

S

sumihiko

New member
input price = close;
input X = { default "0.5", "0.6", "0.7"};

plot up = high + ((high - low) * X );
plot low = low - ((high - low) * X );

→ the value of X supposed to be 0.5 when 0.5 is chosen, yet the arithmetic result is 1 (even I change from 0.5 to 0.9 or letter A)
→ the value of X supposed to be 0.6 when 0.6 is chosen, yet the arithmetic result is 2 (even I change from 0.6 to 1.0 or letter B)
→ the value of X supposed to be 0.7 when 0.7 is chosen, yet the arithmetic result is 3 (even I change from 0.7 to 1.1 or letter C)
→ Can anyone tell me how to fix this problem? Thanks a million!
 
T

tomsk

Well-known member
VIP
Those are not numerical values, when referenced they re the relative position within the enumerated input X.
Hence the text "0.6"is position #2 within that enumerated input X.
I came across this anomaly when I was coding something that used the enumerated input construct
 
S

sumihiko

New member
Those are not numerical values, when referenced they re the relative position within the enumerated input X.
Hence the text "0.6"is position #2 within that enumerated input X.
I came across this anomaly when I was coding something that used the enumerated input construct


Sorry, can you help me solve this problem?
I was trying to make X with a selection of value "0.5, 0.6, 0.7" instead of manually key-in the value.
Thanks a million!
 
T

tomsk

Well-known member
VIP
@sumihiko Seems like kind of a long winded approach but if you really must have the choices being offered, here is your MODIFIED study. It illustrates how to access components within an enumerated list such as yours. Note that the iData low in your posted example above is a reserved word so I used another variable called "down" to represent that

Code:
# Enumerated Example
# tomsk
# 12.27.2019

input X = { default "0.5", "0.6", "0.7"};
def valueX = if x == x."0.5" then 0.5
             else if x == x."0.6" then 0.6
             else 0.7;
plot up = high + ((high - low) * valueX);
plot down = low - ((high - low) * valueX);
# End Enumerated Example
 
Last edited:
S

sumihiko

New member
@tomsk

Thanks for guiding! Now it works well, thanks a million.

I'm sorry. May I ask you another question? I have problems in drawing a price support line on the 1st candle low for next 20 bars of candlesticks on once FullK (stochastic) crosses above FullD, and also drawing a price resistance line on the 1st candle high for the next 20 bars of candlesticks once FullK (stochastic) crosses below FullD.

I've been working for this script over 3 weeks, can you check what's wrong on it? Thanks in advance!

input ExtensionLengthBars = 20;
input UpperExtensionPercentLimit = 5;
input LowerExtensionPercentLimit = 5;
def nan = Double.NaN;


plot SupportLine = if FullK crosses above FullD then nan else double.NaN;
plot ReistLine = if FullK crosses below FullD then nan else double.NaN;

↑ they plot nothing on the upper chart (candlestick chart).
 
Last edited:
T

tomsk

Well-known member
VIP
The issue you're seeing is that Stochastic is essentially an oscillator with values between -100 and +100, displayed on a lower chart
 
Last edited:
S

sumihiko

New member
The issue you're seeing is that Stochastic is essentially am oscillator with values between -100 and +100, displayed on a lower chart
Is there any possibility to draw a line on upper chart based on stochastic crossings?
 
T

tomsk

Well-known member
VIP
Here is a snippet that plots a DOT on the upper chart when the FullK crosses above the FullD.
This should give you some ideas to complete the rest of your script.

Code:
plot Sto = if StochasticFull()."FullK" crosses above StochasticFull()."FullD" 
           then low - TickSize() 
           else Double.NaN;
Sto.SetPaintingStrategy(PaintingStrategy.POINTS);
Sto.SetDefaultColor(Color.ORANGE);
Sto.SetLineWeight(5);
 
S

sumihiko

New member
@tomsk
Thanks a million. Could you guide me a little bit more if I want to make the "points" to carry for the next 3 bars?
 
T

tomsk

Well-known member
VIP
The stochastic FullK crosses above the FullD happens at a single bar. That is known as an "event".

In my snippet above when that condition happens, that particular event is marked by a DOT. At the very next candle that cross had already happened and so no "event" is triggered, and therefore no DOT is plotted. Most traders want to know when a specific event had happened.

Now think real hard about what you're really asking. If you're now asking for dots to be plotted for the next 3 bars after that event was triggered, then you will need to capture the bar number when that cross happened. Then for the 3 bars following that, plot a DOT. However I really don't see the point of that though but if that's what you really want, feel free to play with the code. I've given you the method, so all you need to do is to program that in.
 
S

sumihiko

New member
The stochastic FullK crosses above the FullD happens at a single bar. That is known as an "event".

In my snippet above when that condition happens, that particular event is marked by a DOT. At the very next candle that cross had already happened and so no "event" is triggered, and therefore no DOT is plotted. Most traders want to know when a specific event had happened.

Now think real hard about what you're really asking. If you're now asking for dots to be plotted for the next 3 bars after that event was triggered, then you will need to capture the bar number when that cross happened. Then for the 3 bars following that, plot a DOT. However I really don't see the point of that though but if that's what you really want, feel free to play with the code. I've given you the method, so all you need to do is to program that in.
@tomsk
Thanks for guiding.

plot Sto = if StochasticFull()."FullK" crosses above StochasticFull()."FullD"
then low - TickSize(3)
→I inserted "3" in the TickSize and found it didn't work for the next 3 bars, thus I was asking for help.
 
T

tomsk

Well-known member
VIP
Unfortunately that does not capture the bar number when the cross happened. All that snippet you posted does is to displace the price by 3 ticks. It does not plot anything for the next 3 bars. Scripting is a very precise activity. You'll need to be real explicit about what you're attempting to achieve. This is not a chatroom, and thus getting your ideas across must be very explicit and fully articulated. Otherwise it will be difficult for anyone to help you. I'm off doing other projects the rest of the evening. Meanwhile read over what I have mentioned to you in the last few posts. All the very best
 
Last edited:
T

tomsk

Well-known member
VIP
@sumihiko Since I did not hear back from you, I took a stab at what I thought might be a logical sequence of events that makes sense. The moment the Stochastic FullK crosses ABOVE the FullD, plot a horizontal line at the current price UNTIL the FullK goes BELOW the FullD.

Here is the study that does just that. It has all the components we discussed earlier - capturing the bar number and projecting forward until the condition no longer holds true. When you load this study, also load the TOS Stochastic Full study so you can match the cross points as well.

This should bring you closer to the study you seek

Code:
# Stochastic FullK/FullD Cross Horizontal Line
# tomsk
# 1.3.2020

def bar = barNumber();
def StoCrossBar = if StochasticFull()."FullK" crosses above StochasticFull()."FullD"
                  then bar
                  else StoCrossBar[1];
def crossPrice = if bar == HighestAll(stoCrossBar)
                 then low
                 else crossPrice[1];

plot hLine = if barNumber() >= HighestAll(StoCrossBar) and StochasticFull()."FullK" > StochasticFull()."FullD"
             then crossPrice
             else Double.NaN;
hLine.SetPaintingStrategy(PaintingStrategy.LINE);
hLine.SetDefaultColor(Color.ORANGE);
hLine.SetLineWeight(5);

# End Stochastic Full Cross Horizontal Line
 
Last edited:
S

sumihiko

New member
@sumihiko Since I did not hear back from you, I took a stab at what I thought might be a logical sequence of events that makes sense. The moment the Stochastic FullK crosses ABOVE the FullD, plot a horizontal line at the current price UNTIL the FullK goes BELOW the FullD.

Here is the study that does just that. It has all the components we discussed earlier - capturing the bar number and projecting forward until the condition no longer holds true. When you load this study, also load the TOS Stochastic Full study so you can match the cross points as well.

This should bring you closer to the study you seek

Code:
# Stochastic FullK/FullD Cross Horizontal Line
# tomsk
# 1.3.2020

def bar = barNumber();
def StoCrossBar = if StochasticFull()."FullK" crosses above StochasticFull()."FullD"
                  then bar
                  else StoCrossBar[1];
def crossPrice = if bar == HighestAll(stoCrossBar)
                 then low
                 else crossPrice[1];

plot hLine = if barNumber() >= HighestAll(StoCrossBar) and StochasticFull()."FullK" > StochasticFull()."FullD"
             then crossPrice
             else Double.NaN;
hLine.SetPaintingStrategy(PaintingStrategy.LINE);
hLine.SetDefaultColor(Color.ORANGE);
hLine.SetLineWeight(5);

# End Stochastic Full Cross Horizontal Line
@tomsk

Thanks man, really appreciate your guiding/help.
I took your previous components (not the one you posted 1.3.2020 ) as follows but it only draws a line at a bar.

plot KDup = if StochasticFull()."FullK" crosses above StochasticFull()."FullD"
then low - TickSize()
else Double.NaN;
KDup.SetPaintingStrategy(PaintingStrategy.horizontal);
KDup.SetDefaultColor(Color.BLUE);
KDup.SetLineWeight(3);

plot KDdn = if StochasticFull()."FullK" crosses below StochasticFull()."FullD"
then high - TickSize()
else Double.NaN;
KDdn.SetPaintingStrategy(PaintingStrategy.horizontal);
KDdn.SetDefaultColor(Color.RED);
KDdn.SetLineWeight(3);
 
T

tomsk

Well-known member
VIP
All your code does is to plot a line at the cross point (BAR) when FullK crosses above FullD. It also plots a line at the cross point (BAR) when FullK crosses below FullD. Since the next bar is not a cross point, no line is plotted. To plot across multiple bars, you'll need to mess with barnumbers.
All the best in your Thinkscript learning journey!
 
Last edited:
S

sumihiko

New member
All your code does is to plot a line at the cross point (BAR) when FullK crosses above FullD. It also plots a line at the cross point (BAR) when FullK crosses below FullD. Since the next bar is not a cross point, no line is plotted. To plot across multiple bars, you'll need to mess with barnumbers.
All the best in your Thinkscript learning journey!
@tomsk

You've helped me enough and I can't thank you enough.
 
S

sumihiko

New member
All your code does is to plot a line at the cross point (BAR) when FullK crosses above FullD. It also plots a line at the cross point (BAR) when FullK crosses below FullD. Since the next bar is not a cross point, no line is plotted. To plot across multiple bars, you'll need to mess with barnumbers.
All the best in your Thinkscript learning journey!

@tomsk

Sorry Sir, can you help me a little on coloring?

Something wrong with my script as follows:

def MB = MidBand;
MB.DefineColor("Up", CreateColor(0, 0, 204)); #The color is Blue-ish
MB.DefineColor("Down", CreateColor(255, 0, 0)); #The color is Orange-ish

MB.AssignValueColor( if MB > MB [1] and MB == MB[Z] then MB.Color("Up") else if MB < MB[Z] and MB ==MB[Z] then MB.Color("Down") else double.nan);

→I want MB=MB[1] to stay Blue after MB > MB[1] until it hits MB < MB[1]
→I want MB=MB[1] to say Orange after MB < MB[1] until it hits MB > MB[1]

MB.AssingValueColor → it's got errors.
Can you please help me? Thanks in advance!!!
 

Similar threads

Top