//-------------------------------------------------------------------------
//TDI OIL Brent Crude (1£ Contracts) 2H Credit to ElsborgTrading
//
//-------------------------------------------------------------------------
// code-Parameter
DEFPARAM CumulateOrders = false
//DEFPARAM FlatAfter = 230000
//DEFPARAM Flatbefore = 030000
//MONEY MGT//
PositionSize = 2.5
//TDI indicator
//parameters :
lengthrsi=13
lengthrsipl=2
lengthtradesl=7
//overbought and oversold values of the TDI indicator
upperzone = 65
lowerzone = 7
//upperzone = upz
//lowerzone = loz
//heiken ashi
xClose = (Open+High+Low+Close)/4
if(barindex>2) then
xOpen = (xOpen[1] + xClose[1])/2
xHigh = Max(xOpen, xClose)
xLow = Min(xOpen, xClose)
endif
//indicators
r = rsi[lengthrsi](close)
mab = average[lengthrsipl](r)
mbb = average[lengthtradesl](r)
yellowMA = average[5](TypicalPrice)
yellowMAshifted = yellowMA[2]
//trade conditions
longCondition = mab crosses over mbb AND mab<50 AND xHigh>yellowMAshifted
shortCondition = mab crosses under mbb AND mab>51 AND xLow<yellowMAshifted
//Longsell=mab crosses under mbb AND mab<upperzone and mab>56 AND xlow>yellowMAshifted
//Shortexit= mab crosses over mbb AND mab>lowerzone and mab<56 AND xhigh>yellowMAshifted
Longsell=mab crosses under mbb AND mab<upperzone and mab>55 AND xlow>yellowMAshifted
Shortexit= mab crosses over mbb AND mab>lowerzone and mab<58 AND xhigh>yellowMAshifted
//Longsell2=mab crosses under lowerzone
//Shortexit2=mab crosses over upperzone
//***************************
// open position
// long
IF Not LONGONMARKET AND longcondition THEN
BUY PositionSize CONTRACT AT MARKET
ENDIF
// short
IF Not SHORTONMARKET AND shortCondition THEN
SELLSHORT PositionSize CONTRACT AT MARKET
ENDIF
// close position
IF LONGONMARKET and Longsell then//or longsell2 THEN
SELL AT MARKET
ENDIF
IF SHORTONMARKET and Shortexit then//or shortexit2 THEN
EXITSHORT AT MARKET
ENDIF
SET STOP PLOSS 65
SET TARGET PPROFIT 165 //395