Wow , thank you, 3 masters. 🙂
Just backtesting now.
Many thanks for all 3 contributions. 😉
Have a good weekend.
I think it should be (Barindex – TradeIndex) and not (TradeIndex – BarIndex) and it closes after 30 bars not 10.
I’m guessing you are on your phone Robertogozzi as the code was not inserted correctly – I tidied it up for you 🙂
I WAS on my phone (I also wrote TradeInex instead of TradeIndex, but on the phone I couldn’t see whether it was highlighted or not!) . Thank you Vonasi.
defparam flatafter = 210000
if longonmarket then
alreadybuy=1
endif
if shortonmarket then
alreadysell=1
endif
if intradaybarindex=0 then
alreadybuy=0
alreadysell=0
myprofit=strategyprofit
endif
if time = 061000 then
yh = highest[86](high)
yL=lowest[86](low)
os = 2*pipsize
endif
timeEnterBefore1 = time >= 080000
timeEnterAfter1 = time < 120000
timeEnterBefore2 = time >= 150000
timeEnterAfter2 = time < 200000
if my condition AND ((timeEnterBefore1 AND timeEnterAfter1) or (timeEnterBefore2 AND timeEnterAfter2)) then
if my condition and strategyprofit<=myprofit and yh>0 and yl>0 then
if close<yh+os and not alreadybuy then
buy 1 contract at yh+os stop
endif
if close>yl+os and not alreadysell then
sellshort 1 contract at yl-os stop
endif
endif
set stop ploss 15
set target pprofit 15
I was trying to add 2 time conditions, but it doesn’t seem to be working.
Could somebody advise where I have gone wrong please?
There’s a missing ENDIF at line 37.
Also, testing MY CONDITION at line 29 is useless (but this does not affect performance) since it’s been already evaluated at line 27.
Robertogozzi,
Many thanks for your email reply. 😉
I added an, ENDIF in line 37, but the code doesn’t work?
I get a syntax error: the following variable is undefined : my condition.
Many thanks for all your help.
defparam flatafter = 210000
if longonmarket then
alreadybuy=1
endif
if shortonmarket then
alreadysell=1
endif
if intradaybarindex=0 then
alreadybuy=0
alreadysell=0
myprofit=strategyprofit
endif
if time = 061000 then
yh = highest[86](high)
yL=lowest[86](low)
os = 2*pipsize
endif
timeEnterBefore1 = time >= 080000
timeEnterAfter1 = time < 120000
timeEnterBefore2 = time >= 150000
timeEnterAfter2 = time < 200000
if my condition AND ((timeEnterBefore1 AND timeEnterAfter1) or (timeEnterBefore2 AND timeEnterAfter2)) then
if my condition and strategyprofit<=myprofit and yh>0 and yl>0 then
if close<yh+os and not alreadybuy then
buy 1 contract at yh+os stop
endif
if close>yl+os and not alreadysell then
sellshort 1 contract at yl-os stop
endif
endif
endif
set stop ploss 15
set target pprofit 15
I thought MY CONDITION was a plain text to refer tou tour own undisclosed conditions.
Variable names cannot have spaces, nor special signs, only aphanumeric characters.
You will have to define what your conditions are and write them in palce of MY CONDITIONS, say
Average[10,0](close) CROSSES OVER Average[50,0](close) //or CROSSES UNDER for short trades
or the like.
Roberto,
Ok thank you, I will try.
“my conditions” referred to the time, eg timenterbefore1 etc.
i did write tcondition, but it still didn’t work.
Thanks
MYCONDITION, TCONDITION or whatever else you write MUST be defined before being used, if it refers to the time conditions already in place, just remove it.
robertogozzi
Thank you, that made it work. 😉
defparam flatafter = 210000
if longonmarket then
alreadybuy=1
endif
if shortonmarket then
alreadysell=1
endif
if intradaybarindex=0 then
alreadybuy=0
alreadysell=0
myprofit=strategyprofit
endif
if time = 060500 then
yh = highest[85](high)
yL=lowest[85](low)
os = 3*pipsize
endif
tcondition = time>074500 and time<205000
if tcondition and strategyprofit<=myprofit and yh>0 and yl>0 then
if close<yh+os and not alreadybuy then
buy 1 contract at yh+os stop
endif
if close>yl+os and not alreadysell then
sellshort 1 contract at yl-os stop
endif
endif
set stop ploss 15
set target pprofit 15
Hi,
Please could somebody clarify why my code works some days and not others.
On 5/10/18 my code worked, how I wanted it to work, 0805 it went short, after the breakout of the conditions, yl / yh.
On 8/10/18 my code didn’t work at 0755 short, when it should have, but activated at 1505n short? It’s the same code, the backtest proves it doesn’t work all the time.
I have experienced it on other days as well, sometimes it works and sometimes not, not sure why?
All I was after was a simple breakout strategy, but it seems I may have coded it incorrectly.
Many thanks in advance. (The code should be attached)
On which instrument and TF?
Sorry. 🙄
Wall Street, 5 min chart.
I think line 30 should read “close<yh-os“, but the cause for not entering on 8/10/18 at 0755 is because the previous bar, when the pending orders are placed, the short order was NOT place du to false conditions, because CLOSE (26435.1) < Y+OS(26435.6) and conditions at line 28 were not met.
You can use GRAPH to display variables at runtime, with their values retained each bar.
This debugging tool will help find out errors quickly (well… a bit quicker).
Many thanks again Roberto. 😉 I will have a look into the graph function.
I have changed the code, as you instructed above, it works on the 8/10/18, but there are more trades it does not take, where as the old code did.
I presume there is no way of re-wording my code, to simplify it, so when the price crosses the breakout points, yh / yl , it buys/sells regardless?