- ago
Hi,

DataSets have AAPL / GOOGL two stock,

[Suppose] 2021/5/3

How to running backtest to WriteToDebugLog two stock indicators e.g. RSI value / SMA value.

[WriteToDebugLog Example]

2021/5/3 APPL SMA(5) 120
2021/5/3 GOOGL SMA(5) 2300
----------Next bar----------
2021/5/4 APPL SMA(5) 122
2021/5/4 GOOGL SMA(5) 2350

thx
0
609
Solved
4 Replies

Reply

Bookmark

Sort
- ago
#1
CODE:
using WealthLab.Backtest; using System; using WealthLab.Core; using WealthLab.Indicators; using System.Drawing; using System.Collections.Generic; namespace WealthScript1 { public class MyStrategy : UserStrategyBase {       SMA sma;        //create indicators and other objects here, this is executed prior to the main trading loop public override void Initialize(BarHistory bars) {          sma = SMA.Series(bars.Close, 5); } //execute the strategy rules here, this is executed once for each bar in the backtest history public override void Execute(BarHistory bars, int idx) {          WriteToDebugLog(String.Format("{0} {1}: {2}", bars.Symbol, sma.Description, sma[idx]));           if (!HasOpenPosition(bars, PositionType.Long)) { //code your buy conditions here } else { //code your sell conditions here } } //declare private variables below } }
0
- ago
#2
I mean

Datetime : 5/3 . 5/4 . 5/5 . 5/6 . 5/7

CODE:
string[] Stocks= {"APPL", "GOOGL"}; List<string> StockList = new List<string>(Stocks); for (var i = 1; i < Datetime.count; i++) {    WriteToDebugLog("----------New day----------");    WriteToDebugLog(StockList[0], SMA[idx]);    WriteToDebugLog(StockList[1], SMA[idx]); }


Output :
----------New day----------
AAPL SMA120
GOOGL SMA2300
----------New day----------
AAPL SMA121
GOOGL SMA2310
----------New day----------
AAPL SMA122
GOOGL SMA2305
----------New day----------
AAPL SMA123
GOOGL SMA2360
----------New day----------
AAPL SMA124
GOOGL SMA2350

CODE:
public override void Execute(BarHistory bars, int idx) { }


The Execute is stock by stock ... How do date by date

Thx
0
- ago
#3
You can use PreExecute for that
https://www.wealth-lab.com/Support/ApiReference/UserStrategyBase
0
Best Answer
- ago
#4
Ok, I try it.

Thx.
0

Reply

Bookmark

Sort