Entry at certain time and weekday and Exit after [n]bars

If you need an Indicator or Signal developed or translated from other language, please post all Indicator development REQUESTS to this section here.

Moderator: admin

Entry at certain time and weekday and Exit after [n]bars

Postby loseend » Fri Jan 17, 2020 1:25 pm

Apprentice can you code a EA that opens a position at a certain time and a certain weekday and does a mandatory exit after [n]bars?

For instance,

Trading time = 8 to 17 MEZ
TF = M15 & H1
EntryTime = "16:15"
DayOfEntry = Thu or Fri
Mandatory Exit point = [192]bars past Entry

EntrySignal:
if EntryTime and DayOfEntry
and
max(close[1], close[2], close[3], close[4], close[5]) >
min(open[1], open[2], open[3], open[4], open[5])
and
highH1[1] < highH1[3] then Sell

Exit: either Stop or Target have met or the [n]bar-mandatory close triggers

Can you do that? I'd need each trading day of the week to select and just one point of time to put in manualy and an option to enter the number of [n]bars.

Thank you very much!
loseend
 
Posts: 56
Joined: Tue Jul 31, 2018 12:37 pm

Re: Entry at certain time and weekday and Exit after [n]bars

Postby Apprentice » Sat Jan 18, 2020 5:41 am

Your request is added to the development list.
Development reference 557.
User avatar
Apprentice
FXCodeBase: Confirmed User
 
Posts: 36341
Joined: Thu Dec 31, 2009 11:59 am
Location: Zagreb, Croatia

Re: Entry at certain time and weekday and Exit after [n]bars

Postby loseend » Sat Jan 18, 2020 12:04 pm

The max-Close and the min-Open thing is nonsense, a mistake and has no effect on the signal.

But what I wanted to add is that a mandatory n-bar exit should close each position individually as per customID. Each position should run n bars (if not stopped out before)

I found a similar thing here in the VR_Strategy.lua.
After looping the table the code line says:
...and ( ((row.Time - Source:date(period)) / Candle >= ExitTime) or period == 0) then exit trade.

'ExitTime' is the variable for Mandatory Close, I don't understand that. The guy who requested the strategy was happy with it but I can't get this strategy close the position at all, not at mandatory close and not after n bars. Whatever. Thanks for putting my request on the list.
loseend
 
Posts: 56
Joined: Tue Jul 31, 2018 12:37 pm

Re: Entry at certain time and weekday and Exit after [n]bars

Postby loseend » Mon Jan 20, 2020 8:55 am

Apprentice, just for testing purpose I messed around with the VR Strategy you once coded, I hope you don't mind. I finally got it to exit positions individually after n bars. So now I could implement this function into the strategy I requested in the first place. Looks like it's working fine.

Thing is that I want it to ignore weekends.

If I entry a trade on Friday at 16:30 (what is the corrected entry time) 25 bars would have passed as of close of trading week. When Market opens again on Sunday the nBar function would count 25 bars + about 190 bars = 215 - and it would exit the trade. But actually first open price on Sunday is the 26th bar since entry.

lua is a mystery to me so as I said all I can try is messing around.
What I did is to first assign the bar interval (TF = 15): BarIntV = (1 / 1440) * 15
(I think this is what you did with the get.candle thing, but it doesn't work)

Then calculate the time difference EntryTime minus current date:
TimeDiff = (Source:date(period) - row.Time)
--> if (TimeDiff / BarIntV) >= nBars then exit Position --> works fine!


What I just can't figure out is how to readout the non trading days (to keep it simple: Saturdays and Sundays) within 'TimeDiff'.

If I could do that the most important part of my strategy request would be accomplished.
May be you could just tell me how to get this done.

Do you got a clue for me?


None of the lua functions even remotely relating to this issue won't work:
os.date('%a%', 43817) -> result is always "Thu" (what should be 'Wed' here) not matter which date I want to get the weekday for.
Only thing that works correctly is os.date('%A%', date) = "Monday".

For fun I looked if os.difftime can replace 'TimeDiff': negative.
loseend
 
Posts: 56
Joined: Tue Jul 31, 2018 12:37 pm


Re: Entry at certain time and weekday and Exit after [n]bars

Postby loseend » Thu Jan 23, 2020 5:23 am

Got it done finally. Did take quite a while to grasp the difference between os and core. I replaced the TimeDifference with a simple loop back in time and the nBars Exit is working the way I hoped it would. Very simple and very difficult at the same time, at least for me. I would like to skip Saturday and Sunday.hour < 23 within the loop for this takes runtime for nuts, but don't know how to do it in lua.
Second TF also integrated and working fine. What's still left is an integration of the special hour and the special trading days. But I'll get this done too.

So actually my request is cancelled - but I wasn't aware that you posted an EA for me, Apprentice. Thank you very much! Now I can compare. For sure your solution is a real elegant and tricky one compared to mine. Thanks again!
loseend
 
Posts: 56
Joined: Tue Jul 31, 2018 12:37 pm

Re: Entry at certain time and weekday and Exit after [n]bars

Postby loseend » Thu Jan 23, 2020 5:31 am

Apprentice, the EA you posted is mq4, whatever that is, is it Metatrader? I use TradingStation, I can't get this EA installed neither have a look at it in lua editor. But never mind, I got my stuff.
loseend
 
Posts: 56
Joined: Tue Jul 31, 2018 12:37 pm


Re: Entry at certain time and weekday and Exit after [n]bars

Postby loseend » Thu Jan 23, 2020 4:36 pm

Apprentice, I do not use MT4, Iots of people do, I know but I don't. So it hasn't any use for me.

But I was wrong in the first place. The EA worked perfect in the lua debugger but the weekend thing didn't work in a backtest. I must say this indicore debugger junk is real moron stuff, works like a beta version. Only useful for checking values but not so much in motoring operations.

I did eventually get it done though but I had to go back again to get the time span by subtracting actual candle from entry candle - by additionally adding some tricky adjustments in order to keep calculations for more than one position separate and still correct. If weekend comes into play there still remains a little impreciseness by two bars. If this inaccuracy on weekends would repeat by these 2 bars, what I didn't test so far, then it would be adjustable of course. I'm happy that I did it. So, until next request, goodbye.
loseend
 
Posts: 56
Joined: Tue Jul 31, 2018 12:37 pm


Next

Return to Indicator and Signal Requests

Who is online

Users browsing this forum: Google [Bot] and 8 guests