Type/to search
0
Follow
0
Followers
Uso de exchange.GetAccount() em backtesting
Help
Created 2021-03-11 18:28:35  
 1
 1274

Eu usei o código a seguir para fazer o retorno.
def CalculateMA(n,record):
sumMA = 0
for i in range(n):
sumMA += record[-(i+1)]["Close"]
return sumMA/n

def SimpleMAStrategy(status):
account = exchange.GetAccount()
ticker = exchange.GetTicker()
record = exchange.GetRecords(RecordsTime)
MAFast = CalculateMA(MAFastN,record)
MASlow = CalculateMA(MASlowN,record)
balance = account["Balance"]
stocks = account["Stocks"]
Log ((("A posição atual é:", account["Stocks"], "O saldo atual é:", account["Balance"])
currSell1Price = ticker["Sell"]
if (MAFast >= MASlow and status == 0):
id = exchange.Buy(-1, balance*rate/ticker["Sell"])
status = 1
if (MAFast <= MASlow and status == 1):
id = exchange.Sell(-1, stocks)
status = 0
return status

status = 0
while(true):
status = SimpleMAStrategy(status)
Sleep(3000)

Descobriu que a retrospectiva sempre retorna o saldo atual: 3.89e-07 O saldo atual é: 19999.166986677. Por favor, pergunte na retrospectiva exchange.GetAccount é sempre retornar apenas a informação definida nos parâmetros de configuração?

Related Recommendations
Comment
All comments (1)

    回测需要把原来添加的删掉,重新添加才会生效

    5 years ago
  • 1
Forums
PINE Language
Get the app
iPhone Download
© 2015 - ∞ INVENTOR PTE LTD (SG)