Exponential Moving Average Cross Above/Below VWAP


Category:
0
0

Hi Pete,

Thank you so much for the great tutorials & content. Your site is a fantastic resource and I’m so glad I stumbled upon it. Did my best to search through the existing posts and I did find a couple of posts that were variations of what I’m looking to do but not exactly what I was looking for. Since I’m new to coding, I figured I’d just ask and see if I can get pointed in the right direction.

I wanted to see if there is a way to create a custom conditional wizard watch list that returns a “1” with green background when the Exponential Moving Average cross above the VWAP and a “0” when the Exponential Moving Average crosses below the VWAP?

Any help would be tremendously appreciated.

John Michael

Marked as spam
Posted by (Questions: 1, Answers: 0)
Asked on March 4, 2020 11:55 pm
238 views
0
Private answer

You can't actually accomplish this using the Condition Wizard. Not without modifying the code that it generates. So we can generate the individual components from the Condition Wizard, from which we can assemble the final solution.

For full details on using the Condition Wizard to build custom watchlist solutions see the following video:

https://www.hahn-tech.com/thinkorswim-condition-wizard-watchlist/

So using the Condition Wizard we can generate the code for each of your two conditions. This is the output:

MovAvgExponential()."AvgExp" crosses above reference VWAP()."VWAP"

MovAvgExponential()."AvgExp" crosses below reference VWAP()."VWAP"

Now I will step you through the modifications:

Assign each of these statement to variables:

def crossAboveVWAP = MovAvgExponential()."AvgExp" crosses above reference VWAP()."VWAP";

def crossBelowVWAP = MovAvgExponential()."AvgExp" crosses below reference VWAP()."VWAP";

Notice the only thing we did there was to add the 'def' declaration, followed by the variable name and added a semicolon to the end. Now we can use those variable names for the plot statement, which is the line of code that displays the value in the custom watchlist column.

plot value = if crossAboveVWAP then 1 else if crossBelowVWAP then -1 else 0;

Notice this will output a value of +1 when the moving average crosses above the VWAP and a -1 when the moving average crosses below the VWAP. Be sure to realize that you requested the cross event and not the relative position of these two lines. So this means each candle has 3 possible conditions:

  1. Crossing above
  2. Crossing below
  3. Not crossing (either above or below but specifically crossing on this bar)

So we need to use three values to display the conditions you requested.

If you actually just wanted this to be +1 if moving average is above and zero if moving average is below (not the actual crossing events but the relative positions of those two lines) well you would not have needed to post in the Q&A forum because that could have very easily have been accomplished using the condition wizard without any modifications whatsoever.

Marked as spam
Posted by (Questions: 37, Answers: 4118)
Answered on March 5, 2020 8:26 am