Opportunity Criteria
Opportunity Criteria
0 at
https://mozilla.org/MPL/2.0/
// © daddywookie
//@version=5
indicator("Opportunity Criteria")
enterLong = false
enterShort = false
exitBar = 0
entryPrice = open[movementLength]
longProfit = entryPrice + entryPrice*(profitTarget/100)
shortProfit = entryPrice - entryPrice*(profitTarget/100)
longStop = entryPrice - entryPrice*(stopLimit/100)
shortStop = entryPrice + entryPrice*(stopLimit/100)
stopBar = 0
studyBarOffset=(-1*movementLength)-1
// ---> Set up the metrics we are going to compare as a set of -1 > 1 scales for
short to long
shortlong_Entry = 0
shortlong_EntryStrength = 0
// ---> Step back through the history to compare the open[i] price with the current
high/low. Handle long and short in their own loops
long_i = 1
short_i = 1
// ---> Reference the furthest back bar we are testing for an entry
thisBar = movementLength - long_i
// ---> Did this bar exceed our profit or stop levels and trigger an exit
exitLongStop := low[thisBar] < longStop
exitLongProfit := high[thisBar] > longProfit
// ---> If we hit a profit then flag it, update stats and exit the search
else if(exitLongProfit)
enterLong := true
exitBar := thisBar
shortlong_Entry := 1
shortlong_EntryStrength := 1-(long_i/movementLength)
shortlong_EntryCount += 1
long_EntryCount += 1
long_i := movementLength
else if(exitShortProfit)
enterShort := true
exitBar := thisBar
shortlong_Entry := -1
shortlong_EntryCount += 1
shortlong_EntryStrength := -1+(1*short_i/movementLength)
short_EntryCount += 1
short_i := movementLength
else
short_i += 1
// ---> Show another indicator to see if there is a correlation with our proposed
entries
smoothed_RSI = ta.ema(((ta.rsi(hl2,14)-50))/50,14)
// ---> Advanced indicator to show strength of entry, showing how quickly it will
profit
plot(shortlong_EntryStrength, title="Short or Long Strength",
offset=studyBarOffset, color=color.blue)
// ---> Simple indicator icons for long or short. These appear on the bar which
should calculate your entry, the actual entry would occur at the open of the next
bar
plotshape(enterLong, "Enter Long", shape.triangleup, location.bottom,
offset=studyBarOffset, color=color.new(color.blue,33), size=size.auto)
plotshape(enterShort, "Enter Short", shape.triangledown, location.bottom,
offset=studyBarOffset, color=color.new(color.red,33), size=size.auto)
var barDelta = 0
shortlong_EntryRate = math.round((shortlong_EntryCount/barDelta)*100)
long_EntryRate = math.round((long_EntryCount/barDelta)*100)
short_EntryRate = math.round((short_EntryCount/barDelta)*100)
print(txt) =>
// Create label on the first bar.
var lbl = label.new(bar_index, na, txt, xloc.bar_index, yloc.price, color(na),
label.style_none, color.gray, size.large, text.align_left)
// On next bars, update the label's x and y position, and the text it displays.
label.set_xy(lbl, bar_index, 0)
label.set_text(lbl, txt)
print(reportString)