The resource loading... loading...

Python's chase and kill strategy

Author: Inventors quantify - small dreams, Created: 2020-01-11 14:49:08, Updated: 2023-10-17 21:28:09

img

Python's chase and kill strategy

Trend strategies generally use a variety of indicators to judge the direction of the market, using the results of the numerical contrast of each indicator as trading signals. This avoids the use of parameters, calculating indicators. Since parameters are used, there will be a fit. The strategy performs very well in some markets, but if the market trend is very unfriendly to the current parameters, it may perform very poorly.

This is the code of the strategy:

import time

basePrice = -1
ratio = 0.05
acc = _C(exchange.GetAccount)
lastCancelAll = 0
minStocks = 0.01

def CancelAll():
    while True : 
        orders = _C(exchange.GetOrders)
        for i in range(len(orders)) :
            exchange.CancelOrder(orders[i]["Id"], orders[i])
        if len(orders) == 0 :
            break
        Sleep(1000)

def main():
    global basePrice, acc, lastCancelAll
    exchange.SetPrecision(2, 3)
    while True:
        ticker = _C(exchange.GetTicker)
        if basePrice == -1 :
            basePrice = ticker.Last
        if ticker.Last - basePrice > 0 and (ticker.Last - basePrice) / basePrice > ratio :
            acc = _C(exchange.GetAccount)
            if acc.Balance * ratio / ticker.Last > minStocks :
                exchange.Buy(ticker.Last, acc.Balance * ratio / ticker.Last)
                basePrice = ticker.Last
        if ticker.Last - basePrice < 0 and (basePrice - ticker.Last) / basePrice > ratio : 
            acc = _C(exchange.GetAccount)
            if acc.Stocks * ratio > minStocks :
                exchange.Sell(ticker.Last, acc.Stocks * ratio)
                basePrice = ticker.Last
        ts = time.time()
        if ts - lastCancelAll > 60 * 5 :
            CancelAll()
            lastCancelAll = ts 
        LogStatus(_D(), "\n", "行情信息:", ticker, "\n", "账户信息:", acc)
        Sleep(500)

Strategy is simple analysis

The strategy is very simple, it doesn't use any indicators, it just uses the current price as the basis for triggering the trade, and the main parameter is only one.ratioControl the opening trigger.

Do more triggers:

if ticker.Last - basePrice > 0 and (ticker.Last - basePrice) / basePrice > ratio

Using the current price, contrast the base price, when the current price is greater than the base price and the price is aboveratio * 100 %When you click on the link, you can click on more links. After placing the order, the basic price is updated to the current price.

The blank card triggered:

if ticker.Last - basePrice < 0 and (basePrice - ticker.Last) / basePrice > ratio

The same principle applies when the current price is lower than the base price and the price is higher than the base price.ratio * 100 %When you click on the button, you can see the empty list. After placing the order, the basic price is updated to the current price.

The amount of money available for each orderratio * 100 %I'm not sure. Unless the next order calculated is less than the minimum transaction volume set by the parameterminStocksI'm not sure if I'll be able to make it or not.

This allows the strategy to follow price changes and chase them downwards.

Re-tested

The review period is about one year.img

The results:img

img

Recent users have said that there are fewer Python strategies, and they have since shared more of the strategies written in Python. The strategy code is also very simple, very suitable for inventors to quantify beginner learning. The policy address:https://www.fmz.com/strategy/181185

The strategy is for reference learning only, retesting tests, and interest in optimizing upgrades.


Related

More