Replay Signal on BarsOfData(2) without update ?

Questions about MultiCharts .NET and user contributed studies.
Emmanuel
Posts: 355
Joined: 21 May 2009
Has thanked: 109 times
Been thanked: 28 times

Replay Signal on BarsOfData(2) without update ?

Postby Emmanuel » 23 Mar 2021

Hi,

On Replay, I am using 2 DataSeries : Data 1 with 1 min data and Data 2 with 1 Hour data. (See Attachment Workspace 2 Data)
2 Data.wsp
(149.09 KiB) Downloaded 112 times
As an example, I am using "MovAvg_Cross_LE" signal.

I want the calculus of the Average to be on the 1 Hour Data : Dataserie 2, with an update every minute as in Data 1

I am doing a change in void Create() : m_AverageFC = new AverageFC(this,2);

Code: Select all

protected override void Create() { m_AverageFC = new AverageFC(this,2); m_MACrossLE = OrderCreator.MarketNextBar(new SOrderParameters(Contracts.Default, "MACrossLE", EOrderAction.Buy)); m_Counter = new VariableObject<int>(this); }

I insert the signal on Data 1 but the update is only every 1 Hour.
Test1.txt
(18.58 KiB) Downloaded 117 times
MovAvg_Cross_LE.pln
(2.26 KiB) Downloaded 148 times
How can I have the Moving Average Calculus of 1 hour Data 2 with a 1 minute update on Data 1 ?

In Real time or Replay, with the Signal I don't have any minute update with a calculus on 1 hour data, it is the same with the indicator if I am doing a change in void Create() : m_AverageFC = new AverageFC(this,2);

Code: Select all

protected override void Create() { m_AverageFC = new AverageFC(this,2); m_MACrossLE = OrderCreator.MarketNextBar(new SOrderParameters(Contracts.Default, "MACrossLE", EOrderAction.Buy)); m_Counter = new VariableObject<int>(this); }

Code: Select all

using System; using PowerLanguage.Function; using System.IO; using System.Text; namespace PowerLanguage.Strategy { public class MovAvg_Cross_LE : SignalObject { private AverageFC m_AverageFC; private VariableObject<Int32> m_Counter; private IOrderMarket m_MACrossLE; String path4InputOutPut; StreamWriter sw4; public MovAvg_Cross_LE(object ctx) : base(ctx) { Length = 9; ConfirmBars = 1; } private ISeries<double> Price { get; set; } [Input] public int Length { get; set; } [Input] public int ConfirmBars { get; set; } protected override void Create() { m_AverageFC = new AverageFC(this,2); m_MACrossLE = OrderCreator.MarketNextBar(new SOrderParameters(Contracts.Default, "MACrossLE", EOrderAction.Buy)); m_Counter = new VariableObject<int>(this); } protected override void StartCalc() { Price = BarsOfData(2).Close; // Bars.Close; m_AverageFC.price = Price; m_AverageFC.length = Length; path4InputOutPut = "C:\\Temp\\Test1.txt"; sw4 = new StreamWriter(path4InputOutPut, true, Encoding.ASCII); sw4.AutoFlush = true; } protected override void StopCalc() { if (sw4 != null) { sw4.Close(); } base.StopCalc(); } protected override void CalcBar() { double m_Avg = m_AverageFC[0]; if (PublicFunctions.DoubleGreater(Price[0], m_Avg)){ ++m_Counter.Value; } else{ m_Counter.Value = 0; } if (PublicFunctions.DoubleGreater(Bars.CurrentBar, ConfirmBars) && m_Counter.Value == ConfirmBars) { m_MACrossLE.Send(); } // sw4.WriteLine(this.BarsOfData(1).Time[0].ToString() + " m_Avg : " + m_Avg.ToString()); } } }

User avatar
Kate MultiCharts
Posts: 575
Joined: 21 Oct 2020
Has thanked: 7 times
Been thanked: 144 times

Re: Replay Signal on BarsOfData(2) without update ?

Postby Kate MultiCharts » 30 Mar 2021

Hello Emmanuel,

You are transferring Data2 values to the Price variable. This is a 1 hour chart data. Data is printed every minute according to the first data series bar closing events (once per minute). But Price contains the second data series data. For it to contain different data, it needs to be transferred to it. For example, you can plot a 1 minute chart as the second data series.

To investigate the program’s behaviour in more detail, you can try using an indicator (for example, MovAvg_1 line), you’ll see that, if it is applied to the second data series, it will display values based on the second data series.

Emmanuel
Posts: 355
Joined: 21 May 2009
Has thanked: 109 times
Been thanked: 28 times

Re: Replay Signal on BarsOfData(2) without update ?

Postby Emmanuel » 30 Mar 2021

Hello Kate,

Thank you for your answer, I tried your suggestion and I still have this missing information.

I made a little video with the RSI indicator.
https://drive.google.com/file/d/1DfyZrS ... sp=sharing

When I add in my indicator :

Code: Select all

protected override void Create(){ m_rsi1 = new Function.RSI(this,2);
instead of

Code: Select all

protected override void Create(){ m_rsi1 = new Function.RSI(this);
My indicator is giving me only one calculus every hour, on the close of the bar

I am using an indicators in a signal, I have to specify which datastream I want for my indicator.

If you insert an indicator, you can format, go in Properties, and select "Base Study On", to select the Datastream :
Capture MC14.JPG
(47.63 KiB) Not downloaded yet
If you insert an indicator in your signal, you have to select in your code the Datastream :

Code: Select all

protected override void Create(){ m_rsi1 = new Function.RSI(this,2);
In this case, you have an update only on the close of the datastream bar, which is 1 hour is this case. As you can see on the video.

This don't seem to work correctly, I should have an update every minute like it is with

Code: Select all

m_rsi1 = new Function.RSI(this);
In real time, without replay mode , I have the same : an update only each hour.

Furthermore, if I don't give the 1 hour Datastream in Create {} in my signal :

Code: Select all

m_rsi1 = new Function.RSI(this);
The function won't give a correct result which is normal, because the function need the correct datastream in Create {}

User avatar
Kate MultiCharts
Posts: 575
Joined: 21 Oct 2020
Has thanked: 7 times
Been thanked: 144 times

Re: Replay Signal on BarsOfData(2) without update ?

Postby Kate MultiCharts » 31 Mar 2021

Emmanuel,

Your indicator is applied to the second data series. That is why it is calculated based on it once per hour.

Please apply it to the first data series.
You can find more info and instructions here.

Emmanuel
Posts: 355
Joined: 21 May 2009
Has thanked: 109 times
Been thanked: 28 times

Re: Replay Signal on BarsOfData(2) without update ?

Postby Emmanuel » 31 Mar 2021

Kate,

I know it is applied to the second data series. this is the purpose of my question.

1/ If I apply a one hour indicator of the second series to the first data series , RSI calculus is not correct. (see the video)

https://drive.google.com/file/d/1o1Yy5q ... sp=sharing

As I already reply higher, (please see capture attached " Capture MC14.JPG " )

You can only apply a function to a data series through this command :

Code: Select all

protected override void Create(){ m_rsi1 = new Function.RSI(this, DATASTREAM);
You can specify the datastream only programmatically in a signal

User avatar
Vlada MultiCharts
Posts: 293
Joined: 22 Apr 2020
Has thanked: 8 times
Been thanked: 76 times

Re: Replay Signal on BarsOfData(2) without update ?

Postby Vlada MultiCharts » 02 Aug 2021

Hello Emmanuel,

Try to enable the option Realtime History Matching in your signal properties (Format -> Strategy Properties -> Backtesting tab -> Advanced section).
Thus the real-time bars of data1 will be recalculated on the last open bar of data2. Check the attached screenshot, the real-time bars are highlighted in green.

With such settings, the backtesting results will change if you make changes to the signal (for example, enable and then disable it).
Attachments
Realtime-history matching disabled.png
(214.97 KiB) Not downloaded yet


Return to “MultiCharts .NET”