MikeParticipant
Junior
Hi
Can anyone see why this code won’t run. If I comment IN the defparams the code opens trades on the 1 minute time frame but nothing higher. If I comment the defparams out then no trades are opened.
I plagiarised “Morning CAC 40” from the library and it won’t open any trades either. I have had differing results on my Spreadbet and CFD accounts in the past. Neither will open any trades.
Thanks in advance
DEFPARAM CumulateOrders = False
//defparam flatbefore = 143000
//defparam flatafter = 143300
Stoplevel = SL
Profitlevel = pl
IF time = 142950 THEN
SET STOP pLOSS StopLevel
SET TARGET pPROFIT ProfitLevel
SELLSHORT 10 perpoint at market
ENDIF
In your example you used 50 seconds, so only if a candle closes on that boundary (try on a 10-second TF).
If you use 142900 it’ll work on a 1-minute TF, if you use 142500 it’ll work also on a 5-minute TF, and so forth…
on the 1 minute time frame but nothing higher
That’s because you are using 143300 and so that time can only be met on a 1 min or less TF.
IF time = 142950 THEN
This means that your conditions must be met at that exact time else no trade.
MikeParticipant
Junior
Thanks Roberto
I thought “time” versus “currenttime” worked on the clock time, irrespective of the candle close…Have I misunderstood that?
MikeParticipant
Junior
Thanks GraHal
I thought my condition was the time of day, which must occur once every 24 hours, at which point I thought my trade would open. Again, I may have this wrong but I think “time” is supposed to relate to “real” time and “currenttime” is candles based.
It sounds like I can’t open a trade at this very specif time. Is that correct?
It sounds like I can’t open a trade at this very specif time. Is that correct?
I was wrong, you can open at that specific time.
I thought you have additional conditions, but now I see you haven’t.
See Roberto comment re use of 142950
MikeParticipant
Junior
Sorry, I had the “time” and “currenttime” functions reversed. It’s “currenttime” that is supposed to work independently of the candle/bar.
The code still opens no trades on the daily timeframe. It does, As Roberto suggested it would, open 1 trade at 142950 on the 10 second time frame. However, to reiterate, this seems to be acting like the “time” function” and not the “currenttime” function.
I have to imagine I can open a trade per day at a specific time…. Any further thoughts?
Many thanks
DEFPARAM CumulateOrders = False
//defparam flatbefore = 143000
//defparam flatafter = 143300
Stoplevel = SL
Profitlevel = pl
IF currenttime = 142950 THEN
SET STOP pLOSS StopLevel
SET TARGET pPROFIT ProfitLevel
SELLSHORT 10 perpoint at market
ENDIF
As from Nicolas’ explanation in a comment to official documentation “CurrentTime is the one of the official timezone where the instrument is traded.”
So if you trade Nikkei and it’s 11am UTC+0 and the bar is labelled 100000, OPENTIME will return 100000 (opening time) TIME returns 110000 (closing time), CURRENTTIME will return 110000 + TZ difference for Japan.
Above added as Log 223 here …
Snippet Link Library
I added the Comment … not code but worthy of logging here! 🙂
MikeParticipant
Junior
Thanks again Roberto – yes, I know I will have to offset the time zone difference and my understanding of CURRENTTIME is as you/Nicolas describe it. As a quick start I just wanted to get the code operational. I still don’t see why “currenttime” won’t trigger one trade every 24 hours. CURRENTTIME is acting like TIME. Is this a bug or am I just not getting it!?
To double check I tried this on the DAX and still no trades.
Code is read and decisions on orders made at the close of every candle. At this point the only times that the strategy can use are the ones at the open (OPENTIME) and at the close (TIME) of that candle. If you want a trade to open at time = 142950 then you must ensure that your chart has a candle that has a time of 142950.
Just trying to figure… maybe the trade is still open next day due to high TP or SL and no further entry is allowed.
MikeParticipant
Junior
Thanks Vonasi
The fact the code operates at the close of the candle is the point I had lost sight of!
MikeParticipant
Junior
Thanks for the thoughts Roberto – Vonasi has got it into my head my it’s not working as I had hoped.
I appreciate your time