Kenan Baroud
Kenan Baroud

Reputation: 1

how to make just first crossing when another condition executed

I need to write this indicator : MFI be under 20 and then cross over 20 ( it is main condition) the buy signals appears when first cross up of RSI to rsiMA

I write this code :

    var sessionStart = false
if ta.crossover(mf,20)
    sessionStart := true
var rsicross = false
if rsi < rsiMA or rsi > rsiMA or ta.crossunder(rsi,rsiMA) 
    rsicross := false
if ta.crossover(rsi,rsiMA)
    rsicross := true
//====
buyCondition = sessionStart and rsicross

the problem that : all the rsi rsiMA crosses give buy signals because the main condition MFI crossed 20 before. I need after MFI cross up 20 , just first rsi , rsiMA crossing give buy signals. can someone help me please

thank you

Upvotes: 0

Views: 174

Answers (1)

Rohit Agarwal
Rohit Agarwal

Reputation: 1368

You will have to reset the buyCondition back to false when buy condition has occured. So that it will not give buy condition again until mf crossover occurs.

if buyCondition 
    sessionStart:false

Upvotes: 1

Related Questions