Backtesting with IOG and Bar Magnifier  [SOLVED]

Questions about MultiCharts and user contributed studies.
ghfj444@rambler.ru

Backtesting with IOG and Bar Magnifier

Postby ghfj444@rambler.ru » 14 May 2016

Would appreciate any help with the following issue:

I am trying to backtest a strategy using 1 min bars for signals and ticks for precise entries and exits. I have IOG and Bar Magnifier enabled with 1 tick resolution. The code is below, the chart snapshot is attached.

I am trying to enter on "next bar market" implying next tick market. It enters correctly but then it enters second time on next 1-min bar opening. Why does it enter second time and how to fix that?

Code: Select all

[IntrabarOrderGeneration = true]

//inputs:
variables: Stop1(50), Target1(50), BuyAllowed(true), BuyCondition(false);

SetStopContract;


//Entry

BuyCondition =
Time >= 1251 and Time < 1257
and BuyAllowed = true
and date = 1150123
and L <= 2045.5
;

if MarketPosition = 0 and BuyCondition then begin
Buy 1 contract next bar on market;
BuyAllowed = false;
end;

//Exit

if MarketPosition <> 0 then begin
SetStopLoss(Stop1);
SetProfitTarget(Target1);
end;


if time = 1301 then begin
BuyAllowed = true;
end;
Attachments
Capture.PNG
(10.46 KiB) Downloaded 891 times
Last edited by ghfj444@rambler.ru on 14 May 2016, edited 1 time in total.

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

Re: Backtesting with IOG and Bar Magnifier

Postby TJ » 15 May 2016

A few points:

MarketPosition is calculated at EOB (End of Bar), and the update is available for the subsequent bar.


Look up this useful keyword:

Intrabarpersist

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

Re: Backtesting with IOG and Bar Magnifier

Postby TJ » 15 May 2016

See post #5
[FAQ] Built-In Stops / Profit Targets / OCO Orders
viewtopic.php?f=16&t=10811

ghfj444@rambler.ru

Re: Backtesting with IOG and Bar Magnifier

Postby ghfj444@rambler.ru » 15 May 2016

I changed variables to:

Code: Select all

variables: Stop1(50), Target1(50), intrabarpersist BuyAllowed(true), BuyCondition(false);


And looks like it fixed the issue. Thank you for your help, JT!

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

Re: Backtesting with IOG and Bar Magnifier  [SOLVED]

Postby TJ » 15 May 2016

I changed variables to:

Code: Select all

variables: Stop1(50), Target1(50), intrabarpersist BuyAllowed(true), BuyCondition(false);


And looks like it fixed the issue. Thank you for your help, JT!
Good to hear it works. Thanks for reporting back.

User avatar
syswizard
Posts: 295
Joined: 15 Dec 2012
Has thanked: 16 times
Been thanked: 28 times

Re: Backtesting with IOG and Bar Magnifier

Postby syswizard » 16 May 2016

Why is IntraBarPersist part of a variable declaration ?
I thought it was part of the signal as a declaration ?
[IntraBarPersist]

User avatar
JoshM
Posts: 2195
Joined: 20 May 2011
Location: The Netherlands
Has thanked: 1544 times
Been thanked: 1565 times
Contact:

Re: Backtesting with IOG and Bar Magnifier

Postby JoshM » 28 May 2016

Why is IntraBarPersist part of a variable declaration ?
I thought it was part of the signal as a declaration ?
[IntraBarPersist]
`IntrabarPersist` is placed before variables and arrays when declaring them to make sure that they retain the value that was assigned to them during an intra-bar tick calculation. (For more, see the IntrabarPersist wiki page).

`[IntrabarPersist]` isn't one of the attributes in PowerLanguage according to the wiki page, but there is an attribute named `IntrabarOrderGeneration`. Perhaps you're confusing the two 'intrabar' keywords?


Return to “MultiCharts”