Halfband (hi-lo middle) 2024 trading system – in support for investments

Here is the transformation of the the trading system presented on 1.1.2024 in this blog in Prorealcode for Proreal time:

Please notice the very few lines of code

// from sauciusfinance post of 1.1.2024
halfband = (High[n]+low[n])/2

// default n = 1
centry = close CROSSES OVER halfband
centry2 = close > open
// Condizioni per entrare su posizioni long
IF NOT LongOnMarket AND centry and centry2 THEN
BUY 20000 cash AT MARKET
ENDIF
cexit = close CROSSES under halfband
// Condizioni per uscire da posizioni long
If LongOnMarket AND cexit THEN
SELL AT MARKET
ENDIF

// Stop e target: Inserisci qui i tuoi stop di protezione e profit target
set target %profit pr
set stop %loss lo

graphonprice halfband

5,0 / 5
Grazie per aver votato!

Halfband (=hi-lo middle value) Trading System in support for investments (2024)

First of all, Happy New 2024 and a big hug to Japanese friends… we hope all ok for you all.

This is a very effective system in support for entries and exits for swing traders and investments (i.e. if you want not to see graphs everyday but only once or twice per week and you want to keep a position for some days or weeks). This system beats continually the lazy but good “Buy and Hold” for many and many stocks.

Just Trade in these stocks:

  • * Trade stocks with a ROE> 20% (it depends in the purpose of your investments, but you may select a more ambitious 30%, but there are more risks for going lower than going higher). – Tradingview stock screener is a great help for all market (not only U.S. like Finviz) – Do not regard of any other indicator, like P/E, analysts’ opionions and target price and so on. The behaviour of the market is collapsed into prices movements, and in this technical analsys
  • * Entry when close overcomes the average of the high and low of the last but one bar on weekly chart (=so called “Halfband“). There is a filter of a “green bar” (close > open) for the last bar, i.e. the overcome should not due to a so low level of the halfband (typical in falling markets).
  • * Since in the trading system the order are placed at the opening of the next bar, but the instructions calc_on_order_fills=true is critical, before entry a position check only if the monday’s open (or of first day of the week of market opened) is not below “Haldfband”. Otherwise, stay flat

EXIT the market

  • * in case of a fixed stop loss (risk management), in trading system = 7%
  • * if close is under Haldfband.

The system is very simple, but effective. You don’t need any I.A. or trading machines to implement it. You may do it manually and take into observation dozens of stocks, since analysis is very quick and collapsed in just one or two moment a week.

TRADINGVIEW CODE (fundamental passages are in bold)

//@version=5

strategy(title=’Halfband 2 W_lo’, overlay=true, precision=4, calc_on_order_fills=true, calc_on_every_tick =true, default_qty_type=strategy.percent_of_equity, default_qty_value=100, initial_capital=20000, currency=currency.EUR, commission_type=strategy.commission.percent, commission_value=0.25)

period_ = input.int(1, title=”Length”, minval=1)

halfband = (high[period_]+low[period_])/2

plot(halfband, title=”halfband”, color=color.rgb(243, 222, 33), linewidth = 2, style=plot.style_stepline, precision = 4)

// === INPUT BACKTEST RANGE ===

fromMonth =  input.int (defval = 1, title = “From Month”, minval = 1, maxval = 12)

fromDay =  input.int (defval = 1, title = “From Day”, minval = 1,maxval = 31)

fromYear = input.int(defval = 2022, title = “From Year”,   minval = 1970)

thruMonth = input.int(defval = 1,    title = “Thru Month”,  minval = 1, maxval = 12)

thruDay   = input.int(defval = 1,    title = “Thru Day”,    minval = 1, maxval = 31)

thruYear  = input.int(defval = 2112, title = “Thru Year”,   minval = 1970)

// === FUNCTION EXAMPLE limit for backtest ===

start     = timestamp(fromYear, fromMonth, fromDay, 00, 00)            // backtest start  window

finish    = timestamp(thruYear, thruMonth, thruDay, 23, 59)            // backtest finish window

window()  => time >= start and time <= finish ? true : false           // create function “within window of time”

// entries: version 2 variant is here, in xentryl

Entry1= ta.crossover(close, halfband) and window()

Entry2 = close> open

xentryl = Entry1 and Entry2

xentrys = ta.crossunder(close, halfband) and window()

strategy.entry(‘Long’, strategy.long, when= xentryl)

strategy.close(‘Long’, when=xentrys, comment=’change’)

// MONEY MANAGEMENT

lossp = input.float(7, minval=1, step=1)

losspel = strategy.position_avg_price * (1 – lossp / 100)

fixed_stop_long = close < losspel

strategy.close(‘Long’, when=fixed_stop_long, comment = ‘Stop loss’)

5,0 / 5
Grazie per aver votato!

Parabolic Sar trading system code ..for “a new life” (easy and profitable) – Tradingview e ProrealTime coding

Just a simple Parabolic Sar to make your life easy..

PROREALTIME TRADING SYSTEM CODE// Definizione dei parametri del codice
DEFPARAM CumulateOrders = False // Posizioni cumulate disattivate

// Condizioni per entrare su posizioni long
indicator1 = SAR[0.02,0.02,0.2]
c1 = (close CROSSES OVER indicator1)
c2 = (close >= DOpen(0))
// c2 is “green bar” condition
c3 = (close >= DHigh(1))

IF c1 AND c2 AND c3 THEN
BUY 20000 CASH AT MARKET
ENDIF

// Condizioni per uscire da posizioni long
indicator2 = SAR[0.02,0.02,0.2]
c4 = (close CROSSES UNDER indicator2)
indicator3 = SAR[0.02,0.02,0.2]
c5 = (close <= indicator3[1])

IF c4 AND c5 THEN
SELL AT MARKET
ENDIF

// no other money management

PROREALTIME SCREENER (you can use it once a week, for instance, not everyday)

indicator1 = SAR[0.02,0.02,0.2]
// you have to write every cicle, since Proscreener doesn’t “read” cycle instruction “for.. to”

// giorno oggi
C1 = (close CROSSES OVER indicator1)
c2 = (close > high[1])
c3 = (close > open)
c4 = (c1 and c2 and c3)
if c4 then
i = 0
endif
// ieri
C10 = (close[1] CROSSES OVER indicator1[1])
c20 = (close[1] > high[2])
c30 = (close[1] > open[1])
c40 = (c10 and c20 and c30)
if c40 then
i = 1
endif
// 2 giorni fa
C100 = (close[2] CROSSES OVER indicator1[2])
c200 = (close[2] > high[3])
c300 = (close[2] > open[2])
c400 = (c100 and c200 and c300)
if c400 then
i = 2
endif
// 3 giorni fa
C1000 = (close[3] CROSSES OVER indicator1[3])
c2000 = (close[3] > high[4])
c3000 = (close[3] > open[3])
c4000 = (c1000 and c2000 and c3000)
if c4000 then
i = 3
endif
// 4 giorni fa
C10000 = (close[4] CROSSES OVER indicator1[4])
c20000 = (close[4] > high[5])
c30000 = (close[4] > open[4])
c40000 = (c10000 and c20000 and c30000)
if c40000 then
i = 4
endif
// 5 giorni fa
C100000 = (close[5] CROSSES OVER indicator1[5])
c200000 = (close[5] > high[6])
c300000 = (close[5] > open[5])
c400000 = (c100000 and c200000 and c300000)
if c400000 then
i = 5
endif
// 6 giorni fa
C1000000 = (close[6] CROSSES OVER indicator1[6])
c2000000 = (close[6] > high[7])
c3000000 = (close[6] > open[6])
c4000000 = (c1000000 and c2000000 and c3000000)
if c4000000 then
i = 6
endif
SCREENER[c4 or c40 or c400 or c4000 or c40000 or c400000 or c4000000] (i as “day”, volume as “volume”)

TRADINGVIEW TRADING SYSTEM

//@version=5
// versione 20 redatta 1702 2022
strategy(‘psar_newlife_2023’, calc_on_order_fills=false, calc_on_every_tick=true, commission_type=strategy.commission.percent, commission_value=0.3, overlay=true, default_qty_type=strategy.cash, default_qty_value=20000, initial_capital=20000)
// === INPUT BACKTEST RANGE ===
fromMonth = input.int (defval = 1, title = “From Month”, minval = 1, maxval = 12)
fromDay = input.int (defval = 1, title = “From Day”, minval = 1,maxval = 31)
fromYear = input.int(defval = 2017, title = “From Year”, minval = 1970)
thruMonth = input.int(defval = 1, title = “Thru Month”, minval = 1, maxval = 12)
thruDay = input.int(defval = 1, title = “Thru Day”, minval = 1, maxval = 31)
thruYear = input.int(defval = 2112, title = “Thru Year”, minval = 1970)
// === FUNCTION EXAMPLE limit for backtest ===
start = timestamp(fromYear, fromMonth, fromDay, 00, 00) // backtest start window
finish = timestamp(thruYear, thruMonth, thruDay, 23, 59) // backtest finish window
window() => time >= start and time <= finish ? true : false // create function “within window of time”

//INDICATORI
startsar = input(0.02, “Inizio Sar”)
increment = input(0.02, “Incremento Sar”)
maximum = input(0.2, “Max Sar”)
mysar = ta.sar(startsar, increment, maximum)
plot(mysar, “ParabolicSAR”, linewidth=2, style=plot.style_cross, color=#2962FF)
//sistema (come prorealtime)
c1 = ta.crossover(close,mysar)
c2 = close > open
c3 = close > high[1]
entryl = (c1 and c2 and c3)
strategy.entry(‘Long’, strategy.long, when=entryl)
c4 = ta.crossunder(close,mysar)
c5 = (close < mysar[1])
exit = (c4 and c5)
strategy.close(‘Long’, when=exit)
// altri disegni
mysma = ta.sma(ohlc4,20)
plot(mysma, title=’Media mob’, color = color.rgb(238, 0, 255), linewidth=1, style=plot.style_line)
//Go Saucius Go!!

————————————————————————–

/ 5
Grazie per aver votato!

Strategy Pine Script™ – Triband_Long Only for supporting Investments

Tradingview: guide for beginners

Investors very often correctly select stocks using fundamental analysis. However, the strategy suffers from shortcomings from a “momentum” perspective.
This simply system – which I recommend applying on a monthly basis – is simple and very effective: it uses a simple average of the opening, maximum and minimum of the currentmonth’s candle and compares it with the closing of the current month. If prices are higher than this average you enter/stay in the market, otherwise you exit. Since it is designed to support investment, short operations are not foreseen. In this way the performance compared to simple buy & hold is much improved.
If you want no to use strictly the strategy, however you may check week by week how prices are distant from this average.
You may also decide the period for backtesting.

CODE

//@version=5

strategy(title=’Triband_Long Only for Investments’, overlay=true, precision=4, calc_on_order_fills=true, calc_on_every_tick =true, default_qty_type=strategy.percent_of_equity, default_qty_value=20, initial_capital=100000, currency=currency.EUR, commission_type=strategy.commission.percent, commission_value=0.25)
// by Sauciusfinance

period_ = input.int(1, title=”Length”, minval=1)
halfband = (high[period_]+low[period_]+open[period_])/3
plot(halfband, title=”halfband”, color=color.blue, linewidth = 2, style=plot.style_stepline)

// === INPUT BACKTEST RANGE ===
fromMonth = input.int (defval = 1, title = “From Month”, minval = 1, maxval = 12)
fromDay = input.int (defval = 1, title = “From Day”, minval = 1,maxval = 31)
fromYear = input.int(defval = 2019, title = “From Year”, minval = 1970)
thruMonth = input.int(defval = 1, title = “Thru Month”, minval = 1, maxval = 12)
thruDay = input.int(defval = 1, title = “Thru Day”, minval = 1, maxval = 31)
thruYear = input.int(defval = 2112, title = “Thru Year”, minval = 1970)
// === FUNCTION EXAMPLE limit for backtest ===
start = timestamp(fromYear, fromMonth, fromDay, 00, 00) // backtest start window
finish = timestamp(thruYear, thruMonth, thruDay, 23, 59) // backtest finish window
window() => time >= start and time <= finish ? true : false // create function “within window of time”

// entries

xentryl = ta.crossover(close, halfband) and window()
xentrys = ta.crossunder(close, halfband) and window()

strategy.entry(‘Long’, strategy.long, when= xentryl, comment=’apri’)

strategy.close(‘Long’, when=xentrys, comment=’chiudi’)
// MONEY MANAGEMENT
lossp = input.float(8, minval=1, step=1)
losspel = strategy.position_avg_price * (1 – lossp / 100)
fixed_stop_long = close < losspel
strategy.close(‘Long’, when=fixed_stop_long, comment = ‘Stop loss’)

/ 5
Grazie per aver votato!

Trading system classici, automatici vs nuovi indicatori – Classical, automatic trading systems vs new indicators

Trading yesterday and today: considerations of trading systems and on the work done in the last 4 years

Perhaps this is the most important post of all: as you can see in my blog over the past 4 years I have “translated” in ProRealTime code all the newest proposed indicators of Stocks & Commodities, magazine “leader” in technical analysis.

Why only the “Indicators” (with the concerning section of S & C)?
1 Because are the quickest and rational (ie quantifiable) device to analyze a market
2 Because the so-called “figures” are always subject to the discretion and human interpretation (unless massive simplifications that can be misleading)
3 Because, therefore, money management can be managed in a rational manner since it’s written in formula.

I have developed a trading system, periodically updated, in order to “capture” the beginning of a trend and to “stay” in position until the end, maximizing profits and minimizing errors in input and output, as well as any false signals.

The result was certainly a good system … but suitable for “secondary” daily trends (non-primary), as well as non-adaptable (at least easily) to automated trading.

Instead, the use of classic indicators, in particular for the Italian market (but also for the German and American one), led to the construction of a simple trading system, especially shared by operators since it refers to the indicators known to the public (MACD and SAR).
My job was simply to adapt the parameters of these indicators to the target market.

The logic is the following (very simple):
Open position (long or short) when prices (usually, closing) crosses the SAR (under the constraint that prices are above / below the 20-period moving average)
– Close (and reverse) position if prices cross the SAR or the moving average or if the lines of the MACD cross

Usually the authors of technical analysis follow a contrary rule, using the indicators MACD for open positions and SAR as stop loss, but so it distorts the logic with which it was born the Parabolic SAR.

A more “dynamic”system – in the course of testing (with good anticipations) –  consists in opening positions on the basis of the histogram of the MACD (and not on the basis of its lines as before) when they reach the points of maximum and local minimum.
In detail, long positions should be opened as soon as the MACD histogram retraces from the minimum (ie, begins to grow), even if the prices are below the SAR or the MMA20.
Vice-versa for short positions.
The closure and the reversal of portfolio follow the same rule, in reverse.
This technique is based on the local maxima / minima of the MACD can generate false signals on the 1st retracing (so … be careful!) but it is infallible on 2nd tracing, that is, you are “armored” when you see the so-called figure of the (double) camel hump.

The standard parameters are as follows:

– SAR: 0.01, 0.01, 0.1 with a best version (best) with acceleration factor 0.02 or 0.03  (for inputs and outputs a bit ‘more’ tempestive2)
– MACD: 9,15,10 but also in the classic version (12,26,9) or 11,3,5 (for fast trading) or 11,15,9

[see DAX and FTSEMIB charts]

In conclusion, it is sufficient to set the parameters of SAR and MACD and the game is done (for all markets and all time frames): we have much lighter trading system, – I repeat – “shared” and no substantial differences in profit.
Why this result? Because the environment (domain) in which we operate, ie the data provided by the market and then to the brokers and finally to individuals, it is – as you know – very “poor”: O, H, L, C and volume, but nothing more.
Even the linear treatment through the various indicators of these numbers can not offer, therefore, so “different” results or offer “quantum leaps” in the analysis.

OPERATIONAL NOTES
In the next posts I will indicate some formulations of trading system:
– A suggestion (and sometimes necessity) is to create by yourself formulas for a single line of MACD or its histogram (in order to recall them in the trading system without errors).
– The points of local maximum and minimum can be found with the inverse cotangent (see previous post), function unfortunately not supported in ProRealTime.
The adaptation of the system of “camel humps”, as described above, also using functions that calculate the differences of the MACD histogram, can not find a faithful representation in automated trading system, but it must be implemented only through manual trading .

/ 5
Grazie per aver votato!

Another “investing” trading system on weekly base

In a recent post I’ve published a strategy based upon a monthly pattern.
Good results, but if you want more gains (thus increasing a bit also risks) you may diminish the temporal frame, going into a weekly pattern.
These are the proposed indicators:
 – the “queen”  20-periods moving average (for determining the trend), placed side by side with the 50-periods moving average for determining levels of support and target;
– parabolic sar is used more than keeping position, for fixing “middle” target levels for long/short positions; 
– more “indicative” than psar, is 11-periods RSI, where overcoming the upper/lower bands give a good signal for exiting positions (and therefore a new entrance).
Below some examples (realized on m.prorealtime.com, where the instrument of automatic draw of oblique lines is very useful).
Patter is very easy and works weel with a huge variety of financial instruments (indexes, shares, etc.). The real confirm of the trend is simply the crossing up or down the 20-periods moving average. 
FTSEMIB (Italy)
Comment: Long structure since april 2016: we entered on the reversing of p-sar if we assume a “speculative” approach or, a bit after, on the crossing of the blue line (20-periods mov.avg.). RSI has revealed many “local” stop profit targets (no. 3); this instruments also helps for identifying clearl throwback towards the blue line. 
Recently, the support of 50-p. mov. avg. has avoided the formation of a short structure.
CAC- ALL SHARES (France)
Comment – Very strong long signal in the same period of the previous picture in 2016; no points of uncertainty on keeping long in the last year and half; RSI may have revealed some points of target profit. 
The throwbacks has been always limited to the support of p-sar line or 20-p. mov. avg. 
Simplifying more and more, another conclusion of this pattern is that for reaching good results you may use only 20 and 50 periods moving averages and then comparing the distance among them and the current close and/or the movements of the single/lat 2-3 bars.
I.e.: if the prices are very “distant” to the 20-p. mov. avg. you should except a correction (the probability increases each bar), that may start with a “violent” movement or confirmed by the “lighter” movement of the last 2/3 bars.
In the PAX pictures, there a no strong retracements because prices are increasing steadily: the 20 moving average seems to accompany prices.
L’OREAL (SHARES)

​ 

Comment long from February/March 2016. Clear target in zone 185-190 (see RSI). The decrease of RSI and the support of 50-p. mov. avg. in december 2017 have averted a worsening of the technical framework. Now we are in an oscillating period (use both 20-p. and p-sar for estabilishing levels). Maybe a short period will come soon  

/ 5
Grazie per aver votato!

Finding the maximum and minimum of an indicator

Many indicators (like hystogram of the Macd) reach important levels of local maxima/minima that could be useful for trader.
While manual trading does not need a precise formula for finding these levels (since they are visible to the human eye), on the other hand we must define a formula when approaching authomatic trading.

In this field, trigonometrical operators suit at the best sinusoidal function. In simple terms, you have to apply ARCOCOTANGENT formula to your indicator (e.g. Arcctan(Macd_hystogram)).

The Arcctan has the property of reaching level of -n or + n (depending on single situation), when respectvely the indipendent function (= your indicator) reaches local max or min.
This proxy is necessary because many trading programs naturally don’t support the calculation of derivatives function.

So writing a rule when the system has to open/close a position when absolute levels of n are reached is your easy last step.

Unfortunately, ProRealTime supports very few trigonometric function, i.e. sine, cosine, tangent, arctan.

In Tradingview, insted, you have the possibility of using such trigonometric functions.

/ 5
Grazie per aver votato!

Avaible for programming in Tradingview and Prorealtime

Hi everybody!! 🍾 
I’ve been contacted by many people after publishing Aroon’s Oscillator Tradingview Strategy (https://www.tradingview.com/script/s462P5NL/?amp
I am avaible, under payment of few euros, to personalization to this strategy and to develop indicators and backtests in
– Prorealtime
– Tradingview
Please, for any request,  please complete the contact form in the blog
Bye! 🖐️
———-————————————————-
Italiano 🇮🇹 

Ciao a tutti !! Sono stato contattato da molte persone dopo aver pubblicato la strategia Oscillator Tradingview di Aroon (https://www.tradingview.com/script/s462P5NL/?amp) Sono disponibile, dietro pagamento di pochi euro, alla personalizzazione di questa strategia e allo sviluppo di indicatori e backtests in 
– Prorealtime 
– Tradingview 

Per ogni richiesta, prego completate il form di contatto nel blog
Ciao! ️

/ 5
Grazie per aver votato!

“Revenge trading system” 2019 Strategy in Tradingview – use Triangular M.A. Bands (moving bands) like a trading system

TRADINGVIEW CODE

This system is long only, given the temporary extension of market of being long and not short (in extension ,you can prove to develp an inverse t.s. for short case)
————————————————————————-
//@version=2
////////////////////////////////////////////////////////////
//  Copyright by Saucius, 2019
////////////////////////////////////////////////////////////
strategy(title=”Revenge Long Saub bands only shares easy”,overlay = true,max_bars_back=2000)
Length = input(9, minval=1)
m = input(0.9, minval = 0.1, step = 0.1)
l1 = Length/2
l2 = round(l1)
l3 = Length – l2
TRIMH = sma(sma(high, l2), l3)
TRIML = sma(sma(low, l2), l3)
xHighBand = (1+m/100) * TRIMH
xLowBand = (1-m/100) * TRIML
halfband = (xHighBand + xLowBand)/2
// classical entry: like Keltner Channel, when close breaks upper Band
strategy.entry(“Long”, true, when=crossover(close,xHighBand))
// entry #2 from  the bottom: 2 closes upon inferior band. This means: if prices are lower than the Lower Band and the close confirms consecutevely twice to be over, it’s a good entry point, even if the trend is not clear again.
entry2 = close[2]<xLowBand[2] and close[1]>xLowBand[1] and close>xLowBand
strategy.entry(“Long”, true, when= entry2)
// exit at market cases:
//1. classical exit (like Keltner Channel, when prices are under the lower band
//2. “moderated” exit : when close is confirmed twice under the halfband (halfband is quite similar to a moving average)
//3. “scalping” exit: when prices retrace or go under the HigherBand. This exit is warmly suggested when you have opened in the #2 way, “from the bottom”, since it’s probable that there is a godd gain yet.
//. 4 when CCI reaches extreme values (you don’t need any confirm that prices are high enough)
// exit 2 = 2 close under halfband
exit2 = close[1] < halfband[1] and close < halfband
strategy.close(“Long”, when=crossunder(close, xHighBand))
strategy.close(“Long”, when=crossunder(close,halfband))
strategy.close(“Long”, when=crossunder(close, xLowBand))
//
CCIX = cci(close,20)
strategy.close(“Long”, when= (CCIX > 200 ))
———————–
GOOD TRADE and let me know if you lieke My Bands!!!

5,0 / 5
Grazie per aver votato!

Slow trading with Heikin Ashi

 In my experience I used Heikin Ashi candles even with the use of standard technical indicators.

The use of the smoothing of these candles below (as per formulas that for convenience I report at the bottom) serves to reduce noise, especially if you do it on a monthly basis. Given the time horizon of the candle, this “slow trading” is suitable for those who want to make investments trying to

·        Don’t be stressed about looking at monitors too much

·        Also use fundamental analysis and without being a “slave” to news and rumors

·        Making investments more than short-term trading.

 

 

In this period of my life where with a family I need more tranquility, I feel very good with this type of investment. Just one view once or 2 times a month

For a higher portfolio yield I also select Small and Mid Cap that I already know (so without too much need to look for news).

In order to screen some more shares, you can also click on the “flame” symbol on Tradingview.

 

Usually the change of a short (long) trend is highlighted by the lack of new monthly lows (highs): in this case it is necessary to place for the following month a sell order just below the maximum (minimum) previously reached.

 

 

Already from mid / 20 of the month the candle is sufficiently formed and it is possible to see the first results (possibly proceed with 50% pyramidal methodology and rest 50% of the target value to be invested by the end of the month).

ALTERNATIVELY

you can use a WEEKLY system

·        with input to the first green bar with a significant variation (> 1% leverage 1)

·        Close with the first red bar

·        “oriented” with a moving average of 11 on H-Ashi on hlc3 (and not on ideal values) to understand “where you are” and how far you are from the average

·        “integrates” this “stupid” system that usually works with the news/ “humor” (not rumor) of the moment

 

Heikin Ashi formulas

Heikin-Ashi Opening = [Aperture (Previous Bar) + Close (Previous Bar)] / 2

Heikin-Ashi Closing = (Opening + High + Minimum + Closing) / 4

Maximum Heikin-Ashi = Max (Maximum, Opening or Closing)

Heikin-Ashi Minimum = Min (Minimum, Open or Close)

Monthly graph

Weekly chart

/ 5
Grazie per aver votato!