Hi,
I have tried to write a code that “Catch a move each day with the channel made during night”. It dose that by define a channel each night, and then add some distance to a Buystop and a Sellimit. But I cant get it right, can some please help? 🙂
//Goal to place a buystop some distance over the channel made during night, and a sellimit some distance under the channel made during night.
defparam preloadbars =20
If time = 060000 then // an attempt to define the channel made during night
HL = highest[4](high)
LL = lowest[4](low)
endif
HL1 = HL+2 //an attempt to add distance upp and down on the channel made during night.
LL1 = LL-2
c1 = close > HL1
//c2 = close < LL1
If time > 070000 and time < 170000 and c1 then
buy 1 shares at HL1 stop
sellshort 1 shares at LL1 limit
endif
Exit by Stoploss and takeprofit
Its made for OMX, or similar. And on 30M, or lesser timeframe.

At line 13, for your c1 condition you are testing if close is already above HL1.
Then at line 17 you’re trying to place a stop order at HL1, but you cannot do that, because a stop pending order must be placed above the price (for buying purpose).
If you already known that the price has break up your defined zone (c1 is true), then just BUY at that moment directly on market, without setting a stop order:
buy 1 shares at market
That is for the buy condition. For your sell one, you have totally messed up the whole code here 🙂 Because if you want to set pending orders, don’t test if price has already crossed up or down your trigger prices! Just defined your pending orders and that’s all! 😉
Thanks Nicolas!
I tried this:
defparam preloadbars =400
if intradaybarindex = 0 then
openbuy=0
opensell=0
endif
If time = 060000 then
HL = highest[360](high)
LL = lowest[360](low)
endif
HL1 = HL+2
LL1 = LL-2
c1 = close > HL1
c2 = close < LL1
If time > 060000 and time < 160000 and c1 then
buy 1 shares at market
openbuy = openbuy+1
endif
If time > 060000 and time < 160000 and c2 then
sellshort 1 shares at market
opensell = opensell+1
endif
SET STOP PLOSS 5
But the system takes so many trades a day, like in the picture. I wish it only to take one buy and/or one sell-trade day.
I use it on 1 min timeframe now 🙂
Sorry, I found the problem 🙂
It should be like this:
defparam preloadbars =400
if intradaybarindex = 0 then
openbuy=0
opensell=0
endif
If time = 060000 then
HL = highest[360](high)
LL = lowest[360](low)
endif
HL1 = HL+2
LL1 = LL-2
c1 = close > HL1
c2 = close < LL1
If time > 060000 and time < 160000 and openbuy=0 and c1 then
buy 1 shares at market
openbuy = openbuy+1
endif
If time > 060000 and time < 160000 and opensell=0 and c2 then
sellshort 1 shares at market
opensell = opensell+1
endif
SET STOP PLOSS 5
Hi, i’m working on a breakout strategy and get this:
REM No acumular órdenes
DEFPARAM CumulateOrders=True
REM Horario de operativa
DEFPARAM FlatBefore = 090100
DEFPARAM FlatAfter = 152900
REM APERTURA
//apertura=dopen(0)
REM Maximo y minimo nocturno
if time=080000 then // Select time when max and min are tested
maximo=dhigh(0)+x*pipsize // x= points distance above maximum night range
minimo=dlow(0)-y*pipsize //y= points distance under minimum night range
endif
REM If price is in night range both orders are "STOP"
if HIGH<maximo and LOW>minimo then
if not onmarket then
buy myLOT contract at maximo stop
sellshort myLOT contract at minimo stop
set target pprofit yourprofit
set stop ploss yourstop
endif
REM If price is above maximum
if Close>maximo then
if not longonmarket then
buy myLOT contract at maximo limit // buy in a pullback
buy myLOT contract at market // Buy at market
set target pprofit yourprofit
set stop ploss yourstop
endif
ENDIF
REM ENTRAR AL MERCADO POR DEBAJO DEL RANGO
REM VENDER
IF Close<minimo then
if not shortonmarket and posicion>1 then
sellshort myLOT contract at minimo limit
sellshort mylot shares at market
set target pprofit yourprofit
set stop ploss yourstop
endif
endif
I did a backtest on it and seems like it’s working fine, hope it helps you!
Cheers
Is it possibile maybe to filter trades by, for example, SuperTrend? 🙂
Sorry i don’t know what SuperTrend is… atm!, will check it!
Sorry, my bad, its an indicator:
Supertrend
This was the best I came up with today, BUT it need more backtesting!
//-------------------------------------------------------------------------
// Main code : Tid kväll 2 1 min x
//-------------------------------------------------------------------------
defparam preloadbars =800
cl=461
cs=361
x=5
y=4
if intradaybarindex = 0 then
openbuy=0
opensell=0
endif
//SP = Supertrend[30,10]
//SPU = close > SP
//SPD = close < SP
If time = 060000 then
HL = highest[360](high)
LL = lowest[360](low)
endif
HL1 = HL+x
LL1 = LL-y
c1 = close > HL1
c2 = close < LL1
If time > 060000 and time < 150000 and openbuy=0 and c1 then
buy 1 shares at market
openbuy = openbuy+1
endif
If time > 060000 and time < 150000 and opensell=0 and c2 then
sellshort 1 shares at market
opensell = opensell+1
endif
If longonmarket and close<close[cl] then
sell at market
endif
If shortonmarket and close>close[cs] then
exitshort at market
endif
SET TARGET PPROFIT 70
SET STOP PTRAILING 35
// Optimera cl och cs 0, 725, 25
// Optimera x och y 2, 20, 1
It dosent seem to work on other period then I tested on 🙂
Hi again Nicolas, Adolfo or someone else.
I would like to make a filter (or system) witch only allows trades
if the prize sometime during the day,
during a period of 8 hours hasn’t moved more than 2 points.
If the prize after the 8 hours period breaks up or down,
the system should take an order in the direction.
I have tried to make this, but can’t get it right.
I use it on 5 min timeframe.
I tried this:
HL = highest[96](close)
LL = lowest[96](close)
HL1 = HL+x
LL1 = LL-y
channel = LL1 - HL1 <= 2
But I don’t know how to define the “8h, no more than 2 points” channel.
Thanks!
Hi, i found this error:
HL = highest[96](close)
LL = lowest[96](close)
HL1 = HL+x
LL1 = LL-y
channel = HL1 - LL1 <= 2 // High -Low instead Low - high
Cheers!