Not logged in.  Login/Logout/Register | List snippets | | Create snippet | Upload image | Upload data

28
LINES

< > BotCompany Repo | #1036303 // G22StrategyRun - one run of a trading strategy

JavaX fragment (include) [tags: use-pretranspiled]

Libraryless. Click here for Pure Java version (29633L/186K).

sclass G22StrategyRun {
  settable G22TradingStrategy strategy;
  settable TickerSequence ticker;
  settable new TickerSequence profitTicker;
  settable double finalProfit;
  settable transient IIteratorMonitor iteratorMonitor = dummyIteratorMonitor();
  
  double totalProfit() { ret finalProfit; }
  
  run {
    strategy(strategy.emptyClone());
    strategy.logToPrint(false);
    strategy.actualTicker(ticker);
    strategy.primed(true);
    strategy.active(true);
    
    temp it = iteratorMonitor.monitorIterator("Backtest", ticker.pricePoints());
    for (pricePoint : it) {
      if (!strategy.active()) break;
      strategy.feed(pricePoint);
      double profit = strategy.coinProfit();
      profitTicker.addIfPriceChanged(profit, pricePoint.timestamp);
    }
    
    strategy.closeMyself();
    finalProfit(strategy.coinProfit());
  }
}

download  show line numbers  debug dex  old transpilations   

Travelled to 3 computer(s): elmgxqgtpvxh, mowyntqkapby, mqqgnosmbjvj

No comments. add comment

Snippet ID: #1036303
Snippet name: G22StrategyRun - one run of a trading strategy
Eternal ID of this version: #1036303/15
Text MD5: 1ff77367a31872fada0e79d778edcda8
Transpilation MD5: 5e44dfd5a0cfe0e85fe1d815c9bbec1c
Author: stefan
Category: javax
Type: JavaX fragment (include)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2023-01-22 16:47:29
Source code size: 877 bytes / 28 lines
Pitched / IR pitched: No / No
Views / Downloads: 94 / 193
Version history: 14 change(s)
Referenced in: [show references]