- ago
Code this:

CODE:
using WealthLab.Backtest; using System; using WealthLab.Core; using WealthLab.Indicators; using System.Drawing; using System.Collections.Generic; namespace WealthScript4 { public class MyStrategy : UserStrategyBase {     public MyStrategy() : base() { } public override void Initialize(BarHistory bars) {       indicator1 = bars.Close;       indicator2 = new SMA(bars.Close,200);       PlotIndicator(indicator2,Color.FromArgb(255,0,0,0));          StartIndex = 200; } public override void Execute(BarHistory bars, int idx) {          int index = idx;          Position foundPosition0 = FindOpenPosition(0);          bool condition0;          if (foundPosition0 == null)          {             condition0 = false;             {                if (indicator1.CrossesUnder(indicator2, index))                {                   condition0 = true;                }             }             if (condition0)             {                _transaction = PlaceTrade(bars, TransactionType.Buy, OrderType.Market, 0, 0, "Buy At Market (1)");             }          }          else          {             condition0 = false;             {                condition0 = true;             }             if (condition0)             {                if (idx - foundPosition0.EntryBar + 1 >= 5)                {                   ClosePosition(foundPosition0, OrderType.Market, 0,"Sell after 5 bars");                }             }          } }    private TimeSeries indicator1;    private IndicatorBase indicator2;    private Transaction _transaction; } }


Image this:



The yellow bar condition is true, why signal is next bar ?

How to edit condition true and trigger signal
0
709
1 Replies

Reply

Bookmark

Sort
- ago
#1
Everything is correct and there is nothing to edit here. The crossunder takes place on the yellow bar's close and then your market order gets executed at next bar's open.

In the case you want to make this system enter on close, please refer to the website FAQ:

How can my strategy from Blocks enter or exit at close?
https://www.wealth-lab.com/Support/Faq
0

Reply

Bookmark

Sort