Manchester NH
Experience: Advanced
Platform: Thinkorswim
Broker: TD Ameritrade
Trading: Small Caps
Posts: 90 since Feb 2014
Thanks Given: 31
Thanks Received: 55
|
Good morning everyone, Im trying to make a quick adjustment to the PSAR indicator so I can keep a better eye on the market while im working on other things at my office. Here is the PSAR code below. I am trying to add this to it. I pulled that code from my MACD codeing I dead years ago in college and kinda forgot all of this stuff. But what im trying to do is get the audible "Ring" or "Ding" when PSAR flips. I know I have the incorrect def BUY = diff crosses but no matter what I pull from the PSAR code I cant seem to get it to ring or ding on flip it just rings every 5 mins (I trade 5 min bars) or dings every 5 when the new psar dot flips. I just want it to do that when it crosses over. Thanks for the help in advance!
THING IM TRYING TO ADD
def SELL =diff crosses below 0 ;
def BUY = diff crosses above 0 ;
alert(SELL, "SELL", Alert.BAR, Sound.Ding);
alert(BUY, "BUY", Alert.BAR, Sound.Ring);
PSAR CODE
input accelerationFactor = 0.02;
input accelerationLimit = 0.2;
assert(accelerationFactor > 0, "'acceleration factor' must be positive: " + accelerationFactor);
assert(accelerationLimit >= accelerationFactor, "'acceleration limit' (" + accelerationLimit + ") must be greater than or equal to 'acceleration factor' (" + accelerationFactor + ")");
def state = {default init, long, short};
def extreme;
def SAR;
def acc;
switch (state[1]) {
case init:
state = state.long;
acc = accelerationFactor;
extreme = high;
SAR = low;
case short:
if (SAR[1] < high)
then {
state = state.long;
acc = accelerationFactor;
extreme = high;
SAR = extreme[1];
} else {
state = state.short;
if (low < extreme[1])
then {
acc = min(acc[1] + accelerationFactor, accelerationLimit);
extreme = low;
} else {
acc = acc[1];
extreme = extreme[1];
}
SAR = max(max(high, high[1]), SAR[1] + acc * (extreme - SAR[1]));
}
case long:
if (SAR[1] > low)
then {
state = state.short;
acc = accelerationFactor;
extreme = low;
SAR = extreme[1];
} else {
state = state.long;
if (high > extreme[1])
then {
acc = min(acc[1] + accelerationFactor, accelerationLimit);
extreme = high;
} else {
acc = acc[1];
extreme = extreme[1];
}
SAR = min(min(low, low[1]), SAR[1] + acc * (extreme - SAR[1]));
}
}
plot parSAR = SAR;
parSAR.SetPaintingStrategy(PaintingStrategy.POINTS);
parSAR.SetDefaultColor(GetColor(5));
|