pauls0101

TradeTrackerv2

Library "TradeTrackerv2"

This library can be used to track (hypothetical) trades on the chart. Enter the Open, SL, and TP prices (or TP in R to have it calculated) and then call Trade.TrackTrade(barIndex). Keep track of your trades in an array and then simply call TradeTracker.UpdateAllTrades(close) to update all trades based on the current close price.

How to use:
1. Import the library, as always. I'm assuming the alias of "Tracker" below.
2. The Type Trade is exported, so generate a Trade object like newTrade = Tracker.Trade.new().
3. Set the values for Open, SL, and TP. TP can be set either by price or by R, which will calculate the R based on the Open->SL range:
newTrade.priceOpen = 1.0
newTrade.priceSl = 0.5
newTrade.priceTp = 2.0

-- or in place of the third line above --
newTrade.rTp = 2
4. On each interval you want to update (whether that's per tick/close or on each bar), call trades.UpdateAllTrades(close). This snippet assumes you have an array named trades (var trades = array.new<Tracker.Trade>()).

In future updates, more customization options will be created. This is the initial prototype.

method MakeTradeLines(t, barIdx)
  Namespace types: Trade
  Parameters:
    t (Trade)
    barIdx (int)

method UpdateLabel(t)
  Namespace types: Trade
  Parameters:
    t (Trade)

method MakeLabel(t, barIdx)
  Namespace types: Trade
  Parameters:
    t (Trade)
    barIdx (int)

method CloseTrade(t)
  Namespace types: Trade
  Parameters:
    t (Trade)

method OpenTrade(t)
  Namespace types: Trade
  Parameters:
    t (Trade)

method OpenCloseTrade(t, _close)
  Namespace types: Trade
  Parameters:
    t (Trade)
    _close (float)

method CalculateProfits(t, _close)
  Calculates profits/losses for the Trade, given _close price
  Namespace types: Trade
  Parameters:
    t (Trade)
    _close (float)

method UpdateTrade(t, _close)
  Namespace types: Trade
  Parameters:
    t (Trade)
    _close (float)

method SetInitialValues(t, barIdx)
  Namespace types: Trade
  Parameters:
    t (Trade)
    barIdx (int)

method UpdateAllTrades(trades, _close)
  Namespace types: Trade
  Parameters:
    trades (Trade)
    _close (float)

method TrackTrade(t, barIdx)
  Namespace types: Trade
  Parameters:
    t (Trade)
    barIdx (int)

Trade
  Fields:
    id (series__integer)
    isOpen (series__bool)
    isClosed (series__bool)
    isBuy (series__bool)
    priceOpen (series__float)
    priceTp (series__float)
    priceSl (series__float)
    rTP (series__float)
    profit (series__float)
    r (series__float)
    resultR (series__float)
    lineOpen (series__line)
    lineTp (series__line)
    lineSl (series__line)
    labelStats (series__label)
파인 라이브러리

트레이딩뷰 정신에 따라 오써는 이 파인 코드를 오픈 소스 라이브러리로 퍼블리쉬하여 당사 커뮤니티의 다른 파인 프로그래머들이 쓸 수 있도록 하였습니다. 오써에게 찬사를! 여러분은 이 라이브러리를 프라이빗 또는 오픈 소스 퍼블리케이션에 쓸 수 있지만 퍼블리케이션에 재사용은 하우스룰을 따릅니다.

면책사항

이 정보와 게시물은 TradingView에서 제공하거나 보증하는 금융, 투자, 거래 또는 기타 유형의 조언이나 권고 사항을 의미하거나 구성하지 않습니다. 자세한 내용은 이용 약관을 참고하세요.

이 라이브러리를 쓰시겠습니까?

텍스트를 클립보드에 카피한 뒤 님의 스크립트에 붙여 넣기.