RateOfChangeCrossover display for current session only


Category:
0
0

Hello Hahn,

Hope you’re doing well! I was wondering if you could help me modify the ToS indicator “rate of change crossover (positive to negative) & (negative to positive)” to only display for the current day. Thank you so much for your help!

Marked as spam
Posted by (Questions: 9, Answers: 4)
Asked on April 1, 2023 9:09 am
62 views
0
Private answer

You did not specifically mention you are using an intraday time frame. But for this solution I am assuming you are.

There are many solutions of this type in the forum. You will find examples of this in the following posts:

https://www.hahn-tech.com/ans/previous-ohl-study-show-only-today-with-labels/

https://www.hahn-tech.com/ans/parabolicsar-indicator-display-current-day-only/

https://www.hahn-tech.com/ans/vwap-indicator-for-current-day-only/

https://www.hahn-tech.com/ans/hide-previous-day-sr-lines-camarilla-points-study/

The key to this is in the very first line of code I added to the existing code provided with Thinkorswim. The variable name is "okToPlot" and it is inserted into any section of the code which you want to be active for only the current trading session.

So we add this line to the top of the code:

def okToPlot = GetDay() == GetLastDay();

And we apply that to the plot statement from the original, like this:

plot signal = if okToPlot then crosses(ROC, 0, crossingType == CrossingType."Negative to Positive") else no;

The full solution is listed below:

def okToPlot = GetDay() == GetLastDay();
input length = 14;
input crossingType = {default "Positive to Negative", "Negative to Positive"};
assert(length > 0, "'length' must be positive: " + length);
def price = close;
def ROC = if price[length] != 0 then (price / price[length] - 1) * 100 else 0;
plot signal = if okToPlot then crosses(ROC, 0, crossingType == CrossingType."Negative to Positive") else no;
signal.DefineColor("Negative to Positive", GetColor(8));
signal.DefineColor("Positive to Negative", GetColor(9));
signal.AssignValueColor(if crossingType == CrossingType."Negative to Positive" then signal.color("Negative to Positive") else signal.color("Positive to Negative"));
signal.SetPaintingStrategy(if crossingType == CrossingType."Negative to Positive"
then PaintingStrategy.BOOLEAN_ARROW_UP
else PaintingStrategy.BOOLEAN_ARROW_DOWN);

Marked as spam
Posted by (Questions: 37, Answers: 4091)
Answered on April 1, 2023 10:52 am