- ago
I wanted to know on it's possible to use dividend payouts as a trigger for getting started.
0
206
Solved
7 Replies

Reply

Bookmark

Sort
Cone8
 ( 24.61% )
- ago
#1
Anything is possible, but what does "for getting started" mean?

And, what is trigger condition exactly?
e.g. Buy if a dividend was paid today? 5 days ago? 10 days in the future?
0
- ago
#2
I want a share eg. Sell 1 day before dividend payment and buy again the next day. I need an indicator that detects this dividend payment. thanks for the support
0
- ago
#3
Here's a prototype to start with: Trading around dividends
0
- ago
#4
I bought wealth lab because I like it with the blocks without programming. But I realize this has quickly reached its limits. I am now starting to learn c#. Maybe someone will be kind enough to help me with my program.
I want it to be able to do this.

It should open a postion x days before dividend payment and close x days thereafter. Add a stopless of x percent.
In addition, an entry filter in which month the dividend payment takes place.

many thanks in advance
0
Cone8
 ( 24.61% )
- ago
#5
The WL7 code we pointed you to needed some tweaks for compatibility with WL8, so that was probably a frustrating experience running it. I edited that code so it will work now.

Below will get you started. I don't really understand your month filter - is it for one particular month? a range of months?

You'll need to enable an Event Provider (Data Manager) and a Dividend event. Requests to Event Providers are slow, so be patient for the data when you have them enabled.

Also, we don't have an "Upcoming Dividend" events Provider yet, so this code for now will only work in backtests for past dividends - you won't get Signals for new trades.
I think that in the near future, we can add upcoming dividends to the Nasdaq Event provider - stay tuned!

CODE:
using WealthLab.Backtest; using System; using WealthLab.Core; using System.Drawing; using System.Collections.Generic; using WealthLab.Data; namespace WealthScript123 {    public class DividendStrategy : UserStrategyBase    {       public DividendStrategy()       {          _stopPct = AddParameter("Stop Loss %", ParameterType.Double, 5.0, 2.0, 10.0, 1.0);          _daysBefore = AddParameter("Days Before", ParameterType.Int32, 3, 1, 10, 1);          _daysAfter = AddParameter("Days After", ParameterType.Int32, 3, 1, 10, 1);                }       //Initialize       public override void Initialize(BarHistory bars)       {          _events = bars.GetEventDataPoints("Dividend");          if (_events.Count == 0)          {             DrawHeaderText("No Dividend Events", WLColor.Red, 16);          }       }       //Execute       public override void Execute(BarHistory bars, int idx)       {             if (!HasOpenPosition(bars, PositionType.Long))          {             //entry logic (assumes long)             DateTime dateNext = DateOfUpcomingEvent(bars, idx);             if (dateNext == DateTime.MaxValue)                return;                             int daysToNextDiv = bars.TradingDaysBetweenDates(bars.DateTimes[idx], dateNext);             if (daysToNextDiv == _daysBefore.AsInt)             {                Transaction t = PlaceTrade(bars, TransactionType.Buy, OrderType.Market);             }          }          else          {             //exit logic             Position p = LastPosition;             if (idx - p.EntryBar + 1 > _daysAfter.AsInt)                ClosePosition(p, OrderType.Market);          }                }       //this function will work only in a backtest unless the event provider has future dividends       DateTime DateOfUpcomingEvent(BarHistory bars, int bar)       {          if (_events == null)             return DateTime.MaxValue;          // return the first event in the list that occurred after the current bar          foreach (EventDataPoint edp in _events)          {             if (edp.Date > bars.DateTimes[bar])                return edp.Date;          }                            return DateTime.MaxValue;       }       //private members       List<EventDataPoint> _events;       private DateTime lastDivDate = DateTime.MinValue;       Parameter _stopPct;       Parameter _daysBefore;       Parameter _daysAfter;    } }
That's your freebie - for other custom code solutions, please use the Concierge Service
1
Best Answer
- ago
#6
Hey, thank you. Yes exactly the other code could not be executed. There was a mistake in it. I wanted to filter out that I do not use any dividend payment as entry, because I see in my data feed which are not there at all. for further help I use the Concierge Service.

Thanks again.

0
Cone8
 ( 24.61% )
- ago
#7
There are plenty of free sources for dividend data - even Wealth-Data has them for the symbols it supports (S&P 500, Nasdaq 100, and many ETFs). For more, install Data Extensions that has Morningstar, Nasdaq and others.
0

Reply

Bookmark

Sort