DEFPARAM PreLoadBars = 0
//No multiple entries in same direction
DEFPARAM FlatAfter = 213000
// The market analysis looks at this bar and the one before to set the high low levels JH
StartTime = 141500
// Variables which can be adapted based on your preferences
PositionSize = 1
AmplitudeMax = 120 //used to set max allowable range in 1st 2 bars
AmplitudeMin = 30 //used to stop entry if range of 1st two are too small
OrderDistance = -4 // used to set buy sell confirm trigger below or above 1st two bar highs and lows
MinDistance = 6 //used to stop entry if bars after 1st two are too near
// We initialize this variable once at the beginning of the trading system.
ONCE StartTradingDay = -1
// The variables which can change during the day are initialized
// at the beginning of each new trading day.
IF (Time <= StartTime AND StartTradingDay <> 0) OR IntradayBarIndex = 0 THEN
BuyLevel = 0
SellLevel = 0
BuyPosition = 0
SellPosition = 0
StartTradingDay = 0
ELSIF Time >= StartTime AND StartTradingDay = 0 THEN
// We store the index of the first bar of the trading day
StartTradingDay = 1
ELSIF StartTradingDay = 1 then
// For each trading day, the highest and lowest price of the instrument
// are recorded every 15 minutes since StartTime
// 4 bars
IF BuyLevel = 0 OR SellLevel = 0 THEN
UpperLevel = Highest[4](High)
LowerLevel = Lowest [4](Low)
// Calculation of the difference between the highest
// and lowest price of the instrument since StartTime
DayDistance = UpperLevel - LowerLevel
// Calculation of the buy and sell levels for the day if the conditions are met
IF DayDistance <= AmplitudeMax THEN
IF SellLevel = 0 AND (Close - LowerLevel) >= MinDistance THEN
SellLevel = LowerLevel + OrderDistance
Else
SellLevel=1
ENDIF
IF BuyLevel = 0 AND (UpperLevel - Close) >= MinDistance THEN
BuyLevel = UpperLevel - OrderDistance
Else
BuyLevel=1
ENDIF
ENDIF
ENDIF
// Creation of buy and sell short orders for the day if the conditions are met
IF SellLevel > 0 AND BuyLevel > 0 and (BuyLevel - SellLevel) >= AmplitudeMin THEN
IF BuyPosition = 0 THEN
IF LongOnMarket THEN
BuyPosition = 1
ELSe
BUY PositionSize CONTRACT AT BuyLevel STOP
Set target pprofit 25
ENDIF
ENDIF
IF SellPosition = 0 THEN
IF ShortOnMarket THEN
SellPosition = 1
ELSe
SELLSHORT PositionSize CONTRACT AT SellLevel STOP
Set target pprofit 25
ENDIF
ENDIF
ENDIF
ENDIF