How to compare entry date to current date in intraday chart
Author: djmundus
Creation Date: 8/5/2018 7:19 PM
profile picture

djmundus

#1
I've been playing around with the DipBuyer strategy that comes with Wealth-Lab. I'd like to modify it so that the entry is driven off of daily data, but the exit the next day uses some kind of trailing stop on intraday data rather than selling at market at the open.

How can I create logic that says "if the date of the current bar is greater than the date of the bar the position was entered into then..." I'm guessing it is some combination of Bars.Date and LastPosition.EntryDate...?

Thanks in advance...
profile picture

Eugene

#2
Simply put:
CODE:
Please log in to see this code.


An alternative using Community Components:
CODE:
Please log in to see this code.
profile picture

djmundus

#3
Thanks for replying on a Sunday, Eugene!

My code is below. When I inserted the date filter, the SellAtMarket orders don't get executed... I'm trying to get this intraday version of the strategy to get the same results as the daily version of the strategy before I start tweaking the exit.

What am I doing wrong here?

CODE:
Please log in to see this code.

profile picture

Cone

#4
Not sure that this is the problem, but upon casual inspection, to enable a sell the day after a buy...

CODE:
Please log in to see this code.


Edit... actually, it's likely that you're initiating multiple positions while using single position logic. Try this:

CODE:
Please log in to see this code.
profile picture

djmundus

#5
Thanks, Cone! That did it.
profile picture

Eugene

#6
@djmundus

KAMA is an "unstable" indicator; see Indicators > Stability of Indicators in the WealthScript Programming Guide. Consequently, not only you can't start the trading loop as soon as bar 0 but you should precaution against not entering before 3-4 times your long KAMA period i.e. not before 200 * 3 = 600 bars.

Replace this incorrect line:
CODE:
Please log in to see this code.


With this one:
CODE:
Please log in to see this code.
This website uses cookies to improve your experience. We'll assume you're ok with that, but you can opt-out if you wish (Read more).