A very basic strat i have used manually but with more flexability. Would require
further back testing. Happy for your comments, very new to code so go easy on me!
// Definition of code parameters
DEFPARAM CumulateOrders = False
// Cumulating positions deactivated // The system will cancel all pending orders and close all positions at 0:00. No new ones will be allowed until after the "FLATBEFORE" time.
DEFPARAM FLATBEFORE = 070000
// Cancel all pending orders and close all positions at the "FLATAFTER" time
DEFPARAM FLATAFTER = 184500
// Prevents the system from placing new orders on specified days of the week
daysForbiddenEntry = OpenDayOfWeek = 6 OR OpenDayOfWeek = 0
// Conditions to enter long positions
ignored, ignored, ignored, ignored, ignored, ignored, indicator1 = CALL "Daily Pivots Points"
c1 = (close CROSSES UNDER indicator1)
IF c1 AND not daysForbiddenEntry THEN
BUY 1 PERPOINT AT MARKET
ENDIF
// Conditions to enter short positions
ignored, ignored, ignored, indicator2, ignored, ignored, ignored = CALL "Daily Pivots Points"
c2 = (close CROSSES OVER indicator2)
IF c2 AND not daysForbiddenEntry THEN
SELLSHORT 1 PERPOINT AT MARKET
ENDIF
// Stops and targets
SET STOP pLOSS 10
SET TARGET pPROFIT 20
You should attach also your “Daily PP indicator”.
MazParticipant
Veteran
Hiya, thanks for starting the topic. Would you care to explain a bit more around the premise – why it works, etc?
Apart from eurodollar M3 what other assets and resolutions have you tested this on?
Here is a template / boilerplate that will make it more portable and easier for the community to back test different instruments.
// ====================================== \\
// :: System Parameters --
// -------------------------------------- //
DEFPARAM cumulateOrders = false
DEFPARAM flatBefore = 070000
DEFPARAM flatAfter = 184500
// ====================================== \\
// :: Globals --
// -------------------------------------- //
once positionSize = 1
// ====================================== \\
// :: Optimizations --
// -------------------------------------- //
once optimization = 1
// -- Optimization selection sets
if optimization = 1 then // EUR_USD M3
dayStart = 230000 // for pivot points
tradingTime = not (openDayOfWeek = 6 OR openDayOfWeek = 0)
pointTarget = 20
pointRisk = 10
elsif optimization = 2 then // ANOTHER MARKET
//dayStart = 230000
//tradingTime = not (openDayOfWeek = 6 OR openDayOfWeek = 0)
//pointTarget = 20
//pointRisk = 10
endif
// ====================================== \\
// :: Indicator logic--
// -------------------------------------- //
// -- Pivot points ================= \\
nd = dayStart
if barindex = 0 then
init = 1
lastClose = undefined
lastHigh = undefined
lastLow = undefined
PP = undefined
Res1 = undefined
Res2 = undefined
Res3 = undefined
Sup1 = undefined
Sup2 = undefined
Sup3 = undefined
else
ndA = ( time[2] < nd and time[1] >= nd AND dayofweek <> 0)
ndB = ( time[2] < nd and time[1] >= nd and dayofweek[1] <> 0 and dayofweek[0] = 0)
isNewDay = ndA or ndB // bit of speed optimziation
if isNewDay then
if init = 1 then
lastHigh = High
lastLow = Low
init = 2
elsif init = 2 then
lastClose = Close[1]
PP = (lastClose + lastHigh + lastLow) / 3
hl = lastHigh - lastLow
Res1 = 2 * PP - lastLow
Sup1 = 2 * PP - lastHigh
Res2 = PP + hl
Sup2 = PP - hl
Res3 = Res1 + hl
Sup3 = Sup1 - hl
lastHigh = High
lastLow = Low
endif
endif
if init = 2 then
lastHigh = Max(lastHigh, High)
lastLow = Min(lastLow, Low)
endif
endif
// ----------------------------------- //
// Ignored values to stop PRT kicking up a fuss
if Res2 or Sup2 then
endif
// ====================================== \\
// :: Conditional logic--
// -------------------------------------- //
closeAboveSup3 = (close CROSSES UNDER Sup3)
closeBelowRes3 = (close CROSSES OVER Res3)
bc1 = tradingTime and closeAboveSup3
sc1 = tradingTime and closeBelowRes3
// ====================================== \\
// :: Execution Handlers --
// -------------------------------------- //
// -- Entry --
if bc1 then
buy positionSize perPoint at Market
endif
if sc1 then
sellShort positionSize perPoint at Market
endif
// -- Exit --
if onMarket then
SET STOP pLOSS pointRisk
SET TARGET pPROFIT pointTarget
endif
Hope that’s of use
Best,
M
MazParticipant
Veteran
Indicator is included in above template btw
HI Maz.
Its just a simple fade trading strat really. Wanted to put it out there for traders like yourself to maybe think of ways to add and improve it.
Tested on FSTE wasnt great, but was good on the AUD/USD. I tried 5m but wasnt as good.
Thanks for the code, much more like it!!
I’ve thought about this algo idea many times. Great starting point. Is this pivot point code calculating the Spreadbet / CFD market or real market?
I used it on my spreadbet market IG. I included the spread size of 0.8 tick which is larger than the 0.6 i pay. I done this to allow for slippage.
It might be even more effective if combined with daily ATR.
@MAZ did you format this code with Notepad++ and copy pasted it? It seems like it’s keeping the formatting when I copy it into onenote- that is nice 🙂
Cheers Kasper