Picture of Oscillator Malfunction I went in and took an example from tradingview that was designed for Pinecoders Backtesting engine where you design a external input signal that is typically -3 to positive 3 to be recognized by a strategy as a binary long or short signal. Well if you compile mine you see the Signal plot jumps up to the actual literal market price of a moving crossover or cross under and not the oscillator value I'm trying to assign to it, big problem since I can't get a strategy to read an unknowable value that isn't a -2 or 2 or -1 or 1 etc. I've tried a lot of things and it keeps reading through and plotting the actual crossover or crossunder of the moving average. Any ideas?
//@version=4
// Original Author - Rajandran R
// Updated to Pinescript version 3 by Cosmic_Coin
study(title="TestRiskExternalInput", shorttitle="TestRiskExternalInput")
////////////////////////////////////////////////////////////////////////////////
// Allow selection of signal content.
IncludeFilter = input(true, "Include Filter")
IncludeEntries = input(true, "Include Entries")
IncludeStops = input(true, "Include Stops with Entries")
IncludeExits = input(true, "Include Exits")
// ——————————————————————————————————————————————————————————————————————————————————————
// ▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼
// This part is the section where you would put your own indicator and define conditions.
// ————— TV built-in MACD code.
fastLength = input(12)
slowlength = input(26)
MACDLength = input(9)
MACD = ema(close, fastLength) - ema(close, slowlength)
aMACD = ema(MACD, MACDLength)
quickMa = sma(close, fastLength)
slowMa = sma(close, slowlength)
// ————— Exits.
//SourceTypeL = 0//crossover(quickMa, slowMa)//[idx]
//SourceTypeS = 0 //crossunder(quickMa, slowMa)//[idx]
tempcharL = 0
tempcharS = 0
if crossover(quickMa, slowMa)
tempcharL := 2
tempcharS := 0
if crossunder(quickMa, slowMa)
tempcharS := -2
tempcharL := 0
// ————— Filter.
FilterLong = MACD > 0
FilterShort = MACD < 0
// ————— Entries.
EnterLong = tempcharL
EnterShort = tempcharS
// ————— Stops.
Atr = atr(14)
StopLong = min(lowest(5), min(close, open) - Atr * 1.5)
StopShort = max(highest(5), max(close, open) + Atr * 1.5)
// ————— Exits.
ExitLong = crossunder(MACD, aMACD) and MACD > 0
ExitShort = crossover(MACD, aMACD) and MACD < 0
// ▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲
// ——————————————————————————————————————————————————————————————————————————————————————
// ————— This function ensures that no stop value equal to one of the protocol's reserved values is sent, so it isn't misinterpreted as a signal.
// The fudge is in the direction where the trade's risk is decreased by a tick, so added for longs and subtracted for shorts.
FudgeStop(_stop, _fudgedir) =>
_stop == 1.0 or _stop == 2.0 or _stop == 3.0 ?
_stop + syminfo.mintick * _fudgedir : _stop
// ————— Build required values corresponding to states.
Filter = FilterLong ? 1 : FilterShort ? -1 : 0
Entries = tempcharL == 2 ? 2 : tempcharS == -2 ? -2 : 0
FudgeStop__1 = FudgeStop(StopLong, 1)
FudgeStop__2 = FudgeStop(StopShort, -1)
Stops = EnterLong ? FudgeStop__1 : EnterShort ? -FudgeStop__2 : 0
Exits = ExitLong ? 3 : ExitShort ? -3 : 0
// ————— We must decide which value will be sent in case more than one is different than 0, since only one value can be sent at each bar.
// Priority is given to exits, with filter states coming last.
Signal = IncludeExits and Exits != 0 ? Exits : IncludeStops and Stops != 0 ? Stops :
IncludeEntries and Entries != 0 ? Entries :
IncludeFilter and Filter != 0 ? Filter : na
// ————— Plot signal which is to be connected to the Engine through the External Indicator field at the very bottom of the Engine's Settings/Inputs.
plot(Signal, "Signal")
