Help adding arrows & alerts to SchaffTrendCycle

liminal-rider

New member
Hi There forum,

I wish to do the following:
  • add up/down arrow below/above the price candle when the STC crosses above/below the oversold/overbought lines.
  • add buy/sell alert messages when the above condition is met.
Code:

Code:
declare lower;

input fastLength = 23;
input slowLength = 50;
input KPeriod = 10;
input DPeriod = 3;
input over_bought = 75;
input over_sold = 25;
input neutral_zone = 50;
input averageType = AverageType.EXPONENTIAL;

def macd = MovingAverage(averageType, close, fastLength) - MovingAverage(averageType, close, slowLength);
def fastK1 = FastKCustom(macd, KPeriod);
def fastD1 = MovingAverage(averageType, fastK1, DPeriod);
def fastK2 = FastKCustom(fastD1, KPeriod);
plot STC = MovingAverage(averageType, fastK2, DPeriod);
plot OverBought = over_bought;
plot OverSold = over_sold;
plot Neutral = neutral_zone;
STC.SetDefaultColor(GetColor(8));
OverBought.SetDefaultColor(GetColor(7));
OverSold.SetDefaultColor(GetColor(7));
Neutral.SetDefaultColor(GetColor(7));
 
Last edited by a moderator:

MerryDay

Administrative
Staff member
Staff
VIP
Code:
#TOS SchaffTrendCycle upper
input fastLength = 23;
input slowLength = 50;
input KPeriod = 10;
input DPeriod = 3;
input over_bought = 75;
input over_sold = 25;
input neutral_zone = 50;
input averageType = AverageType.EXPONENTIAL;

def macd = MovingAverage(averageType, close, fastLength) - MovingAverage(averageType, close, slowLength);
def fastK1 = FastKCustom(macd, KPeriod);
def fastD1 = MovingAverage(averageType, fastK1, DPeriod);
def fastK2 = FastKCustom(fastD1, KPeriod);
def STC = MovingAverage(averageType, fastK2, DPeriod);
def OverBought = over_bought;
def OverSold = over_sold;

def arrow_plots = high – low;
def plotHigh    = high + arrow_plots * 0.3;
def plotLow     = low  - arrow_plots * 0.3;

plot STCcrossUP = if STC crosses above close then plotlow else double.NaN ;
plot STCcrossDN = if STC crosses below close then plothigh else double.NaN ;

STCcrossUP.SetPaintingStrategy(PaintingStrategy.ARROW_UP) ;
STCcrossUP.SetLineWeight(2);
STCcrossUP.SetDefaultColor(color.cyan) ;

STCcrossDN.SetPaintingStrategy(PaintingStrategy.ARROW_DOWN);
STCcrossDN.SetLineWeight(2);
STCcrossDN.SetDefaultColor(color.magenta) ;

# Alerts
Alert(STCcrossUP, " ", Alert.Bar, Sound.Ring);
Alert(STCcrossDN, " ", Alert.Bar, Sound.Bell);

Shared Link:
http://tos.mx/tIdaDhK
 

liminal-rider

New member
Hi MaryDay, thanks for your effort. The adustments made changed the indicator. I ran the STC in the lower and the crosses don't match up... Is there way to just plot the arrows in the upper with the indicator running in the lower graph.

-JP
 

liminal-rider

New member
Hi MaryDay, just a follow up...I figured it out...your initial script helped me see what I was missing on my original script which had the arrows ploting on the lower graph properly... by changing the plot of the caculations to def and adding your def arrow_plots and plothigh & plotlow I got it to work. Thanks so much.

-JP
 

Similar threads

Top