{"id":13,"date":"2024-08-04T14:45:00","date_gmt":"2024-08-04T14:45:00","guid":{"rendered":""},"modified":"2025-06-21T15:30:04","modified_gmt":"2025-06-21T15:30:04","slug":"my-sets-of-favourite-pine-codes-for","status":"publish","type":"post","link":"https:\/\/kriptos.my\/index.php\/2024\/08\/04\/my-sets-of-favourite-pine-codes-for\/","title":{"rendered":"My sets of favourite pine codes (for easy revision)"},"content":{"rendered":"<div class=\"separator\" style=\"clear: both; text-align: center;\"><a href=\"https:\/\/blogger.googleusercontent.com\/img\/b\/R29vZ2xl\/AVvXsEixeQJoEWvXBHjmrz7KFnjebHdM646yeJ7nvLx6zuezA0SpdxrdoLiCsjCryjFxH7f2ER7NiNHBwJjxjZsWtZiC8FjGF_ff6bUrSkq412ZK40vLMJHXvlPhDRowQVKuEThN60_oKHuPDr9NhhlyhXR80gsca5Ot84_6snIKEm-sdl7FaijwNIXoiiHvQeG7\/s1024\/pine%20script%20codes%20examples.jpg\" style=\"margin-left: 1em; margin-right: 1em;\"><img fetchpriority=\"high\" decoding=\"async\" border=\"0\" data-original-height=\"1024\" data-original-width=\"1024\" height=\"320\" src=\"https:\/\/blogger.googleusercontent.com\/img\/b\/R29vZ2xl\/AVvXsEixeQJoEWvXBHjmrz7KFnjebHdM646yeJ7nvLx6zuezA0SpdxrdoLiCsjCryjFxH7f2ER7NiNHBwJjxjZsWtZiC8FjGF_ff6bUrSkq412ZK40vLMJHXvlPhDRowQVKuEThN60_oKHuPDr9NhhlyhXR80gsca5Ot84_6snIKEm-sdl7FaijwNIXoiiHvQeG7\/s320\/pine%20script%20codes%20examples.jpg\" width=\"320\" \/><\/a><\/div>\n<p>This post is mainly for my own reference actually, so that i could easily come back grab the lines of pine scripts to be inserted into my pine script strategy. They are all version 5 pine script.<\/p>\n<h3 style=\"text-align: left;\">1. Top line&nbsp;<\/h3>\n<p>Strategy with preset of initial capital, order size, and commission percentage:<\/p>\n<div style=\"background-color: #131722; color: white; font-family: Menlo, &quot;Ubuntu Mono&quot;, Consolas, source-code-pro, monospace, Consolas, &quot;Courier New&quot;, monospace; font-size: 13px; line-height: 18px; white-space: pre;\">\n<div><span style=\"color: #787b86;\">\/\/ <\/span><span style=\"color: #787b86; font-weight: bold;\">@version=<\/span><span style=\"color: #787b86;\">5<\/span><\/div>\n<div><span style=\"color: #5b9cf6;\">strategy<\/span>(<span style=\"color: #388e3c;\">&#8220;Strategy Name [capayam.com]&#8221;<\/span><span style=\"color: #42bda8;\">,<\/span> <span style=\"color: #d1d4dc;\">overlay<\/span><span style=\"color: #42bda8;\">=<\/span><span style=\"color: #f77c80;\">false<\/span><span style=\"color: #42bda8;\">,<\/span> <span style=\"color: #d1d4dc;\">initial_capital<\/span> <span style=\"color: #42bda8;\">=<\/span> <span style=\"color: #f57f17;\">100<\/span><span style=\"color: #42bda8;\">,<\/span> <span style=\"color: #d1d4dc;\">default_qty_type<\/span><span style=\"color: #42bda8;\">=<\/span><span style=\"color: #f77c80;\">strategy.percent_of_equity<\/span><span style=\"color: #42bda8;\">,<\/span> <span style=\"color: #d1d4dc;\">default_qty_value<\/span><span style=\"color: #42bda8;\">=<\/span><span style=\"color: #f57f17;\">100<\/span><span style=\"color: #42bda8;\">,<\/span> <span style=\"color: #d1d4dc;\">commission_type<\/span><span style=\"color: #42bda8;\">=<\/span><span style=\"color: #f77c80;\">strategy.commission.percent<\/span> <span style=\"color: #42bda8;\">,<\/span> <span style=\"color: #d1d4dc;\">commission_value<\/span><span style=\"color: #42bda8;\">=<\/span><span style=\"color: #f57f17;\">0.1<\/span>)<\/div>\n<div><span style=\"color: #42bda8;\"><\/span><\/div>\n<\/div>\n<p><\/p>\n<h3 style=\"text-align: left;\">2. Input groups<\/h3>\n<p>They are usually for adjusting Take Profit and Stop Loss level. I use this to set Oversold level as well that determine my entry threshold.<\/p>\n<div style=\"background-color: #131722; color: white; font-family: Menlo, &quot;Ubuntu Mono&quot;, Consolas, source-code-pro, monospace, Consolas, &quot;Courier New&quot;, monospace; font-size: 13px; line-height: 18px; white-space: pre;\">\n<div><span style=\"color: #787b86;\">\/\/ Input Groups<\/span><\/div>\n<div><span style=\"color: #d1d4dc;\">OverboughtLevel<\/span> <span style=\"color: #42bda8;\">=<\/span> <span style=\"color: #5b9cf6;\">input.int<\/span>(<span style=\"color: #f57f17;\">50<\/span><span style=\"color: #42bda8;\">,<\/span> <span style=\"color: #d1d4dc;\">title<\/span><span style=\"color: #42bda8;\">=<\/span><span style=\"color: #388e3c;\">&#8220;OverboughtLevel&#8221;<\/span>)<\/div>\n<div><span style=\"color: #d1d4dc;\">OversoldLevel<\/span> <span style=\"color: #42bda8;\">=<\/span> <span style=\"color: #5b9cf6;\">input.int<\/span>(<span style=\"color: #f57f17;\">-50<\/span><span style=\"color: #42bda8;\">,<\/span> <span style=\"color: #d1d4dc;\">title<\/span><span style=\"color: #42bda8;\">=<\/span><span style=\"color: #388e3c;\">&#8220;OversoldLevel&#8221;<\/span>)<\/div>\n<\/div>\n<p><\/p>\n<h3 style=\"text-align: left;\">3.&nbsp; Timestamp<\/h3>\n<p>This is useful when backtesting a specified shorter period within a long period of time backtesting range (usually with TF 1hour and above)&nbsp;<\/p>\n<div style=\"background-color: #131722; font-family: Menlo, &quot;Ubuntu Mono&quot;, Consolas, source-code-pro, monospace, Consolas, &quot;Courier New&quot;, monospace; font-size: 13px; line-height: 18px; white-space: pre;\">\n<div style=\"color: white;\"><span style=\"color: #787b86;\">\/\/ Input Group<\/span><\/div>\n<div style=\"color: white;\"><span style=\"color: #d1d4dc;\">start_year<\/span> <span style=\"color: #42bda8;\">=<\/span> <span style=\"color: #5b9cf6;\">input<\/span>(<span style=\"color: #f57f17;\">2024<\/span><span style=\"color: #42bda8;\">,<\/span> <span style=\"color: #d1d4dc;\">title<\/span><span style=\"color: #42bda8;\">=<\/span><span style=\"color: #388e3c;\">&#8220;Start Year&#8221;<\/span>)<\/div>\n<div style=\"color: white;\"><span style=\"color: #d1d4dc;\">start_month<\/span> <span style=\"color: #42bda8;\">=<\/span> <span style=\"color: #5b9cf6;\">input<\/span>(<span style=\"color: #f57f17;\">1<\/span><span style=\"color: #42bda8;\">,<\/span> <span style=\"color: #d1d4dc;\">title<\/span><span style=\"color: #42bda8;\">=<\/span><span style=\"color: #388e3c;\">&#8220;Start Month&#8221;<\/span>)<\/div>\n<div><span style=\"color: #d1d4dc;\">start_day<\/span><span style=\"color: white;\"> <\/span><span style=\"color: #42bda8;\">=<\/span><span style=\"color: white;\"> <\/span><span style=\"color: #5b9cf6;\">input<\/span><span style=\"color: white;\">(<\/span><span style=\"color: #f57f17;\">1<\/span><span style=\"color: #42bda8;\">,<\/span><span style=\"color: white;\"> <\/span><span style=\"color: #d1d4dc;\">title<\/span><span style=\"color: #42bda8;\">=<\/span><span style=\"color: #388e3c;\">&#8220;Start Day&#8221;<\/span><span style=\"color: white;\">)<\/span><\/div>\n<div><span style=\"color: white;\"><br \/><\/span><\/div>\n<div>\n<div style=\"color: white;\"><span style=\"color: #d1d4dc;\">stop_year<\/span> <span style=\"color: #42bda8;\">=<\/span> <span style=\"color: #5b9cf6;\">input<\/span>(<span style=\"color: #f57f17;\">2024<\/span><span style=\"color: #42bda8;\">,<\/span> <span style=\"color: #d1d4dc;\">title<\/span><span style=\"color: #42bda8;\">=<\/span><span style=\"color: #388e3c;\">&#8220;Stop Year&#8221;<\/span>)<\/div>\n<div style=\"color: white;\"><span style=\"color: #d1d4dc;\">stop_month<\/span> <span style=\"color: #42bda8;\">=<\/span> <span style=\"color: #5b9cf6;\">input<\/span>(<span style=\"color: #f57f17;\">12<\/span><span style=\"color: #42bda8;\">,<\/span> <span style=\"color: #d1d4dc;\">title<\/span><span style=\"color: #42bda8;\">=<\/span><span style=\"color: #388e3c;\">&#8220;Stop Month&#8221;<\/span>)<\/div>\n<div style=\"color: white;\"><span style=\"color: #d1d4dc;\">stop_day<\/span> <span style=\"color: #42bda8;\">=<\/span> <span style=\"color: #5b9cf6;\">input<\/span>(<span style=\"color: #f57f17;\">31<\/span><span style=\"color: #42bda8;\">,<\/span> <span style=\"color: #d1d4dc;\">title<\/span><span style=\"color: #42bda8;\">=<\/span><span style=\"color: #388e3c;\">&#8220;Stop Day&#8221;<\/span>)<\/div>\n<p><br style=\"color: white;\" \/><\/p>\n<div style=\"color: white;\"><span style=\"color: #787b86;\">\/\/ Create timestamps from the input dates<\/span><\/div>\n<div style=\"color: white;\"><span style=\"color: #d1d4dc;\">start_trading_date<\/span> <span style=\"color: #42bda8;\">=<\/span> <span style=\"color: #5b9cf6;\">timestamp<\/span>(<span style=\"color: #d1d4dc;\">start_year<\/span><span style=\"color: #42bda8;\">,<\/span> <span style=\"color: #d1d4dc;\">start_month<\/span><span style=\"color: #42bda8;\">,<\/span> <span style=\"color: #d1d4dc;\">start_day<\/span><span style=\"color: #42bda8;\">,<\/span> <span style=\"color: #f57f17;\">0<\/span><span style=\"color: #42bda8;\">,<\/span> <span style=\"color: #f57f17;\">0<\/span>)<\/div>\n<div style=\"color: white;\"><span style=\"color: #d1d4dc;\">stop_trading_date<\/span> <span style=\"color: #42bda8;\">=<\/span> <span style=\"color: #5b9cf6;\">timestamp<\/span>(<span style=\"color: #d1d4dc;\">stop_year<\/span><span style=\"color: #42bda8;\">,<\/span> <span style=\"color: #d1d4dc;\">stop_month<\/span><span style=\"color: #42bda8;\">,<\/span> <span style=\"color: #d1d4dc;\">stop_day<\/span><span style=\"color: #42bda8;\">,<\/span> <span style=\"color: #f57f17;\">23<\/span><span style=\"color: #42bda8;\">,<\/span> <span style=\"color: #f57f17;\">59<\/span>)<\/div>\n<\/div>\n<p><span style=\"color: white;\"><\/p>\n<div style=\"background-color: #131722; font-family: Menlo, &quot;Ubuntu Mono&quot;, Consolas, source-code-pro, monospace, Consolas, &quot;Courier New&quot;, monospace; font-size: 13px; line-height: 18px; white-space: pre;\"><span style=\"color: white;\"><br \/><\/span><\/div>\n<div style=\"background-color: #131722; font-family: Menlo, &quot;Ubuntu Mono&quot;, Consolas, source-code-pro, monospace, Consolas, &quot;Courier New&quot;, monospace; font-size: 13px; line-height: 18px; white-space: pre;\"><span style=\"color: white;\"><br \/><\/span><\/div>\n<div style=\"background-color: #131722; font-family: Menlo, &quot;Ubuntu Mono&quot;, Consolas, source-code-pro, monospace, Consolas, &quot;Courier New&quot;, monospace; font-size: 13px; line-height: 18px; white-space: pre;\">\n<div><span style=\"color: #787b86;\">\/\/ Define Buy Signal<\/span><\/div>\n<div><span style=\"color: #d1d4dc;\">BuySignal<\/span> <span style=\"color: #42bda8;\">=<\/span> <span style=\"color: #d1d4dc;\">oversold<\/span> <span style=\"color: #42bda8;\">and<\/span> (<span style=\"color: #f77c80;\">time<\/span> <span style=\"color: #42bda8;\">&gt;=<\/span> <span style=\"color: #d1d4dc;\">start_trading_date<\/span>) <span style=\"color: #42bda8;\">and<\/span> (<span style=\"color: #f77c80;\">time<\/span> <span style=\"color: #42bda8;\">&lt;=<\/span> <span style=\"color: #d1d4dc;\">stop_trading_date<\/span>)<\/div>\n<div><\/div>\n<\/div>\n<div style=\"background-color: #131722; font-family: Menlo, &quot;Ubuntu Mono&quot;, Consolas, source-code-pro, monospace, Consolas, &quot;Courier New&quot;, monospace; font-size: 13px; line-height: 18px; white-space: pre;\"><\/div>\n<p><\/span><\/div>\n<h3 style=\"text-align: left;\">4. Calculate Take Profit or Stop Loss (by percentage)<\/h3>\n<div style=\"background-color: #131722; color: white; font-family: Menlo, &quot;Ubuntu Mono&quot;, Consolas, source-code-pro, monospace, Consolas, &quot;Courier New&quot;, monospace; font-size: 13px; line-height: 18px; white-space: pre;\">\n<div><span style=\"color: #787b86;\">\/\/ Input parameters<\/span><\/div>\n<div><span style=\"color: #d1d4dc;\">profit_target_percent<\/span> <span style=\"color: #42bda8;\">=<\/span> <span style=\"color: #5b9cf6;\">input<\/span>(<span style=\"color: #f57f17;\">6<\/span><span style=\"color: #42bda8;\">,<\/span> <span style=\"color: #d1d4dc;\">title<\/span><span style=\"color: #42bda8;\">=<\/span><span style=\"color: #388e3c;\">&#8220;Profit Target (%)&#8221;<\/span>)<\/div>\n<div><span style=\"color: #d1d4dc;\">stop_loss_percent<\/span> <span style=\"color: #42bda8;\">=<\/span> <span style=\"color: #5b9cf6;\">input<\/span>(<span style=\"color: #f57f17;\">3<\/span><span style=\"color: #42bda8;\">,<\/span> <span style=\"color: #d1d4dc;\">title<\/span><span style=\"color: #42bda8;\">=<\/span><span style=\"color: #388e3c;\">&#8220;Stop Loss (%)&#8221;<\/span>)<\/div>\n<\/div>\n<p><\/p>\n<div style=\"background-color: #131722; color: white; font-family: Menlo, &quot;Ubuntu Mono&quot;, Consolas, source-code-pro, monospace, Consolas, &quot;Courier New&quot;, monospace; font-size: 13px; line-height: 18px; white-space: pre;\">\n<div><span style=\"color: #787b86;\">\/\/ Calculate profit target and stop loss levels<\/span><\/div>\n<div><span style=\"color: #d1d4dc;\">entry_price<\/span> <span style=\"color: #42bda8;\">=<\/span> <span style=\"color: #f77c80;\">strategy.position_avg_price<\/span><\/div>\n<div><span style=\"color: #d1d4dc;\">profit_target<\/span> <span style=\"color: #42bda8;\">=<\/span> <span style=\"color: #d1d4dc;\">entry_price<\/span> <span style=\"color: #42bda8;\">*<\/span> (<span style=\"color: #f57f17;\">1<\/span> <span style=\"color: #42bda8;\">+<\/span> <span style=\"color: #d1d4dc;\">profit_target_percent<\/span> <span style=\"color: #42bda8;\">\/<\/span> <span style=\"color: #f57f17;\">100<\/span>)<\/div>\n<div><span style=\"color: #d1d4dc;\">stop_loss<\/span> <span style=\"color: #42bda8;\">=<\/span> <span style=\"color: #d1d4dc;\">entry_price<\/span> <span style=\"color: #42bda8;\">*<\/span> (<span style=\"color: #f57f17;\">1<\/span> <span style=\"color: #42bda8;\">&#8211;<\/span> <span style=\"color: #d1d4dc;\">stop_loss_percent<\/span> <span style=\"color: #42bda8;\">\/<\/span> <span style=\"color: #f57f17;\">100<\/span>)<\/div>\n<p><\/p>\n<div><span style=\"color: #787b86;\">\/\/ Exit conditions<\/span><\/div>\n<div><span style=\"color: #5b9cf6;\">strategy.exit<\/span>(<span style=\"color: #388e3c;\">&#8220;Exit&#8221;<\/span><span style=\"color: #42bda8;\">,<\/span> <span style=\"color: #d1d4dc;\">limit<\/span><span style=\"color: #42bda8;\">=<\/span><span style=\"color: #d1d4dc;\">profit_target<\/span><span style=\"color: #42bda8;\">,<\/span> <span style=\"color: #d1d4dc;\">stop<\/span><span style=\"color: #42bda8;\">=<\/span><span style=\"color: #d1d4dc;\">stop_loss<\/span>)<\/div>\n<\/div>\n<h3 style=\"text-align: left;\"><\/h3>\n<h3 style=\"text-align: left;\">5. Calculate TP and SL (by Recent swing low &amp; Risk reward ratio)<\/h3>\n<div style=\"background-color: #131722; color: white; font-family: Menlo, &quot;Ubuntu Mono&quot;, Consolas, source-code-pro, monospace, Consolas, &quot;Courier New&quot;, monospace; font-size: 13px; line-height: 18px; white-space: pre;\">\n<div><span style=\"color: #787b86;\">\/\/ Input Groups<\/span><\/div>\n<div><span style=\"color: #d1d4dc;\">swingLowLookback<\/span> <span style=\"color: #42bda8;\">=<\/span> <span style=\"color: #5b9cf6;\">input.int<\/span>(<span style=\"color: #f57f17;\">5<\/span><span style=\"color: #42bda8;\">,<\/span> <span style=\"color: #d1d4dc;\">title<\/span><span style=\"color: #42bda8;\">=<\/span><span style=\"color: #388e3c;\">&#8220;Swing Low Lookback Period&#8221;<\/span>)<\/div>\n<\/div>\n<p><\/p>\n<div style=\"background-color: #131722; color: white; font-family: Menlo, &quot;Ubuntu Mono&quot;, Consolas, source-code-pro, monospace, Consolas, &quot;Courier New&quot;, monospace; font-size: 13px; line-height: 18px; white-space: pre;\">\n<div><span style=\"color: #787b86;\">\/\/ Define the stop loss at the recent swing low<\/span><\/div>\n<div><span style=\"color: #d1d4dc;\">recentSwingLow<\/span> <span style=\"color: #42bda8;\">=<\/span> <span style=\"color: #5b9cf6;\">ta.lowest<\/span>(<span style=\"color: #f77c80;\">low<\/span><span style=\"color: #42bda8;\">,<\/span> <span style=\"color: #d1d4dc;\">swingLowLookback<\/span>)<\/div>\n<p><\/p>\n<div><span style=\"color: #787b86;\">\/\/ Calculate stop loss and take profit levels<\/span><\/div>\n<div><span style=\"color: #d1d4dc;\">entryPrice<\/span> <span style=\"color: #42bda8;\">=<\/span> <span style=\"color: #f77c80;\">close<\/span><\/div>\n<div><span style=\"color: #d1d4dc;\">stopLoss<\/span> <span style=\"color: #42bda8;\">=<\/span> <span style=\"color: #d1d4dc;\">recentSwingLow<\/span><\/div>\n<div><span style=\"color: #d1d4dc;\">takeProfit<\/span> <span style=\"color: #42bda8;\">=<\/span> <span style=\"color: #d1d4dc;\">entryPrice<\/span> <span style=\"color: #42bda8;\">+<\/span> <span style=\"color: #f57f17;\">2<\/span> <span style=\"color: #42bda8;\">*<\/span> (<span style=\"color: #d1d4dc;\">entryPrice<\/span> <span style=\"color: #42bda8;\">&#8211;<\/span> <span style=\"color: #d1d4dc;\">stopLoss<\/span>)<\/div>\n<p><\/p>\n<div><span style=\"color: #787b86;\">\/\/ Strategy entry with stop loss and take profit<\/span><\/div>\n<div><span style=\"color: #42bda8;\">if<\/span> (<span style=\"color: #d1d4dc;\">BuySignal<\/span>)<\/div>\n<div>&nbsp; &nbsp; <span style=\"color: #5b9cf6;\">strategy.entry<\/span>(<span style=\"color: #388e3c;\">&#8220;Buy&#8221;<\/span><span style=\"color: #42bda8;\">,<\/span> <span style=\"color: #f77c80;\">strategy.long<\/span>)<\/div>\n<div>&nbsp; &nbsp; <span style=\"color: #5b9cf6;\">strategy.exit<\/span>(<span style=\"color: #388e3c;\">&#8220;Exit&#8221;<\/span><span style=\"color: #42bda8;\">,<\/span> <span style=\"color: #388e3c;\">&#8220;Buy&#8221;<\/span><span style=\"color: #42bda8;\">,<\/span> <span style=\"color: #d1d4dc;\">stop<\/span><span style=\"color: #42bda8;\">=<\/span><span style=\"color: #d1d4dc;\">stopLoss<\/span><span style=\"color: #42bda8;\">,<\/span> <span style=\"color: #d1d4dc;\">limit<\/span><span style=\"color: #42bda8;\">=<\/span><span style=\"color: #d1d4dc;\">takeProfit<\/span>)<\/div>\n<p><\/div>\n<p><\/p>\n<h3 style=\"text-align: left;\">6. Strategy logic and execution<\/h3>\n<div style=\"background-color: #131722; color: white; font-family: Menlo, &quot;Ubuntu Mono&quot;, Consolas, source-code-pro, monospace, Consolas, &quot;Courier New&quot;, monospace; font-size: 13px; line-height: 18px; white-space: pre;\">\n<div><span style=\"color: #787b86;\">\/\/ Define Buy Exit condition<\/span><\/div>\n<div><span style=\"color: #d1d4dc;\">BuySignal<\/span> <span style=\"color: #42bda8;\">=<\/span> <span style=\"color: #d1d4dc;\">oversold<\/span><\/div>\n<div><span style=\"color: #d1d4dc;\">SellSignal<\/span> <span style=\"color: #42bda8;\">=<\/span> <span style=\"color: #d1d4dc;\">overbought<\/span><\/div>\n<div><span style=\"color: #787b86;\">\/\/ Strategy entry and exit conditions<\/span><\/div>\n<div><span style=\"color: #42bda8;\">if<\/span> (<span style=\"color: #d1d4dc;\">BuySignal<\/span>)<\/div>\n<div>&nbsp; &nbsp; <span style=\"color: #5b9cf6;\">strategy.entry<\/span>(<span style=\"color: #388e3c;\">&#8220;Buy&#8221;<\/span><span style=\"color: #42bda8;\">,<\/span> <span style=\"color: #f77c80;\">strategy.long<\/span>)<\/div>\n<div>&nbsp; &nbsp; <\/div>\n<div><span style=\"color: #42bda8;\">if<\/span> (Sell<span style=\"color: #d1d4dc;\">Signal<\/span>)<\/div>\n<div>&nbsp; &nbsp; <span style=\"color: #5b9cf6;\">strategy.close<\/span>(<span style=\"color: #388e3c;\">&#8220;Buy&#8221;<\/span>)<\/div>\n<\/div>\n<p><\/p>\n<h3 style=\"text-align: left;\">7. Stop loss OR Close position with profit<\/h3>\n<div style=\"background-color: #131722; color: white; font-family: Menlo, &quot;Ubuntu Mono&quot;, Consolas, source-code-pro, monospace, Consolas, &quot;Courier New&quot;, monospace; font-size: 13px; line-height: 18px; white-space: pre;\">\n<div><span style=\"color: #787b86;\">\/\/ Strategy entry with Stop Loss OR Close position with Profit <\/span><\/div>\n<div><span style=\"color: #42bda8;\">if<\/span> (B<span style=\"color: #d1d4dc;\">uySignal<\/span>)<\/div>\n<div>&nbsp; &nbsp; <span style=\"color: #5b9cf6;\">strategy.entry<\/span>(<span style=\"color: #388e3c;\">&#8220;Buy&#8221;<\/span><span style=\"color: #42bda8;\">,<\/span> <span style=\"color: #f77c80;\">strategy.long<\/span>)<\/div>\n<div>&nbsp; &nbsp; <span style=\"color: #5b9cf6;\">strategy.exit<\/span>(<span style=\"color: #388e3c;\">&#8220;StopLoss&#8221;<\/span><span style=\"color: #42bda8;\">,<\/span> <span style=\"color: #388e3c;\">&#8220;Buy&#8221;<\/span><span style=\"color: #42bda8;\">,<\/span> <span style=\"color: #d1d4dc;\">stop<\/span><span style=\"color: #42bda8;\">=<\/span><span style=\"color: #d1d4dc;\">stopLoss<\/span>)<\/div>\n<p><\/p>\n<div><span style=\"color: #42bda8;\">if<\/span> (S<span style=\"color: #d1d4dc;\">ellSignal<\/span>)<\/div>\n<div>&nbsp; &nbsp; <span style=\"color: #5b9cf6;\">strategy.close<\/span>(<span style=\"color: #388e3c;\">&#8220;Buy&#8221;<\/span>)<\/div>\n<\/div>\n<p><\/p>\n<p><\/p>\n","protected":false},"excerpt":{"rendered":"<p>This post is mainly for my own reference actually, so that i could easily come back grab the lines of pine scripts to be inserted into my pine script strategy.<\/p>\n<p><a href=\"https:\/\/kriptos.my\/index.php\/2024\/08\/04\/my-sets-of-favourite-pine-codes-for\/\" class=\"btn btn-skin btn-radius\">Continue Reading<span class=\"screen-reader-text\">My sets of favourite pine codes (for easy revision)<\/span><\/a><\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[3],"class_list":["post-13","post","type-post","status-publish","format-standard","hentry","category-pine-script-strategy","tag-pine-script-strategy"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v25.3.1 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>My sets of favourite pine codes (for easy revision) - kriptos.my<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/kriptos.my\/index.php\/2024\/08\/04\/my-sets-of-favourite-pine-codes-for\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"My sets of favourite pine codes (for easy revision) - kriptos.my\" \/>\n<meta property=\"og:description\" content=\"This post is mainly for my own reference actually, so that i could easily come back grab the lines of pine scripts to be inserted into my pine script strategy.Continue ReadingMy sets of favourite pine codes (for easy revision)\" \/>\n<meta property=\"og:url\" content=\"https:\/\/kriptos.my\/index.php\/2024\/08\/04\/my-sets-of-favourite-pine-codes-for\/\" \/>\n<meta property=\"og:site_name\" content=\"kriptos.my\" \/>\n<meta property=\"article:published_time\" content=\"2024-08-04T14:45:00+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2025-06-21T15:30:04+00:00\" \/>\n<meta name=\"author\" content=\"kriptos\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"kriptos\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"2 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\/\/kriptos.my\/index.php\/2024\/08\/04\/my-sets-of-favourite-pine-codes-for\/#article\",\"isPartOf\":{\"@id\":\"https:\/\/kriptos.my\/index.php\/2024\/08\/04\/my-sets-of-favourite-pine-codes-for\/\"},\"author\":{\"name\":\"kriptos\",\"@id\":\"https:\/\/kriptos.my\/#\/schema\/person\/ab6ae0f7dc407600d321d44b02da9556\"},\"headline\":\"My sets of favourite pine codes (for easy revision)\",\"datePublished\":\"2024-08-04T14:45:00+00:00\",\"dateModified\":\"2025-06-21T15:30:04+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/kriptos.my\/index.php\/2024\/08\/04\/my-sets-of-favourite-pine-codes-for\/\"},\"wordCount\":451,\"commentCount\":0,\"publisher\":{\"@id\":\"https:\/\/kriptos.my\/#organization\"},\"image\":{\"@id\":\"https:\/\/kriptos.my\/index.php\/2024\/08\/04\/my-sets-of-favourite-pine-codes-for\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/blogger.googleusercontent.com\/img\/b\/R29vZ2xl\/AVvXsEixeQJoEWvXBHjmrz7KFnjebHdM646yeJ7nvLx6zuezA0SpdxrdoLiCsjCryjFxH7f2ER7NiNHBwJjxjZsWtZiC8FjGF_ff6bUrSkq412ZK40vLMJHXvlPhDRowQVKuEThN60_oKHuPDr9NhhlyhXR80gsca5Ot84_6snIKEm-sdl7FaijwNIXoiiHvQeG7\/s320\/pine%20script%20codes%20examples.jpg\",\"keywords\":[\"Pine Script Strategy\"],\"articleSection\":[\"Pine Script Strategy\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\/\/kriptos.my\/index.php\/2024\/08\/04\/my-sets-of-favourite-pine-codes-for\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/kriptos.my\/index.php\/2024\/08\/04\/my-sets-of-favourite-pine-codes-for\/\",\"url\":\"https:\/\/kriptos.my\/index.php\/2024\/08\/04\/my-sets-of-favourite-pine-codes-for\/\",\"name\":\"My sets of favourite pine codes (for easy revision) - kriptos.my\",\"isPartOf\":{\"@id\":\"https:\/\/kriptos.my\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\/\/kriptos.my\/index.php\/2024\/08\/04\/my-sets-of-favourite-pine-codes-for\/#primaryimage\"},\"image\":{\"@id\":\"https:\/\/kriptos.my\/index.php\/2024\/08\/04\/my-sets-of-favourite-pine-codes-for\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/blogger.googleusercontent.com\/img\/b\/R29vZ2xl\/AVvXsEixeQJoEWvXBHjmrz7KFnjebHdM646yeJ7nvLx6zuezA0SpdxrdoLiCsjCryjFxH7f2ER7NiNHBwJjxjZsWtZiC8FjGF_ff6bUrSkq412ZK40vLMJHXvlPhDRowQVKuEThN60_oKHuPDr9NhhlyhXR80gsca5Ot84_6snIKEm-sdl7FaijwNIXoiiHvQeG7\/s320\/pine%20script%20codes%20examples.jpg\",\"datePublished\":\"2024-08-04T14:45:00+00:00\",\"dateModified\":\"2025-06-21T15:30:04+00:00\",\"breadcrumb\":{\"@id\":\"https:\/\/kriptos.my\/index.php\/2024\/08\/04\/my-sets-of-favourite-pine-codes-for\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/kriptos.my\/index.php\/2024\/08\/04\/my-sets-of-favourite-pine-codes-for\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/kriptos.my\/index.php\/2024\/08\/04\/my-sets-of-favourite-pine-codes-for\/#primaryimage\",\"url\":\"https:\/\/blogger.googleusercontent.com\/img\/b\/R29vZ2xl\/AVvXsEixeQJoEWvXBHjmrz7KFnjebHdM646yeJ7nvLx6zuezA0SpdxrdoLiCsjCryjFxH7f2ER7NiNHBwJjxjZsWtZiC8FjGF_ff6bUrSkq412ZK40vLMJHXvlPhDRowQVKuEThN60_oKHuPDr9NhhlyhXR80gsca5Ot84_6snIKEm-sdl7FaijwNIXoiiHvQeG7\/s320\/pine%20script%20codes%20examples.jpg\",\"contentUrl\":\"https:\/\/blogger.googleusercontent.com\/img\/b\/R29vZ2xl\/AVvXsEixeQJoEWvXBHjmrz7KFnjebHdM646yeJ7nvLx6zuezA0SpdxrdoLiCsjCryjFxH7f2ER7NiNHBwJjxjZsWtZiC8FjGF_ff6bUrSkq412ZK40vLMJHXvlPhDRowQVKuEThN60_oKHuPDr9NhhlyhXR80gsca5Ot84_6snIKEm-sdl7FaijwNIXoiiHvQeG7\/s320\/pine%20script%20codes%20examples.jpg\"},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/kriptos.my\/index.php\/2024\/08\/04\/my-sets-of-favourite-pine-codes-for\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/kriptos.my\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"My sets of favourite pine codes (for easy revision)\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/kriptos.my\/#website\",\"url\":\"https:\/\/kriptos.my\/\",\"name\":\"kriptos.my\",\"description\":\"Trading Bot Enthusiast\",\"publisher\":{\"@id\":\"https:\/\/kriptos.my\/#organization\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/kriptos.my\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Organization\",\"@id\":\"https:\/\/kriptos.my\/#organization\",\"name\":\"kriptos.my\",\"url\":\"https:\/\/kriptos.my\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/kriptos.my\/#\/schema\/logo\/image\/\",\"url\":\"https:\/\/kriptos.my\/wp-content\/uploads\/2025\/06\/cropped-kriptosmy-perkataan.png\",\"contentUrl\":\"https:\/\/kriptos.my\/wp-content\/uploads\/2025\/06\/cropped-kriptosmy-perkataan.png\",\"width\":872,\"height\":199,\"caption\":\"kriptos.my\"},\"image\":{\"@id\":\"https:\/\/kriptos.my\/#\/schema\/logo\/image\/\"}},{\"@type\":\"Person\",\"@id\":\"https:\/\/kriptos.my\/#\/schema\/person\/ab6ae0f7dc407600d321d44b02da9556\",\"name\":\"kriptos\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/kriptos.my\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/a20605acecdd9f3d901b43544301ee4d59d4b1755e81596045ff947403d36442?s=96&d=mm&r=g\",\"contentUrl\":\"https:\/\/secure.gravatar.com\/avatar\/a20605acecdd9f3d901b43544301ee4d59d4b1755e81596045ff947403d36442?s=96&d=mm&r=g\",\"caption\":\"kriptos\"},\"url\":\"https:\/\/kriptos.my\/index.php\/author\/08464702926718497666\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"My sets of favourite pine codes (for easy revision) - kriptos.my","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/kriptos.my\/index.php\/2024\/08\/04\/my-sets-of-favourite-pine-codes-for\/","og_locale":"en_US","og_type":"article","og_title":"My sets of favourite pine codes (for easy revision) - kriptos.my","og_description":"This post is mainly for my own reference actually, so that i could easily come back grab the lines of pine scripts to be inserted into my pine script strategy.Continue ReadingMy sets of favourite pine codes (for easy revision)","og_url":"https:\/\/kriptos.my\/index.php\/2024\/08\/04\/my-sets-of-favourite-pine-codes-for\/","og_site_name":"kriptos.my","article_published_time":"2024-08-04T14:45:00+00:00","article_modified_time":"2025-06-21T15:30:04+00:00","author":"kriptos","twitter_card":"summary_large_image","twitter_misc":{"Written by":"kriptos","Est. reading time":"2 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/kriptos.my\/index.php\/2024\/08\/04\/my-sets-of-favourite-pine-codes-for\/#article","isPartOf":{"@id":"https:\/\/kriptos.my\/index.php\/2024\/08\/04\/my-sets-of-favourite-pine-codes-for\/"},"author":{"name":"kriptos","@id":"https:\/\/kriptos.my\/#\/schema\/person\/ab6ae0f7dc407600d321d44b02da9556"},"headline":"My sets of favourite pine codes (for easy revision)","datePublished":"2024-08-04T14:45:00+00:00","dateModified":"2025-06-21T15:30:04+00:00","mainEntityOfPage":{"@id":"https:\/\/kriptos.my\/index.php\/2024\/08\/04\/my-sets-of-favourite-pine-codes-for\/"},"wordCount":451,"commentCount":0,"publisher":{"@id":"https:\/\/kriptos.my\/#organization"},"image":{"@id":"https:\/\/kriptos.my\/index.php\/2024\/08\/04\/my-sets-of-favourite-pine-codes-for\/#primaryimage"},"thumbnailUrl":"https:\/\/blogger.googleusercontent.com\/img\/b\/R29vZ2xl\/AVvXsEixeQJoEWvXBHjmrz7KFnjebHdM646yeJ7nvLx6zuezA0SpdxrdoLiCsjCryjFxH7f2ER7NiNHBwJjxjZsWtZiC8FjGF_ff6bUrSkq412ZK40vLMJHXvlPhDRowQVKuEThN60_oKHuPDr9NhhlyhXR80gsca5Ot84_6snIKEm-sdl7FaijwNIXoiiHvQeG7\/s320\/pine%20script%20codes%20examples.jpg","keywords":["Pine Script Strategy"],"articleSection":["Pine Script Strategy"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/kriptos.my\/index.php\/2024\/08\/04\/my-sets-of-favourite-pine-codes-for\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/kriptos.my\/index.php\/2024\/08\/04\/my-sets-of-favourite-pine-codes-for\/","url":"https:\/\/kriptos.my\/index.php\/2024\/08\/04\/my-sets-of-favourite-pine-codes-for\/","name":"My sets of favourite pine codes (for easy revision) - kriptos.my","isPartOf":{"@id":"https:\/\/kriptos.my\/#website"},"primaryImageOfPage":{"@id":"https:\/\/kriptos.my\/index.php\/2024\/08\/04\/my-sets-of-favourite-pine-codes-for\/#primaryimage"},"image":{"@id":"https:\/\/kriptos.my\/index.php\/2024\/08\/04\/my-sets-of-favourite-pine-codes-for\/#primaryimage"},"thumbnailUrl":"https:\/\/blogger.googleusercontent.com\/img\/b\/R29vZ2xl\/AVvXsEixeQJoEWvXBHjmrz7KFnjebHdM646yeJ7nvLx6zuezA0SpdxrdoLiCsjCryjFxH7f2ER7NiNHBwJjxjZsWtZiC8FjGF_ff6bUrSkq412ZK40vLMJHXvlPhDRowQVKuEThN60_oKHuPDr9NhhlyhXR80gsca5Ot84_6snIKEm-sdl7FaijwNIXoiiHvQeG7\/s320\/pine%20script%20codes%20examples.jpg","datePublished":"2024-08-04T14:45:00+00:00","dateModified":"2025-06-21T15:30:04+00:00","breadcrumb":{"@id":"https:\/\/kriptos.my\/index.php\/2024\/08\/04\/my-sets-of-favourite-pine-codes-for\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/kriptos.my\/index.php\/2024\/08\/04\/my-sets-of-favourite-pine-codes-for\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/kriptos.my\/index.php\/2024\/08\/04\/my-sets-of-favourite-pine-codes-for\/#primaryimage","url":"https:\/\/blogger.googleusercontent.com\/img\/b\/R29vZ2xl\/AVvXsEixeQJoEWvXBHjmrz7KFnjebHdM646yeJ7nvLx6zuezA0SpdxrdoLiCsjCryjFxH7f2ER7NiNHBwJjxjZsWtZiC8FjGF_ff6bUrSkq412ZK40vLMJHXvlPhDRowQVKuEThN60_oKHuPDr9NhhlyhXR80gsca5Ot84_6snIKEm-sdl7FaijwNIXoiiHvQeG7\/s320\/pine%20script%20codes%20examples.jpg","contentUrl":"https:\/\/blogger.googleusercontent.com\/img\/b\/R29vZ2xl\/AVvXsEixeQJoEWvXBHjmrz7KFnjebHdM646yeJ7nvLx6zuezA0SpdxrdoLiCsjCryjFxH7f2ER7NiNHBwJjxjZsWtZiC8FjGF_ff6bUrSkq412ZK40vLMJHXvlPhDRowQVKuEThN60_oKHuPDr9NhhlyhXR80gsca5Ot84_6snIKEm-sdl7FaijwNIXoiiHvQeG7\/s320\/pine%20script%20codes%20examples.jpg"},{"@type":"BreadcrumbList","@id":"https:\/\/kriptos.my\/index.php\/2024\/08\/04\/my-sets-of-favourite-pine-codes-for\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/kriptos.my\/"},{"@type":"ListItem","position":2,"name":"My sets of favourite pine codes (for easy revision)"}]},{"@type":"WebSite","@id":"https:\/\/kriptos.my\/#website","url":"https:\/\/kriptos.my\/","name":"kriptos.my","description":"Trading Bot Enthusiast","publisher":{"@id":"https:\/\/kriptos.my\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/kriptos.my\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/kriptos.my\/#organization","name":"kriptos.my","url":"https:\/\/kriptos.my\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/kriptos.my\/#\/schema\/logo\/image\/","url":"https:\/\/kriptos.my\/wp-content\/uploads\/2025\/06\/cropped-kriptosmy-perkataan.png","contentUrl":"https:\/\/kriptos.my\/wp-content\/uploads\/2025\/06\/cropped-kriptosmy-perkataan.png","width":872,"height":199,"caption":"kriptos.my"},"image":{"@id":"https:\/\/kriptos.my\/#\/schema\/logo\/image\/"}},{"@type":"Person","@id":"https:\/\/kriptos.my\/#\/schema\/person\/ab6ae0f7dc407600d321d44b02da9556","name":"kriptos","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/kriptos.my\/#\/schema\/person\/image\/","url":"https:\/\/secure.gravatar.com\/avatar\/a20605acecdd9f3d901b43544301ee4d59d4b1755e81596045ff947403d36442?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/a20605acecdd9f3d901b43544301ee4d59d4b1755e81596045ff947403d36442?s=96&d=mm&r=g","caption":"kriptos"},"url":"https:\/\/kriptos.my\/index.php\/author\/08464702926718497666\/"}]}},"jetpack_featured_media_url":"","_links":{"self":[{"href":"https:\/\/kriptos.my\/index.php\/wp-json\/wp\/v2\/posts\/13","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/kriptos.my\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/kriptos.my\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/kriptos.my\/index.php\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/kriptos.my\/index.php\/wp-json\/wp\/v2\/comments?post=13"}],"version-history":[{"count":0,"href":"https:\/\/kriptos.my\/index.php\/wp-json\/wp\/v2\/posts\/13\/revisions"}],"wp:attachment":[{"href":"https:\/\/kriptos.my\/index.php\/wp-json\/wp\/v2\/media?parent=13"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/kriptos.my\/index.php\/wp-json\/wp\/v2\/categories?post=13"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/kriptos.my\/index.php\/wp-json\/wp\/v2\/tags?post=13"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}