I’m trying a mtf code in demo live, and I wanna share with you how I am unable to see errors in opening trades…
This is the code:
//-------------------------------------------------------------------------
// Codice principale : RSIOMA MTF DAX 30M
//-------------------------------------------------------------------------
defparam preloadbars=10000
defparam cumulateorders=true
myRSIoMA, myLevelUp, myLevelDown, mymedlevel = CALL "PRC_RSIoMA extended"[14, 21, 1, 50, 80, 20](close)
TIMEFRAME (Daily, updateonclose)
//your daily conditions
dlong=myRSIoMA>myRSIoMA[1]
dshort=myRSIoMA<myRSIoMA[1]
TIMEFRAME (4 hours, updateonclose)
//your 4-hour conditions
h4long=myRSIoMA>mymedlevel
h4short=myRSIoMA<mymedlevel
TIMEFRAME (1 hour, updateonclose)
//your 1-hour conditions
h1long=myRSIoMA>myLevelUp
h1short=myRSIoMA<myLevelDown
myST=Supertrend[3,10]
TIMEFRAME (default)
//your code to Enter/Exit trades
//your stop loss code
entrylong=myRSIoMA crosses over mylevelup
entryshort=myRSIoMA crosses under myleveldown
if dlong and h4long and h1long and entrylong then
buy 1 contracts at market
endif
if dshort and h4short and h1short and entryshort then
sellshort 1 contracts at market
endif
if longonmarket and close crosses under myST or myRSIOMA crosses under mylevelup then
sell at market
endif
if shortonmarket and close crosses over myST or myRSIOMA crosses over myleveldown then
exitshort at market
endif
///breakeven
startBreakeven = 50 //how much pips/points in gain to activate the breakeven function?
PointsToKeep = 5 //how much pips/points to keep in profit above of below our entry price when the breakeven is activated (beware of spread)
//reset the breakevenLevel when no trade are on market
IF NOT ONMARKET THEN
breakevenLevel=0
ENDIF
// --- BUY SIDE ---
//test if the price have moved favourably of "startBreakeven" points already
IF LONGONMARKET AND close-tradeprice(1)>=startBreakeven*pipsize THEN
//calculate the breakevenLevel
breakevenLevel = tradeprice(1)+PointsToKeep*pipsize
ENDIF
//place the new stop orders on market at breakevenLevel
IF breakevenLevel>0 THEN
SELL AT breakevenLevel STOP
ENDIF
// --- end of BUY SIDE ---
//sell side
IF SHORTONMARKET AND tradeprice(1)-close>startBreakeven*pipsize THEN
//calculate the breakevenLevel
breakevenLevel = tradeprice(1)-PointsToKeep*pipsize
ENDIF
//place the new stop orders on market at breakevenLevel
IF breakevenLevel>0 THEN
EXITSHORT AT breakevenLevel STOP
ENDIF
//stoploss for long position
If longonmarket then
//calculate the long stoploss (difference between the open price of the trade and the lowest low)
Slong = Tradeprice-Lowest [15](low)
Set stop loss Slong
Endif
//stoploss for short position
if shortonmarket then
//calculate the short order stoploss (difference between the open price of the trade and the highest high)
Sshort = Highest [10](high) - Tradeprice
Set stop loss Sshort
Endif
set target pprofit 100
//-------------------------------------------------------------------------
// Funzione : PRC_RSIoMA extended
//-------------------------------------------------------------------------
//PRC_RSIoMA extended | indicator
//27.08.2018
//Nicolas @ www.prorealcode.com
//Sharing ProRealTime knowledge
//converted from MT5 version
// --- settings
//RsiPeriod = 14 // Rsi period
//PriceSmoothing = 21 // Price smoothing (<= 1 for no smoothing)
//PriceSmoothingM = 1 // Price smoothing method (MA mode)
//MinMaxPeriod = 50 // Floating levels period (<= 1 for fixed levels)
//LevelUp = 80.0 // Up level %
//LevelDown = 20.0 // Down level %
// --- end of settings
RsiPrice = customclose // Price to use
n=max(1,PriceSmoothing)
ma=average[n,PriceSmoothingM](RsiPrice)
rsioma=rsi[RsiPeriod](ma)
//levels
mmin = rsioma
mmax = rsioma
for k=1 to MinMaxPeriod-1 do
mmin=min(rsioma[k],mmin)
mmax=max(rsioma[k],mmax)
next
rrange = mmax-mmin
levelupz = mmin+LevelUp * rrange/100
leveldnz = mmin+LevelDown * rrange/100
levelmi = mmin+0.5*rrange
//colours
r=192
g=192
b=192
if rsioma>levelupz then
r=50
g=205
b=50
elsif rsioma<leveldnz then
r=255
g=165
b=0
endif
slope=rsioma-rsioma[1]
long=slope crosses over 0 and rsioma<levelupz
short=slope crosses under 0 and rsioma>levelupz
if long then
drawarrowup(rsioma,low) coloured(0,255,0)
endif
if short then
drawarrowdown(rsioma,high) coloured(255,0,0)
endif
return rsioma coloured(r,g,b) style(line,3) as "RSIoMA",levelupz coloured(50,205,50) style(dottedline,2) as "Level Up", leveldnz coloured(255,165,0) style(dottedline,2) as "Level Down", levelmi coloured(155,155,155) style(dottedline,2) as "mid level"
And this is a screenshot from actual live trades:
[attachment file=”REPORT PER PRT.JPG”]
As you can see, the need for having superior tfs above upperlevel (green zones) and crossing up of base tf (30m) are not respected.
Why?