Creating an alert to notify of a slope change on custom T3 moving average


0
0

Hello,

I wanted to thank you again for the time and effort you put into this forum and your videos.

I’m using a version of a T3 moving average that changes color when the slope changes. I’d like to create a simple alert that notifies me when this happens.

Here is the code:

input indicator    = { T1, T2, default T3, T4, T5, T6 };
input price        = close;
input period       = 10;
input volumeFactor = 0.70;
input displace     = 0;
input sign         = { default plus, minus };
input Label        = Yes;
input paintbars    = No;

script _gd {
input _price  = close;
input _period = 10;
input _v      = 0.70;
input _sign   = { default plus, minus };
def _ema      = ExpAverage( _price, _period );
plot _gd      = ( _ema * ( 1 + _v ) ) – ( ExpAverage( _ema, _period ) * _v );
}

def _t1 = _gd( price[-displace], period, volumeFactor, sign );
def _t2 = _gd( _t1,   period, volumeFactor, sign );
def _t3 = _gd( _t2,   period, volumeFactor, sign );
def _t4 = _gd( _t3,   period, volumeFactor, sign );
def _t5 = _gd( _t4,   period, volumeFactor, sign );
def _t6 = _gd( _t5,   period, volumeFactor, sign );

plot T3;
switch( indicator ) {
case T1:
T3 = _t1;
case T2:
T3 = _t2;
case T3:
T3 = _t3;
case T4:
T3 = _t4;
case T5:
T3 = _t5;
case T6:
T3 = _t6;
}

T3.AssignValueColor(if T3 > T3[1] then Color.White else Color.Red);
T3.SetLineWeight(3);
T3.HideBubble();

AddLabel(Label, if T3 > T3[1] then ”  T3-10 Up  ” else ”  T3-10 Down  “, if T3 > T3[1] then color.green else color.red);

assignPriceColor(if paintbars and T3 <T3[1] then color.red else if paintbars and T3 > T3[1] then color.green else color.CURRENT);

Thank you for all your help. I’ll be sure to make a nice donation to your site.

Thomas

 

Attachments:
Marked as spam
Posted by (Questions: 1, Answers: 0)
Asked on May 7, 2017 7:08 pm
650 views
0
Private answer

Thank you for providing all the details required to solve this in one step. You provided the source code as well as a screenshot. This is an exceptionally good post.

Given your existing code the alerts should be enabled using this code. I have not tested this, so give this a try and let me know how it works. If you find anything amiss I will make corrections as needed.

def t3CrossesUp = T3 > T3[1] and T3[1] < T3[2];
def t3CrossesDown = T3 < T3[1] and T3[1] > T3[2];
Alert(t3CrossesUp, "T3 Crossing Up", Alert.BAR, Sound.RING);
Alert(t3CrossesDown, "T3 Crossing Down", Alert.BAR, Sound.RING);

Marked as spam
Posted by (Questions: 37, Answers: 4118)
Answered on May 7, 2017 9:56 pm