This repository has been archived by the owner on Oct 27, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #4 from ppodds/feat/blocks
Add trend indicator blocks
- Loading branch information
Showing
10 changed files
with
227 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
import Blockly from "blockly"; | ||
|
||
Blockly.Blocks["apo"] = { | ||
init: function () { | ||
this.appendDummyInput().appendField("APO"); | ||
this.appendDummyInput() | ||
.appendField("(fast period =") | ||
.appendField(new Blockly.FieldNumber(14, 0), "FAST_PERIOD") | ||
.appendField("days)"); | ||
this.appendDummyInput() | ||
.appendField("(slow period =") | ||
.appendField(new Blockly.FieldNumber(30, 0), "SLOW_PERIOD") | ||
.appendField("days)"); | ||
this.setOutput(true, "Array"); | ||
this.setColour(230); | ||
this.setTooltip(""); | ||
this.setHelpUrl(""); | ||
}, | ||
}; | ||
|
||
Blockly.JavaScript["apo"] = function (block) { | ||
const number_fast_period: number = block.getFieldValue("FAST_PERIOD"); | ||
const number_slow_period: number = block.getFieldValue("SLOW_PERIOD"); | ||
const code = | ||
"indicatorts.absolutePriceOscillator(" + | ||
number_fast_period + | ||
", " + | ||
number_slow_period + | ||
", stock.closings)"; | ||
return [code, Blockly.JavaScript.ORDER_ATOMIC]; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
import Blockly from "blockly"; | ||
|
||
Blockly.Blocks["ema"] = { | ||
init: function () { | ||
this.appendDummyInput().appendField("EMA"); | ||
this.appendDummyInput() | ||
.appendField("(period =") | ||
.appendField(new Blockly.FieldNumber(14, 0), "PERIOD") | ||
.appendField("days)"); | ||
this.setOutput(true, "Array"); | ||
this.setColour(230); | ||
this.setTooltip(""); | ||
this.setHelpUrl(""); | ||
}, | ||
}; | ||
|
||
Blockly.JavaScript["ema"] = function (block) { | ||
const number_period: number = block.getFieldValue("PERIOD"); | ||
const code = "indicatorts.ema(" + number_period + ", stock.closings)"; | ||
return [code, Blockly.JavaScript.ORDER_ATOMIC]; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,16 @@ | ||
export default defineNuxtPlugin((nuxtApp) => { | ||
nuxtApp.hook("app:beforeMount", async () => { | ||
await import("./custom-rsi"); | ||
await import("./rsi"); | ||
await import("./theme/custom-renderer"); | ||
await Promise.all([ | ||
import("./custom-rsi"), | ||
import("./rsi"), | ||
import("./ema"), | ||
import("./apo"), | ||
import("./sma"), | ||
import("./macd"), | ||
import("./psar"), | ||
import("./kdj"), | ||
import("./vwma"), | ||
import("./theme/custom-renderer"), | ||
]); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
import Blockly from "blockly"; | ||
|
||
Blockly.Blocks["kdj"] = { | ||
init: function () { | ||
this.appendDummyInput().appendField("KDJ"); | ||
this.appendDummyInput() | ||
.appendField("(RSI period =") | ||
.appendField(new Blockly.FieldNumber(9, 2), "R_PERIOD") | ||
.appendField("days)"); | ||
this.appendDummyInput() | ||
.appendField("(K period =") | ||
.appendField(new Blockly.FieldNumber(3, 2), "K_PERIOD") | ||
.appendField("days)"); | ||
this.appendDummyInput() | ||
.appendField("(D period =") | ||
.appendField(new Blockly.FieldNumber(3, 2), "D_PERIOD") | ||
.appendField("days)"); | ||
this.appendDummyInput() | ||
.appendField("(") | ||
.appendField( | ||
new Blockly.FieldDropdown([ | ||
["K", "K"], | ||
["D", "D"], | ||
["J", "J"], | ||
]), | ||
"KDJ", | ||
) | ||
.appendField(")"); | ||
this.setOutput(true, "Array"); | ||
this.setColour(230); | ||
this.setTooltip(""); | ||
this.setHelpUrl(""); | ||
}, | ||
}; | ||
|
||
Blockly.JavaScript["kdj"] = function (block) { | ||
const number_r_period: number = block.getFieldValue("R_PERIOD"); | ||
const number_k_period: number = block.getFieldValue("K_PERIOD"); | ||
const number_d_period: number = block.getFieldValue("D_PERIOD"); | ||
const dropdown_kdj: string = block.getFieldValue("KDJ").toLowerCase(); | ||
const code = | ||
"indicatorts.kdj(" + | ||
number_r_period + | ||
", " + | ||
number_k_period + | ||
", " + | ||
number_d_period + | ||
", stock.highs, stock.lows, stock.closings)." + | ||
dropdown_kdj; | ||
return [code, Blockly.JavaScript.ORDER_ATOMIC]; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
import Blockly from "blockly"; | ||
|
||
Blockly.Blocks["macd"] = { | ||
init: function () { | ||
this.appendDummyInput().appendField("MACD"); | ||
this.setOutput(true, "Array"); | ||
this.setColour(230); | ||
this.setTooltip(""); | ||
this.setHelpUrl(""); | ||
}, | ||
}; | ||
|
||
Blockly.JavaScript["macd"] = function (_) { | ||
const code = "indicatorts.macd(stock.closings).macdLine"; | ||
return [code, Blockly.JavaScript.ORDER_ATOMIC]; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
import Blockly from "blockly"; | ||
|
||
Blockly.Blocks["psar"] = { | ||
init: function () { | ||
this.appendDummyInput().appendField("Parabolic SAR"); | ||
this.setOutput(true, "Array"); | ||
this.setColour(230); | ||
this.setTooltip(""); | ||
this.setHelpUrl(""); | ||
}, | ||
}; | ||
|
||
Blockly.JavaScript["psar"] = function (_) { | ||
const code = | ||
"indicatorts.parabolicSar(stock.highs, stock.lows, stock.closings).psar"; | ||
return [code, Blockly.JavaScript.ORDER_ATOMIC]; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
import Blockly from "blockly"; | ||
|
||
Blockly.Blocks["sma"] = { | ||
init: function () { | ||
this.appendDummyInput().appendField("SMA"); | ||
this.appendDummyInput() | ||
.appendField("(period =") | ||
.appendField(new Blockly.FieldNumber(10, 1), "PERIOD") | ||
.appendField("days)"); | ||
this.setOutput(true, "Array"); | ||
this.setColour(230); | ||
this.setTooltip(""); | ||
this.setHelpUrl(""); | ||
}, | ||
}; | ||
|
||
Blockly.JavaScript["sma"] = function (block) { | ||
const number_period: number = block.getFieldValue("PERIOD"); | ||
const code = "indicatorts.sma(" + number_period + ", stock.closings)"; | ||
return [code, Blockly.JavaScript.ORDER_ATOMIC]; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
import Blockly from "blockly"; | ||
|
||
Blockly.Blocks["vwma"] = { | ||
init: function () { | ||
this.appendDummyInput().appendField("VWMA"); | ||
this.appendDummyInput() | ||
.appendField("(period =") | ||
.appendField(new Blockly.FieldNumber(15, 1), "PERIOD") | ||
.appendField("days)"); | ||
this.setOutput(true, "Array"); | ||
this.setColour(230); | ||
this.setTooltip(""); | ||
this.setHelpUrl(""); | ||
}, | ||
}; | ||
|
||
Blockly.JavaScript["vwma"] = function (block) { | ||
const number_period: number = block.getFieldValue("PERIOD"); | ||
const code = | ||
"indicatorts.vwma(" + number_period + ", stock.closings, stock.volumes)"; | ||
return [code, Blockly.JavaScript.ORDER_ATOMIC]; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters