MDSParticipant
Junior
Hi All,
I’m trying to develope a TS.
The TS enter at market when 3 conditions are accomplished.
I need to know ho to get the index of a bar, because when a condition occurs, the other maybe not and I’d like to define a window of validity.
Anyway I want a condition is valid for N candles.
I tried to get the barindex and store into a variable… but this values follows the evolution of barindex
How to can I achieve that?
Best Regards,
Mauro
Hello MDS
It would be useful / helpful to you if your current code is shown on here then we can see better what you are trying to do / need?
Cheers
GraHal
MDSParticipant
Junior
Thanks, if needed I’ll translate in english. The conditions have to be valid for N candles
once divergenzaLongCondizione = 0
once divergenzaShortCondizione = 0
once divergenzaConditionIndex = 0
divergenzaSeniority = window*1.1
if (pHigh[window] - Chikou)*pipfactor>soglia then
divergenzaLongCondizione = 1
divergenzaConditionIndex = divergenzaConditionIndex+1 // tried barindex before, but it's variable
endif
if (Chikou - pLow[window])*pipfactor>soglia then
divergenzaShortCondizione = 1
divergenzaConditionIndex = divergenzaConditionIndex+1
endif
if barindex-divergenzaConditionIndex > divergenzaSeniority then
divergenzaLongCondizione = 0
divergenzaShortCondizione = 0
divergenzaConditionIndex = 0
endif
if divergenzaLongCondizione then
endif
CONDIZIONILONG= divergenzaLongCondizione
CONDIZIONISTOPLONG=0 and spana <> spanb
CONDIZIONISHORT= divergenzaShortCondizione
CONDIZIONISTOPSHORT=0
// Condizioni per entrare su posizioni long
IF NOT LongOnMarket AND CONDIZIONILONG THEN
BUY 1 CONTRACTS AT MARKET
SET TARGET PPROFIT TP
SET STOP pLOSS SL
ENDIF
// Condizioni per uscire da posizioni long
If LongOnMarket AND CONDIZIONISTOPLONG THEN
SELL AT MARKET
ENDIF
// Condizioni per entrare su posizioni short
IF NOT ShortOnMarket AND CONDIZIONISHORT THEN
SELLSHORT 1 CONTRACTS AT MARKET
SET TARGET PPROFIT TP
SET STOP pLOSS SL
ENDIF
// Condizioni per uscire da posizioni short
IF ShortOnMarket AND CONDIZIONISTOPSHORT THEN
EXITSHORT AT MARKET
ENDIF
MDSParticipant
Junior
Hi all.
I resolved in this way.
I wanted that a condition was valid for n candles.
So.
Once index=0
Condition =0
If condition then
Index=index+1
Endif
Then there is a reset policy.
Regards,
Mauro
Hey great MDS, you duid it all by yourself! 🙂
Often happnes to me that … I ask a question, it makes me think about it more and I come up with the solution anyway.
Good Work
GraHal
MDSParticipant
Junior
Thx a lot…
Aniway it could be achived using barindex. It’s the very same.
Regards