TOS scan using TMV study and have alerts fire based on candle color


Category:
0
0

Hi, re-sending study in text file, please see attached.  Would like the TOS scan to fire when candle turns green and crosses top band and fire when candle turns red and crosses lower band.

 

Thanks

Attachments:
Marked as spam
Posted by (Questions: 4, Answers: 1)
Asked on May 1, 2020 6:36 pm
180 views
0
Private answer

The logic we need for this scan signal is all contained within the last line of the code:

AssignPriceColor( if ADX > ADX[1] and price > SMA then globalColor("Up") else if ADX > ADX[1] and price < SMA then globalColor("Down") else globalColor("Neutral"));

So we have the green candle based on: ADX > ADX[1] and price > SMA

While the red candle is based on: ADX > ADX[1] and price < SMA

In order to convert any chart study to a scan there are really only two steps:

  1. Convert all plot statements to def
  2. Remove all the style statements applied to the former plot statements

Having completed those two steps we are left with the following:

input price = close;
input KeltnerLength = 13;
input VolumeFastLength = 1;
input VolumeSlowLength = 20;
input ADXLength = 10;
input SMALength = 8;
def KeltnerSMA = Average(hlc3, KeltnerLength);
def AvgRange = Average(high - low, KeltnerLength);
def VolumeOsc = (Average(volume, VolumeFastLength) - Average(volume, VolumeSlowLength)) / Average(volume, VolumeSlowLength);
def ADX = reference ADX(length = ADXLength);
def SMA = Average(price, SMALength);
def KeltnerHigh = KeltnerSMA + AvgRange;
def KeltnerMid = KeltnerSMA;
def KeltnerLow = KeltnerSMA - AvgRange;
def VolumeSpike = VolumeOsc > 0.5;

Every scan requires one plot statement. So we take that code I just posted and add the following plot statement to scan for the green candles produced by this chart study:

plot scan = ADX > ADX[1] and price > SMA;

and for the red candles we would instead add the following:

plot scan = ADX > ADX[1] and price < SMA;

Remember, only one plot statement can be included in a scan at any one time. So you cannot have both of those plot statements in the same Study Filter of your scan.

That's it. Nothing more to it than that.

Marked as spam
Posted by (Questions: 37, Answers: 4118)
Answered on May 1, 2020 6:55 pm
0
Great!, thanks
( at May 1, 2020 7:03 pm)