Hi guys, i did this code that should go short at minimum of previous day and long at maximum prev day,
// Definizione dei parametri del codice
DEFPARAM CumulateOrders = False // Posizioni cumulate disattivate
DEFPARAM FLATAFTER = 220000
DEFPARAM FLATBEFORE = 010000
// Condizioni per entrare su posizioni long
c1 = (ABS((Dopen(1)-Dclose(1))))<= ((ABS((Dhigh(1)-Dlow(1))))/2)
IF c1 THEN
BUY 1 share AT Dhigh(1) stop
ENDIF
// Condizioni per entrare su posizioni short
c2 = (ABS((Dopen(1)-Dclose(1))))<= ((ABS((Dhigh(1)-Dlow(1))))/2)
IF c2 THEN
SELLSHORT 1 share AT Dlow(1) stop
ENDIF
Problem is that sometime the entry level is totally random not according with the code, like in the photo. Do you know why? Thanks
Firstly you should graph on the price chart what is the value of dlow(1), so you have an hint of what the code is using:
graphonprice dlow(1)
Are you using custom trading hours? Because the OHLC constants returned by instruction such as Dlow are always using the official instrument timezone.
Thanks Nicholas, custom trading hours? I don’k know what it is so i think no im not using that, just left the default chart price but now i can understand the problem, the problem is on the Mondays. I’m on the Gold (Spot Gold mini 10 oz, hope this is the right chart for the standard gold quote) and i see that dlow(1) and dhigh(1) don’t take the lowest and the highest price of the previous Friday but something different. I think i can solve this but can you explain me why this happens? Gold quotations are by Monday 0.00 to Friday 22.30 right ? So what’s there that changes the variable of dlow(1) and dhigh(1) ??
Since I use similar stuff I can say… On Mondays Dhigh and Dlow is taken over from Sunday trading. Sunday evening the forex and gold market is open from 10:00 p.m. and a Sunday candle is lit. A dhigh(1), which is used on Monday, then refers to this candle.
good evening, does this code change anything
DEFPARAM CumulateOrders = False // Posizioni cumulate disattivate
DEFPARAM FLATAFTER = 220000
DEFPARAM FLATBEFORE = 010000
if OpenDayOfWeek>0 and OpenDayOfWeek<=5 then
dailylow=dlow(0)
dailyhigh=dhigh(0)
endif
// Condizioni per entrare su posizioni long
c1 = (ABS((Dopen(1)-Dclose(1))))<= ((ABS((dailyhigh[1]-dailylow[1])))/2)
IF c1 THEN
BUY 1 share AT Dhigh(1) stop
ENDIF
// Condizioni per entrare su posizioni short
c2 = (ABS((Dopen(1)-Dclose(1))))<= ((ABS((dailyhigh[1]-dailylow[1])))/2)
IF c2 THEN
SELLSHORT 1 share AT Dlow(1) stop
ENDIF
Really? So the gold market opens on Sunday at 10.00 pm like the Forex? that is strange cause on the gold’s chart it doesn’t show the Sunday candle, it jumps directly from Friday to Monday, in the Forex currencies it shows a candle in Sunday intstead.
thank you FIFI but don’t worry, i have already solved it in a simple way, changing the variable when it is Monday using something like this:
n=1
IF OPENDAYOFWEEK = 1 THEN
n=2
ENDIF
dhigh(n)...
dlow(n)...