OpenD, CloseD etc fetching wrong values  [SOLVED]

Questions about MultiCharts and user contributed studies.
chiyin00
Posts: 6
Joined: 27 Mar 2020
Has thanked: 3 times

OpenD, CloseD etc fetching wrong values

Postby chiyin00 » 28 Mar 2020

Hi,

Code: Select all

[IntrabarOrderGeneration = false]; Var:pass(false),openv(0); if time = 0920 then begin openv=OpenD(0); pass=true; end; if (marketposition = 0) and (close > (openv+100)) and (pass=true) then buy(NumToStr(openv,0)) next bar (openv +50) limit; if time = 1600 then pass=false; SetExitOnClose ;
version of MultiCharts: 12.0 Release (Build 19562)

Instruments: I have test runned the program using two sets of data. (Both in 5mins resolution)
One provided by IB, another one I downloaded online in the format of ASCII Mapping(1min data)
Both symbols show the same issue.
Ive also tested on 1min resolution, so it seems that the problem happens to all chart resolutions too.

I observed this problem during a back test.
The aim of the program is: when the price reaches the [open price of the day +100] and falls back 50pts, then it will buy one contract.

The variable "Pass" is to make sure that the trade only occurs in between 0920 and 1600

I used the function OpenD to retrieve the open price of the day, but it doesnt seem to work all the time.

Code: Select all

buy(NumToStr(openv,0))
I named the trade "Openv" so I can keep track of what price is retrieved for each trade

Sometimes it worked accordingly like in the following picture:
1.png
(26.39 KiB) Not downloaded yet
But in the other times, it always return the open price of the day BEFORE instead.
Ived tried changing the time from 0920 to other times like 0921 or 1000, but still doesnt solve the problem
2.png
(53.04 KiB) Not downloaded yet
3.png
(14.25 KiB) Not downloaded yet
Ive tried using different sessions of the symbol, including the default 24/7 and custom sessions(Mon to fri from 0915 to 1600)
Both shows the problem still.

Can anyone please help?

Thanks,
CY

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

Re: OpenD, CloseD etc fetching wrong values

Postby TJ » 28 Mar 2020

What is your session time?

chiyin00
Posts: 6
Joined: 27 Mar 2020
Has thanked: 3 times

Re: OpenD, CloseD etc fetching wrong values

Postby chiyin00 » 28 Mar 2020

4.png
(19.74 KiB) Not downloaded yet
Mon-Fri 0915-1600

But Ive tried to use the 24/7 session, still shows the same problem
Thanks

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

Re: OpenD, CloseD etc fetching wrong values

Postby TJ » 28 Mar 2020

You can try this:

Code: Select all

if time = 0915 then begin openv=Open; pass=true; end;

chiyin00
Posts: 6
Joined: 27 Mar 2020
Has thanked: 3 times

Re: OpenD, CloseD etc fetching wrong values

Postby chiyin00 » 28 Mar 2020

Forgot to tell you that Ive actually tried to use Close instead of CloseD before, still got the same results.
Thanks.

Image
5.png
(31.87 KiB) Not downloaded yet

chiyin00
Posts: 6
Joined: 27 Mar 2020
Has thanked: 3 times

Re: OpenD, CloseD etc fetching wrong values

Postby chiyin00 » 28 Mar 2020

Oh sorry, Ive missed that you have also change the time from 0920 to 0915.
So I quickly did the change to the program.
But when I change to "time = 0915" no orders are made no matter using which set of the two datas I have.
Image
Attachments
6.png
(29.62 KiB) Not downloaded yet

User avatar
Svetlana MultiCharts
Posts: 645
Joined: 19 Oct 2017
Has thanked: 3 times
Been thanked: 163 times

Re: OpenD, CloseD etc fetching wrong values

Postby Svetlana MultiCharts » 30 Mar 2020

Hello chiyin00,

The issue was not reproduced on our end.
Please send us the following files to our support email address so that we would be able to investigate the issue:
1. The workspace where the issue is reproduced.
2. Export of used symbols (with data) from QuoteManager in .qmd archive:
http://www.multicharts.com/trading-soft ... rting_Data

wilkinsw
Posts: 662
Joined: 21 Apr 2013
Has thanked: 154 times
Been thanked: 104 times

Re: OpenD, CloseD etc fetching wrong values

Postby wilkinsw » 30 Mar 2020

Have you tried Open/CloseS instead of D?

chiyin00
Posts: 6
Joined: 27 Mar 2020
Has thanked: 3 times

Re: OpenD, CloseD etc fetching wrong values

Postby chiyin00 » 30 Mar 2020

Yes I have tried using OpenS, still got the same results.
Also here is the data and also the workspace if anyone want to check out.
https://www.dropbox.com/sh/wi4bt8spyyjk ... 0m7wa?dl=0

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

Re: OpenD, CloseD etc fetching wrong values

Postby TJ » 30 Mar 2020

See post #2, the third point.
viewtopic.php?t=10811

User avatar
Svetlana MultiCharts
Posts: 645
Joined: 19 Oct 2017
Has thanked: 3 times
Been thanked: 163 times

Re: OpenD, CloseD etc fetching wrong values  [SOLVED]

Postby Svetlana MultiCharts » 31 Mar 2020

As you can see in the screenshot, all conditions were met on 16:00 bar.

if ( marketposition = 0 ) and ( close > ( openv + 100 )) and ( pass = true ) then
begin
print(currentbar + MaxBarsBack, " t = ", time, " openv = ", openv );
buy( NumToStr(openv, 0) ) next bar ( openv + 50 ) limit;
end;

The order had been generated, and only after that Pass variable became False.

if time = 1600 then
begin
pass = false;
end;

The indicator specifies Openv + 100 and Openv + 50 which are plotted according to the condition

if( close > ( openv + 100 )) and ( pass = true ) then
image (31.03).png
(162.87 KiB) Not downloaded yet

chiyin00
Posts: 6
Joined: 27 Mar 2020
Has thanked: 3 times

Re: OpenD, CloseD etc fetching wrong values

Postby chiyin00 » 31 Mar 2020

Thankyou Svetlana and TJ.
Ill try to get my logics right next time by using the plot functions.

I can see that the order generated is carried overnight and thus the contract is bought on the opening of the day.
And I want to prevent this from happening, is there any kind of code that can automatically cancel unfulfilled order at the end of the session/day?

Thanks.

wilkinsw
Posts: 662
Joined: 21 Apr 2013
Has thanked: 154 times
Been thanked: 104 times

Re: OpenD, CloseD etc fetching wrong values

Postby wilkinsw » 31 Mar 2020

-if sessionlastbar =true: don’t buy/sell


Return to “MultiCharts”