交易策略工具包

了解如何編寫移動平均策略和KDJ指標,以使用Tradingview中的鬆散腳本分析和預測庫存趨勢和價格模式的變化。

工具包
工具包

Enter your email to unlock the resource.

Join the Algo Trading Club! Sign up to the newsletter and never miss the latest trading news, trading strategy tutorials and special offers! Email

Loading...

Strategy

 

Moving Average Strategy

strategy("Yaonology Moving Average Tutoring", overlay=true, default_qty_type= strategy.percent_of_equity ,default_qty_value=100, currency=currency.USD, initial_capital=10000, commission_type=strategy.commission.percent, commission_value=0)
fst = input(title = “MA_Fast”, defval = 20) slw = input(title = “MA_Slow”, defval = 40) ma_fast = sma(close, fst) ma_slow = sma(close, slw) plot(ma_fast, color = color.blue) plot(ma_slow, color = color.green)   if ma_fast > ma_slow          strategy.entry(id = “ma_long”, long = true)   if ma_slow > ma_fast         strategy.close(id = “ma_long”)
 

KDJ Indicators

// KDJ Indicators
strategy(“Yaonology KDJ Indicators Tutorial”, overlay=false, default_qty_type = strategy.percent_of_equity, default_qty_value = 100, currency = currency.USD, initial_capital = 10000, commission_type = strategy.commission.percent, commission_value = 0) prd = input(9, title=”period”) sgnl = input(3, title=”signal”) v(s,l,m) => v = 0.0 v := (m*s+(l-m)*nz(v[1]))/l c = close h = highest(high, prd) l = lowest(low,prd) RSV = 100*((c-l)/(h-l)) K = v(RSV, sgnl, 1) D = v(K, sgnl, 1) J = 3 * K-2 * D plot(K, color = color.green) plot(D, color = color.red) plot(J, color = color.black) if (K < 20 and D < 20 and J < 20 and K > D and K[1] < D[1]) or (J > 0 and J[1] < 0)           strategy.entry(id = “kd”, long = true) if (K > 80 and D > 80 and J > 80 and K < D and K[1] > D[1]) or (J < 100 and J[1] > 100)            strategy.close(id = “kd”)  
 

Basic Concept

 

Strategy

The function sets a number of strategy properties
Example strategy(“Yaonology Moving Average Tutoring”, overlay=true, default_qty_type= strategy.percent_of_equity, default_qty_value = 100, currency = currency.USD, initial_capital = 10000, commission_type = strategy.commission.percent, commission_value = 0)
Details overlay:
  • true: the plot would be added as an overlay for the main series
  • false: the plot would be added on a separate chart pane.
  • default_qty_type
  • strategy.fixed: fixed quantity by default
  • strategy.cash: specified in the currency of the symbol and the amount is converted into quantity
  • strategy.percent_of_equity: % of currently available equity
  • default_qty_value
  • Number of contracts if strategy.fixed is used
  • Amount of cash in currency if strategy.cash is used
  • Number of percents of currency if strategy.percent_of_equity is used
  • currency
  • USD, EUR, AUD, GBP, CAD, HKD, JPY
  • Initial_capital
  • the amount of initial capital
  • commission_type
  • strategy.commission.percent: a percentage of the cash volume of order
  • strategy.commission.cash_per_contract: money displayed per contract
  • strategy.commission.cash_per_order: money displayed per order
  • commission_order
  • Number of Percentage or money, depending on the commision_type selected
 

Input

 
User can see and edit inputs on the Format Object dialog of the script study
Example fst = input(title = “MA_Fast”, defval = “20”)
Details title title of the input defval default value of the input valuable
 

SMA

 
The sma function returns the moving average
Example ma_fast = sma(close, fst)
Details source(series) close : close price open: open price high: highest price lowe: lowest price length(integer) Number of bars
 

Plot

 
Plots a series of data on the chart
Example plot(ma_fast, color = color.blue)
Details source(series) Series of data to be plotted color color of the plot. color = color.red color = #ff001a color = close >= open ? color.green : color.red
 

Strategy.Entry

It is a command to enter market position
Example strategy.entry(id = “ma_long”, long = true)
Details id A required parameter. The order identifier. long true: the strategy.entry for long false: the strategy.entry for short
 

Strategy.Close

 
It is a command to exit from the entry with the specified ID.
Example strategy.close(id = “ma_long”)
Details id A required parameter. The order identifier.

This website uses cookies to ensure you get the best experience on our website.

Read Privacy Policy