MACD STOCH rising w price bounce on lower keltner


Category:
0
0

First off I’d like to say thank you I’ve recently started to code bits and pieces together thanks to your help and explanation on the condition wizard.

Secondly I’m having difficulty setting up a watchlist column/ scan that would show green when the MACD and StochFull are raising and price  enters and then bounces off the the lower channel.

Here is what ive got so far.

def value = close is less than or equal to KeltnerChannels().”Lower_Band”;
def value1 = StochasticFull().”FullK” is greater than StochasticFull().”FullD” ;
def value2 = MACD().”Diff” is greater than MACD().”ZeroLine”;
AssignBackgroundColor( if value1 == 1 and value2 == 1 then Color.GREEN else Color.CURRENT);

I placed 3 different columns on my watchlist to show weekly, daily and 4 hr. and to this point its just loading endlessly.  any help would be greatly appreciated.  Thank you in advance for any help!  its truly appreciated.

Attachments:
Marked as spam
Posted by (Questions: 1, Answers: 1)
Asked on November 15, 2020 9:45 am
136 views
0
Private answer

Your screenshot does not appear to show all three of these conditions taking place on the same candle. The close is not less than or equal to the lower KeltnerChannel band. And the MACD is below zero. Only one of your stated conditions is true for any of the bars in your screenshot. Which means your screenshot does not tell us anything.

When I copy/paste your code into a watchlist column the code cannot be applied unless I add a plot statement. So if your watchlist column is displaying "loading" this means you have applied some other code to your watchlist column, something different than what you have provided in your request. Otherwise you would never be able to apply it to the column in the first place.

So to your code, I had to add the following plot statement:

plot data = value1 == 1 and value2 == 1;

The code can then be applied to the column and it works just fine. But it's wrong. It does not include all three conditions specified in your code. You are only including "value1" and "value2" in your AssignBackgroundColor() statement. You have completely omitted the the variable named "value" from that statement, which means your code is not picking up the Keltner channel condition.

If you name each variable using terms that are clear and concise, you can avoid a great many problems such as this. Take a look at the following solution and notice the changes:

def conditionKeltner = close is less than or equal to KeltnerChannels().”Lower_Band”;
def conditionStochastic = StochasticFull().”FullK” is greater than StochasticFull().”FullD” ;
def conditionMACD = MACD().”Diff” is greater than MACD().”ZeroLine”;
plot data = conditionKeltner and conditionStochastic and conditionMACD;
AssignBackgroundColor( if data then Color.GREEN else Color.CURRENT);

Instead of using meaningless variable names such "value#", I have created variable names that actually describe what each one contains. So when it comes time to assemble them all into the plot statement I can clearly see that I have applied all three conditions. Better yet, if I need to split things out to troubleshoot an issue I have variable names that tell me exactly what each one is doing. I can very quickly check each of those three conditions individually so see what each one is doing.

Notice that for any true/false variable there is never a need to check if it is equal to 1 . You do not need to check if "value1 == 1".

plot scan = value1 == 1; is the same exact thing as plot scan = value1;

...and you can chain them together...

plot scan = value1 == 1 and value2 == 1; is the same as plot scan = value1 and value2;

And the plot statement is required anyway, so why not use that to contain the true/false value of your combined conditions:

plot data = conditionKeltner and conditionStochastic and conditionMACD;

Then you can use just that one variable in your AssignBackgroundColor() statement:

AssignBackgroundColor( if data then Color.GREEN else Color.CURRENT);

Marked as spam
Posted by (Questions: 37, Answers: 4118)
Answered on November 15, 2020 10:42 am
0
Thank you very much Pete! I just started my journey in learning to code these things and your insight and expertise is greatly appreciated!
( at November 15, 2020 11:46 am)