Buy/Sell indicator isn’t fast enough, help moving it to plot sooner


Category:
0
0

Straightforward, I have an awesome indicator that I’m trying to use, but its slow. It takes around 3-4, 2 min candles before it even plots on both the short and long. It would be amazing if it was faster! please help someone if you can. Also, if you can make an alert on top of it to alert when it plots awesome! Thanks! Logan

 

input signalOffsetFactor = 0.20;

def signalOffset = Average(TrueRange(high, close, low), 9) * signalOffsetFactor;
plot Data = hlc3;

def triggerSell = If(If(close[-1] < high, 1, 0) and (hlc3[-2] < close[-1] or hlc3[-3] < close[-1]), 1, 0);

def triggerBuy = If(If(close[-1] > low, 1, 0) and (hlc3[-2] > close[-1] or hlc3[-3] > close[-1]), 1, 0);

rec buySellSwitch = If(triggerSell, 1, If(triggerBuy, 0, buySellSwitch[1]));

def thirdBarClosed = If(IsNaN(hlc3[-3]), 0, 1);

plot SBS = If(triggerSell and thirdBarClosed and !buySellSwitch[1], high + signalOffset, If(triggerBuy and thirdBarClosed and buySellSwitch[1], low – signalOffset, Double.NaN));

SBS.SetStyle(Curve.FIRM);
SBS.SetPaintingStrategy(PaintingStrategy.LINE_VS_POINTS);
SBS.SetLineWeight(2);

SBS.AssignValueColor(if triggerSell then
if thirdBarClosed then
#UpPos
createcolor (255, 0, 0) else
#UpNeg
CreateColor (255, 0, 0)
else if triggerBuy then
#DnPos
CreateColor(255, 255, 255) else
#DnNeg
CreateColor(255, 255, 255));

Marked as spam
Posted by (Questions: 2, Answers: 1)
Asked on March 11, 2017 4:14 pm
428 views
0
Private answer

I really don’t think we have a solution for you. Do you see in your code all the places where you use a negative value in brackets? [-1], [-2], [-3]….

Well those are referencing future values. So from first glance, this code requires that you know the future before it happens. That is why you see the signals occurring only after 3-4 candles have elapsed. There is no way to fix this. I would welcome anyone else’s input on this. It is pretty late in the evening and I might have missed something.

Marked as spam
Posted by (Questions: 37, Answers: 4118)
Answered on March 11, 2017 11:20 pm