Init
What is it?
Syntax
public Init(): void {
// initialization logic here
}What Happens in Init
InitExample
Why It Matters
Pro Tip
Last updated
public Init(): void {
// initialization logic here
}InitLast updated
export default class MACrossoverStrategy extends StrategyImplementation {
public LotSize!: TOptValue_number;
public MAFastPeriod!: TOptValue_number;
public MASlowPeriod!: TOptValue_number;
public MAMethod!: TOptValue_number;
public MagicNumber!: TOptValue_number;
private lastBarTime!: FTODate;
public Init() {
// strategy info
this.api.setStrategyShortName("MA Crossover Strategy");
this.api.setStrategyDescription(
"A strategy that opens and closes positions based on the crossover of two moving averages."
);
// initialize and register options
this.LotSize = this.api.createTOptValue_number(0.1);
this.MAFastPeriod = this.api.createTOptValue_number(14);
this.MASlowPeriod = this.api.createTOptValue_number(50);
this.MAMethod = this.api.createTOptValue_number(0);
this.MagicNumber = this.api.createTOptValue_number(123456);
// register options
this.api.RegOption("Lot size", TOptionType.DOUBLE, this.LotSize);
this.api.RegOption(
"Fast MA Period",
TOptionType.INTEGER,
this.MAFastPeriod
);
this.api.RegOption(
"Slow MA Period",
TOptionType.INTEGER,
this.MASlowPeriod
);
this.api.RegMATypeOption(this.MAMethod, "MA Method");
this.api.RegOption("Magic Number", TOptionType.INTEGER, this.MagicNumber);
// initialize global variables
this.lastBarTime = this.api.createFTODate(0);
}