Ciao Roberto, ti confermo che scrivere:
IF cLong or cLong2 THEN
BUY 1 CONTRACTS AT MARKET
ENDIF
If cShort or cShort2 THEN
SELLSHORT 1 CONTRACTS AT MARKET
ENDIF
produce gli stessi identici risultati che scrivere:
IF cLong or (cLong2 and countoflongshares=0) THEN
BUY 1 CONTRACTS AT MARKET
ENDIF
If cShort or (cShort2 and countofshortshares=0) THEN
SELLSHORT 1 CONTRACTS AT MARKET
ENDIF
ossia stop and reverse completi, ossia da: cLong o cLong2 sia a cShort che cShort2 (il contrario per lo short)
se invece si vuole lo stop and reverse parziale, ossia SOLO da cLong sia a cShort che cShort2 (il contrario per lo short) occorre scrivere (e da alcune prove limitate sembra funzionare (in ogni caso produce risultati diversi dai primi due che sono identici e riduce, come dovrebbe, il numero delle operazioni (ovvio in quanto vengono presi solo una parte degli stop and reverse, dato che è appunto parziale) occorre scrivere:
IF cLong or (cLong2 and countofshortshares=0) THEN
BUY 1 CONTRACTS AT MARKET
ENDIF
If cShort or (cShort2 and countoflongshares=0) THEN
SELLSHORT 1 CONTRACTS AT MARKET
ENDIF
Questa è la bozza di TS assemblata con semplici condizioni, facili da verificare, con cui ho fatto delle prove (Nasdaq micro future – 3 minuti). Spero che mi confermi (o comunque risolvi) la cosa almeno abbiamo chiarito
DEFPARAM CumulateOrders=False
// DATETIME SETTING
DEFPARAM Flatbefore = 020000
DEFPARAM Flatafter = 215500
limitHour = time<213000
//Ctime = (time >=001500 and time<=215500)
//------------------------------------------------------------------------------------
trailingActivation = (close * 0.7 / 100) / pointsize
trailingDelta = (close * 0.6 / 100) / pointsize
// ---------------------------------------------------------------------------------------------------------------OSCILLATORS LIST:
//-----------------------------------------------------------------------------------------------------------------------
myMacd = exponentialaverage[12]-exponentialaverage[32] //MY MACD Mauro
myMacdSignal = exponentialaverage[52](mymacd)
myKama = AdaptiveAverage[20,2,30](mymacd)
//-----------------------------------------------------------------------------------------------------------------------------
Multiplier = 3 //SUPERTREND INVERSO Roberto Gozzi
Periods = 10
Multiplier = Max(1,Min(999,Multiplier))
Periods = Max(1,Min(999,Periods))
IF BarIndex > Max(Periods,Multiplier) THEN
MyATR = AverageTrueRange[Periods](close) * Multiplier
BasicUPPER = MedianPrice + MyATR
BasicLOWER = MedianPrice - MyATR
IF (BasicUPPER < FinalUPPER[1]) OR (close[1] > FinalUPPER[1]) THEN
FinalUPPER = BasicUPPER
ENDIF
IF (BasicLOWER > FinalLOWER[1]) OR (close[1] < FinalLOWER[1]) THEN
FinalLOWER = BasicLOWER
ENDIF
IF (ST[1] = FinalUPPER[1]) AND (close <= FinalUPPER) THEN
ST = FinalUPPER
SX = FinalLOWER
ELSE
IF (ST[1] = FinalUPPER[1]) AND (close > FinalUPPER) THEN
ST = FinalLOWER
SX = FinalUPPER
ELSE
IF (ST[1] = FinalLOWER[1]) AND (close >= FinalLOWER) THEN
ST = FinalLOWER
SX = FinalUPPER
ELSE
IF (ST[1] = FinalLOWER[1]) AND (close < FinalLOWER) THEN
ST = FinalUPPER
SX = FinalLOWER
ENDIF
ENDIF
ENDIF
ENDIF
ENDIF
//------------------------------------------------------------- LISTA CONDIZIONI SINGOLE
c1=myMacd>myMacdSignal
c2=myMacd[5]<myMacdSignal[5]
c3=high > st
c1A=myMacd>myKama
c2A=myMacd[5]<myKama[5]
c3A=high > st
//--------------------------------------------------------------
d1=myMacd<myMacdSignal
d2=myMacd[5]>myMacdSignal[5]
d3=low < st
d1A=myMacd<myKama
d2A=myMacd[5]>myKama[5]
d3A=low < st
// ------------------------------------------------------------ CONDIZIONI RAGGRUPPATE
cLong=c1 and c2 and c3 and limitHour
cLong2=c1A and c2A and c3A and limitHour
cShort=d1 and d2 and d3 and limitHour
cShort2=d1A and d2A and d3A and limitHour
// ------------------------------------------------------------ CONDIZIONI ENTRATA - USCITA
IF cLong or (cLong2 and countofshortshares=0) THEN
BUY 1 CONTRACTS AT MARKET
ENDIF
If cShort or (cShort2 and countoflongshares=0) THEN
SELLSHORT 1 CONTRACTS AT MARKET
ENDIF
//------------------------------------------------------------- TRAILING
If not onmarket then
MaxPrice=0
MinPrice=close
priceExit=0
endif
If longonmarket then
MaxPrice=Max(MaxPrice,high)
if MaxPrice-tradeprice(1)>trailingActivation*pointsize then
priceExit=MaxPrice-trailingDelta*pointsize
endif
endif
if shortonmarket then
MinPrice=Min(MinPrice,low)
if tradeprice(1)-MinPrice>trailingActivation*pointsize then
priceExit=Minprice+trailingDelta*pointsize
endif
endif
if onmarket and priceExit>0 then
sell at priceExit STOP
exitshort at priceExit STOP
endif
//-------------------------------------------------------------- STOP LOSS e TAKE PROFIT
Set stop %loss 1
Set target %profit 1.2
questo problema delle multicondizioni. CIAO