1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42
| // This Pine Script® code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
//@version=6 strategy("我的策略", overlay=true, fill_orders_on_standard_ohlc = true)
longCondition = ta.crossover(ta.sma(close, 14), ta.sma(close, 28)) if (longCondition) strategy.entry("My Long Entry Id", strategy.long)
shortCondition = ta.crossunder(ta.sma(close, 14), ta.sma(close, 28)) if (shortCondition) strategy.entry("My Short Entry Id", strategy.short)
f_tradeAnalysis(_tradeNum, _closedTrades = true, _lblSze = size.normal) => if barstate.islastconfirmedhistory or barstate.isrealtime
_entryPrice = _closedTrades ? strategy.closedtrades.entry_price(_tradeNum) : strategy.opentrades.entry_price(_tradeNum) _entryBarindex = _closedTrades ? strategy.closedtrades.entry_bar_index(_tradeNum) : strategy.opentrades.entry_bar_index(_tradeNum) _entryTime = _closedTrades ? strategy.closedtrades.entry_time(_tradeNum) : strategy.opentrades.entry_time(_tradeNum) _positionSize = _closedTrades ? strategy.closedtrades.size(_tradeNum) : strategy.opentrades.size(_tradeNum) _profit = _closedTrades ? strategy.closedtrades.profit(_tradeNum) : strategy.opentrades.profit(_tradeNum) _maxRunUp = _closedTrades ? strategy.closedtrades.max_runup(_tradeNum) : strategy.opentrades.max_runup(_tradeNum) _maxDrawdown = _closedTrades ? strategy.closedtrades.max_drawdown(_tradeNum) : strategy.opentrades.max_drawdown(_tradeNum) _exitPrice = _closedTrades ? strategy.closedtrades.exit_price(_tradeNum) : na _exitBarindex = _closedTrades ? strategy.closedtrades.exit_bar_index(_tradeNum) : na _exitTime = _closedTrades ? strategy.closedtrades.exit_time(_tradeNum) : na
_entryText = "Entry # {0} @ {1}\n{2} {3} {4}" _entryText := str.format(_entryText, _tradeNum, _entryPrice, _positionSize > 0 ? "Long" : "Short", _positionSize, syminfo.basecurrency) _l_entry = label.new(_entryTime, _entryPrice, _entryText, xloc.bar_time, color = color.black, textcolor = color.white, style = _positionSize > 0 ? label.style_label_upper_right : label.style_label_upper_right, size = _lblSze, textalign = text.align_right)
_exitText = "Exit # {0} @ {1}\nProfit:{2, number, #.#########}\nMax Run Up: {3}\n Max Drawdown: -{4}" _exitText := str.format(_exitText, _tradeNum, _entryPrice, strategy.convert_to_account(_profit), _maxRunUp, _maxDrawdown) _l_exit = label.new(_exitTime, _exitPrice, _exitText, xloc.bar_time, color = _profit > 0 ? color.green : color.red, textcolor = color.black, style = _positionSize > 0 ? label.style_label_upper_left : label.style_label_upper_left, size = _lblSze, textalign = text.align_left)
i_tradeNum = input.int(1, "Trade #", minval =1 ) -1 i_openTrades = not input.bool(false, "Show Open Trades")
f_tradeAnalysis(i_tradeNum, _lblSze = size.large)
|