Scusami Roberto, contrariamente a quando credevo non funziona , praticamente nei backtest che eseguo, ultimamente sull’argento TF 1 ora , le entrate e le uscite sono determinate dalle date ma non dal valore che inserisco.
Ti allego i due codici che uso per vedere dove sbaglio.
Versione long
DEFPARAM CumulateOrders = FALSE
TradingTime=Time>=080000and Time<=180000
// LONG
indicator1 = Volume
indicator2 = ExponentialAverage[14](Volume)
c1 = (indicator1 >= indicator2)
IF ( close > open and close[1] > open[1] ) and c1 and TradingTime Then
BUY 1 CONTRACTS AT MARKET
endif
PrezzoUscita =2400
IF shortOnMarket AND close = PrezzoUscita then
QUIT
endif
SET STOP LOSS l*AverageTrueRange[10](close)
SET TARGET PROFIT p*AverageTrueRange[12](close)
//trailing stop
trailingstop = tra
//resetting variables when no trades are on market
if not onmarket then
MAXPRICE = 0
MINPRICE = close
priceexit = 0
endif
//case SHORT order
if shortonmarket then
MINPRICE = MIN(MINPRICE,close) //saving the MFE of the current trade
if tradeprice(1)-MINPRICE>=trailingstop*pointsize then //if the MFE is higher than the trailingstop then
priceexit = MINPRICE+trailingstop*pointsize //set the exit price at the MFE + trailing stop price level
endif
endif
//case LONG order
if longonmarket then
MAXPRICE = MAX(MAXPRICE,close) //saving the MFE of the current trade
if MAXPRICE-tradeprice(1)>=trailingstop*pointsize then //if the MFE is higher than the trailingstop then
priceexit = MAXPRICE-trailingstop*pointsize //set the exit price at the MFE – trailing stop price level
endif
endif
//exit on trailing stop price levels
if onmarket and priceexit>0 then
EXITSHORT AT priceexit STOP
SELL AT priceexit STOP
endif
Versione short
DEFPARAM CumulateOrders = False
TradingTime=Time>=090000and Time<=210000
// SHORT
indicator1 = Volume
indicator2 = ExponentialAverage[14](Volume)
c1 = (indicator1 >= indicator2)
IF ( ( close < open and close[1] < open[1] )) and c1 and TradingTime THEN
SELLSHORT 1 CONTRACTS AT MARKET
endif
PrezzoUscita= 2150
IF shortOnMarket AND close = PrezzoUscita then
QUIT
SET STOP LOSS l*AverageTrueRange[10](close)
SET TARGET PROFIT p*AverageTrueRange[12](close)
ENDIF
//trailing stop
trailingstop = tra
//resetting variables when no trades are on market
if not onmarket then
MAXPRICE = 0
MINPRICE = close
priceexit = 0
endif
//case SHORT order
if shortonmarket then
MINPRICE = MIN(MINPRICE,close) //saving the MFE of the current trade
if tradeprice(1)-MINPRICE>=trailingstop*pointsize then //if the MFE is higher than the trailingstop then
priceexit = MINPRICE+trailingstop*pointsize //set the exit price at the MFE + trailing stop price level
endif
endif
//case LONG order
if longonmarket then
MAXPRICE = MAX(MAXPRICE,close) //saving the MFE of the current trade
if MAXPRICE-tradeprice(1)>=trailingstop*pointsize then //if the MFE is higher than the trailingstop then
priceexit = MAXPRICE-trailingstop*pointsize //set the exit price at the MFE – trailing stop price level
endif
endif
//exit on trailing stop price levels
if onmarket and priceexit>0 then
EXITSHORT AT priceexit STOP
SELL AT priceexit STOP
endif