unable to use barssinceexit(1) but able to print it  [SOLVED]

Questions about MultiCharts and user contributed studies.
dvdkite
Posts: 65
Joined: 16 May 2018
Has thanked: 10 times
Been thanked: 1 time

unable to use barssinceexit(1) but able to print it

Postby dvdkite » 20 Nov 2019

Hello,

I'm basically trying to avoid an entry if there was already an entry closed in the previous bar. So just to be sure I decided the avoid entries at least for 3 bars after the last trade so I made this code:

Code: Select all

if (EntriesToday(Date) > 0 = true) then begin if barssinceexit(1) > 3 then canEntry= true else canEntry= false; if barstatus = 2 then print("barssinceexit(1) = ", barssinceexit(1)); end; if marketposition = 0 and canEntry then begin

The problem is that by adding "canEntry" in the " if marketposition = 0 and canEntry then begin" the strategy doesn't perform any trade. By removing canentry the backtest is showing 731 trade.
Ok so I tryied to print barssinceexit(1) and it work!!!!! It is correclty showing values in the Output as this exampe:

Code: Select all

barssinceexit(1) = 0.00 barssinceexit(1) = 1.00 barssinceexit(1) = 2.00 barssinceexit(1) = 3.00 barssinceexit(1) = 4.00 barssinceexit(1) = 5.00 barssinceexit(1) = 6.00 barssinceexit(1) = 7.00 barssinceexit(1) = 8.00 barssinceexit(1) = 9.00 barssinceexit(1) = 10.00 barssinceexit(1) = 11.00 barssinceexit(1) = 12.00 barssinceexit(1) = 13.00

So if I'm able to PRINT it then barssinceexit(1) HAS a value and why my code is basically never doing a trade? --------> Why canEntry is always false?

Any help would be appreciated.

Thanks

David

dvdkite
Posts: 65
Joined: 16 May 2018
Has thanked: 10 times
Been thanked: 1 time

Re: unable to use barssinceexit(1) but able to print it

Postby dvdkite » 22 Nov 2019

Hello,

still no luck with this issue. I searched another way to avoid entries if the at the previous bar there was a trade but I cannot find it. I have this problem on ly with higher time frame like 15 and 30 minutes.

Any ideas?

Thanks

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

Re: unable to use barssinceexit(1) but able to print it

Postby wilkinsw » 23 Nov 2019

Can you post any more signal code?

out of interest, do you use “open next bar” in your signal?

dvdkite
Posts: 65
Joined: 16 May 2018
Has thanked: 10 times
Been thanked: 1 time

Re: unable to use barssinceexit(1) but able to print it

Postby dvdkite » 28 Nov 2019

Can you post any more signal code?

out of interest, do you use “open next bar” in your signal?
Hello, ok this is simplest line of code I've tryed before the other conditions that trigger an entry...

Code: Select all

if marketposition = 0 and barssinceexit(1) > 3 then begin
So if barssinceexit(1) > 3 is true it ALLOW the entries , otherwise (so < 3) it shouldn't ... but just using this condition it NEVER pass this line of code and it never do a trade... if I just remove barssinceexit(1) > 3 it perform all the trades INCLUDED the consecutive trades in 2 consecutive bars that I want to avoid...

The strange thing is that if you refer to the "print code" above in this thread it is actually able to print the barssinceexit(1) values... but if I use the condition barssinceexit(1) > 3as in the line of code showed above then ALL the value printed for barssinceexit(1) > 3 are ZERO ("0").
That's a mistery.

Is that a BUG of MC???

By the way I perform LIMIT entries and not at open

Thanks

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

Re: unable to use barssinceexit(1) but able to print it

Postby wilkinsw » 29 Nov 2019

ctrl+f “open next bar”

any hits?

dvdkite
Posts: 65
Joined: 16 May 2018
Has thanked: 10 times
Been thanked: 1 time

Re: unable to use barssinceexit(1) but able to print it

Postby dvdkite » 29 Nov 2019

ctrl+f “open next bar”

any hits?
Can you please explane better how should I use it?

thanks

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

Re: unable to use barssinceexit(1) but able to print it

Postby wilkinsw » 29 Nov 2019

Use what?

Question was: if "open next bar" anywhere in your code?

dvdkite
Posts: 65
Joined: 16 May 2018
Has thanked: 10 times
Been thanked: 1 time

Re: unable to use barssinceexit(1) but able to print it

Postby dvdkite » 29 Nov 2019

Use what?

Question was: if "open next bar" anywhere in your code?
sorry... I already answered in my first reply... I use only LIMIT ORDERS for entries and setProfittaget and setstopploss for exit

dvdkite
Posts: 65
Joined: 16 May 2018
Has thanked: 10 times
Been thanked: 1 time

Re: unable to use barssinceexit(1) but able to print it

Postby dvdkite » 29 Nov 2019

Anyway , if possible, I would APPRECIATE an official Answer to my question by the Multicharts teams thanks as it seems to be a bug.

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

Re: unable to use barssinceexit(1) but able to print it

Postby wilkinsw » 29 Nov 2019

Sorry bud, i think you’ve gotten in a muddle with terminologies there. Have a read up on open next bar.

To rephrase:

What event is triggering your code to calculate (e.g. Barstatus(1)=2)?

I was merely curious to see if non barstatus=2 calculation was to blame.

dvdkite
Posts: 65
Joined: 16 May 2018
Has thanked: 10 times
Been thanked: 1 time

Re: unable to use barssinceexit(1) but able to print it

Postby dvdkite » 30 Nov 2019

Sorry bud, i think you’ve gotten in a muddle with terminologies there. Have a read up on open next bar.

To rephrase:

What event is triggering your code to calculate (e.g. Barstatus(1)=2)?

I was merely curious to see if non barstatus=2 calculation was to blame.

Hello sorry for the misunderstanding...
I'm sure that bartstatus is not the problem because as I said abive I've tryied to remove almost all the cose to keep the entry condition simple and I used just a code like this

Code: Select all

if marketposition = 0 and barssinceexit(1) > 3 then begin
And nothing change. There must be a bug because barsincexit(1) can be printed but used like this it always made false the condition above and consequently it never enter a trade..

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

Re: unable to use barssinceexit(1) but able to print it  [SOLVED]

Postby rrams » 02 Dec 2019

There is no bug. You don't have a valid set of initial conditions to allow a first trade.
Just write it simply:

Code: Select all

if (MarketPosition=0 and BarsSinceExit(1)>3) or MarketPosition(1)=0 then buy next bar market;

dvdkite
Posts: 65
Joined: 16 May 2018
Has thanked: 10 times
Been thanked: 1 time

Re: unable to use barssinceexit(1) but able to print it

Postby dvdkite » 04 Dec 2019

There is no bug. You don't have a valid set of initial conditions to allow a first trade.
Just write it simply:

Code: Select all

if (MarketPosition=0 and BarsSinceExit(1)>3) or MarketPosition(1)=0 then buy next bar market;
Really thank you very much!! You solved it! :-D


Return to “MultiCharts”