mrsic8
 ( 8.64% )
- ago
Hello,
can anyone help me. I did migrate the strategy to WL7 but I am getting errors. Some of them on line 28, but I can't find a solution. It's the same as in WL6. I am not a programmer, but i do my best.
WL7
CODE:
using System; using System.Globalization; using System.IO; using WealthLab.Backtest; using WealthLab.Core; namespace WealthScript8 {    class FundamentalGerman : UserStrategyBase    {       //create indicators and other objects here, this is executed prior to the main trading loop       public override void Initialize(BarHistory bars)       {       }       //execute the strategy rules here, this is executed once for each bar in the backtest history       public override void Execute(BarHistory bars, int idx)       {          var file = @"D:\Fundamental\dax\" + bars.Symbol + ".txt";          double buyAt = Double.MinValue, sellAt = Double.MaxValue;          IFormatProvider format = new CultureInfo("de-DE");          foreach (string line in File.ReadAllLines(file))          {             if (!string.IsNullOrEmpty(line))             {                string[] s = line.Split(new char[] { ';' });                try                {                   if (double.TryParse(s[0], NumberStyles.Float, format, out buyAt))                      if (double.TryParse(s[1], NumberStyles.Float, format, out sellAt))                      {                      }                   break;                }                catch                {                   // ignored                }             }          }          //code your buy conditions here          if (LastPosition != null)          {             if (bars.Close[idx] < buyAt)             {                string signalName = string.Format("Close: {0:0.00}, Buy At: {1:0.00}, Sell At: {2:0.00}", bars.Close,                   buyAt, sellAt);                //OrderType.Market (bars + 1, signalName);                PlaceTrade(bars, TransactionType.Buy, OrderType.Market, Convert.ToDouble(signalName));             }             else             {                if (sellAt < bars.Close[idx])                {                   ClosePosition(LastPosition, OrderType.Market);                }             }          }          //declare private variables below       }    } }


WF6
CODE:
using System; using System.Globalization; using System.IO; using WealthLab; namespace DamirStrateyFundamental {    class DaxMarket : WealthScript    {       protected override void Execute()       {          var file = @"D:\Fundamental\dax\" + Bars.Symbol + ".txt";          double buyAt = Double.MinValue, sellAt = Double.MaxValue;          IFormatProvider format = new CultureInfo("de-DE");          foreach (string line in File.ReadAllLines(file))          {             if (!string.IsNullOrEmpty(line))             {                string[] s = line.Split(new char[] { ';' });                try                {                   if (double.TryParse(s[0], NumberStyles.Float, format, out buyAt))                      if (double.TryParse(s[1], NumberStyles.Float, format, out sellAt))                         break;                }                catch                {                   // ignored                }             }          }          for (int bar = GetTradingLoopStartBar(1); bar < Bars.Count; bar++)          {             if (IsLastPositionActive)             {                if (sellAt < Close[bar])                {                   SellAtMarket(bar + 1, LastPosition);                }             }             else             {                if (Close[bar] < buyAt)                {                   string signalName = string.Format("Close: {0:0.00}, Buy Under: {1:0.00}, Sell Above: {2:0.00}", Close[bar], buyAt, sellAt);                   BuyAtMarket(bar + 1, signalName);                }             }          }       }    } }


0
612
9 Replies

Reply

Bookmark

Sort
- ago
#1
Hi,

Double check your files, it looks like Windows cannot find BMW.de.txt etc. at the path you're pointing WL7 to.

Realizing that the code originates from here I've made some changes to reflect the original idea:
https://wl6.wealth-lab.com/Forum/Posts/Supply-entry-prices-from-File-to-make-trades-39655

CODE:
using System; using System.Globalization; using System.IO; using WealthLab.Backtest; using WealthLab.Core; namespace WealthScript8 {    class FundamentalGerman : UserStrategyBase    {       double buyAt = Double.MinValue, sellAt = Double.MaxValue;       IFormatProvider format = new CultureInfo("de-DE");       //create indicators and other objects here, this is executed prior to the main trading loop       public override void Initialize(BarHistory bars)       {       }       //execute the strategy rules here, this is executed once for each bar in the backtest history       public override void Execute(BarHistory bars, int idx)       {          var file = @"D:\Fundamental\dax\" + bars.Symbol + ".txt";          foreach (string line in File.ReadAllLines(file))          {             if (!string.IsNullOrEmpty(line))             {                string[] s = line.Split(new char[] { ';' });                try                {                   if (double.TryParse(s[0], NumberStyles.Float, format, out buyAt))                      if (double.TryParse(s[1], NumberStyles.Float, format, out sellAt))                      {                         break;                      }                }                catch                {                   // ignored                }             }          }          //code your buy conditions here          if (LastPosition == null)          {             string signalName = string.Format("Close: {0:0.00}, Buy At: {1:0.00}, Sell At: {2:0.00}", bars.Close, buyAt, sellAt);             PlaceTrade(bars, TransactionType.Buy, OrderType.Limit, buyAt, signalName);          }          else          {             if (sellAt < bars.Close[idx])             {                ClosePosition(LastPosition, OrderType.Limit, sellAt, sellAt.ToString());             }          }       }    } }
0
mrsic8
 ( 8.64% )
- ago
#2
Thanks Eugene,

it's works.
But I think something is wrong with the code of presentation of the closing price.


0
- ago
#3
You're welcome Damir. It's a little inaccuracy in your code that I overlooked. Here's how to fix it:
CODE:
string signalName = string.Format("Close: {0:0.00}, Buy At: {1:0.00}, Sell At: {2:0.00}", bars.Close[idx], buyAt, sellAt);
0
mrsic8
 ( 8.64% )
- ago
#4
Thanks.
Does anyone know why i am getting under Exit Date "Open" instead of an "Exit" date ? Daimler has already reached € 75.00.
I did try several things but unsuccessful.

It has to be like in the old Version of WL 6, see attachment.
I did try several things but unsuccessful.






0
- ago
#5
Don't break the working code in Post #1 and it will keep working.
0
mrsic8
 ( 8.64% )
- ago
#6
@Eugene I see, it's fine. The only thing i am getting confused, why i am getting four signals although "buyAt" is not reached yet.

I've read wealth lab help "Important Notes for Market Open Basis" and i think that has nothing to do with Quantity or i am wrong?
"Signal Quantity for entry orders is shown in the dollar amount for display only." For display only??

Do you know why i am getting four signals?


0
- ago
#7
Damir, the Signals in WL7 is the equivalent of Alerts in WL6. And like Alerts they may get triggered or may not.

What are you trying to accomplish by importing entry and exit prices from file?
0
mrsic8
 ( 8.64% )
- ago
#8
The first number is for entry and the second for exit.

If the price falls under 50,00 then i want to get a signal for the entry part. And if it goes above 70,00 i want get a signal for the exit part.


The Positions looks fine. That's why I'm confused, there shouldn't be any entry positions (signals), except for an open position with "TKA.DE", which is fine.


0
- ago
#9
All the Positions look fine because all the symbols eventually went below 50. If you want to disable the triggering on historical data, condition your code to trigger a Signal (ex-Alert) on the last bar like this:
CODE:
if (LastPosition == null && idx == bars.Count-1)
0

Reply

Bookmark

Sort