Alternative Trading Ideas — K-line Area Trading Strategy (2024)

Looking at a not-so-reliable trading idea — the K-line area trading strategy, in this article, we will explore the concept and try to implement the script.

The K-line area strategy is a trading strategy based on the area relationship between price K-lines and moving averages. Its main idea is to predict possible trends in stock prices by analyzing the magnitude and changes of price trends, as well as shifts in buying and selling sentiment, thereby determining when to open positions and exit. This strategy relies on the area between the K-line and moving averages, as well as values from the KDJ indicator, to generate long and short trading signals.

The area of the K-line refers to the spatial area between the price K-line and the moving average, calculated by subtracting the moving average value from each bar’s closing price and then summing it up. When there is a large increase in price over a long period of time, the K-line area will become larger, while during volatile markets or after volatility reversals, the K-line area is smaller. According to the principle of “what goes up must come down”, as an upward trend becomes larger and lasts longer, its corresponding K-line area also increases; thus increasing its probability for reversal — much like a spring that rebounds with greater force when stretched further. Therefore, setting a threshold for this K-line area can indicate when prices may have reached their peak and are likely to reverse.

To further confirm an impending trend reversal, we introduce the use of KDJ indicators which help determine shifts in buying or selling sentiment. The thresholds for the strategy and values for these indicators can be adjusted according to specific circ*mstances and needs in order to enhance accuracy.

The advantage of the K-line area strategy lies in its combination of the magnitude and changes of price trends, as well as the shift in buying and selling sentiment, providing a relatively complete quantitative trading strategy. Its advantages include:

  • It provides a simple and intuitive method to identify the possibility of trend reversal, helping traders better grasp market trends.
  • By combining the K-line area and KDJ indicator, it increases the reliability and accuracy of the strategy.
  • High flexibility allows for parameter adjustments according to market conditions to meet different trading needs.

Although the K-line area strategy has certain advantages, it also carries some risks, including:

  • The setting of thresholds may require some experience and adjustment. If it set improperly, it could lead to misjudgment of market trends.
  • The accuracy of the KDJ indicator is affected by market fluctuations and noise, which may result in false signals.
  • The performance of the strategy may vary under different market conditions and needs constant optimization and adjustment.

To optimize the K-line area strategy, consider the following directions:

  • Parameter optimization: Continuously adjust and optimize threshold values and KDJ indicator parameters to adapt to different market conditions and trading needs.
  • Risk management: Implement effective risk management strategies, including stop-loss and take-profit rules, to reduce loss risks.
  • Multi-strategy combination: Combine the K-line area strategy with other strategies to improve the performance of comprehensive trading strategies.
  • Real-time monitoring and adjustment: Regularly monitor the performance of strategies, adjusting and improving based on actual situations.
  • Calculate K-line Area
  • Long position opening signal:

(1) The “K-line area” of the downward trend reaches the threshold, it can be established beforehand.

(2) KDJ indicator value is greater than 80.

  • Short position opening signal:

(1) The “K-line area” of the upward trend reaches the threshold, it can be established beforehand.

(2) KDJ indicator value is less than 20.

Exit for Long/Short positions: ATR trailing stop loss and take profit.

Code implementation

// Parameter
var maPeriod = 30
var threshold = 50000
var amount = 0.1

// Global variable
let c = KLineChart({})
let openPrice = 0
let tradeState = "NULL" // NULL BUY SELL

function calculateKLineArea(r, ma) {
var lastCrossUpIndex = null
var lastCrossDownIndex = null
for (var i = r.length - 1 ; i >= 0 ; i--) {
if (ma[i] !== null && r[i].Open < ma[i] && r[i].Close > ma[i]) {
lastCrossUpIndex = i
break
} else if (ma[i] !== null && r[i].Open > ma[i] && r[i].Close < ma[i]) {
lastCrossDownIndex = i
break
}

if (i >= 1 && ma[i] !== null && ma[i - 1] !== null && r[i - 1].Close < ma[i - 1] && r[i].Close > ma[i]) {
lastCrossUpIndex = i
break
} else if (i >= 1 && ma[i] !== null && ma[i - 1] !== null && r[i - 1].Close > ma[i - 1] && r[i].Close < ma[i]) {
lastCrossDownIndex = i
break
}
}

var area = 0
if (lastCrossDownIndex !== null) {
for (var i = r.length - 1 ; i >= lastCrossDownIndex ; i--) {
area -= Math.abs(r[i].Close - ma[i])
}
} else if (lastCrossUpIndex !== null) {
for (var i = r.length - 1 ; i >= lastCrossUpIndex ; i--) {
area += Math.abs(r[i].Close - ma[i])
}
}

return [area, lastCrossUpIndex, lastCrossDownIndex]
}

function onTick() {
var r = _C(exchange.GetRecords)
if (r.length < maPeriod) {
LogStatus(_D(), "Insufficient number of K-line")
return
}
var ma = TA.MA(r, maPeriod)
var atr = TA.ATR(r)
var kdj = TA.KDJ(r)
var lineK = kdj[0]
var lineD = kdj[1]
var lineJ = kdj[2]
var areaInfo = calculateKLineArea(r, ma)
var area = _N(areaInfo[0], 0)
var lastCrossUpIndex = areaInfo[1]
var lastCrossDownIndex = areaInfo[2]

r.forEach(function(bar, index) {
c.begin(bar)
c.plotcandle(bar.Open, bar.High, bar.Low, bar.Close, {overlay: true})
let maLine = c.plot(ma[index], "ma", {overlay: true})
let close = c.plot(bar.Close, 'close', {overlay: true})
c.fill(maLine, close, {color: bar.Close > ma[index] ? 'rgba(255, 0, 0, 0.1)' : 'rgba(0, 255, 0, 0.1)'})
if (lastCrossUpIndex !== null) {
c.plotchar(bar.Time, {char: '$:' + area, overlay: true})
} else if (lastCrossDownIndex !== null) {
c.plotchar(bar.Time, {char: '$:' + area, overlay: true})
}
c.plot(lineK[index], "K")
c.plot(lineD[index], "D")
c.plot(lineJ[index], "J")

c.close()
})

if (tradeState == "NULL" && area < -threshold && lineK[lineK.length - 1] > 70) {
// long
let tradeInfo = $.Buy(amount)
if (tradeInfo) {
openPrice = tradeInfo.price
tradeState = "BUY"
}
} else if (tradeState == "NULL" && area > threshold && lineK[lineK.length - 1] < 30) {
// short
let tradeInfo = $.Sell(amount)
if (tradeInfo) {
openPrice = tradeInfo.price
tradeState = "SELL"
}
}

let stopBase = tradeState == "BUY" ? Math.max(openPrice, r[r.length - 2].Close) : Math.min(openPrice, r[r.length - 2].Close)
if (tradeState == "BUY" && r[r.length - 1].Close < stopBase - atr[atr.length - 2]) {
// cover long
let tradeInfo = $.Sell(amount)
if (tradeInfo) {
tradeState = "NULL"
openPrice = 0
}
} else if (tradeState == "SELL" && r[r.length - 1].Close > stopBase + atr[atr.length - 2]) {
// cover short
let tradeInfo = $.Buy(amount)
if (tradeInfo) {
tradeState = "NULL"
openPrice = 0
}
}

LogStatus(_D(), "area:", area, ", lineK[lineK.length - 2]:", lineK[lineK.length - 2])
}

function main() {
if (exchange.GetName().includes("_Futures")) {
throw "not support Futures"
}
while (true) {
onTick()
Sleep(1000)
}
}

The strategy logic is very simple:

  1. First, some global variables and parameters are defined, including:

Strategy parameters

  • maPeriod: The period of moving average.
  • threshold: A threshold used to determine the timing of buying or selling.
  • amount: The quantity for each transaction.

Global variables

  • c: A K-line chart object, used for drawing charts.
  • openPrice: Records the opening price.
  • tradeState: Records the trading status, which can be “NULL” (empty position), “BUY” or “SELL”.

Calculate function

  • calculateKLineArea function: It is used to calculate the area between the price and moving average line on a K-line chart over a certain period of time, and returns the area value, the index of the last upward crossing K-line, and the index of the last downward crossing K-line. These values are used in subsequent decisions to determine when to buy and sell.

Main loop function

onTick function: It is the main strategy execution function, and here are the operations within the function:

  • a. Obtain the latest K-line data and ensure that the number of K-lines is not less than maPeriod, otherwise record status and return.
  • b. Calculate moving average line ma and ATR indicator atr, as well as KDJ indicator.
  • c. Get area information from areaInfo, last cross-over K-line index, and last cross-under K-line index.
  • d. Use K-line chart object c to draw K-lines and indicator lines while filling in different colors based on price’s relationship with moving average line.
  • e. Determine buying or selling timing according to conditions:

If tradeState is “NULL”, and the area is less than -threshold, and the K value of KDJ is greater than 70, execute a buy operation.
If tradeState is “NULL”, and the area is greater than threshold, and the K value of KDJ is less than 30, execute a sell operation.

f. Set stop loss and take profit conditions. If these conditions are met, close positions:

If it’s in buying state, when the price falls below the closing price of last trading day minus previous day’s ATR (Average True Range), close position.
If it’s in selling state, when the price rises above last trading day’s closing price plus previous day’s ATR (Average True Range), close position.

main function: This serves as main execution entry point. It checks if exchange name contains “_Futures”. If so, an exception will be thrown; otherwise it enters into an infinite loop where onTick function gets executed every second.

In a word, this strategy mainly relies on K-line charts and technical indicators for making buying or selling decisions while also employing stop-loss & take-profit strategies to manage risk. Please note that this just serves as an example strategy which needs to be adjusted & optimized according to market situations & specific requirements during actual use.

On FMZ.COM, using JavaScript language didn’t require many lines of code, instead, it implemented this model easily. And with help from KLineChart function graphical representation of K-line chart area was easily achieved, too. The strategy design caters towards cryptocurrency spot markets by utilizing ‘Digital Currency Spot Trading Library’ template for placing orders through encapsulated functions within template, which makes it very simple & easy to understand and use.

Alternative Trading Ideas — K-line Area Trading Strategy (2)
Alternative Trading Ideas — K-line Area Trading Strategy (3)

I selected a backtesting period randomly. Although I didn’t lose money, I didn’t accumulate profits continuously, either, and the drawdown issue is quite significant. There should be other directions and room for optimization for the strategy. Those who are interested can try to upgrade the strategy.

Alternative Trading Ideas — K-line Area Trading Strategy (4)
Alternative Trading Ideas — K-line Area Trading Strategy (5)

Through the strategy, we not only learned a rather unconventional trading idea, but also learned how to plot diagrams; representing the area enclosed by K-line and moving average line; ploting KDJ indicators etc.

The K-line area strategy is a trading strategy based on price trend magnitude and the KDJ indicator. It helps traders predict market trends by analyzing the area between the K-line and moving averages, as well as shifts in buying and selling sentiment. Despite certain risks, this strategy can provide powerful trading tools through continuous optimization and adjustment, helping traders better cope with market fluctuations. Moreover, traders should adjust the parameters and rules of the strategy flexibly according to specific situations and market conditions to achieve better trading performance.

From: https://blog.mathquant.com/2023/11/06/alternative-trading-ideas-k-line-area-trading-strategy.html

Alternative Trading Ideas — K-line Area Trading Strategy (2024)

FAQs

Alternative Trading Ideas — K-line Area Trading Strategy? ›

Main Idea of the K-Line Area Strategy

What is the simplest most profitable trading strategy? ›

One of the simplest and most widely known fundamental strategies is value investing. This strategy involves identifying undervalued assets based on their intrinsic value and holding onto them until the market recognizes their true worth.

Which trading strategy is most successful? ›

Trend trading strategy. This strategy describes when a trader uses technical analysis to define a trend, and only enters trades in the direction of the pre-determined trend. The above is a famous trading motto and one of the most accurate in the markets.

Is there a 100% trading strategy? ›

The short answer will be no. There simply isn't a 100% winning strategy in forex. What works in a specific market at a specific moment may not be replicated or repeated to bring the same results. Trading forex is risky and complicated, and no strategy can guarantee consistent profits.

What is the rich cheap strategy? ›

The rich-cheap strategy is designed so that the likelihood of positive alpha is greater when both traded pair constituents are at or near their 30-day extremes.

Which trading style is most profitable? ›

Day Trading

The defining feature of day trading is that traders do not hold positions overnight; instead, they seek to profit from short-term price movements occurring during the trading session.It can be considered one of the most profitable trading methods available to investors.

Is there a trading system that can win 100% of the trades? ›

There is no such thing as a trading plan that wins 100% of the time. After all, losses are a part of the game. But losses can be psychologically traumatizing, so a trader who has two or three losing trades in a row might decide to skip the next trade.

What is the most consistently profitable option strategy? ›

1. Selling Covered Calls – The Best Options Trading Strategy Overall. The What: Selling a covered call obligates you to sell 100 shares of the stock at the designated strike price on or before the expiration date. For taking on this obligation, you will be paid a premium.

What strategy do most day traders use? ›

7 Common Day Trading Strategies
  1. Technical Analysis. Technical analysis is a type of trading method that uses price patterns to forecast future movement. ...
  2. Swing Trading. ...
  3. Momentum Trading. ...
  4. Scalp Trading. ...
  5. Penny Stocks. ...
  6. Limit and Market Orders. ...
  7. Margin Trading.

What is the 3-5-7 rule in trading? ›

The 3-5-7 rule is a simple approach to managing your trades. Here's how it works: as your trade gains value, you take profits at three different levels—3%, 5%, and 7%. This method helps you lock in profits gradually, instead of waiting and hoping for a bigger win that might never come.

Which type of trading is most profitable for beginners? ›

The defining feature of day trading is that traders do not hold positions overnight; instead, they seek to profit from short-term price movements occurring during the trading session.It can be considered one of the most profitable trading methods available to investors.

What is the simplest day trading strategy? ›

Trend Trading

Trend trading relies on the mantra 'the trend is your friend. ' Trend traders focus on directional price movements and take a position according to the prevailing trend. If you choose this strategy, you'd go long when there's a general upward movement in price, and sell if it's the opposite.

Top Articles
Enduring Word Bible Commentary John 15:1-11 – Prepared to Abide
How to Stop Worrying and End Anxious Thoughts
Genesis Parsippany
Atvs For Sale By Owner Craigslist
THE 10 BEST Women's Retreats in Germany for September 2024
Aiken County government, school officials promote penny tax in North Augusta
Directions To Lubbock
Tabler Oklahoma
biBERK Business Insurance Provides Essential Insights on Liquor Store Risk Management and Insurance Considerations
Aita Autism
Https://Gw.mybeacon.its.state.nc.us/App
The Binding of Isaac
ExploreLearning on LinkedIn: This month&#39;s featured product is our ExploreLearning Gizmos Pen Pack, the…
Kinkos Whittier
Walthampatch
Calmspirits Clapper
Prosser Dam Fish Count
Bj Alex Mangabuddy
Huntersville Town Billboards
Atdhe Net
Boscov's Bus Trips
Melendez Imports Menu
Happy Life 365, Kelly Weekers | 9789021569444 | Boeken | bol
Best Nail Salons Open Near Me
Where to eat: the 50 best restaurants in Freiburg im Breisgau
Air Quality Index Endicott Ny
Ac-15 Gungeon
Talk To Me Showtimes Near Marcus Valley Grand Cinema
Sofia the baddie dog
Jesus Revolution Showtimes Near Regal Stonecrest
Divide Fusion Stretch Hoodie Daunenjacke für Herren | oliv
Truvy Back Office Login
What does wym mean?
Ucm Black Board
P3P Orthrus With Dodge Slash
Wbli Playlist
Clark County Ky Busted Newspaper
PA lawmakers push to restore Medicaid dental benefits for adults
Page 5662 – Christianity Today
Main Street Station Coshocton Menu
Wait List Texas Roadhouse
Casamba Mobile Login
Weather Underground Cedar Rapids
Jamesbonchai
Blackwolf Run Pro Shop
Gw2 Support Specter
Madden 23 Can't Hire Offensive Coordinator
Model Center Jasmin
Powah: Automating the Energizing Orb - EnigmaticaModpacks/Enigmatica6 GitHub Wiki
King Fields Mortuary
Blippi Park Carlsbad
Latest Posts
Article information

Author: Rueben Jacobs

Last Updated:

Views: 5932

Rating: 4.7 / 5 (57 voted)

Reviews: 88% of readers found this page helpful

Author information

Name: Rueben Jacobs

Birthday: 1999-03-14

Address: 951 Caterina Walk, Schambergerside, CA 67667-0896

Phone: +6881806848632

Job: Internal Education Planner

Hobby: Candle making, Cabaret, Poi, Gambling, Rock climbing, Wood carving, Computer programming

Introduction: My name is Rueben Jacobs, I am a cooperative, beautiful, kind, comfortable, glamorous, open, magnificent person who loves writing and wants to share my knowledge and understanding with you.