Tralasciando il target e trailing stop che possiamo aggiungere in seguito, non entra ed esce correttamente….non capisco.
Time H1
EUR/USD
Ciao Roberto,
ho usato la riga 24.
Tolto tutta la parte sotto del target e trailing.
Test sul giorno 30/03/2020 (dalle ore 06:00 alle ore 22:00) , EUR/USD, H1 , Spread 1
Dovrebbe entrare alla fine candela delle ore 12 che termina alle 13 e chiudere alla fine della candela ore 16:00
NON ENTRA
Avevo fatto un paio d’errori nella definizione della candela Piatta (senza un’ombra), poi io avevo messo zero come shift, non so se te avevi messo 3 oppure no.
Adesso va, anche se ho provato ed entra alle 13, ed esce alle 17. Ovviamente se provi solo quel giorno, provando con uno storico di 100K a quell’ora è già a mercato Short e quindi non entra.
Fammi sapere, questo è il codice aggiornato:
Defparam CumulateOrders = false
// HA - definizione 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))
xRange = xHigh - xLow
//
Rialzo = xClose > xopen
Ribasso = xClose < xOpen
Piatta = (Rialzo AND xLow = xOpen) OR (Ribasso AND xHigh = xOpen)
Corpo = abs(xOpen - xClose)
OmbraSU = xHigh - max(xOpen,xClose)
OmbraGIU = min(xOpen,Xclose) - xLow
Doji = Corpo <= xRange * 0.10 //Doji = corpo <= 10% del range
//
Shift = 3 //da 0 a N (non negativo)
//Sma3 = Average[3,0](xClose[Shift]) //calcolo sulle candele HA
Sma3 = Average[3,0](close[Shift]) //calcolo sulla normali candele giapponesi
// entrata LONG
LongCond = Rialzo AND Piatta AND xOpen > Sma3
If LongCond and not OnMarket then
Buy 1 contract at Market
Endif
// uscita LONG
L1 = Rialzo AND OmbraGIU > Corpo
L2 = xHigh < xHigh[1]
L3 = Doji
L4 = xClose < Sma3
L5 = Ribasso AND Rialzo[1]
ExitL = L1 or L2 or L3 or L4 or L5
IF ExitL AND LongOnMarket THEN
SELL AT MARKET
ENDIF
//entrata SHORT
ShortCond = Ribasso AND Piatta AND xOpen < Sma3
If ShortCond and not OnMarket then
Sellshort 1 contract at Market
Endif
// uscita SHORT
S1 = Ribasso AND OmbraSU > Corpo
S2 = xLow > xLow[1]
S3 = Doji
S4 = xClose > Sma3
S5 = Rialzo AND Ribasso[1]
ExitS = S1 or S2 or S3 or S4 or S5
IF ExitS AND ShortOnMarket THEN
EXITSHORT AT MARKET
ENDIF
//
//Set Target pProfit 100
//Set Stop pLoss 50
////************************************************************************
////trailing stop function
//trailingstart = 10 //trailing will start @trailinstart points profit
//trailingstep = 5 //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
////************************************************************************
Avrai sbagliato a fare il copia e incolla, a me funziona sia Long che Short, su Dax, Eur/Usd,SP, Ftse MIN, ecc.. con TF 1 ora.