我对我的松树脚本有疑问。 战略思想: -简单的趋势跟随策略 -检查是否有上升/下降趋势 -当吞入蜡烛时,我想在下一根蜡烛上进行交易
问题: 我想在那吞噬蜡烛的低位止损。 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)
答案 0 :(得分:0)
这应该使您更接近目标:
// © c4ss10p314
//@version=4
strategy(title = "3emaFXlong", shorttitle = "3emaL", overlay=true, initial_capital = 100000, default_qty_type=strategy.percent_of_equity, default_qty_value = 10)
price = close
//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)
inpTakeProfit = input(1.25, title = "Example-Take Profit Multiplier", minval = 0.1, maxval = 5, step = 0.1)
//Candlestick patterns
invertedHammer = (abs(close - open) / syminfo.mintick <= hammerBodyHeight) and (close > open) and ((high - close) > (close - open)) and ((open - low) <= (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)
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')
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
longExit = close <= ema13
//Risk management variables
// RM - inputs
// position_size =
execProfitTarget = (price * 1.05) / syminfo.mintick
execStopLoss = (price * 0.98)
//timeframe
start = timestamp(2000, 5, 27, 0, 0)
end = timestamp(2020, 6, 30 , 0, 0)
//Entry & exit
if time >= start and time <= end and longEntry and strategy.opentrades == 0
strategy.entry("Long", strategy.long)
strategy.exit("Exit Long", from_entry = "Long", profit = execProfitTarget, stop = execStopLoss)
// Debugging.
plotchar(longEntry, "longEntry", "▲", location.top, size = size.tiny)
plotchar(close > ema8, "close > ema8", "•", location.bottom, size = size.tiny)
plotchar(ema8 > ema13, "ema8 > ema13", "—", location.bottom, size = size.tiny)
plotchar(execProfitTarget, "execProfitTarget", "", location.top, size = size.tiny)
plotchar(execStopLoss, "execStopLoss", "", location.top, size = size.tiny)
plotchar(strategy.opentrades, "strategy.opentrades", "", location.top, size = size.tiny)
// © c4ss10p314
//@version=4
strategy(title = "3emaFXlong", shorttitle = "3emaL", overlay=true, initial_capital = 100000, default_qty_type=strategy.percent_of_equity, default_qty_value = 10)
price = close
//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)
inpTakeProfit = input(1.25, title = "Example-Take Profit Multiplier", minval = 0.1, maxval = 5, step = 0.1)
//Candlestick patterns
invertedHammer = (abs(close - open) / syminfo.mintick <= hammerBodyHeight) and (close > open) and ((high - close) > (close - open)) and ((open - low) <= (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)
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')
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
longExit = close <= ema13
//Risk management variables
// RM - inputs
// position_size =
//timeframe
start = timestamp(2000, 5, 27, 0, 0)
end = timestamp(2020, 6, 30 , 0, 0)
//Entry & exit
var float execProfitTarget = na
var float execProfitPrice = na
var float execStopLoss = na
if time >= start and time <= end and longEntry and strategy.opentrades == 0
// We know that we enter here only when a bullEngulfing was encountered,
// which means the current OHLC prices are those of that engulfing bar.
execProfitTarget := (abs(close - open) * 1.25) / syminfo.mintick
execProfitPrice := close + execProfitTarget * syminfo.mintick
execStopLoss := low
strategy.entry("Long", strategy.long)
strategy.exit("Exit Long", from_entry = "Long", profit = execProfitTarget, stop = execStopLoss)
// Plot stop and target.
inTrade = strategy.opentrades != 0
plot(inTrade ? execStopLoss : na, "Stop", color.red, 1, plot.style_circles)
plot(inTrade ? execProfitPrice : na, "Target", color.lime, 1, plot.style_circles)
// Debugging.
// plotchar(strategy.opentrades, "strategy.opentrades", "", location.top, size = size.tiny)
// plotchar(inTrade, "inTrade", "", location.top, size = size.tiny)
// plotchar(longEntry, "longEntry", "▲", location.top, size = size.tiny)
// plotchar(close > ema8, "close > ema8", "•", location.bottom, size = size.tiny)
// plotchar(ema8 > ema13, "ema8 > ema13", "—", location.bottom, size = size.tiny)
// plotchar(execProfitTarget, "execProfitTarget", "", location.top, size = size.tiny)
// plotchar(execStopLoss, "execStopLoss", "", location.top, size = size.tiny)
// plotchar(strategy.opentrades, "strategy.opentrades", "", location.top, size = size.tiny)