ProRealCode - Trading & Coding with ProRealTime™
Avrei un immenso favore da chiedervi, ovvero di tradurre queste idee in codice. Sto usando molto la piattaforma prorealtime, ma faccio ancora fatica a trascrivere le strategie in codice, spero possiate comprendermi.
Vi lascio in allegato il pdf con le idee di trading System.
Grazie in anticipo.
Piano piano si possono fare, in parte.
Renko è possibile, ma i mattoncini non sono quelli di ProrealTime, in quanto per le strategie si possono usare solo TF a tempo; qjuindi vanno adattati al tempo e non sono sempre identici, perchè tra una candela e l’altra non ci possono essere gli stessi Pips. Se vuoi avere un’dea di come sono costruiti e di strategie basta che cerchi RENKO sul forum utilizzando l’apposita casella di ricerca che si apre quando passi sopra il tuo avatar sulla barra blù in alto a destra. Inoltre, siccome ogni volta partono da barre iniziali diverse, i risultati dei backtest non sranno mai uguali.
Point & Figure non credo si possano simulare, non l’ho mai fatto.
Nei prossimi giorni ti farò sapere.
Quale indicatore di frattali usi?
innanzitutto grazie per la riposta Roberto, poi scusami per la mia ignoranza ma cosa intendi con “quale indicatore di frattali”?
Ci sono vari indicatori di frattali. Comunque userò quello che mi sembra migliore.
FRATTALI
————
L’ho provato sul DAX (Daily, 1h, 30min TF’s); per il trailing stop ho usato il codice di Nicolas:
// Frattali
//
// https://www.prorealcode.com/topic/trading-system-1-1/
//
// basato sull'ndicatore:
//
// https://www.prorealcode.com/prorealtime-indicators/bill-williams-fractals/)
//
DEFPARAM CumulateOrders = False
//
cp = 2 //2 (default)
LH = 0
LL = 0
if high[cp] >= highest[2*cp+1](high) then
LH = 1
endif
if low[cp] <= lowest[2*cp+1](low) then
LL= -1
endif
//
IF LL < 0 AND Not LongOnMarket THEN
BUY 1 CONTRACT AT MARKET
ELSIF LH > 0 AND Not ShortOnMarket THEN
SELLSHORT 1 CONTRACT AT MARKET
ENDIF
//*********************************************************************************
// https://www.prorealcode.com/blog/trading/complete-trailing-stop-code-function/
// (righe 17- 56), with the addition of DISTANCE
//
//trailing stop function
trailingstart = 25 //20 trailing will start @trailinstart points profit
trailingstep = 25 //25 trailing step to move the "stoploss"
distance = 10 //10 pips distance from caurrent price (if required by the broker)
//reset the stoploss value
IF NOT ONMARKET THEN
newSL=0
ENDIF
//manage long positions
IF LONGONMARKET THEN
//first move (breakeven)
IF newSL=0 AND close-tradeprice(1)>=trailingstart*pipsize THEN
newSL = tradeprice(1)+trailingstep*pipsize
ENDIF
//next moves
IF newSL>0 AND close-newSL>=trailingstep*pipsize THEN
newSL = newSL+trailingstep*pipsize
ENDIF
ENDIF
//manage short positions
IF SHORTONMARKET THEN
//first move (breakeven)
IF newSL=0 AND tradeprice(1)-close>=trailingstart*pipsize THEN
newSL = tradeprice(1)-trailingstep*pipsize
ENDIF
//next moves
IF newSL>0 AND newSL-close>=trailingstep*pipsize THEN
newSL = newSL-trailingstep*pipsize
ENDIF
ENDIF
//stop order to exit the positions
IF newSL>0 THEN
IF LongOnMarket THEN
IF (close + distance) > newSL THEN
SELL AT newSL STOP
ELSIF (close - distance) < newSL THEN
SELL AT newSL LIMIT
ELSE
SELL AT Market
ENDIF
ELSIF ShortOnmarket THEN
IF (close + distance) < newSL THEN
EXITSHORT AT newSL STOP
ELSIF (close - distance) > newSL THEN
EXITSHORT AT newSL LIMIT
ELSE
EXITSHORT AT Market
ENDIF
ENDIF
ENDIF
//*********************************************************************************
Grazie mille Roberto
RENKO
———
Provato sul DAX, 5 minuti:
// Renko
//
// https://www.prorealcode.com/topic/initialising-renko-charts/#post-131050
//
once boxsize = 50 * pointsize //50
once renkoMax = ROUND(close / boxSize) * boxSize
once renkoMin = renkoMax - boxSize
IF close crosses over renkoMax + boxSize THEN
WHILE close > renkoMax + boxSize
renkoMax = renkoMax + boxSize
renkoMin = renkoMin + boxSize
Bullish = 1
Bearish = 0
WEND
ELSIF close crosses under renkoMin - boxSize THEN
WHILE close < renkoMin - boxSize
renkoMax = renkoMax - boxSize
renkoMin = renkoMin - boxSize
Bullish = 0
Bearish = 1
WEND
ENDIF
IF Bullish AND Not LongOnMarket THEN
BUY 1 CONTRACT AT MARKET
ENDIF
IF Bearish AND Not ShortOnMarket THEN
SELLSHORT 1 CONTRACT AT MARKET
ENDIF
//*********************************************************************************
// Nicolas'code (with the addition of DISTANCE)
//
// https://www.prorealcode.com/blog/trading/complete-trailing-stop-code-function/
// (righe 17- 56)
//
//trailing stop function
IF (BarIndex - TradeIndex) >= 0 THEN //0
trailingstart = 25 //25 trailing will start @trailinstart points profit
trailingstep = 25 //10 trailing step to move the "stoploss"
distance = 10 //10 pips distance from caurrent price (if required by the broker)
//reset the stoploss value
IF NOT ONMARKET THEN
newSL=0
ENDIF
//manage long positions
IF LONGONMARKET THEN
//first move (breakeven)
IF newSL=0 AND close-tradeprice(1)>=trailingstart*pipsize THEN
newSL = tradeprice(1)+trailingstep*pipsize
ENDIF
//next moves
IF newSL>0 AND close-newSL>=trailingstep*pipsize THEN
newSL = newSL+trailingstep*pipsize
ENDIF
ENDIF
//manage short positions
IF SHORTONMARKET THEN
//first move (breakeven)
IF newSL=0 AND tradeprice(1)-close>=trailingstart*pipsize THEN
newSL = tradeprice(1)-trailingstep*pipsize
ENDIF
//next moves
IF newSL>0 AND newSL-close>=trailingstep*pipsize THEN
newSL = newSL-trailingstep*pipsize
ENDIF
ENDIF
//stop order to exit the positions
IF newSL>0 THEN
IF LongOnMarket THEN
IF (close + distance) > newSL THEN
SELL AT newSL STOP
ELSIF (close - distance) < newSL THEN
SELL AT newSL LIMIT
ELSE
SELL AT Market
ENDIF
ELSIF ShortOnmarket THEN
IF (close + distance) < newSL THEN
EXITSHORT AT newSL STOP
ELSIF (close - distance) > newSL THEN
EXITSHORT AT newSL LIMIT
ELSE
EXITSHORT AT Market
ENDIF
ENDIF
ENDIF
ENDIF
//*********************************************************************************
Grazie mille Roberto, sempre disponibile. Buona serata
Ecco il terzo (l’ho provato sul DAX, Giornaliero):
// HA & AO
//
// https://www.prorealcode.com/topic/initialising-renko-charts/#post-131050
//
// definizione Heikin-Ashi
ONCE xOpen = open
xClose = (Open + High + Low + Close) / 4
IF BarIndex > 0 THEN
xOpen = (xOpen[1] + xClose[1]) / 2
ENDIF
Bullish = xClose > xOpen //HA rialzista
Bearish = xClose < xOpen //HA ribassista
// definizione dell'Awesome Oscillator
ONCE FastMM = 5 //5 Fast Average
ONCE SlowMM = 34 //34 Slow Average
//AO = Average[FastMM,0](xClose) - Average[SlowMM,0](xClose) //AO con Heikin-Ashi
AO = Average[FastMM,0](close) - Average[SlowMM,0](close) //AO normale
BullAO = AO > AO[1] //AO rialzista
BearAO = AO < AO[1] //AO ribassista
// entrtata LONG
IF Bullish AND BullAO AND Not LongOnMarket THEN
BUY 1 CONTRACT AT MARKET
ENDIF
// entrata SHORT
IF Bearish AND BearAO AND Not ShortOnMarket THEN
SELLSHORT 1 CONTRACT AT MARKET
ENDIF
//*********************************************************************************
// Nicolas'code (with the addition of DISTANCE)
//
// https://www.prorealcode.com/blog/trading/complete-trailing-stop-code-function/
// (righe 17- 56)
//
//trailing stop function
IF (BarIndex - TradeIndex) >= 0 THEN //0
trailingstart = 25 //25 trailing will start @trailinstart points profit
trailingstep = 25 //10 trailing step to move the "stoploss"
distance = 10 //10 pips distance from caurrent price (if required by the broker)
//reset the stoploss value
IF NOT ONMARKET THEN
newSL=0
ENDIF
//manage long positions
IF LONGONMARKET THEN
//first move (breakeven)
IF newSL=0 AND close-tradeprice(1)>=trailingstart*pipsize THEN
newSL = tradeprice(1)+trailingstep*pipsize
ENDIF
//next moves
IF newSL>0 AND close-newSL>=trailingstep*pipsize THEN
newSL = newSL+trailingstep*pipsize
ENDIF
ENDIF
//manage short positions
IF SHORTONMARKET THEN
//first move (breakeven)
IF newSL=0 AND tradeprice(1)-close>=trailingstart*pipsize THEN
newSL = tradeprice(1)-trailingstep*pipsize
ENDIF
//next moves
IF newSL>0 AND newSL-close>=trailingstep*pipsize THEN
newSL = newSL-trailingstep*pipsize
ENDIF
ENDIF
//stop order to exit the positions
IF newSL>0 THEN
IF LongOnMarket THEN
IF (close + distance) > newSL THEN
SELL AT newSL STOP
ELSIF (close - distance) < newSL THEN
SELL AT newSL LIMIT
ELSE
SELL AT Market
ENDIF
ELSIF ShortOnmarket THEN
IF (close + distance) < newSL THEN
EXITSHORT AT newSL STOP
ELSIF (close - distance) > newSL THEN
EXITSHORT AT newSL LIMIT
ELSE
EXITSHORT AT Market
ENDIF
ENDIF
ENDIF
ENDIF
//*********************************************************************************
Ecco il quarto (provato sul DAX, h1):
// Renko & Frattali
//
// https://www.prorealcode.com/topic/trading-system-1-1/
//
DEFPARAM CumulateOrders = False
//------------------------------------------------------------------------------------
// frattali
cp = 2 //2 (default)
BullFractal = 0
BearFractal = 0
if high[cp] >= highest[2*cp+1](high) then
BullFractal = 1
endif
if low[cp] <= lowest[2*cp+1](low) then
BearFractal = 1
endif
//------------------------------------------------------------------------------------
// Renko boxes
once boxsize = 50 * pointsize //50
once renkoMax = ROUND(close / boxSize) * boxSize
once renkoMin = renkoMax - boxSize
Bullish = 0
Bearish = 0
IF close crosses over renkoMax + boxSize THEN
WHILE close > renkoMax + boxSize
renkoMax = renkoMax + boxSize
renkoMin = renkoMin + boxSize
Bullish = 1
WEND
ELSIF close crosses under renkoMin - boxSize THEN
WHILE close < renkoMin - boxSize
renkoMax = renkoMax - boxSize
renkoMin = renkoMin - boxSize
Bearish = 1
WEND
ENDIF
//------------------------------------------------------------------------------------
//
IF BullFractal AND Bullish AND Not LongOnMarket THEN
BUY 1 CONTRACT AT MARKET
ELSIF BearFractal AND Bearish AND Not ShortOnMarket THEN
SELLSHORT 1 CONTRACT AT MARKET
ENDIF
// uscita Long
IF Bullish AND LongOnMarket THEN //uscire al primo mattoncino inverso dopo l'entrata
SELL AT Market
ENDIF
// uscitaShort
IF Bearish AND ShortOnMarket THEN //uscire al primo mattoncino inverso dopo l'entrata
SELL AT Market
ENDIF
//*********************************************************************************
// https://www.prorealcode.com/blog/trading/complete-trailing-stop-code-function/
// (righe 17- 56), with the addition of DISTANCE
//
//trailing stop function
trailingstart = 25 //20 trailing will start @trailinstart points profit
trailingstep = 25 //25 trailing step to move the "stoploss"
distance = 10 //10 pips distance from caurrent price (if required by the broker)
//reset the stoploss value
IF NOT ONMARKET THEN
newSL=0
ENDIF
//manage long positions
IF LONGONMARKET THEN
//first move (breakeven)
IF newSL=0 AND close-tradeprice(1)>=trailingstart*pipsize THEN
newSL = tradeprice(1)+trailingstep*pipsize
ENDIF
//next moves
IF newSL>0 AND close-newSL>=trailingstep*pipsize THEN
newSL = newSL+trailingstep*pipsize
ENDIF
ENDIF
//manage short positions
IF SHORTONMARKET THEN
//first move (breakeven)
IF newSL=0 AND tradeprice(1)-close>=trailingstart*pipsize THEN
newSL = tradeprice(1)-trailingstep*pipsize
ENDIF
//next moves
IF newSL>0 AND newSL-close>=trailingstep*pipsize THEN
newSL = newSL-trailingstep*pipsize
ENDIF
ENDIF
//stop order to exit the positions
IF newSL>0 THEN
IF LongOnMarket THEN
IF (close + distance) > newSL THEN
SELL AT newSL STOP
ELSIF (close - distance) < newSL THEN
SELL AT newSL LIMIT
ELSE
SELL AT Market
ENDIF
ELSIF ShortOnmarket THEN
IF (close + distance) < newSL THEN
EXITSHORT AT newSL STOP
ELSIF (close - distance) > newSL THEN
EXITSHORT AT newSL LIMIT
ELSE
EXITSHORT AT Market
ENDIF
ENDIF
ENDIF
//*********************************************************************************
Ecco il quinto ed ultimo codice (è la strategia scritta da verdi55 https://www.prorealcode.com/prorealtime-trading-strategies/point-figure-charts-automated-trading-system/, con qualche piccola modifica e l’aggiunta del trailing stop di Ncolas):
//https://www.prorealcode.com/prorealtime-trading-strategies/point-figure-charts-automated-trading-system/
//
defparam cumulateorders = false
//
ONCE n = 1 //Number of lots
ONCE uptrend = 1
ONCE downtrend = 1
ONCE Boxsize = 20 //Box size
//
turnafternn = 4
LowerBorderBox = round((close / Boxsize) - 0.5) * Boxsize
ONCE DowntrendLow = LowerBorderBox
ONCE UptrendHigh = LowerBorderBox
If LowerBorderBox > LowerBorderBox[1] then
If uptrend = 1 then
downtrend = 0
ONCE DowntrendLow = LowerBorderBox
If LowerBorderBox > UptrendHigh then
UptrendHigh = LowerBorderBox
endif
endif
If downtrend = 1 and LowerBorderBox >= DowntrendLow + (turnafternn * Boxsize) then
UptrendHigh = LowerBorderBox
uptrend = 1
downtrend = 0
endif
elsif LowerBorderBox < LowerBorderBox[1] then
If downtrend = 1 then
uptrend = 0
ONCE UptrendHigh = LowerBorderBox
If LowerBorderBox < DowntrendLow then
DowntrendLow = LowerBorderBox
endif
endif
If uptrend = 1 and LowerBorderBox <= UptrendHigh - (turnafternn * Boxsize) then
DowntrendLow = LowerBorderBox
uptrend = 0
downtrend = 1
endif
endif
If uptrend = 1 and uptrend[1] = 0 AND Not LongOnMarket then
buy n contracts at market
endif
If downtrend = 1 and downtrend[1] = 0 AND Not ShortOnMarket then
sellshort n contracts at market
endif
set stop ploss 50
//*********************************************************************************
// https://www.prorealcode.com/blog/trading/complete-trailing-stop-code-function/
// (righe 17- 56), with the addition of DISTANCE
//
//trailing stop function
trailingstart = 25 //20 trailing will start @trailinstart points profit
trailingstep = 25 //25 trailing step to move the "stoploss"
distance = 10 //10 pips distance from caurrent price (if required by the broker)
//reset the stoploss value
IF NOT ONMARKET THEN
newSL=0
ENDIF
//manage long positions
IF LONGONMARKET THEN
//first move (breakeven)
IF newSL=0 AND close-tradeprice(1)>=trailingstart*pipsize THEN
newSL = tradeprice(1)+trailingstep*pipsize
ENDIF
//next moves
IF newSL>0 AND close-newSL>=trailingstep*pipsize THEN
newSL = newSL+trailingstep*pipsize
ENDIF
ENDIF
//manage short positions
IF SHORTONMARKET THEN
//first move (breakeven)
IF newSL=0 AND tradeprice(1)-close>=trailingstart*pipsize THEN
newSL = tradeprice(1)-trailingstep*pipsize
ENDIF
//next moves
IF newSL>0 AND newSL-close>=trailingstep*pipsize THEN
newSL = newSL-trailingstep*pipsize
ENDIF
ENDIF
//stop order to exit the positions
IF newSL>0 THEN
IF LongOnMarket THEN
IF (close + distance) > newSL THEN
SELL AT newSL STOP
ELSIF (close - distance) < newSL THEN
SELL AT newSL LIMIT
ELSE
SELL AT Market
ENDIF
ELSIF ShortOnmarket THEN
IF (close + distance) < newSL THEN
EXITSHORT AT newSL STOP
ELSIF (close - distance) > newSL THEN
EXITSHORT AT newSL LIMIT
ELSE
EXITSHORT AT Market
ENDIF
ENDIF
ENDIF
//*********************************************************************************
Grazie mille Roberto, gentilissimo
Trading system 1.1 point & figure
This topic contains 12 replies,
has 2 voices, and was last updated by Gael
4 years, 7 months ago.
| Forum: | ProOrder: Trading Automatico & Backtesting |
| Language: | Italian |
| Started: | 06/06/2021 |
| Status: | Active |
| Attachments: | 6 files |
The information collected on this form is stored in a computer file by ProRealCode to create and access your ProRealCode profile. This data is kept in a secure database for the duration of the member's membership. They will be kept as long as you use our services and will be automatically deleted after 3 years of inactivity. Your personal data is used to create your private profile on ProRealCode. This data is maintained by SAS ProRealCode, 407 rue Freycinet, 59151 Arleux, France. If you subscribe to our newsletters, your email address is provided to our service provider "MailChimp" located in the United States, with whom we have signed a confidentiality agreement. This company is also compliant with the EU/Swiss Privacy Shield, and the GDPR. For any request for correction or deletion concerning your data, you can directly contact the ProRealCode team by email at privacy@prorealcode.com If you would like to lodge a complaint regarding the use of your personal data, you can contact your data protection supervisory authority.