hi
I need help coding a strategy ive been backtesting manually and forwardtested for a while now. Results look promising.
rules:
- from todays open (midnight) to US open, (15:30 my time gmt +2) creates a rangebox
- if ADR is below 50%, put sell/buy stop orders 10 pips below/above rangebox
- target 50 pips, SL 100 pips, breakeven SL after 25 pips
- if ADR is above 50% no trades
What ADR is the one you are referencing?:
- Advance/Decline Ratio
- Average Daily Range calculated on Highs & Lows
- Average Daily Range calculated on Range (pips)
Do you have any link to that indicator? PRT have ADX, ADXR, but no ADR.
average daily range in pips. Could be one thats based on similar calculation in prt 🙂 thanks!
Try this:
DEFPARAM CumulateOrders = FALSE
IF Not OnMarket THEN
MyExit = 0
ELSE
c1 = 0
ENDIF
// ADR Average Daily Range
MyADR = average[300,0](range)
//
IF Time = 000000 THEN
MyHI = high
MyLO = low
c1 = 0
ENDIF
IF Time <= 153000 THEN
MyHI = max(MyHI,high)
MyLO = min(MyLO,low)
MyRange = MyHI - MyLO
c1 = ((MyRange / MyADR) * 100) < 50
ENDIF
IF Time >= 153000 AND c1 THEN
BUY 1 Contract AT MyHI + 10 * pipsize STOP
SELLSHORT 1 Contract AT MyLO - 10 * pipsize STOP
SET TARGET pPROFIT 50
SET STOP pLOSS 100
ENDIF
IF MyExit = 0 THEN
IF (LongOnMarket AND (close - TradePrice) >= 25 * pipsize) OR (ShortOnMarket AND (TradePrice - close) >= 25 * pipsize) THEN
MyExit = TradePrice
ENDIF
ENDIF
IF MyExit > 0 THEN
SELL AT MyExit STOP
EXITSHORT AT MyExit STOP
ENDIF
//GraphOnPrice TradePrice coloured(0,0,255,255)
//GraphOnPrice MyHI coloured(0,128,0,200)
//GraphOnPrice MyLO coloured(255,0,0,255)
//Graph close - TradePrice
//Graph c1
//Graph MyADR
//Graph MyRange
Should Line 15 read as below?
IF Time >= 153000 THEN //not <
No, those two values must be updated earlier or on that time.
After that time the range is defined and trades can be entered.
it does not take any trades at all? tested with 100k bars on 1 min, 5 min, 30 min
Try this one. I changed the average with yesterday’s range:
DEFPARAM CumulateOrders = FALSE
IF Not OnMarket THEN
MyExit = 0
ELSE
c1 = 0
ENDIF
// ADR Average Daily Range
MyADR = average[20,0](Dhigh(1) - Dlow(1))
//
IF (Time = 000000) OR ((Time > 000000) AND (Time < Time[1])) THEN
MyHI = high
MyLO = low
c1 = 0
ENDIF
IF Time <= 153000 THEN
MyHI = max(MyHI,high)
MyLO = min(MyLO,low)
MyRange = MyHI - MyLO
c1 = ((MyRange / MyADR) * 100) < 50
ENDIF
IF Time >= 153000 AND c1 THEN
BUY 1 Contract AT MyHI + 10 * pipsize STOP
SELLSHORT 1 Contract AT MyLO - 10 * pipsize STOP
SET TARGET pPROFIT 50
SET STOP pLOSS 100
ENDIF
IF MyExit = 0 THEN
IF (LongOnMarket AND (close - TradePrice) >= 25 * pipsize) OR (ShortOnMarket AND (TradePrice - close) >= 25 * pipsize) THEN
MyExit = TradePrice
ENDIF
ENDIF
IF MyExit > 0 THEN
SELL AT MyExit STOP
EXITSHORT AT MyExit STOP
ENDIF
//GraphOnPrice TradePrice coloured(0,0,255,255)
//GraphOnPrice MyHI coloured(0,128,0,200)
//GraphOnPrice MyLO coloured(255,0,0,255)
//Graph close - TradePrice
//Graph c1
//Graph MyADR
//Graph MyRange
perfect! thanks alot roberto!! 😀
Roberto, could you possibly devide this code into one SL,TP and BE-stop for long and one for short? Want to try to optimze code for both long and short 😀
There you go:
DEFPARAM CumulateOrders = FALSE
IF Not OnMarket THEN
MyExit = 0
ELSE
c1 = 0
ENDIF
// ADR Average Daily Range
MyADR = average[20,0](Dhigh(1) - Dlow(1))
//
IF (Time = 000000) OR ((Time > 000000) AND (Time < Time[1])) THEN
MyHI = high
MyLO = low
c1 = 0
ENDIF
IF Time <= 153000 THEN
MyHI = max(MyHI,high)
MyLO = min(MyLO,low)
MyRange = MyHI - MyLO
c1 = ((MyRange / MyADR) * 100) < 50
ENDIF
IF LongOnMarket THEN
SET TARGET pPROFIT 50 //you can change this value for LONG trades
SET STOP pLOSS 100 //you can change this value for LONG trades
ELSIF ShortOnMarket THEN
SET TARGET pPROFIT 50 //you can change this value for SHORT trades
SET STOP pLOSS 100 //you can change this value for SHORT trades
ENDIF
IF Time >= 153000 AND c1 AND Not OnMarket THEN
BUY 1 Contract AT MyHI + 10 * pipsize STOP
SELLSHORT 1 Contract AT MyLO - 10 * pipsize STOP
SET TARGET pPROFIT 50 //initial values cannot be different with pending orders
SET STOP pLOSS 100
ENDIF
IF MyExit = 0 THEN
IF LongOnMarket AND (close - TradePrice) >= 25 * pipsize THEN //you can change this value for LONG trades
MyExit = TradePrice
ENDIF
IF ShortOnMarket AND (TradePrice - close) >= 25 * pipsize THEN //you can change this value for SHORT trades
MyExit = TradePrice
ENDIF
ENDIF
IF MyExit > 0 THEN
IF LongOnMarket THEN
SELL AT MyExit STOP
ELSIF ShortOnMarket THEN
EXITSHORT AT MyExit STOP
ENDIF
ENDIF
//GraphOnPrice TradePrice coloured(0,0,255,255)
//GraphOnPrice MyHI coloured(0,128,0,200)
//GraphOnPrice MyLO coloured(255,0,0,255)
//Graph close - TradePrice
//Graph c1
//Graph MyADR
//Graph MyRange
wow, perfect 😀 thanks roberto!!!
one more quick question,
- could you add line to not take a position after certain time, example at 10 aclock
- and a line for maximum numbers of trades per day
There you go:
DEFPARAM CumulateOrders = FALSE
ONCE MaxTrades = 2 //no more than 2 trades a day
ONCE Tally = 0
IF IntraDayBarIndex = 0 THEN
Tally = 0
ENDIF
IF Not OnMarket THEN
MyExit = 0
ELSE
c1 = 0
ENDIF
////////////////////////////////////////////////////////////////////////////////////////////////////////////
NewTrade = (OnMarket AND Not OnMarket[1]) OR (LongOnMarket AND ShortOnMarket[1]) OR (LongOnMarket[1] AND ShortOnMarket) OR ((Not OnMarket AND Not OnMarket[1]) AND (StrategyProfit <> StrategyProfit[1]))
IF NewTrade THEN
Tally = Tally + 1
ENDIF
////////////////////////////////////////////////////////////////////////////////////////////////////////////
// ADR Average Daily Range
MyADR = average[20,0](Dhigh(1) - Dlow(1))
//
IF (Time = 000000) OR ((Time > 000000) AND (Time < Time[1])) THEN
MyHI = high
MyLO = low
c1 = 0
ENDIF
IF Time <= 153000 THEN
MyHI = max(MyHI,high)
MyLO = min(MyLO,low)
MyRange = MyHI - MyLO
c1 = ((MyRange / MyADR) * 100) < 50
ENDIF
IF LongOnMarket THEN
SET TARGET pPROFIT 50 //you can change this value for LONG trades
SET STOP pLOSS 100 //you can change this value for LONG trades
ELSIF ShortOnMarket THEN
SET TARGET pPROFIT 50 //you can change this value for SHORT trades
SET STOP pLOSS 100 //you can change this value for SHORT trades
ENDIF
IF Time >= 153000 AND Time <= 180000 AND c1 AND Tally < MaxTrades AND Not OnMarket THEN //trade only between 15:30 and 18:00
BUY 1 Contract AT MyHI + 10 * pipsize STOP
SELLSHORT 1 Contract AT MyLO - 10 * pipsize STOP
SET TARGET pPROFIT 50 //initial values cannot be different with pending orders
SET STOP pLOSS 100
ENDIF
IF MyExit = 0 THEN
IF LongOnMarket AND (close - TradePrice) >= 25 * pipsize THEN //you can change this value for LONG trades
MyExit = TradePrice
ENDIF
IF ShortOnMarket AND (TradePrice - close) >= 25 * pipsize THEN //you can change this value for SHORT trades
MyExit = TradePrice
ENDIF
ENDIF
IF MyExit > 0 THEN
IF LongOnMarket THEN
SELL AT MyExit STOP
ELSIF ShortOnMarket THEN
EXITSHORT AT MyExit STOP
ENDIF
ENDIF
//GraphOnPrice TradePrice coloured(0,0,255,255)
//GraphOnPrice MyHI coloured(0,128,0,200)
//GraphOnPrice MyLO coloured(255,0,0,255)
//Graph close - TradePrice
//Graph c1
//Graph MyADR
//Graph MyRange
i love you roberto!! thanks! 😀
Roberto, i ended up using this version. But system is not taking any positions last 18 days. But it should, could you take a look at what might be wrong?
//-------------------------------------------------------------------------
// Main code : ryd range box 1-2 min US30 DOW
//-------------------------------------------------------------------------
DEFPARAM CumulateOrders = FALSE
ONCE PL = 130.0
ONCE SL = 60.0
ONCE t = 50.0
ONCE tS = 50.0
ONCE x = 40.0
ONCE y = 1.0
IF Not OnMarket THEN
MyExit = 0
ELSE
c1 = 0
ENDIF
// ADR Average Daily Range
MyADR = average[20,0](Dhigh(1) - Dlow(1))
//
IF (Time = 000000) OR ((Time > 000000) AND (Time < Time[1])) THEN
MyHI = high
MyLO = low
c1 = 0
ENDIF
IF Time <= 142900 THEN
MyHI = max(MyHI,high)
MyLO = min(MyLO,low)
MyRange = MyHI - MyLO
c1 = ((MyRange / MyADR) * 100) < x //75
ENDIF
IF Time >= 142900 AND c1 THEN
BUY 0.2 Contract AT MyHI + y * pipsize STOP
SELLSHORT 0.2 Contract AT MyLO - y * pipsize STOP
SET TARGET pPROFIT PL //40
SET STOP pLOSS SL //80
ENDIF
IF MyExit = 0 THEN
IF (LongOnMarket AND (close - TradePrice) >= t * pipsize) OR (ShortOnMarket AND (TradePrice - close) >= tS * pipsize) THEN //27.5 37.5
MyExit = TradePrice
ENDIF
ENDIF
IF MyExit > 0 THEN
SELL AT MyExit STOP
EXITSHORT AT MyExit STOP
ENDIF
//GraphOnPrice TradePrice coloured(0,0,255,255)
//GraphOnPrice MyHI coloured(0,128,0,200)
//GraphOnPrice MyLO coloured(255,0,0,255)
//Graph close - TradePrice
//Graph c1
//Graph MyADR
//Graph MyRange