intrabarpersist var doesn’t work in real time trade  [SOLVED]

Questions about MultiCharts and user contributed studies.
kinwai
Posts: 89
Joined: 03 May 2019
Has thanked: 12 times
Been thanked: 1 time

intrabarpersist var doesn’t work in real time trade  [SOLVED]

Postby kinwai » 11 Jun 2021

Once opens a buy order, use below code to close my position if meet target price

Code: Select all

sell(“JobName”) next bar at <target> limit
From my strategy, I need to reset my program variable immediately if the position is closed, so I use the below code to detect whether the above limit order hit my target price.

Code: Select all

var: intrabarpersist mp(0); if mp > 0 and marketposition=0 then begin // reset variable end; mp = marketposition;
I found that the above code works in backtest, however, in real-time trade, the above code has never executed, so that variable cannot reset, anyone has idea?

User avatar
TJ
Posts: 7742
Joined: 29 Aug 2006
Location: Global Citizen
Has thanked: 1033 times
Been thanked: 2222 times

Re: intrabarpersist var doesn’t work in real time trade

Postby TJ » 11 Jun 2021

Why are you using intrabarpersist ?

kinwai
Posts: 89
Joined: 03 May 2019
Has thanked: 12 times
Been thanked: 1 time

Re: intrabarpersist var doesn’t work in real time trade

Postby kinwai » 11 Jun 2021

Thanks for asking.

I am using 1 min timeframe, the intrabarpersis can check per tick, if not use intrabarpersist, the checking for hit target price will only check at the close of each bar, that mean only check 1 min per time. However, I want to reset my program variable immediately when hit my target price.

User avatar
rrams
Posts: 128
Joined: 10 Feb 2011
Location: USA
Has thanked: 7 times
Been thanked: 70 times
Contact:

Re: intrabarpersist var doesn’t work in real time trade

Postby rrams » 12 Jun 2021

You need to add

Code: Select all

IntraBarOrderGeneration=True;
or set it in properties.

https://markplex.com/free-tutorials/tut ... variables/

kinwai
Posts: 89
Joined: 03 May 2019
Has thanked: 12 times
Been thanked: 1 time

Re: intrabarpersist var doesn’t work in real time trade

Postby kinwai » 12 Jun 2021

From Multicharts document, it doesn’t mention intrabarpersist request IntraBarOrderGeneration (IOG) mode.
https://www.multicharts.com/trading-sof ... BarPersist

I got a challenge when enable IOG mode since my strategy needs to calculate by bar close (IOG disable) to place order, once order placed, only request to reset variable immediately once position closed, so that I only use intrabarpersist var to check position.

User avatar
rrams
Posts: 128
Joined: 10 Feb 2011
Location: USA
Has thanked: 7 times
Been thanked: 70 times
Contact:

Re: intrabarpersist var doesn’t work in real time trade

Postby rrams » 13 Jun 2021

If you need to calculate something or place an order at the close of a bar then use BarStatus to test the bar condition.

Code: Select all

[IntrabarOrderGeneration=true]; var: IntraBarPersist mp(0); if BarStatus(1)=2 then begin // will calculate at end of bar sell("JobName") next bar at xxx limit; end; if mp>0 and marketposition=0 then begin // reset variable end; mp=marketposition;
Or split your code into two separate signals and run one with IOG on and the other off.
If you need more help then please submit all your code in it's entirety, so that it can be properly debugged.

User avatar
TJ
Posts: 7742
Joined: 29 Aug 2006
Location: Global Citizen
Has thanked: 1033 times
Been thanked: 2222 times

Re: intrabarpersist var doesn’t work in real time trade

Postby TJ » 13 Jun 2021

Try this:

Code: Select all

var: mp(0); if mp > 0 and marketposition=0 then begin // reset variable end; if marketposition>mp then mp = marketposition;

kinwai
Posts: 89
Joined: 03 May 2019
Has thanked: 12 times
Been thanked: 1 time

Re: intrabarpersist var doesn’t work in real time trade

Postby kinwai » 14 Jun 2021

Hi rrams, I am still testing your suggestion, I believe it should work under IOG mode since IOG calculate value by tick. Thanks

Hi TJ, the modified code still failed.

Hi MC engineer, the IntraBarPersist should work under IOG disable, any MC engineer can get back why backtest work, but not in real time mode? Is it a system bug?

kinwai
Posts: 89
Joined: 03 May 2019
Has thanked: 12 times
Been thanked: 1 time

Re: intrabarpersist var doesn’t work in real time trade

Postby kinwai » 20 Jun 2021

The below code proved that intrabarpersist variable requests IOG mode

Code: Select all

[IntrabarOrderGeneration = true] var: aa(0), intrabarpersist bb(0); aa = aa + 1; bb = bb + 1; print(date, " | ", time_s, " |aa[1] = ", aa[1], ", |aa = ", aa, ", |bb[1] = ", bb[1], ", |bb = ", bb);


Return to “MultiCharts”