diff --git a/Projects/Superalgos/Schemas/Docs-Nodes/formula.json b/Projects/Superalgos/Schemas/Docs-Nodes/formula.json
index d85bd591e..af18947b6 100644
--- a/Projects/Superalgos/Schemas/Docs-Nodes/formula.json
+++ b/Projects/Superalgos/Schemas/Docs-Nodes/formula.json
@@ -8,15 +8,151 @@
},
{
"style": "Text",
- "text": "In the context of the trading engine, formulas are used to create user defined statistics."
+ "text": "In the context of a trading system, formulas are used to determine the values for several properties, such as the target rate, target size, managed stop loss, managed take profit, and so on."
},
{
"style": "Text",
- "text": "Formulas may use indicators and object properties made available by the trading engine. They must evaluate to a number."
+ "text": "Formulas may use indicators and trading engine properties. The main difference between writing a formula and writing a condition is that while conditions must evaluate to true or false, formulas must evaluate to a number."
+ },
+ {
+ "style": "Text",
+ "text": "A simple math example:"
+ },
+ {
+ "style": "Text",
+ "text": "This simple formula may be used to define an initial take profit target 3% above the rate at which the position was taken."
+ },
+ {
+ "style": "Text",
+ "text": "tradingEngine.current.position.entryTargetRate.value * 1.03"
},
{
"style": "Note",
- "text": "To learn how to write formulas, see syntax overview."
+ "text": "You may use any variable made available by the trading engine, as explained on the accessing runtime data page."
+ },
+ {
+ "style": "Text",
+ "text": "A simple JavaScript example:"
+ },
+ {
+ "style": "Text",
+ "text": "A bit of very basic JavaScript, introducing conditional statements, allows more intelligence. For example, in this case, we ask if the proposed formula results in a number greater than the current stop loss value; if it does, then the proposed formula is used; if not, then the current stop loss value is left as is."
+ },
+ {
+ "style": "Text",
+ "text": "This is—basically—a trailing stop loss 2% below the moving average that may go higher if the moving average goes up, but it may never come down—thanks to the use of the IF ELSE clause."
+ },
+ {
+ "style": "Text",
+ "text": "if (chart.at01hs.bollingerBand.movingAverage * 0.98 > tradingEngine.current.position.stopLoss.value)"
+ },
+ {
+ "style": "Text",
+ "text": " {chart.at01hs.bollingerBand.movingAverage * 0.98}"
+ },
+ {
+ "style": "Text",
+ "text": " else"
+ },
+ {
+ "style": "Text",
+ "text": " {tradingEngine.current.position.stopLoss.value}"
+ },
+ {
+ "style": "Text",
+ "text": "For developers:"
+ },
+ {
+ "style": "Text",
+ "text": "To build more complex logic within a formula, create a function that implements the logic and returns a numerical value, and then call the function:"
+ },
+ {
+ "style": "Text",
+ "text": "function orderRate() {"
+ },
+ {
+ "style": "Text",
+ "text": " const ORDER_STEP_NUMBER = 1 // Secuential step number, starting with 1 from the closest to the price."
+ },
+ {
+ "style": "Text",
+ "text": " const BUY_SELL_SIGN = -1 // 1 for buy orders, -1 for sell orders."
+ },
+ {
+ "style": "Text",
+ "text": " const STEP_SEPARATION = 0.15 // % of separation of stair steps between them."
+ },
+ {
+ "style": "Text",
+ "text": " const BASE_FACTOR = 0.2 // % above or below bollinger band without bias."
+ },
+ {
+ "style": "Text",
+ "text": " const BIAS_FACTOR = 0.3 // % to move the whole stair of orders up or down depending on the bias."
+ },
+ {
+ "style": "Text",
+ "text": " const BAND_RATE = chart.at01min.bollingerBand.lowerBand // Upper Bollinger Band for sell orders, and Lower for buy orders."
+ },
+ {
+ "style": "Text",
+ "text": " let inbalance = tradingEngine.current.episode.episodeBaseAsset.beginBalance.value - tradingEngine.current.episode.episodeBaseAsset.balance.value"
+ },
+ {
+ "style": "Text",
+ "text": " let BIAS_SIGN"
+ },
+ {
+ "style": "Text",
+ "text": " if (inbalance === 0) {"
+ },
+ {
+ "style": "Text",
+ "text": " BIAS_SIGN = 0"
+ },
+ {
+ "style": "Text",
+ "text": " }"
+ },
+ {
+ "style": "Text",
+ "text": " if (inbalance < 0) {"
+ },
+ {
+ "style": "Text",
+ "text": " BIAS_SIGN = + 1"
+ },
+ {
+ "style": "Text",
+ "text": " }"
+ },
+ {
+ "style": "Text",
+ "text": " if (inbalance > 0) {"
+ },
+ {
+ "style": "Text",
+ "text": " BIAS_SIGN = - 1"
+ },
+ {
+ "style": "Text",
+ "text": " }"
+ },
+ {
+ "style": "Text",
+ "text": " let rate = BAND_RATE + BUY_SELL_SIGN BAND_RATE (BASE_FACTOR + ORDER_STEP_NUMBER STEP_SEPARATION + BIAS_SIGN BIAS_FACTOR) / 100"
+ },
+ {
+ "style": "Text",
+ "text": " return rate"
+ },
+ {
+ "style": "Text",
+ "text": "}"
+ },
+ {
+ "style": "Text",
+ "text": "orderRate()"
},
{
"style": "Title",
@@ -24,7 +160,7 @@
},
{
"style": "Text",
- "text": "To add the formula node, select Add Missing Items on the parent node menu."
+ "text": "To add a formula, select Add Formula on the corresponding parent node menu."
}
]
}
\ No newline at end of file
diff --git a/Projects/Superalgos/Schemas/Docs-Nodes/space-style.json b/Projects/Superalgos/Schemas/Docs-Nodes/space-style.json
index 4ec9a6e12..640200912 100644
--- a/Projects/Superalgos/Schemas/Docs-Nodes/space-style.json
+++ b/Projects/Superalgos/Schemas/Docs-Nodes/space-style.json
@@ -136,63 +136,63 @@
},
{
"style": "Text",
- "text": "| DARK | 48, 48, 54 | |"
+ "text": "| DARK | 48, 48, 54 | RGB(48, 48, 54) |"
},
{
"style": "Text",
- "text": "| LIGHT | 234, 226, 222 | |"
+ "text": "| LIGHT | 234, 226, 222 | RGB(234, 226, 222); border: 1px black |"
},
{
"style": "Text",
- "text": "| GREY | 150, 150, 150 | |"
+ "text": "| GREY | 150, 150, 150 | RGB(150, 150, 150) |"
},
{
"style": "Text",
- "text": "| LIGHT_GREY | 247, 247, 247 | |"
+ "text": "| LIGHT_GREY | 247, 247, 247 | RGB(247, 247, 247) |"
},
{
"style": "Text",
- "text": "| WHITE | 255, 255, 255 | |"
+ "text": "| WHITE | 255, 255, 255 | RGB(255, 255, 255) |"
},
{
"style": "Text",
- "text": "| BLACK | 0, 0, 0 | |"
+ "text": "| BLACK | 0, 0, 0 | RGB(0, 0, 0) |"
},
{
"style": "Text",
- "text": "| GOLDEN_ORANGE | 240, 162, 2 | |"
+ "text": "| GOLDEN_ORANGE | 240, 162, 2 | RGB(240, 162, 2) |"
},
{
"style": "Text",
- "text": "| RUSTED_RED | 204, 88, 53 | |"
+ "text": "| RUSTED_RED | 204, 88, 53 | RGB(204, 88, 53) |"
},
{
"style": "Text",
- "text": "| GREEN | 188, 214, 67 | |"
+ "text": "| GREEN | 188, 214, 67 | RGB(188, 214, 67) |"
},
{
"style": "Text",
- "text": "| RED | 223, 70, 60 | |"
+ "text": "| RED | 223, 70, 60 | RGB(223, 70, 60) |"
},
{
"style": "Text",
- "text": "| PATINATED_TURQUOISE | 27, 153, 139 | |"
+ "text": "| PATINATED_TURQUOISE | 27, 153, 139 | RGB(27, 153, 139) |"
},
{
"style": "Text",
- "text": "| TITANIUM_YELLOW | 244, 228, 9 | |"
+ "text": "| TITANIUM_YELLOW | 244, 228, 9 | RGB(244, 228, 9) |"
},
{
"style": "Text",
- "text": "| MANGANESE_PURPLE | 91,80, 122 | |"
+ "text": "| MANGANESE_PURPLE | 91,80, 122 | RGB(91,80, 122) |"
},
{
"style": "Text",
- "text": "| TURQUOISE | 74, 207, 217 | |"
+ "text": "| TURQUOISE | 74, 207, 217 | RGB(74, 207, 217) |"
},
{
"style": "Text",
- "text": "| DARK_TURQUOISE | 2, 149, 170 | |"
+ "text": "| DARK_TURQUOISE | 2, 149, 170 | RGB(2, 149, 170) |"
},
{
"style": "Text",
diff --git a/Projects/Superalgos/Schemas/Docs-Nodes/style.json b/Projects/Superalgos/Schemas/Docs-Nodes/style.json
index ee3db1d4b..68dc56d0f 100644
--- a/Projects/Superalgos/Schemas/Docs-Nodes/style.json
+++ b/Projects/Superalgos/Schemas/Docs-Nodes/style.json
@@ -156,63 +156,63 @@
},
{
"style": "Text",
- "text": "| DARK | 48, 48, 54 | |"
+ "text": "| DARK | 48, 48, 54 | RGB(48, 48, 54) |"
},
{
"style": "Text",
- "text": "| LIGHT | 234, 226, 222 | |"
+ "text": "| LIGHT | 234, 226, 222 | RGB(234, 226, 222); border: 1px black |"
},
{
"style": "Text",
- "text": "| GREY | 150, 150, 150 | |"
+ "text": "| GREY | 150, 150, 150 | RGB(150, 150, 150) |"
},
{
"style": "Text",
- "text": "| LIGHT_GREY | 247, 247, 247 | |"
+ "text": "| LIGHT_GREY | 247, 247, 247 | RGB(247, 247, 247) |"
},
{
"style": "Text",
- "text": "| WHITE | 255, 255, 255 | |"
+ "text": "| WHITE | 255, 255, 255 | RGB(255, 255, 255) |"
},
{
"style": "Text",
- "text": "| BLACK | 0, 0, 0 | |"
+ "text": "| BLACK | 0, 0, 0 | RGB(0, 0, 0) |"
},
{
"style": "Text",
- "text": "| GOLDEN_ORANGE | 240, 162, 2 | |"
+ "text": "| GOLDEN_ORANGE | 240, 162, 2 | RGB(240, 162, 2) |"
},
{
"style": "Text",
- "text": "| RUSTED_RED | 204, 88, 53 | |"
+ "text": "| RUSTED_RED | 204, 88, 53 | RGB(204, 88, 53) |"
},
{
"style": "Text",
- "text": "| GREEN | 188, 214, 67 | |"
+ "text": "| GREEN | 188, 214, 67 | RGB(188, 214, 67) |"
},
{
"style": "Text",
- "text": "| RED | 223, 70, 60 | |"
+ "text": "| RED | 223, 70, 60 | RGB(223, 70, 60) |"
},
{
"style": "Text",
- "text": "| PATINATED_TURQUOISE | 27, 153, 139 | |"
+ "text": "| PATINATED_TURQUOISE | 27, 153, 139 | RGB(27, 153, 139) |"
},
{
"style": "Text",
- "text": "| TITANIUM_YELLOW | 244, 228, 9 | |"
+ "text": "| TITANIUM_YELLOW | 244, 228, 9 | RGB(244, 228, 9) |"
},
{
"style": "Text",
- "text": "| MANGANESE_PURPLE | 91,80, 122 | |"
+ "text": "| MANGANESE_PURPLE | 91,80, 122 | RGB(91,80, 122) |"
},
{
"style": "Text",
- "text": "| TURQUOISE | 74, 207, 217 | |"
+ "text": "| TURQUOISE | 74, 207, 217 | RGB(74, 207, 217) |"
},
{
"style": "Text",
- "text": "| DARK_TURQUOISE | 2, 149, 170 | |"
+ "text": "| DARK_TURQUOISE | 2, 149, 170 | RGB(2, 149, 170) |"
},
{
"style": "List",
diff --git a/Projects/Superalgos/UI/Spaces/Docs-Space/DocsSpace.js b/Projects/Superalgos/UI/Spaces/Docs-Space/DocsSpace.js
index 7652b399b..c425b4b4e 100644
--- a/Projects/Superalgos/UI/Spaces/Docs-Space/DocsSpace.js
+++ b/Projects/Superalgos/UI/Spaces/Docs-Space/DocsSpace.js
@@ -376,32 +376,16 @@ function newSuperalgosDocSpace() {
return false
}
- if (paragraphNode.id === undefined || paragraphNode.id.indexOf('paragraph') < 0) {
- paragraphNode = paragraphNode.parentNode
- }
- if (paragraphNode.id === undefined || paragraphNode.id.indexOf('paragraph') < 0) {
- paragraphNode = paragraphNode.parentNode
- }
- if (paragraphNode.id === undefined || paragraphNode.id.indexOf('paragraph') < 0) {
- paragraphNode = paragraphNode.parentNode
- }
- if (paragraphNode.id === undefined || paragraphNode.id.indexOf('paragraph') < 0) {
- paragraphNode = paragraphNode.parentNode
- }
- if (paragraphNode.id === undefined || paragraphNode.id.indexOf('paragraph') < 0) {
- paragraphNode = paragraphNode.parentNode
- }
- if (paragraphNode.id === undefined || paragraphNode.id.indexOf('paragraph') < 0) {
- paragraphNode = paragraphNode.parentNode
- }
- if (paragraphNode.id === undefined || paragraphNode.id.indexOf('paragraph') < 0) {
- paragraphNode = paragraphNode.parentNode
+
+ for (let i = 1; i < 10; i++) {
+ if (paragraphNode.id === undefined || paragraphNode.id.indexOf('paragraph') < 0) {
+ paragraphNode = paragraphNode.parentNode
+ if (paragraphNode === undefined) { return false}
+ }
}
if (paragraphNode.id === undefined || paragraphNode.id.indexOf('paragraph') < 0) {
return false
}
-
-
/*
Depending on the Style of Paragraph we will need to remove
some info from the innerText.