Custom Indicator Example
The following script is only a demonstration example of automated trading logic and does not constitute investment advice. Please invest cautiously and pay attention to risk control.
MACD Strategy
Trading Logic: Golden cross to close short and open long positions, dead cross to close long and open short positions
// Declare strategy configuration, define relevant parameters. See the strategy configuration field declaration below for specific supported parameters
tradeConfig(price="market", amount=1)
// Calculate the values of the indicator
[dif, dea, macd] = macd(close, 12, 26, 9, 'EMA', 'EMA')
// Calculate the values of the alert conditions
golden_cross = crossup(dif, dea)
dead_cross = crossdown(dif, dea)
// Execute trading instructions
exitLong(dead_cross)
exitShort(golden_cross)
enterLong(golden_cross)
enterShort(dead_cross)
Time-Specific Order
Trading Logic: Execute specified trading instructions at specified times. The time and trading instructions can be modified as needed
// @version=2
// Convert the date to a comparable time
t1 = parse_time("2023-10-24 12:14:00")
t2 = parse_time("2023-10-24 12:15:00")
t3 = parse_time("2023-10-24 12:16:00")
t4 = parse_time("2023-10-24 12:17:00")
// Define conditions
s1 = time == t1
s2 = time == t2
s3 = time == t3
s4 = time == t4
// Define alert conditions for use in the alert window
alertcondition(s1, title='t1')
alertcondition(s2, title='t2')
alertcondition(s3, title='t3')
alertcondition(s4, title='t4')
enterLong(s1, price='market', amount=1)
exitLong(s2, price='market', amount=1)
enterShort(s3, price='market', amount=1)
exitShort(s4, price='market', amount=1)
// Plot the closing price on the chart
plot(close, title="Closing Price")
Pin Order
Trading Logic: Open short on upper pin bar, open long on lower pin bar. It is recommended to run on a one-minute cycle for BTC.//@version=2
// Amplitude threshold
amplLimit=0.003
// Solid threshold
solidLimit=0
// Shadow limit
shadowPctLimit=0.002
// Calculate upper shadow
overshadow = high - max(open, close)
// Calculate candle body
solid = abs(close - open)
// Calculate lower shadow
undershadow = min(close, open) - low
// Calculate amplitude
ampl = (high - low) / close[1]
// Calculate upper shadow percentage change
overshadowPct = overshadow / max(open, close)
// Calculate lower shadow percentage change
undershadowPct = undershadow / min(close, open)
// Pin bar judgment algorithm
pinbar = 0
if (ampl > amplLimit) {
if (solid > solidLimit && undershadowPct > shadowPctLimit && overshadowPct > shadowPctLimit) {
pinbar := 4
} else if (solid >= solidLimit && undershadowPct > shadowPctLimit) {
pinbar := -1
} else if (solid >= solidLimit && overshadowPct > shadowPctLimit) {
pinbar := 1
}
}
// 1 is upper pin bar
// -1 is lower pin bar
// 4 is upper and lower pin bar
up = pinbar == 1
down = pinbar == -1
// Create corresponding alert conditions for use in the alert window
alertcondition(up, title='Upper Pin Bar', direction="sell")
alertcondition(down, title='Lower Pin Bar', direction="buy")
// Plot on the chart
plot(close, title="Close")
plotShape(up, title="Upper Pin Bar", shape='arrowDown', color='red', refSeries=close, placement='top', fill=true)
plotShape(down, title="Lower Pin Bar", shape='arrowUp', color='green', refSeries=close, placement='bottom', fill=true)
// Trading configuration
// Open long on lower pin bar
enterLong(down, price='market', amount=1)
// Open short on upper pin bar
enterShort(up, price='market', amount=1)
Related Reading:
AICoin Automated Live Trading - Quick Start
AICoin Automated Live Trading - Real-life Signal Alert Example
AICoin Automated Live Trading - Real-life Indicator Win Rate Example
AICoin Automated Live Trading - Handling Common Issues
免责声明:本文章仅代表作者个人观点,不代表本平台的立场和观点。本文章仅供信息分享,不构成对任何人的任何投资建议。用户与作者之间的任何争议,与本平台无关。如网页中刊载的文章或图片涉及侵权,请提供相关的权利证明和身份证明发送邮件到support@aicoin.com,本平台相关工作人员将会进行核查。