From f2cb8bde476f08b3206ff89e650ef0c3d75a0891 Mon Sep 17 00:00:00 2001 From: LucF <50338286+LucFF@users.noreply.github.com> Date: Wed, 31 Jul 2019 07:32:42 -0400 Subject: [PATCH 01/34] Update README.md --- guides/faq_and_code/README.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/guides/faq_and_code/README.md b/guides/faq_and_code/README.md index c77513a..0e8d7c8 100644 --- a/guides/faq_and_code/README.md +++ b/guides/faq_and_code/README.md @@ -23,13 +23,13 @@ greenCandle = close>open triggerCondition = close>close[1] alertcondition(triggerCondition, title="Create Alert dialog box name", message="Text sent with alert.") ``` -When you need to create multiple alerts you can repeat the method above for every alert you want your indicator to generate, but you can also use the method shown in [this indicator](https://www.tradingview.com/script/8AUuFonD-5-MAs-w-alerts-LucF/). Here, all the different alert conditions are bunched up in one `alertcondition()` statement. In this case, you must provide the means for users to first select which conditions will trigger the alert in the *Inputs* dialog box. When all the required conditions are selected, the user creates an alert using the only alert this indicator makes available, but since TradingView remembers the state of the *Inputs* when creating an alert, only the selected conditions will trigger the alert once it’s created, even if Inputs selections are modified by the user after the alert is created. +When you need to create multiple alerts you can repeat the method above for every alert you want your indicator to generate, but you can also use the method shown in [this indicator](https://www.tradingview.com/script/8AUuFonD-5-MAs-w-alerts-LucF/). Here, all the different alert conditions are bunched up in one `alertcondition()` statement. In this case, you must provide the means for users to first select which conditions will trigger the alert in the *Inputs* dialog box. When all the required conditions are selected, the user creates an alert using the only alert this indicator makes available, but since TradingView remembers the state of the *Inputs* when creating an alert, only the selected conditions will trigger the alert once it’s created, even if *Inputs* selections are modified by the user after the alert is created. When more than one condition can trigger a single alert, you will most probably need to have visual cues for each condition so that when users bring up a chart on which an alert triggered they can figure out which condition caused the alert to trigger. This is a method that allows users of your script to customize the alert to their needs. When TradingView creates an alert, it saves a snapshot of the environment that will enable the alert to run on the servers. The important elements saved with an alert are: - Current symbol, - Current time frame (interval), -- State of the scipt's Inputs selections, +- State of the script's *Inputs* selections, - Current version of the script. Subsequent updates to the script’s code will not affect the alerts created with prior versions. -Also note that alerts are not available from within strategies. +**Also note that alerts are not available from within strategies.** From bf69d8f837cc7dfa325a61b3f39fe81f8c95b898 Mon Sep 17 00:00:00 2001 From: LucF <50338286+LucFF@users.noreply.github.com> Date: Wed, 31 Jul 2019 07:34:07 -0400 Subject: [PATCH 02/34] Update README.md --- guides/faq_and_code/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/guides/faq_and_code/README.md b/guides/faq_and_code/README.md index 0e8d7c8..ce707c5 100644 --- a/guides/faq_and_code/README.md +++ b/guides/faq_and_code/README.md @@ -29,7 +29,7 @@ When more than one condition can trigger a single alert, you will most probably When TradingView creates an alert, it saves a snapshot of the environment that will enable the alert to run on the servers. The important elements saved with an alert are: - Current symbol, -- Current time frame (interval), +- Current time frame (interval) , - State of the script's *Inputs* selections, - Current version of the script. Subsequent updates to the script’s code will not affect the alerts created with prior versions. **Also note that alerts are not available from within strategies.** From 56d15919626631fda012ae2ef52afcb4a924baa4 Mon Sep 17 00:00:00 2001 From: LucF <50338286+LucFF@users.noreply.github.com> Date: Wed, 31 Jul 2019 07:34:19 -0400 Subject: [PATCH 03/34] Update README.md --- guides/faq_and_code/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/guides/faq_and_code/README.md b/guides/faq_and_code/README.md index ce707c5..0e8d7c8 100644 --- a/guides/faq_and_code/README.md +++ b/guides/faq_and_code/README.md @@ -29,7 +29,7 @@ When more than one condition can trigger a single alert, you will most probably When TradingView creates an alert, it saves a snapshot of the environment that will enable the alert to run on the servers. The important elements saved with an alert are: - Current symbol, -- Current time frame (interval) , +- Current time frame (interval), - State of the script's *Inputs* selections, - Current version of the script. Subsequent updates to the script’s code will not affect the alerts created with prior versions. **Also note that alerts are not available from within strategies.** From b6a33287a07600cff2d63613d3421a9073843f05 Mon Sep 17 00:00:00 2001 From: LucF <50338286+LucFF@users.noreply.github.com> Date: Wed, 31 Jul 2019 07:37:33 -0400 Subject: [PATCH 04/34] Update README.md --- guides/faq_and_code/README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/guides/faq_and_code/README.md b/guides/faq_and_code/README.md index 0e8d7c8..6801dd1 100644 --- a/guides/faq_and_code/README.md +++ b/guides/faq_and_code/README.md @@ -19,6 +19,7 @@ greenCandle = close>open ``` ## How do I make an alert available from my indicator? +See the User Manual page on [`alertcondition()`](https://www.tradingview.com/pine-script-docs/en/v4/annotations/Alert_conditions.html) ``` triggerCondition = close>close[1] alertcondition(triggerCondition, title="Create Alert dialog box name", message="Text sent with alert.") @@ -29,7 +30,7 @@ When more than one condition can trigger a single alert, you will most probably When TradingView creates an alert, it saves a snapshot of the environment that will enable the alert to run on the servers. The important elements saved with an alert are: - Current symbol, -- Current time frame (interval), +- Current time frame, - State of the script's *Inputs* selections, - Current version of the script. Subsequent updates to the script’s code will not affect the alerts created with prior versions. **Also note that alerts are not available from within strategies.** From 8b84b4d4b11c305fef6609c4b15e59afa41e4350 Mon Sep 17 00:00:00 2001 From: LucF <50338286+LucFF@users.noreply.github.com> Date: Wed, 31 Jul 2019 07:38:19 -0400 Subject: [PATCH 05/34] Update README.md --- guides/faq_and_code/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/guides/faq_and_code/README.md b/guides/faq_and_code/README.md index 6801dd1..df15277 100644 --- a/guides/faq_and_code/README.md +++ b/guides/faq_and_code/README.md @@ -19,7 +19,7 @@ greenCandle = close>open ``` ## How do I make an alert available from my indicator? -See the User Manual page on [`alertcondition()`](https://www.tradingview.com/pine-script-docs/en/v4/annotations/Alert_conditions.html) +See the User Manual page on [`alertcondition()`](https://www.tradingview.com/pine-script-docs/en/v4/annotations/Alert_conditions.html). Code to create an alert condition looks like: ``` triggerCondition = close>close[1] alertcondition(triggerCondition, title="Create Alert dialog box name", message="Text sent with alert.") From 727f955bcccf7b59862fb2c12d00abeac7ff60d8 Mon Sep 17 00:00:00 2001 From: LucF <50338286+LucFF@users.noreply.github.com> Date: Wed, 31 Jul 2019 07:40:27 -0400 Subject: [PATCH 06/34] Update README.md --- guides/faq_and_code/README.md | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/guides/faq_and_code/README.md b/guides/faq_and_code/README.md index df15277..525bf85 100644 --- a/guides/faq_and_code/README.md +++ b/guides/faq_and_code/README.md @@ -28,9 +28,10 @@ When you need to create multiple alerts you can repeat the method above for ever When more than one condition can trigger a single alert, you will most probably need to have visual cues for each condition so that when users bring up a chart on which an alert triggered they can figure out which condition caused the alert to trigger. This is a method that allows users of your script to customize the alert to their needs. -When TradingView creates an alert, it saves a snapshot of the environment that will enable the alert to run on the servers. The important elements saved with an alert are: +When TradingView creates an alert, it saves a snapshot of the environment that will enable the alert to run on the servers. The elements saved with an alert are: - Current symbol, - Current time frame, - State of the script's *Inputs* selections, - Current version of the script. Subsequent updates to the script’s code will not affect the alerts created with prior versions. -**Also note that alerts are not available from within strategies.** + +**Note that while alert condition code will compile in strategy code, they are only functional in studies.** From c43798eaac489b04c70f8f8c718b853f0ee4d094 Mon Sep 17 00:00:00 2001 From: LucF <50338286+LucFF@users.noreply.github.com> Date: Wed, 31 Jul 2019 07:40:45 -0400 Subject: [PATCH 07/34] Update README.md --- guides/faq_and_code/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/guides/faq_and_code/README.md b/guides/faq_and_code/README.md index 525bf85..45790b3 100644 --- a/guides/faq_and_code/README.md +++ b/guides/faq_and_code/README.md @@ -34,4 +34,4 @@ When TradingView creates an alert, it saves a snapshot of the environment that w - State of the script's *Inputs* selections, - Current version of the script. Subsequent updates to the script’s code will not affect the alerts created with prior versions. -**Note that while alert condition code will compile in strategy code, they are only functional in studies.** +**Note that while alert condition code will compile in strategy scripts, they are only functional in studies.** From 7df0e236ac79991def3b6b3ec684d0844bb3041f Mon Sep 17 00:00:00 2001 From: LucF <50338286+LucFF@users.noreply.github.com> Date: Thu, 1 Aug 2019 05:18:36 -0400 Subject: [PATCH 08/34] Update README.md --- guides/faq_and_code/README.md | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/guides/faq_and_code/README.md b/guides/faq_and_code/README.md index 45790b3..3d211cb 100644 --- a/guides/faq_and_code/README.md +++ b/guides/faq_and_code/README.md @@ -8,17 +8,22 @@ This is a compendium of frequently asked questions on Pine. Answers are short an ### Table of Contents -1. [AA](#script-structure) - -## What is the variable name for the current price? +1. [Built-in variables](#built-in-variables) +1. [Indicators (a.k.a. studies)](#indicators) +1. [Strategies](#strategies) +1. [Alerts](#alerts) + +## 1. Built-in variables +### What is the variable name for the current price? + 1. What is the variable name for the current price? The `close` variable holds both the price at the close of historical bars and the current price when code is running on the realtime bar. -## What’s the code for a green candle? +### What’s the code for a green candle? ``` greenCandle = close>open ``` -## How do I make an alert available from my indicator? +### How do I make an alert available from my indicator? See the User Manual page on [`alertcondition()`](https://www.tradingview.com/pine-script-docs/en/v4/annotations/Alert_conditions.html). Code to create an alert condition looks like: ``` triggerCondition = close>close[1] From 33503537d050a1e6914daafec7441ea16b56cfdd Mon Sep 17 00:00:00 2001 From: LucF <50338286+LucFF@users.noreply.github.com> Date: Thu, 1 Aug 2019 05:20:37 -0400 Subject: [PATCH 09/34] Update README.md --- guides/faq_and_code/README.md | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/guides/faq_and_code/README.md b/guides/faq_and_code/README.md index 3d211cb..50534c3 100644 --- a/guides/faq_and_code/README.md +++ b/guides/faq_and_code/README.md @@ -13,16 +13,17 @@ This is a compendium of frequently asked questions on Pine. Answers are short an 1. [Strategies](#strategies) 1. [Alerts](#alerts) -## 1. Built-in variables -### What is the variable name for the current price? +1. Built-in variables 1. What is the variable name for the current price? The `close` variable holds both the price at the close of historical bars and the current price when code is running on the realtime bar. -### What’s the code for a green candle? + 1. What’s the code for a green candle? ``` greenCandle = close>open ``` +## 1. Indicators + ### How do I make an alert available from my indicator? See the User Manual page on [`alertcondition()`](https://www.tradingview.com/pine-script-docs/en/v4/annotations/Alert_conditions.html). Code to create an alert condition looks like: ``` From 7e082c7b82ff11ac375c902a1e548a75578b72a3 Mon Sep 17 00:00:00 2001 From: LucF <50338286+LucFF@users.noreply.github.com> Date: Thu, 1 Aug 2019 05:22:53 -0400 Subject: [PATCH 10/34] Update README.md --- guides/faq_and_code/README.md | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/guides/faq_and_code/README.md b/guides/faq_and_code/README.md index 50534c3..6110955 100644 --- a/guides/faq_and_code/README.md +++ b/guides/faq_and_code/README.md @@ -9,21 +9,22 @@ This is a compendium of frequently asked questions on Pine. Answers are short an ### Table of Contents 1. [Built-in variables](#built-in-variables) -1. [Indicators (a.k.a. studies)](#indicators) -1. [Strategies](#strategies) -1. [Alerts](#alerts) +2. [Indicators (a.k.a. studies)](#indicators) +3. [Strategies](#strategies) +4. [Alerts](#alerts) -1. Built-in variables - 1. What is the variable name for the current price? +## 1. Built-in variables +### What is the variable name for the current price? The `close` variable holds both the price at the close of historical bars and the current price when code is running on the realtime bar. - 1. What’s the code for a green candle? +### What’s the code for a green candle? ``` greenCandle = close>open ``` -## 1. Indicators +## 2. Indicators +## 4 Alerts ### How do I make an alert available from my indicator? See the User Manual page on [`alertcondition()`](https://www.tradingview.com/pine-script-docs/en/v4/annotations/Alert_conditions.html). Code to create an alert condition looks like: ``` From da055d8a98694deae6bc78e02947c79caf2e1e29 Mon Sep 17 00:00:00 2001 From: LucF <50338286+LucFF@users.noreply.github.com> Date: Thu, 1 Aug 2019 05:23:25 -0400 Subject: [PATCH 11/34] Update README.md --- guides/faq_and_code/README.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/guides/faq_and_code/README.md b/guides/faq_and_code/README.md index 6110955..6696ac6 100644 --- a/guides/faq_and_code/README.md +++ b/guides/faq_and_code/README.md @@ -14,10 +14,10 @@ This is a compendium of frequently asked questions on Pine. Answers are short an 4. [Alerts](#alerts) ## 1. Built-in variables -### What is the variable name for the current price? +#### What is the variable name for the current price? The `close` variable holds both the price at the close of historical bars and the current price when code is running on the realtime bar. -### What’s the code for a green candle? +#### What’s the code for a green candle? ``` greenCandle = close>open ``` @@ -25,7 +25,7 @@ greenCandle = close>open ## 2. Indicators ## 4 Alerts -### How do I make an alert available from my indicator? +#### How do I make an alert available from my indicator? See the User Manual page on [`alertcondition()`](https://www.tradingview.com/pine-script-docs/en/v4/annotations/Alert_conditions.html). Code to create an alert condition looks like: ``` triggerCondition = close>close[1] From 75344f11947d44a2527da82357b4a7335bb169a8 Mon Sep 17 00:00:00 2001 From: LucF <50338286+LucFF@users.noreply.github.com> Date: Thu, 1 Aug 2019 05:24:58 -0400 Subject: [PATCH 12/34] Update README.md --- guides/faq_and_code/README.md | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/guides/faq_and_code/README.md b/guides/faq_and_code/README.md index 6696ac6..2086179 100644 --- a/guides/faq_and_code/README.md +++ b/guides/faq_and_code/README.md @@ -9,23 +9,25 @@ This is a compendium of frequently asked questions on Pine. Answers are short an ### Table of Contents 1. [Built-in variables](#built-in-variables) -2. [Indicators (a.k.a. studies)](#indicators) -3. [Strategies](#strategies) -4. [Alerts](#alerts) +1. [Indicators (a.k.a. studies)](#indicators) +1. [Strategies](#strategies) +1. [Alerts](#alerts) ## 1. Built-in variables -#### What is the variable name for the current price? +### What is the variable name for the current price? The `close` variable holds both the price at the close of historical bars and the current price when code is running on the realtime bar. -#### What’s the code for a green candle? +### What’s the code for a green candle? ``` greenCandle = close>open ``` ## 2. Indicators -## 4 Alerts -#### How do I make an alert available from my indicator? +## 3. Strategies + +## 4. Alerts +### How do I make an alert available from my indicator? See the User Manual page on [`alertcondition()`](https://www.tradingview.com/pine-script-docs/en/v4/annotations/Alert_conditions.html). Code to create an alert condition looks like: ``` triggerCondition = close>close[1] From c8f53876ddd77e851d9a35f35576420259014a96 Mon Sep 17 00:00:00 2001 From: LucF <50338286+LucFF@users.noreply.github.com> Date: Thu, 1 Aug 2019 05:26:05 -0400 Subject: [PATCH 13/34] Update README.md --- guides/faq_and_code/README.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/guides/faq_and_code/README.md b/guides/faq_and_code/README.md index 2086179..cdeccc1 100644 --- a/guides/faq_and_code/README.md +++ b/guides/faq_and_code/README.md @@ -19,7 +19,7 @@ The `close` variable holds both the price at the close of historical bars and th ### What’s the code for a green candle? ``` -greenCandle = close>open +greenCandle = close > open ``` ## 2. Indicators @@ -30,8 +30,8 @@ greenCandle = close>open ### How do I make an alert available from my indicator? See the User Manual page on [`alertcondition()`](https://www.tradingview.com/pine-script-docs/en/v4/annotations/Alert_conditions.html). Code to create an alert condition looks like: ``` -triggerCondition = close>close[1] -alertcondition(triggerCondition, title="Create Alert dialog box name", message="Text sent with alert.") +triggerCondition = close > close[1] +alertcondition(triggerCondition, title = "Create Alert dialog box name", message = "Text sent with alert.") ``` When you need to create multiple alerts you can repeat the method above for every alert you want your indicator to generate, but you can also use the method shown in [this indicator](https://www.tradingview.com/script/8AUuFonD-5-MAs-w-alerts-LucF/). Here, all the different alert conditions are bunched up in one `alertcondition()` statement. In this case, you must provide the means for users to first select which conditions will trigger the alert in the *Inputs* dialog box. When all the required conditions are selected, the user creates an alert using the only alert this indicator makes available, but since TradingView remembers the state of the *Inputs* when creating an alert, only the selected conditions will trigger the alert once it’s created, even if *Inputs* selections are modified by the user after the alert is created. From 56c15ae8385410faabe82776505fbbf178987045 Mon Sep 17 00:00:00 2001 From: LucF <50338286+LucFF@users.noreply.github.com> Date: Thu, 1 Aug 2019 05:30:18 -0400 Subject: [PATCH 14/34] Update README.md --- guides/faq_and_code/README.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/guides/faq_and_code/README.md b/guides/faq_and_code/README.md index cdeccc1..2b9ce75 100644 --- a/guides/faq_and_code/README.md +++ b/guides/faq_and_code/README.md @@ -28,6 +28,10 @@ greenCandle = close > open ## 4. Alerts ### How do I make an alert available from my indicator? +Two steps are required: +1. Insert an `alertcondition()` call in an indicator script. +2. Create an alert from the TV Web user interface (ALT-A) and choose the script's alert condition. + See the User Manual page on [`alertcondition()`](https://www.tradingview.com/pine-script-docs/en/v4/annotations/Alert_conditions.html). Code to create an alert condition looks like: ``` triggerCondition = close > close[1] From 78f0330df373c470892c119db73239d2518ee7d7 Mon Sep 17 00:00:00 2001 From: LucF <50338286+LucFF@users.noreply.github.com> Date: Thu, 1 Aug 2019 07:16:27 -0400 Subject: [PATCH 15/34] Update README.md --- guides/faq_and_code/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/guides/faq_and_code/README.md b/guides/faq_and_code/README.md index 2b9ce75..f8fec96 100644 --- a/guides/faq_and_code/README.md +++ b/guides/faq_and_code/README.md @@ -4,7 +4,7 @@ ## Introduction -This is a compendium of frequently asked questions on Pine. Answers are short and often come with examples of code or links where more information can be found. +This is a compendium of frequently asked questions on Pine. Answers are short and often come with examples of code or links where relevant information can be found. ### Table of Contents From f85ad139f09bf4569d35fb120ef39839615b399c Mon Sep 17 00:00:00 2001 From: LucF <50338286+LucFF@users.noreply.github.com> Date: Thu, 1 Aug 2019 07:16:44 -0400 Subject: [PATCH 16/34] Update README.md --- guides/faq_and_code/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/guides/faq_and_code/README.md b/guides/faq_and_code/README.md index f8fec96..f292fa4 100644 --- a/guides/faq_and_code/README.md +++ b/guides/faq_and_code/README.md @@ -17,7 +17,7 @@ This is a compendium of frequently asked questions on Pine. Answers are short an ### What is the variable name for the current price? The `close` variable holds both the price at the close of historical bars and the current price when code is running on the realtime bar. -### What’s the code for a green candle? +### What is the code for a green candle? ``` greenCandle = close > open ``` From 6cb9a49268db7dd0df544ea8cec1831c1d184096 Mon Sep 17 00:00:00 2001 From: LucF <50338286+LucFF@users.noreply.github.com> Date: Thu, 1 Aug 2019 07:19:56 -0400 Subject: [PATCH 17/34] Update README.md --- guides/faq_and_code/README.md | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/guides/faq_and_code/README.md b/guides/faq_and_code/README.md index f292fa4..3931e3e 100644 --- a/guides/faq_and_code/README.md +++ b/guides/faq_and_code/README.md @@ -21,6 +21,11 @@ The `close` variable holds both the price at the close of historical bars and th ``` greenCandle = close > open ``` +Once you have defined the `greenCandle` variable, if you wanted a boolean variable to be `true` when the 3 last candles were green ones, you could write: +``` +threeGreenCandles = greenCandle and greenCandle[1] and greenCandle[2] +``` + ## 2. Indicators From 1eef9143922b55aed07a6f55b85a3647510c7722 Mon Sep 17 00:00:00 2001 From: LucF <50338286+LucFF@users.noreply.github.com> Date: Thu, 1 Aug 2019 07:25:45 -0400 Subject: [PATCH 18/34] Update README.md --- guides/faq_and_code/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/guides/faq_and_code/README.md b/guides/faq_and_code/README.md index 3931e3e..f85ea61 100644 --- a/guides/faq_and_code/README.md +++ b/guides/faq_and_code/README.md @@ -15,7 +15,7 @@ This is a compendium of frequently asked questions on Pine. Answers are short an ## 1. Built-in variables ### What is the variable name for the current price? -The `close` variable holds both the price at the close of historical bars and the current price when code is running on the realtime bar. +The `close` variable holds both the price at the close of historical bars and the current price when an indicator is running on the realtime bar. If the script is a strategy running on the realtime bar, by default it runs only at the bar's close. If the `calc_on_every_tick` parameter of the `strategy()` declaration statement is set to `true`, the strategy will behave as an indicator and run on every price change of the realtime bar. ### What is the code for a green candle? ``` From a8deb9ec6d247abb4368ef38ad4a991dd9f78dae Mon Sep 17 00:00:00 2001 From: LucF <50338286+LucFF@users.noreply.github.com> Date: Thu, 1 Aug 2019 07:26:40 -0400 Subject: [PATCH 19/34] Update README.md --- guides/faq_and_code/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/guides/faq_and_code/README.md b/guides/faq_and_code/README.md index f85ea61..166b8ff 100644 --- a/guides/faq_and_code/README.md +++ b/guides/faq_and_code/README.md @@ -15,7 +15,7 @@ This is a compendium of frequently asked questions on Pine. Answers are short an ## 1. Built-in variables ### What is the variable name for the current price? -The `close` variable holds both the price at the close of historical bars and the current price when an indicator is running on the realtime bar. If the script is a strategy running on the realtime bar, by default it runs only at the bar's close. If the `calc_on_every_tick` parameter of the `strategy()` declaration statement is set to `true`, the strategy will behave as an indicator and run on every price change of the realtime bar. +The `close` variable holds both the price at the close of historical bars and the current price when an **indicator** is running on the realtime bar. If the script is a **strategy** running on the realtime bar, by default it runs only at the bar's close. If the `calc_on_every_tick` parameter of the `strategy()` declaration statement is set to `true`, the strategy will behave as an indicator and run on every price change of the realtime bar. ### What is the code for a green candle? ``` From 42859d07b35c588c7a34453c4b3647b972228163 Mon Sep 17 00:00:00 2001 From: LucF <50338286+LucFF@users.noreply.github.com> Date: Thu, 1 Aug 2019 07:28:15 -0400 Subject: [PATCH 20/34] Update README.md --- guides/faq_and_code/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/guides/faq_and_code/README.md b/guides/faq_and_code/README.md index 166b8ff..13f1f66 100644 --- a/guides/faq_and_code/README.md +++ b/guides/faq_and_code/README.md @@ -25,7 +25,7 @@ Once you have defined the `greenCandle` variable, if you wanted a boolean variab ``` threeGreenCandles = greenCandle and greenCandle[1] and greenCandle[2] ``` - +Note that the variable name `3GreenCandles` is not legal in Pine as it begins with a digit. ## 2. Indicators From ff71fb6c9fc9b8fbc4660165cb5140809b3e6671 Mon Sep 17 00:00:00 2001 From: LucF <50338286+LucFF@users.noreply.github.com> Date: Thu, 1 Aug 2019 07:30:01 -0400 Subject: [PATCH 21/34] Update README.md --- guides/faq_and_code/README.md | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/guides/faq_and_code/README.md b/guides/faq_and_code/README.md index 13f1f66..d76f7dd 100644 --- a/guides/faq_and_code/README.md +++ b/guides/faq_and_code/README.md @@ -8,12 +8,12 @@ This is a compendium of frequently asked questions on Pine. Answers are short an ### Table of Contents -1. [Built-in variables](#built-in-variables) -1. [Indicators (a.k.a. studies)](#indicators) -1. [Strategies](#strategies) -1. [Alerts](#alerts) +- [Built-in variables](#built-in-variables) +- [Indicators (a.k.a. studies)](#indicators) +- [Strategies](#strategies) +- [Alerts](#alerts) -## 1. Built-in variables +## Built-in variables ### What is the variable name for the current price? The `close` variable holds both the price at the close of historical bars and the current price when an **indicator** is running on the realtime bar. If the script is a **strategy** running on the realtime bar, by default it runs only at the bar's close. If the `calc_on_every_tick` parameter of the `strategy()` declaration statement is set to `true`, the strategy will behave as an indicator and run on every price change of the realtime bar. @@ -27,11 +27,11 @@ threeGreenCandles = greenCandle and greenCandle[1] and greenCandle[2] ``` Note that the variable name `3GreenCandles` is not legal in Pine as it begins with a digit. -## 2. Indicators +## Indicators -## 3. Strategies +## Strategies -## 4. Alerts +## Alerts ### How do I make an alert available from my indicator? Two steps are required: 1. Insert an `alertcondition()` call in an indicator script. From 4259da50f0c2baba4f09dd5296fa62fd0e4e0336 Mon Sep 17 00:00:00 2001 From: LucF <50338286+LucFF@users.noreply.github.com> Date: Thu, 1 Aug 2019 07:30:56 -0400 Subject: [PATCH 22/34] Update README.md --- guides/faq_and_code/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/guides/faq_and_code/README.md b/guides/faq_and_code/README.md index d76f7dd..791fc52 100644 --- a/guides/faq_and_code/README.md +++ b/guides/faq_and_code/README.md @@ -13,7 +13,7 @@ This is a compendium of frequently asked questions on Pine. Answers are short an - [Strategies](#strategies) - [Alerts](#alerts) -## Built-in variables +## BUILT-IN VARIABLES ### What is the variable name for the current price? The `close` variable holds both the price at the close of historical bars and the current price when an **indicator** is running on the realtime bar. If the script is a **strategy** running on the realtime bar, by default it runs only at the bar's close. If the `calc_on_every_tick` parameter of the `strategy()` declaration statement is set to `true`, the strategy will behave as an indicator and run on every price change of the realtime bar. From 0a0abed9736393423887811155cc7784612d4504 Mon Sep 17 00:00:00 2001 From: LucF <50338286+LucFF@users.noreply.github.com> Date: Thu, 1 Aug 2019 07:34:06 -0400 Subject: [PATCH 23/34] Update README.md --- guides/faq_and_code/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/guides/faq_and_code/README.md b/guides/faq_and_code/README.md index 791fc52..d02f1e6 100644 --- a/guides/faq_and_code/README.md +++ b/guides/faq_and_code/README.md @@ -25,7 +25,7 @@ Once you have defined the `greenCandle` variable, if you wanted a boolean variab ``` threeGreenCandles = greenCandle and greenCandle[1] and greenCandle[2] ``` -Note that the variable name `3GreenCandles` is not legal in Pine as it begins with a digit. +Note that the variable name `3GreenCandles` would have caused a compilation error. It is not legal in Pine as it begins with a digit. ## Indicators From 3b25cdae17ffaec5323bb5666f80bb02ee0f34a1 Mon Sep 17 00:00:00 2001 From: LucF <50338286+LucFF@users.noreply.github.com> Date: Thu, 1 Aug 2019 07:34:44 -0400 Subject: [PATCH 24/34] Update README.md --- guides/faq_and_code/README.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/guides/faq_and_code/README.md b/guides/faq_and_code/README.md index d02f1e6..913fee4 100644 --- a/guides/faq_and_code/README.md +++ b/guides/faq_and_code/README.md @@ -27,11 +27,11 @@ threeGreenCandles = greenCandle and greenCandle[1] and greenCandle[2] ``` Note that the variable name `3GreenCandles` would have caused a compilation error. It is not legal in Pine as it begins with a digit. -## Indicators +## INDICATORS -## Strategies +## STRATEGIES -## Alerts +## ALERTS ### How do I make an alert available from my indicator? Two steps are required: 1. Insert an `alertcondition()` call in an indicator script. From 04493072d78f2e67bf5f3fb09dd8293037958d87 Mon Sep 17 00:00:00 2001 From: LucF <50338286+LucFF@users.noreply.github.com> Date: Thu, 1 Aug 2019 07:36:45 -0400 Subject: [PATCH 25/34] Update README.md --- guides/faq_and_code/README.md | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/guides/faq_and_code/README.md b/guides/faq_and_code/README.md index 913fee4..7869d27 100644 --- a/guides/faq_and_code/README.md +++ b/guides/faq_and_code/README.md @@ -53,3 +53,8 @@ When TradingView creates an alert, it saves a snapshot of the environment that w - Current version of the script. Subsequent updates to the script’s code will not affect the alerts created with prior versions. **Note that while alert condition code will compile in strategy scripts, they are only functional in studies.** + +### I have a custom script that generates alerts. How do I run it on many symbols? +You need to create a separate alert for each symbol. There is currently no way to create an alert for all the symbols in a watchlist or for the Screener. + +If one of the generic indicators supplied with the Screener suits your needs and your symbols are tagged with a color label, you can create an alert on those markets from within the Screener. From e7fc62029af818a7cf603c518bf4b0fa973db9af Mon Sep 17 00:00:00 2001 From: LucF <50338286+LucFF@users.noreply.github.com> Date: Thu, 1 Aug 2019 07:41:16 -0400 Subject: [PATCH 26/34] Update README.md --- guides/faq_and_code/README.md | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/guides/faq_and_code/README.md b/guides/faq_and_code/README.md index 7869d27..768d66c 100644 --- a/guides/faq_and_code/README.md +++ b/guides/faq_and_code/README.md @@ -9,6 +9,8 @@ This is a compendium of frequently asked questions on Pine. Answers are short an ### Table of Contents - [Built-in variables](#built-in-variables) +- [Built-in functions](#built-in-functions) +- [Plotting](#plotting) - [Indicators (a.k.a. studies)](#indicators) - [Strategies](#strategies) - [Alerts](#alerts) @@ -27,10 +29,29 @@ threeGreenCandles = greenCandle and greenCandle[1] and greenCandle[2] ``` Note that the variable name `3GreenCandles` would have caused a compilation error. It is not legal in Pine as it begins with a digit. + + +## BUILT-IN FUNCTIONS + + + +## PLOTTING + + + +### Can I plot diagonals between two points on the chart? +Yes, using the [`line.new()`](https://www.tradingview.com/pine-script-reference/v4/#fun_line{dot}new) function available in v4. + + + ## INDICATORS + + ## STRATEGIES + + ## ALERTS ### How do I make an alert available from my indicator? Two steps are required: From 5511b11953e595b6afeba957810fa3613fe3b6c7 Mon Sep 17 00:00:00 2001 From: LucF <50338286+LucFF@users.noreply.github.com> Date: Thu, 1 Aug 2019 07:42:12 -0400 Subject: [PATCH 27/34] Update README.md --- guides/faq_and_code/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/guides/faq_and_code/README.md b/guides/faq_and_code/README.md index 768d66c..ac4fb49 100644 --- a/guides/faq_and_code/README.md +++ b/guides/faq_and_code/README.md @@ -73,7 +73,7 @@ When TradingView creates an alert, it saves a snapshot of the environment that w - State of the script's *Inputs* selections, - Current version of the script. Subsequent updates to the script’s code will not affect the alerts created with prior versions. -**Note that while alert condition code will compile in strategy scripts, they are only functional in studies.** +Note that while alert condition code will compile in strategy scripts, they are only functional in studies. ### I have a custom script that generates alerts. How do I run it on many symbols? You need to create a separate alert for each symbol. There is currently no way to create an alert for all the symbols in a watchlist or for the Screener. From 65827e5b16841cccaf22690f2a1993ba3c4698be Mon Sep 17 00:00:00 2001 From: LucF <50338286+LucFF@users.noreply.github.com> Date: Thu, 1 Aug 2019 07:42:30 -0400 Subject: [PATCH 28/34] Update README.md --- guides/faq_and_code/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/guides/faq_and_code/README.md b/guides/faq_and_code/README.md index ac4fb49..0d69d4d 100644 --- a/guides/faq_and_code/README.md +++ b/guides/faq_and_code/README.md @@ -73,7 +73,7 @@ When TradingView creates an alert, it saves a snapshot of the environment that w - State of the script's *Inputs* selections, - Current version of the script. Subsequent updates to the script’s code will not affect the alerts created with prior versions. -Note that while alert condition code will compile in strategy scripts, they are only functional in studies. +> Note that while alert condition code will compile in strategy scripts, they are only functional in studies. ### I have a custom script that generates alerts. How do I run it on many symbols? You need to create a separate alert for each symbol. There is currently no way to create an alert for all the symbols in a watchlist or for the Screener. From 32eaa23ec73840ae02b0492e2705884abb3a4be3 Mon Sep 17 00:00:00 2001 From: LucF <50338286+LucFF@users.noreply.github.com> Date: Thu, 1 Aug 2019 07:42:56 -0400 Subject: [PATCH 29/34] Update README.md --- guides/faq_and_code/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/guides/faq_and_code/README.md b/guides/faq_and_code/README.md index 0d69d4d..6b88bd6 100644 --- a/guides/faq_and_code/README.md +++ b/guides/faq_and_code/README.md @@ -27,7 +27,7 @@ Once you have defined the `greenCandle` variable, if you wanted a boolean variab ``` threeGreenCandles = greenCandle and greenCandle[1] and greenCandle[2] ``` -Note that the variable name `3GreenCandles` would have caused a compilation error. It is not legal in Pine as it begins with a digit. +> Note that the variable name `3GreenCandles` would have caused a compilation error. It is not legal in Pine as it begins with a digit. From 1823afb0fdd229315ed95b073e181e96971e2e0b Mon Sep 17 00:00:00 2001 From: LucF <50338286+LucFF@users.noreply.github.com> Date: Thu, 1 Aug 2019 10:02:25 -0400 Subject: [PATCH 30/34] Update README.md --- guides/faq_and_code/README.md | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/guides/faq_and_code/README.md b/guides/faq_and_code/README.md index 6b88bd6..c772095 100644 --- a/guides/faq_and_code/README.md +++ b/guides/faq_and_code/README.md @@ -14,8 +14,13 @@ This is a compendium of frequently asked questions on Pine. Answers are short an - [Indicators (a.k.a. studies)](#indicators) - [Strategies](#strategies) - [Alerts](#alerts) +- [Techniques](#techniques) + ## BUILT-IN VARIABLES + + + ### What is the variable name for the current price? The `close` variable holds both the price at the close of historical bars and the current price when an **indicator** is running on the realtime bar. If the script is a **strategy** running on the realtime bar, by default it runs only at the bar's close. If the `calc_on_every_tick` parameter of the `strategy()` declaration statement is set to `true`, the strategy will behave as an indicator and run on every price change of the realtime bar. @@ -48,11 +53,19 @@ Yes, using the [`line.new()`](https://www.tradingview.com/pine-script-reference/ +### Can I create an indicator that plots like the built-in Volume or Volume Profile indicators? +No. + + + ## STRATEGIES ## ALERTS + + + ### How do I make an alert available from my indicator? Two steps are required: 1. Insert an `alertcondition()` call in an indicator script. @@ -79,3 +92,15 @@ When TradingView creates an alert, it saves a snapshot of the environment that w You need to create a separate alert for each symbol. There is currently no way to create an alert for all the symbols in a watchlist or for the Screener. If one of the generic indicators supplied with the Screener suits your needs and your symbols are tagged with a color label, you can create an alert on those markets from within the Screener. + + + +## TECHNIQUES + + + +### How do I save a value or state for use later? +Backtest Rookies has a [blog post](https://backtest-rookies.com/2018/11/23/tradingview-save-a-variable-store-a-value-for-later/) on the subject. +Pine Example: [Holding a state in a variable](https://www.tradingview.com/script/llcoIPKG-Pine-Example-Holding-a-state-in-a-variable/) by vitvlkv. + + From 497c65308326e8d637d978a9e909b26ebe60f60a Mon Sep 17 00:00:00 2001 From: LucF <50338286+LucFF@users.noreply.github.com> Date: Thu, 1 Aug 2019 10:05:36 -0400 Subject: [PATCH 31/34] Update README.md --- guides/faq_and_code/README.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/guides/faq_and_code/README.md b/guides/faq_and_code/README.md index c772095..70ecaf3 100644 --- a/guides/faq_and_code/README.md +++ b/guides/faq_and_code/README.md @@ -103,4 +103,8 @@ If one of the generic indicators supplied with the Screener suits your needs and Backtest Rookies has a [blog post](https://backtest-rookies.com/2018/11/23/tradingview-save-a-variable-store-a-value-for-later/) on the subject. Pine Example: [Holding a state in a variable](https://www.tradingview.com/script/llcoIPKG-Pine-Example-Holding-a-state-in-a-variable/) by vitvlkv. +### How do I calculate averages? +1. If you just want the average between two values, you can use `avg(val1, val2)` or `(val1 + val2)/2`. +1. To average the last x values in a series, you can use `sma(series, x)`. +1. To average an unknown quantity of values you’ll need to keep track of them, as is done [here](https://www.tradingview.com/script/isSfahiX-Averages-PineCoders-FAQ/). From c3dbe63a8014ad36a36ac63f34f0ef371d2f4fdc Mon Sep 17 00:00:00 2001 From: LucF <50338286+LucFF@users.noreply.github.com> Date: Thu, 1 Aug 2019 10:10:21 -0400 Subject: [PATCH 32/34] Update README.md --- guides/faq_and_code/README.md | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/guides/faq_and_code/README.md b/guides/faq_and_code/README.md index 70ecaf3..9e26f6c 100644 --- a/guides/faq_and_code/README.md +++ b/guides/faq_and_code/README.md @@ -106,5 +106,7 @@ Pine Example: [Holding a state in a variable](https://www.tradingview.com/script ### How do I calculate averages? 1. If you just want the average between two values, you can use `avg(val1, val2)` or `(val1 + val2)/2`. 1. To average the last x values in a series, you can use `sma(series, x)`. -1. To average an unknown quantity of values you’ll need to keep track of them, as is done [here](https://www.tradingview.com/script/isSfahiX-Averages-PineCoders-FAQ/). + +### How can I calculate averages only when a condition is true? +[This script](https://www.tradingview.com/script/isSfahiX-Averages-PineCoders-FAQ/) shows how to calculate a conditional average using three different methods. From 6e81cac4d9b6b4fc8f5f027e808a919f6041d361 Mon Sep 17 00:00:00 2001 From: LucF <50338286+LucFF@users.noreply.github.com> Date: Thu, 1 Aug 2019 11:49:40 -0400 Subject: [PATCH 33/34] Update README.md --- guides/faq_and_code/README.md | 23 ++++++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) diff --git a/guides/faq_and_code/README.md b/guides/faq_and_code/README.md index 9e26f6c..ae03f76 100644 --- a/guides/faq_and_code/README.md +++ b/guides/faq_and_code/README.md @@ -62,6 +62,27 @@ No. +### How do I implement date range filtering in strategies? +``` +DateFilter = input(false, "═════════════ Date Range Filtering") +FromYear = input(1900, "From Year", minval=1900) +FromMonth = input(1, "From Month", minval=1, maxval=12) +FromDay = input(1, "From Day", minval=1, maxval=31) +ToYear = input(2999, "To Year", minval=1900) +ToMonth = input(1, "To Month", minval=1, maxval=12) +ToDay = input(1, "To Day", minval=1, maxval=31) +FromDate = timestamp(FromYear, FromMonth, FromDay, 00, 00) +ToDate = timestamp(ToYear, ToMonth, ToDay, 23, 59) +TradeDateIsAllowed() => DateFilter? (time >= FromDate and time <= ToDate) : true +``` +You can then use the result of `TradeDateIsAllowed()` to confirm your entries using something like this: +``` +EnterLong = GoLong and TradeDateIsAllowed() +``` +> Note that with this code snippet allows date filtering to be enabled/disabled using a checkbox. This way, you don't have to reset dates when filtering is no longer needed; just uncheck the box. + + + ## ALERTS @@ -99,7 +120,7 @@ If one of the generic indicators supplied with the Screener suits your needs and -### How do I save a value or state for use later? +### How do I save a value or state for later use? Backtest Rookies has a [blog post](https://backtest-rookies.com/2018/11/23/tradingview-save-a-variable-store-a-value-for-later/) on the subject. Pine Example: [Holding a state in a variable](https://www.tradingview.com/script/llcoIPKG-Pine-Example-Holding-a-state-in-a-variable/) by vitvlkv. From 7445106cf7c5b8f3e8b357f4dfaf27bd085776af Mon Sep 17 00:00:00 2001 From: LucF <50338286+LucFF@users.noreply.github.com> Date: Thu, 1 Aug 2019 11:53:11 -0400 Subject: [PATCH 34/34] Update README.md --- guides/faq_and_code/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/guides/faq_and_code/README.md b/guides/faq_and_code/README.md index ae03f76..f1f03f2 100644 --- a/guides/faq_and_code/README.md +++ b/guides/faq_and_code/README.md @@ -79,7 +79,7 @@ You can then use the result of `TradeDateIsAllowed()` to confirm your entries us ``` EnterLong = GoLong and TradeDateIsAllowed() ``` -> Note that with this code snippet allows date filtering to be enabled/disabled using a checkbox. This way, you don't have to reset dates when filtering is no longer needed; just uncheck the box. +> Note that with this code snippet, date filtering can be enabled/disabled using a checkbox. This way you don't have to reset dates when filtering is no longer needed; just uncheck the box.