【发布时间】:2020-06-04 14:55:22
【问题描述】:
我对我的 pine 脚本有疑问。 战略思路: - 简单的趋势跟踪策略 - 检查是否处于上升/下降趋势 - 当吞没蜡烛形态时,我想在下一根蜡烛上进行交易
问题: 我想在吞没蜡烛的低点设置止损。 TP 应该是(前一个)吞没蜡烛高度的 1.25 倍。
最后一部分我有点挣扎。
谁能帮忙?
一切顺利!
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © c4ss10p314
//@version=4
strategy(title = "3emaFX", shorttitle = "3ema", overlay = true, initial_capital = 100000, process_orders_on_close = false)
price = strategy.position_avg_price
//input variables
hammerBodyHeight = input(title="Hammer Body, Max Height (Pips)",minval=1,maxval=100,step=1,defval=300,confirm=false)
bullEnHeight = input(title="BullEn, Height (Pips)",minval=1,maxval=100,step=1,defval=3,confirm=false)
bullEnAbove = input(title="BullEn Above (Pips)",minval=1,maxval=100,step=1,defval=1,confirm=false)
bullEnBelow = input(title="BullEn, Below (Pips)",minval=1,maxval=100,step=1,defval=0,confirm=false)
bearEnHeight = input(title="BearEn, Height (Pips)",minval=1,maxval=100,step=1,defval=3,confirm=false)
bearEnAbove = input(title="BearEn Above (Pips)",minval=1,maxval=100,step=1,defval=0,confirm=false)
bearEnBelow = input(title="BearEn, Below (Pips)",minval=1,maxval=100,step=1,defval=1,confirm=false)
//Candlestick patterns
invertedHammer = (abs(close - open) / syminfo.mintick <= hammerBodyHeight) and (close > open) and ((high - close) > (close - open)) and ((open - low) <= (close - open) / 2)
hammer = (abs(close - open) / syminfo.mintick <= hammerBodyHeight) and (close > open) and ((close - open) < (open - low)) and ((high - close) <= (close - open) / 2)
bullEngulfing = ((open[1] - close[1]) / syminfo.mintick >= bullEnHeight) and (close > open) and ((close - open[1]) / syminfo.mintick >= bullEnAbove) and ((close[1] - open) / syminfo.mintick >= bullEnBelow)
bearEngulfing = ((close[1] - open[1]) / syminfo.mintick >= bearEnHeight) and (close < open) and ((open - close[1]) / syminfo.mintick >= bearEnAbove) and ((open[1] - close) / syminfo.mintick >= bearEnBelow)
ema8 = ema(close, 8)
ema13 = ema(close, 13)
ema21 = ema(close, 21)
//chart plotters
plotshape(bullEngulfing, style=shape.arrowup, location=location.abovebar, color = color.green, text='BullEng')
plotshape(invertedHammer, style=shape.flag, location=location.abovebar, color = color.green, text='Inv Hammer')
plotshape(hammer, style=shape.flag, location=location.abovebar, color = color.green, text='Hammer')
plotshape(bearEngulfing, style=shape.arrowdown, location=location.belowbar, color = color.red, text='BearEng')
plot(ema8, color = color.blue, linewidth=1)
plot(ema13, color = color.green, linewidth=1)
plot(ema21, color = color.orange, linewidth=1)
//Trade conditions
longEntry = close > ema8 and ema8 > ema13 and bullEngulfing and barstate.isconfirmed
shortEntry = close < ema8 and ema8 < ema13 and bearEngulfing
longExit = close <= ema13
//Risk management variables
// RM - inputs
// position_size =
clockwork = barssince(valuewhen(bullEngulfing, price, 1)) + 1
EngHeight = abs(open[clockwork] - close[clockwork]) / syminfo.mintick
execProfitTarget = (price + (EngHeight * 1.25))
execStopLoss = (price - EngHeight)
//timeframe
start = timestamp(2019, 6, 3, 0, 0)
end = timestamp(2020, 6, 5 , 0, 0)
//Entry
if time >= start and time <= end
strategy.entry("Long", strategy.long, strategy.equity[0.01], when = longEntry)
// strategy.entry("Short", strategy.short, strategy.equity[0.01], when = shortEntry)
// Exit
strategy.exit("Exit Long", from_entry = "Long", profit = execProfitTarget, stop = execStopLoss)
// strategy.close("Close Long", from_entry = "Long", profit = execProfitTarget, loss = execStopLoss)
// Check ob trend die letzten x Kerzen schon trend war
// Line 49: Strategy.equity - andere Lösung (Positionsgröße berechnen)
【问题讨论】:
标签: pine-script trading