ORDER DIFFERENT ALERT
Posted: Fri Sep 10, 2021 3:40 am
When I backtest the Daily breakout strategy on BTCUSD (FT 15M) and the alert settings. It happened that there was no order but the message was yes. please help me fix it.
------------------------------
/@version=4
strategy("Daily Breakout Strategy", overlay=true, default_qty_value=1000000)
// Get user input
entryPips = input(title="Entry Pips", defval=3.0, type=input.float, tooltip="How many pips above high to place entry order")
stopPips = input(title="Stop Pips", defval=5.0, type=input.float, tooltip="Fixed pip stop loss distance")
targetPips = input(title="Target Pips", defval=10.0, type=input.float, tooltip="Fixed pip profit target distance")
// Get highs and lows
dailyHigh = security(syminfo.tickerid, "D", high)
dailyLow = security(syminfo.tickerid, "D", low)
// Determine buy & sell point (default 3 pips/30 points above/below high/low)
buyPoint = dailyHigh + (entryPips * 10 * syminfo.mintick)
sellPoint = dailyLow - (entryPips * 10 * syminfo.mintick)
// Determine stop loss (default 5 pips/50 points above/below buy/sell point)
stopLossLong = buyPoint - (stopPips * 10 * syminfo.mintick)
stopLossShort = sellPoint + (stopPips * 10 * syminfo.mintick)
// Determine take profit (default 10 pips/100 points above/below buy/sell point)
takeProfitLong = buyPoint + (targetPips * 10 * syminfo.mintick)
takeProfitShort = sellPoint - (targetPips * 10 * syminfo.mintick)
// If a new day has started and we're flat, place a buy stop & sell stop
var stopLossLongSaved = 0.0
var takeProfitLongSaved = 0.0
var stopLossShortSaved = 0.0
var takeProfitShortSaved = 0.0
newDay = change(time("D"))
if newDay
if strategy.position_size == 0
stopLossLongSaved := stopLossLong
takeProfitLongSaved := takeProfitLong
strategy.entry(id="buy", long=strategy.long, stop=buyPoint, oca_name="x", oca_type=strategy.oca.cancel,comment="buy",alert_message="buy")
stopLossShortSaved := stopLossShort
takeProfitShortSaved := takeProfitShort
strategy.entry(id="sell", long=strategy.short, stop=sellPoint, oca_name="x", oca_type=strategy.oca.cancel,comment="sell",alert_message="sell")
// Exit our trade if our stop loss or take profit is hit
strategy.exit(id="close", from_entry="buy", limit=takeProfitLongSaved, stop=stopLossLongSaved,comment="close",alert_message="close")
strategy.exit(id="close", from_entry="sell", limit=takeProfitShortSaved, stop=stopLossShortSaved,comment="close",alert_message="close")
// Draw data to the chart
plot(dailyHigh, color=color.blue, linewidth=2, title="Daily High")
plot(dailyLow, color=color.blue, linewidth=2, title="Daily Low")
plot(buyPoint, color=color.purple, title="Buy Stop")
plot(stopLossLong, color=color.red, title="Long Stop Loss")
plot(takeProfitLong, color=color.green, title="Long Profit Target")
plot(sellPoint, color=color.purple, title="Sell Stop")
plot(stopLossShort, color=color.red, title="Short Stop Loss")
plot(takeProfitShort, color=color.green, title="Short Profit Target")
------------------------------
/@version=4
strategy("Daily Breakout Strategy", overlay=true, default_qty_value=1000000)
// Get user input
entryPips = input(title="Entry Pips", defval=3.0, type=input.float, tooltip="How many pips above high to place entry order")
stopPips = input(title="Stop Pips", defval=5.0, type=input.float, tooltip="Fixed pip stop loss distance")
targetPips = input(title="Target Pips", defval=10.0, type=input.float, tooltip="Fixed pip profit target distance")
// Get highs and lows
dailyHigh = security(syminfo.tickerid, "D", high)
dailyLow = security(syminfo.tickerid, "D", low)
// Determine buy & sell point (default 3 pips/30 points above/below high/low)
buyPoint = dailyHigh + (entryPips * 10 * syminfo.mintick)
sellPoint = dailyLow - (entryPips * 10 * syminfo.mintick)
// Determine stop loss (default 5 pips/50 points above/below buy/sell point)
stopLossLong = buyPoint - (stopPips * 10 * syminfo.mintick)
stopLossShort = sellPoint + (stopPips * 10 * syminfo.mintick)
// Determine take profit (default 10 pips/100 points above/below buy/sell point)
takeProfitLong = buyPoint + (targetPips * 10 * syminfo.mintick)
takeProfitShort = sellPoint - (targetPips * 10 * syminfo.mintick)
// If a new day has started and we're flat, place a buy stop & sell stop
var stopLossLongSaved = 0.0
var takeProfitLongSaved = 0.0
var stopLossShortSaved = 0.0
var takeProfitShortSaved = 0.0
newDay = change(time("D"))
if newDay
if strategy.position_size == 0
stopLossLongSaved := stopLossLong
takeProfitLongSaved := takeProfitLong
strategy.entry(id="buy", long=strategy.long, stop=buyPoint, oca_name="x", oca_type=strategy.oca.cancel,comment="buy",alert_message="buy")
stopLossShortSaved := stopLossShort
takeProfitShortSaved := takeProfitShort
strategy.entry(id="sell", long=strategy.short, stop=sellPoint, oca_name="x", oca_type=strategy.oca.cancel,comment="sell",alert_message="sell")
// Exit our trade if our stop loss or take profit is hit
strategy.exit(id="close", from_entry="buy", limit=takeProfitLongSaved, stop=stopLossLongSaved,comment="close",alert_message="close")
strategy.exit(id="close", from_entry="sell", limit=takeProfitShortSaved, stop=stopLossShortSaved,comment="close",alert_message="close")
// Draw data to the chart
plot(dailyHigh, color=color.blue, linewidth=2, title="Daily High")
plot(dailyLow, color=color.blue, linewidth=2, title="Daily Low")
plot(buyPoint, color=color.purple, title="Buy Stop")
plot(stopLossLong, color=color.red, title="Long Stop Loss")
plot(takeProfitLong, color=color.green, title="Long Profit Target")
plot(sellPoint, color=color.purple, title="Sell Stop")
plot(stopLossShort, color=color.red, title="Short Stop Loss")
plot(takeProfitShort, color=color.green, title="Short Profit Target")