why I set the system to start trading if barindex > 100 but it keeps starting trade from the first candle???
where’s the problem??
DEFPARAM CumulateOrders = False
RSII = RSI[5](close)
MA = Average[100](close)
//long
long = (BarIndex > 100 and RSII <= 30 and close > MA)
short = (BarIndex > 100 and RSII >= 70 and close < MA)
if long then
buy 1 contracts at market
endif
//short
if short then
sellshort 1 contracts at market
endif
//exit
SET STOP PTRAILING 50
Try below, the default preload bars is 200
Let us know how you get on?
DEFPARAM Preloadbars = 0
PS I guess we can expect a few more WHY’s from you? 🙂 Catchy and memorable username! 🙂
Couldn’t resist a tweak … tried a few and ended up at below to keep it simple.
Results attached with spread = 4.
Need to do some Walk Forward testing, but I’m setting it going on Demo Forward Test as is anyway.
//https://www.prorealcode.com/topic/barindex-problems/
DEFPARAM CumulateOrders = False
RSII = RSI[8](close)
MA = Average[90](close)
//long
long = (RSII <= 30 and close > MA)
short = (RSII >= 70 and close < MA)
if long then
buy 1 contracts at market
SET STOP PLOSS 250
endif
//short
if short then
sellshort 1 contracts at market
SET STOP PLOSS 250
endif
thanks for your advice, but i have another problem
i supposed it will buy a contract at the first bar but it didn’t.
WHY?
once trend = 0
IF NOT LongOnMarket AND trend = 0 THEN
BUY 1 CONTRACTS AT MARKET
trend = 1
ENDIF
Try your code without “NOT LONGONMARKET”.
If you want to buy on first bar of the strategy, try with “if barindex<=1”