On the wiki about Pair Trading in Backtesting it says that in Portfolio Trader, strategies run sequentially.
After a lot of tries, I could not get it working and there is always a time difference between bars calculating across the strategies in the portfolio. You can try it with the following code.When you have GV on first series, you should be able to get those GV when script is calculated on next data series. The calculation of the script is sequential. It means that the script is first calculated on bar 1 of data A and it generates a sell order (as an example) and passes a value through global variable. Then the script is calculated on bar 1 of data B where it reads the global variable and generates identical buy order. Though everything happens sequentially, in fact the sell and buy orders are generated on the bars with the same timestamp (if data A and data B have identical series).
Code: Select all
namespace PowerLanguage.Strategy
{
public class ParallelSignal : SignalObject
{
public ParallelSignal(object ctx) : base(ctx) { }
protected override void StartCalc()
{
Output.WriteLine(Bars.Info.Name + " started");
}
protected override void CalcBar()
{
Output.WriteLine(Bars.Info.Name + " calculated bar number " + Bars.CurrentBar);
}
}
}
- Strategy 1
- Instruments
- symbol A
- Signals
- ParallelSignal
- Instruments
- Strategy 2
- Instruments
- symbol B
- Signals
- ParallelSignal
- Instruments
- Strategy 3
- Instruments
- symbol C
- Signals
- ParallelSignal
- Instruments
Code: Select all
SYMBOL_A started
SYMBOL_B started
SYMBOL_C started
SYMBOL_A calculated bar number 1
SYMBOL_A calculated bar number 2
SYMBOL_B calculated bar number 1
SYMBOL_A calculated bar number 3
SYMBOL_B calculated bar number 2
SYMBOL_A calculated bar number 4
SYMBOL_B calculated bar number 3
SYMBOL_A calculated bar number 5
SYMBOL_B calculated bar number 4
SYMBOL_A calculated bar number 6
SYMBOL_B calculated bar number 5
SYMBOL_A calculated bar number 7
SYMBOL_B calculated bar number 6
SYMBOL_A calculated bar number 8
SYMBOL_B calculated bar number 7
SYMBOL_A calculated bar number 9
SYMBOL_A calculated bar number 10
SYMBOL_B calculated bar number 8
SYMBOL_A calculated bar number 11
SYMBOL_B calculated bar number 9
SYMBOL_A calculated bar number 12
SYMBOL_B calculated bar number 10
SYMBOL_A calculated bar number 13
SYMBOL_B calculated bar number 11
SYMBOL_A calculated bar number 14
SYMBOL_B calculated bar number 12
SYMBOL_A calculated bar number 15
SYMBOL_B calculated bar number 13
SYMBOL_A calculated bar number 16
SYMBOL_B calculated bar number 14
SYMBOL_C calculated bar number 1
SYMBOL_A calculated bar number 17
SYMBOL_B calculated bar number 15
SYMBOL_C calculated bar number 2
SYMBOL_A calculated bar number 18
SYMBOL_A calculated bar number 19
SYMBOL_B calculated bar number 16
SYMBOL_C calculated bar number 3
SYMBOL_A calculated bar number 20
SYMBOL_B calculated bar number 17
SYMBOL_C calculated bar number 4
SYMBOL_A calculated bar number 21
SYMBOL_B calculated bar number 18
SYMBOL_C calculated bar number 5
SYMBOL_A calculated bar number 22
SYMBOL_B calculated bar number 19
SYMBOL_C calculated bar number 6
SYMBOL_A calculated bar number 23
SYMBOL_B calculated bar number 20
SYMBOL_C calculated bar number 7
SYMBOL_A calculated bar number 24
SYMBOL_B calculated bar number 21
SYMBOL_A calculated bar number 25
SYMBOL_B calculated bar number 22
SYMBOL_C calculated bar number 8
SYMBOL_A calculated bar number 26
SYMBOL_B calculated bar number 23
SYMBOL_C calculated bar number 9
SYMBOL_A calculated bar number 27
SYMBOL_B calculated bar number 24
SYMBOL_C calculated bar number 10
SYMBOL_A calculated bar number 28
SYMBOL_B calculated bar number 25
SYMBOL_C calculated bar number 11
SYMBOL_A calculated bar number 29
SYMBOL_B calculated bar number 26
SYMBOL_A calculated bar number 30
SYMBOL_B calculated bar number 27
SYMBOL_C calculated bar number 12
SYMBOL_A calculated bar number 31
SYMBOL_B calculated bar number 28
SYMBOL_C calculated bar number 13
SYMBOL_A calculated bar number 32
SYMBOL_B calculated bar number 29
SYMBOL_C calculated bar number 14
SYMBOL_A calculated bar number 33
SYMBOL_B calculated bar number 30
SYMBOL_C calculated bar number 15
SYMBOL_A calculated bar number 34
SYMBOL_B calculated bar number 31
SYMBOL_C calculated bar number 16
SYMBOL_A calculated bar number 35
SYMBOL_B calculated bar number 32
SYMBOL_C calculated bar number 17
SYMBOL_A calculated bar number 36
SYMBOL_B calculated bar number 33
SYMBOL_A calculated bar number 37
SYMBOL_B calculated bar number 34
SYMBOL_C calculated bar number 18
SYMBOL_A calculated bar number 38
SYMBOL_B calculated bar number 35
SYMBOL_C calculated bar number 19
SYMBOL_A calculated bar number 39
SYMBOL_B calculated bar number 36
SYMBOL_C calculated bar number 20
SYMBOL_A calculated bar number 40
SYMBOL_B calculated bar number 37
SYMBOL_A calculated bar number 41
SYMBOL_B calculated bar number 38
SYMBOL_C calculated bar number 21
SYMBOL_A calculated bar number 42
SYMBOL_B calculated bar number 39
SYMBOL_C calculated bar number 22
SYMBOL_A calculated bar number 43
SYMBOL_B calculated bar number 40
SYMBOL_A calculated bar number 44
SYMBOL_B calculated bar number 41
SYMBOL_A calculated bar number 45
SYMBOL_B calculated bar number 42
SYMBOL_C calculated bar number 23
SYMBOL_A calculated bar number 46
SYMBOL_B calculated bar number 43
SYMBOL_C calculated bar number 24
SYMBOL_A calculated bar number 47
SYMBOL_B calculated bar number 44
SYMBOL_C calculated bar number 25
SYMBOL_A calculated bar number 48
SYMBOL_B calculated bar number 45
SYMBOL_A calculated bar number 49
SYMBOL_B calculated bar number 46
SYMBOL_A calculated bar number 50
SYMBOL_B calculated bar number 47
SYMBOL_C calculated bar number 26
SYMBOL_A calculated bar number 51
SYMBOL_B calculated bar number 48
SYMBOL_C calculated bar number 27
SYMBOL_A calculated bar number 52
SYMBOL_B calculated bar number 49
SYMBOL_C calculated bar number 28
SYMBOL_A calculated bar number 53
SYMBOL_B calculated bar number 50
SYMBOL_A calculated bar number 54
SYMBOL_B calculated bar number 51
SYMBOL_C calculated bar number 29
SYMBOL_A calculated bar number 55
SYMBOL_B calculated bar number 52
SYMBOL_A calculated bar number 56
SYMBOL_B calculated bar number 53
SYMBOL_C calculated bar number 30
SYMBOL_A calculated bar number 57
SYMBOL_B calculated bar number 54
SYMBOL_A calculated bar number 58
SYMBOL_B calculated bar number 55
SYMBOL_A calculated bar number 59
SYMBOL_C calculated bar number 31
SYMBOL_A calculated bar number 60
How can I make it run as documented? Please help.
Thanks!