GaelParticipant
Average
Salve a tutti, avrei un favore da chiedervi.
Postreste per favore tradurre queste tre idee di Trading System (Allegato) in codice per favore.
Sono a disposizione se non si capisce qualcosa dell’idea.
Vi ringrazio in anticipo.
Buona giornata
Cercherò di farteli, magari uno alla volta.
Ecco il primo:
// Trading System 1
//
// https://www.prorealcode.com/topic/3-trading-system/
//
DEFPARAM CumulateOrders = FALSE
// definzizione candele Heikin-Ashi
once xOpen = open
xClose = (open + close + high + low) / 4
if barindex > 0 then
xOpen = (xOpen + xClose[1]) / 2
endif
xLow = min(low,min(xClose,xOpen))
xHigh = max(high,max(xClose,xOpen))
Bullish = xClose > xOpen
Bearish = xClose < xOpen
UpperWick = xHigh - max(xOpen,xClose)
LowerWick = min(xOpen,xClose) - xLow
//
MySAR = SAR[0.02,0.02,0.2]
//
// Entrata LONG
IF Bullish AND (xClose CROSSES OVER MySAR) AND (LowerWick = 0) AND Not OnMarket THEN
BUY 1 Contract at Market
MyTS = (abs(MySAR - xOpen) / 2) / PipSize
ENDIF
// Entrata SHORT
IF Bearish AND (xClose CROSSES UNDER MySAR) AND (UpperWick = 0) AND Not OnMarket THEN
SELLSHORT 1 Contract at Market
MyTS = (abs(MySAR - xOpen) / 2) / PipSize
ENDIF
//
// Uscita da LONG
IF LongOnMarket AND Bearish THEN
SELL at Market
ENDIF
// Uscita da SHORT
IF ShortOnMarket AND Bullish THEN
EXITSHORT at Market
ENDIF
//
//*********************************************************************************
// https://www.prorealcode.com/blog/trading/complete-trailing-stop-code-function/
// (lines 17- 56)
//
// Nicolas' trailing stop function
trailingstart = MyTS //trailing will start @trailinstart points profit
trailingstep = MyTS //trailing step to move the "stoploss"
//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
SELL AT newSL STOP
EXITSHORT AT newSL STOP
ENDIF
//*********************************************************************************
Non so se avevi già letto il post sopra (Trading System 1), ma ti avviso che l’ho cambiato leggermente ed ho allegato il file ITF.
Ecco il secondo:
// Trading System 2
//
// https://www.prorealcode.com/topic/3-trading-system/
//
DEFPARAM CumulateOrders = FALSE
ONCE N = 3 //3 numero candele
// definzizione candele Heikin-Ashi
once xOpen = open
xClose = (open + close + high + low) / 4
if barindex > 0 then
xOpen = (xOpen + xClose[1]) / 2
endif
xLow = min(low,min(xClose,xOpen))
xHigh = max(high,max(xClose,xOpen))
Bullish = xClose > xOpen
Bearish = xClose < xOpen
UpperWick = xHigh - max(xOpen,xClose)
LowerWick = min(xOpen,xClose) - xLow
//
MySAR = SAR[0.02,0.02,0.2]
//
// Entrata LONG
IF Bullish AND (xClose CROSSES OVER MySAR) AND (LowerWick = 0) AND Not OnMarket THEN
BUY 1 Contract at Market
MyTS = (abs(MySAR - xOpen) / 2) / PipSize
ENDIF
// Entrata SHORT
IF Bearish AND (xClose CROSSES UNDER MySAR) AND (UpperWick = 0) AND Not OnMarket THEN
SELLSHORT 1 Contract at Market
MyTS = (abs(MySAR - xOpen) / 2) / PipSize
ENDIF
//
// Uscita da LONG
IF LongOnMarket AND (BarIndex - TradeIndex) = (N - 1) THEN
SELL at Market
ENDIF
// Uscita da SHORT
IF ShortOnMarket AND (BarIndex - TradeIndex) = (N - 1) THEN
EXITSHORT at Market
ENDIF
//
//*********************************************************************************
// https://www.prorealcode.com/blog/trading/complete-trailing-stop-code-function/
// (lines 17- 56)
//
// Nicolas' trailing stop function
trailingstart = MyTS //trailing will start @trailinstart points profit
trailingstep = MyTS //trailing step to move the "stoploss"
//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
SELL AT newSL STOP
EXITSHORT AT newSL STOP
ENDIF
//*********************************************************************************
Terzo ed ultimo:
// Trading System 3
//
// https://www.prorealcode.com/topic/3-trading-system/
//
DEFPARAM CumulateOrders = FALSE
// definzizione candele Heikin-Ashi
once xOpen = open
xClose = (open + close + high + low) / 4
if barindex > 0 then
xOpen = (xOpen + xClose[1]) / 2
endif
xLow = min(low,min(xClose,xOpen))
xHigh = max(high,max(xClose,xOpen))
Bullish = xClose > xOpen
Bearish = xClose < xOpen
UpperWick = xHigh - max(xOpen,xClose)
LowerWick = min(xOpen,xClose) - xLow
// ParabolicSAR
MySAR = SAR[0.02,0.02,0.2]
// Donchian Channel
ONCE p = 40 //periodi per il canale Donchian
hh = highest[p](high)
ll = lowest[p](low)
UPsar = MySAR => hh
DNsar = MySAR <= ll
//
// Entrata LONG
IF Bullish AND (xClose CROSSES OVER MySAR) AND (LowerWick = 0) AND DNsar AND Not OnMarket THEN
BUY 1 Contract at Market
MyTS = (abs(MySAR - xOpen) / 2) / PipSize
ENDIF
// Entrata SHORT
IF Bearish AND (xClose CROSSES UNDER MySAR) AND (UpperWick = 0) AND UPsar AND Not OnMarket THEN
SELLSHORT 1 Contract at Market
MyTS = (abs(MySAR - xOpen) / 2) / PipSize
ENDIF
//
// Uscita da LONG
IF LongOnMarket AND xHigh >= HH THEN
SELL at Market
ENDIF
// Uscita da SHORT
IF ShortOnMarket AND xLow <= LL THEN
EXITSHORT at Market
ENDIF
//
//*********************************************************************************
// https://www.prorealcode.com/blog/trading/complete-trailing-stop-code-function/
// (lines 17- 56)
//
// Nicolas' trailing stop function
trailingstart = MyTS //trailing will start @trailinstart points profit
trailingstep = MyTS //trailing step to move the "stoploss"
//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
SELL AT newSL STOP
EXITSHORT AT newSL STOP
ENDIF
//*********************************************************************************
GaelParticipant
Average
Grazie mille Roberto, davvero troppo gentile.
Scusa ancora i disturbo, ma ho solo un problema ad aprire i file (.itf), comunque grazie ancora.
Buona serata