Reputation: 11
Just wondering if anyone know if it's possible to impose a trading signal that is based on another security? i.e. Trading signal is based on crossover strategy of security [A], if long/short condition is met, the trading strategy instead takes a long on another security [B]. So far I've managed to work out the trading signal generation for [A] but not sure how I am able to impose this on security [B].
Strategy for security [A]
strategy("MACD with RSI", overlay=true, pyramiding=3)
macd = ema(close, 20) - ema (close, 35) signal = ema(macd, 15)
rsi = rsi(low, 35) roc = roc(close, 15)
short = crossover(macd, signal) long = crossunder(macd, signal)
longcondition = long and macd - signal < 0.02 shortcondition = short and macd - signal > -0.02
strategy.entry("long", strategy.long, 1, when = longcondition) strategy.entry("short", strategy.short, 1, when = shortcondition)
closelong = rsi > 80 closeshort= rsi < 20
strategy.close("long", when = closelong) strategy.close("short", when = closeshort)
Upvotes: 1
Views: 550
Reputation: 16
Hey bud this is prety foward.
You using the close global var to calculate everything about the indicators right?
Something you can do its to use the function security() here is a sample code for you to take a look:
//@version=4
study("Cross Security",overlay=false)
actualSymbol = input(true,title="Use Current Simbol?",type=input.bool)
Chosen = input("EURUSD",title="security[A]", type=input.symbol)
security_B = input("GBPUSD",title="security[B]", type=input.symbol)
rsilen = input(14,"RSI Length")
//Get two or more differnet symbol values to calculate the indicators
security_A = actualSymbol? syminfo.tickerid : Chosen //use window symbol or chosen
close_A = security(security_A,timeframe.period,close[1]) //will giver you close values of security_A
close_B = security(security_B,timeframe.period,close[1]) //will giver you close values of security_B
//use the close value to calculate the indicators
RSI_A = rsi(close_A, rsilen)
RSI_B = rsi(close_B, rsilen)
// Use the values to build what ever ....
hline(80)
hline(50)
hline(20)
plot(RSI_A,color=color.red)
plot(RSI_B,color=color.orange)
Upvotes: 0