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.
WRONG RESULT IN SIGNAL
- Marina Pashkova
- Posts: 2758
- Joined: 27 Jul 2007
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.
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
- Marina Pashkova
- Posts: 2758
- Joined: 27 Jul 2007
Hi ppan,
A particular exit can only be applied to a particular entry once. Which means that your code should look like as follows:
Hope the above helps.
Regards.
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 ;
Regards.