커뮤니티

수식에 오류가 있다고 하는데 어느 부분인지 모르겠어요.. 수정 부탁드립니다.

프로필 이미지
yunmx
2023-02-24 10:28:11
940
글번호 166643
답변완료
// 설정 변수 period = input(title="Period", defval=20, minval=1) stoploss = input(title="Stop Loss", type=input.float, defval=1.0, minval=0.1, step=0.1) takeprofit = input(title="Take Profit", type=input.float, defval=1.5, minval=0.1, step=0.1) // 지표 maValue = sma(close, period) rsiValue = rsi(close, period) emaValue = ema(close, period) macdValue = macd(close, 12, 26, 9) // 매수 신호 buySignal = crossover(emaValue, maValue) and rsiValue > 50 and macdValue > 0 // 매도 신호 sellSignal = crossunder(emaValue, maValue) and rsiValue < 50 and macdValue < 0 // 포지션 진입/청산 if buySignal strategy.entry("Buy", strategy.long) if sellSignal strategy.entry("Sell", strategy.short) // 포지션 청산 if strategy.position_size > 0 and close < (strategy.position_avg_price * (1 - stoploss)) strategy.exit("Stop Loss", strategy.short) if strategy.position_size < 0 and close > (strategy.position_avg_price * (1 + takeprofit)) strategy.exit("Take Profit", strategy.short)
시스템
답변 1
프로필 이미지

예스스탁 예스스탁 답변

2023-02-24 11:45:30

안녕하세요 예스스탁입니다. 올리신 수식의 저희 프로그램 언어가 아닙니다. 예스랭귀지로 수정해 드립니다. input : period(20),stoploss(1.0),takeprofit(1.5); var : mavalue(0),rsivalue(0),Emavalue(0),macdvalue(0); var : buySignal(False),sellSignal(False); maValue = ma(close, period); rsiValue = rsi(period); emaValue = ema(close, period); macdValue = macd(12, 26); // 매수 신호 buySignal = CrossUp(emaValue, maValue) and rsiValue > 50 and macdValue > 0; // 매도 신호 sellSignal = CrossDown(emaValue, maValue) and rsiValue < 50 and macdValue < 0; // 포지션 진입/청산 if buySignal == true Then Buy(); if sellSignal == true Then Sell(); // 포지션 청산 if MarketPosition == 1 and close < (EntryPrice * (1 - stoploss)) Then ExitLong(); if MarketPosition == -1 and close > (EntryPrice * (1 + takeprofit)) Then ExitShort(); 즐거운 하루되세요 > yunmx 님이 쓴 글입니다. > 제목 : 수식에 오류가 있다고 하는데 어느 부분인지 모르겠어요.. 수정 부탁드립니다. > // 설정 변수 period = input(title="Period", defval=20, minval=1) stoploss = input(title="Stop Loss", type=input.float, defval=1.0, minval=0.1, step=0.1) takeprofit = input(title="Take Profit", type=input.float, defval=1.5, minval=0.1, step=0.1) // 지표 maValue = sma(close, period) rsiValue = rsi(close, period) emaValue = ema(close, period) macdValue = macd(close, 12, 26, 9) // 매수 신호 buySignal = crossover(emaValue, maValue) and rsiValue > 50 and macdValue > 0 // 매도 신호 sellSignal = crossunder(emaValue, maValue) and rsiValue < 50 and macdValue < 0 // 포지션 진입/청산 if buySignal strategy.entry("Buy", strategy.long) if sellSignal strategy.entry("Sell", strategy.short) // 포지션 청산 if strategy.position_size > 0 and close < (strategy.position_avg_price * (1 - stoploss)) strategy.exit("Stop Loss", strategy.short) if strategy.position_size < 0 and close > (strategy.position_avg_price * (1 + takeprofit)) strategy.exit("Take Profit", strategy.short)