WRONG RESULT IN SIGNAL

Questions about MultiCharts and user contributed studies.
ppan
Posts: 106
Joined: 31 Jan 2007
Has thanked: 2 times

WRONG RESULT IN SIGNAL

Postby ppan » 29 Oct 2008

I have the following signal and apply in a 30 min chart.
----------------------------------------------------------------------------
SETEXITONCLOSE;

IF DATE <> DATE[1] THEN BEGIN
BUY ("B1") 5 CONTRACTS NEXT BAR AT MARKET;
BUY ("B2") 5 CONTRACTS NEXT BAR AT MARKET;
END;

IF DATE = DATE[1] THEN BEGIN
SELL ("S1") 1 CONTRACT TOTAL NEXT BAR AT MARKET;
END;
----------------------------------------------------------------------------

The result is wrong:
The "S1" will only run 1 time per day. Then all the opening position will be closed at the end of day.

User avatar
Marina Pashkova
Posts: 2758
Joined: 27 Jul 2007

Postby Marina Pashkova » 30 Oct 2008

Hi ppan,

Could you please specify what exactly is wrong? How exactly are the results different from what you expected them to be?

Attached, you will find a screenshot showing this strategy in MC and TS. The results are identical. So I am not sure what might be wrong here.

Regards.
Attachments
forum_5710.PNG
(114.41 KiB) Downloaded 382 times

ppan
Posts: 106
Joined: 31 Jan 2007
Has thanked: 2 times

Postby ppan » 30 Oct 2008

I expect the "SELL ("S1") " will sell 1 contract in each 30 min bar until there is no buy position remain.
May be my code is wrong. How can I write the code?

User avatar
Marina Pashkova
Posts: 2758
Joined: 27 Jul 2007

Postby Marina Pashkova » 28 Nov 2008

Hi ppan,

A particular exit can only be applied to a particular entry once. Which means that your code should look like as follows:

Code: Select all


var: _counter(0) ;

SETEXITONCLOSE;

IF DATE <> DATE[1] THEN BEGIN
BUY ("B1") 5 CONTRACTS NEXT BAR AT MARKET;
BUY ("B2") 5 CONTRACTS NEXT BAR AT MARKET;
_counter = 0 ;
END;

IF DATE = DATE[1] and _counter = 1 THEN
SELL("S1") 1 CONTRACT entry("B1") NEXT BAR AT MARKET;
IF DATE = DATE[1] and _counter = 2 THEN
SELL("S2") 1 CONTRACT entry("B1") NEXT BAR AT MARKET;
IF DATE = DATE[1] and _counter = 3 THEN
SELL("S3") 1 CONTRACT entry("B1") NEXT BAR AT MARKET;
IF DATE = DATE[1] and _counter = 4 THEN
SELL("S4") 1 CONTRACT entry("B1") NEXT BAR AT MARKET;
IF DATE = DATE[1] and _counter = 5 THEN
SELL("S5") 1 CONTRACT entry("B1") NEXT BAR AT MARKET;
IF DATE = DATE[1] and _counter = 6 THEN
SELL("S6") 1 CONTRACT entry("B2") NEXT BAR AT MARKET;
IF DATE = DATE[1] and _counter = 7 THEN
SELL("S7") 1 CONTRACT entry("B2") NEXT BAR AT MARKET;
IF DATE = DATE[1] and _counter = 8 THEN
SELL("S8") 1 CONTRACT entry("B2") NEXT BAR AT MARKET;
IF DATE = DATE[1] and _counter = 9 THEN
SELL("S9") 1 CONTRACT entry("B2") NEXT BAR AT MARKET;
IF DATE = DATE[1] and _counter = 10 THEN
SELL("S10") 1 CONTRACT entry("B2") NEXT BAR AT MARKET;
if ( barstatus = 2 ) then _counter += 1 ;
Hope the above helps.

Regards.


Return to “MultiCharts”