- ago
Hello.
I have a strategy developed in Wealth Lab 6.9 in which one of its functions is to buy on certain dates.
So far, in version 6.9 this line of code worked fine for me:

CODE:
if (Bars.Date[bar].Month == 7 && Bars.Date[bar].Day == 15)    {    BuyAtClose(bar-1, "Buy Date");    }


I have tried to adapt it as follows to Wealth Lab 7 but it gives me an error because it does not recognize "Date":

CODE:
public override void Execute(BarHistory bars, int idx)       {          int bar = idx;          Position foundPosition0 = FindOpenPosition(0);          bool condition0;          if (foundPosition0 == null)          {             condition0 = false;             {                if (bars.Date[bar].Month == 7 && bars.Date[bar].Day == 15)                {                   condition0 = true;                }             }             if (condition0)             {                _transaction = PlaceTrade(bars, TransactionType.Buy, OrderType.Market, 0, 0);             }          }

What is wrong in the line "if (bars.Date[bar].Month == 7 && bars.Date[bar].Day == 15)" for WL7?

0
1,003
4 Replies

Reply

Bookmark

Sort
- ago
#1
Either change the template code...
CODE:
public override void Execute(BarHistory bars, int idx)

...to:
CODE:
public override void Execute(BarHistory bars, int bar)


Or simply adjust your code to use "idx" and not "bar".
0
- ago
#2
Thanks Eugene.
I change that, but the error persist in the line:

"if (bars.Date[bar].Month == 7 && bars.Date[bar].Day == 15)"

It's underlined "Date".

Full code:

CODE:
public override void Execute(BarHistory bars, int bar)       {                    Position foundPosition0 = FindOpenPosition(0);          bool condition0;          if (foundPosition0 == null)          {             condition0 = false;             {                if (bars.Date[bar].Month == 7 && bars.Date[bar].Day == 15)                {                   condition0 = true;                }             }             if (condition0)             {                _transaction = PlaceTrade(bars, TransactionType.Buy, OrderType.Market, 0, 0);             }          }
0
- ago
#3
There is no Date collection in WL7. It is called DateTimes now. Please check the QuickRef when you have any doubts regarding the naming of collections, properties and methods.
0
- ago
#4
Thanks Eugene.
Sorry for the inconvenience, but I honestly couldn't find the equivalence between WL6.9 and WL7 for this.
Now it works
0

Reply

Bookmark

Sort