Hello, I have a small task … if I want to manage 2 positions with an RSI output, how can I write that?
As a fictitious example: RSI2> 95 then sell short 2 positions. With exitshort there should be 2 outputs, 1 position closes with RSI2 <40, the 2nd position closes with RSI2 <10.
How can I code this?
Hi Phoentzs this is just one example (Dax, 15m)
DEFPARAM cumulateOrders = false
myRsi = Rsi[2](close)
level40 = 40
level10 = 10
cLong = close crosses over average[50](close) and high> high[2]
exitLongRsiA = myRsi crosses under level40
exitLongRsiB = myRsi crosses under level10
//-------------------------------------------------------------
if not onMarket and cLong then
buy 2 contracts at market
flagShort = 0
endif
if exitLongRsiA and flagShort = 0 then
sell 1 contract at market
flagShort = 1
endif
if exitLongRsiB then
sell 1 contract at market
endif
Very good. With a flag … thank you. I try to build it into my strategy like this. But … as a mean reversion in trend, I actually thought it was. So in the downtrend sell short at Crossover 95 and then the exits at the lower levels of the RSI. At least I think that’s a good idea. I’ll try.
DEFPARAM cumulateOrders = false
myRsi = Rsi[2](close)
cEnterShort = myrsi crosses over levelEnterShort
levelEnterShort = 95
levelA = 40
levelB = 10
cShort = cEnterShort
exitRsiLevelA = myRsi crosses under levelA
exitRsiLevelB = myRsi crosses under levelB
//-------------------------------------------------------------
if not onMarket and cShort then
sellShort 2 contracts at market
flagExit = 0
endif
if exitRsiLevelA and flagExit = 0 then
exitShort 1 contract at market
flagExit = 1
endif
if exitRsiLevelB then
exitShort 1 contract at market
endif