Open next bar strategies with multiple data streams

Questions about MultiCharts and user contributed studies.
pmathews
Posts: 3
Joined: 07 Apr 2022

Open next bar strategies with multiple data streams

Postby pmathews » 08 Apr 2022

This issue has been visited a long time ago on this forum and I wanted to have another go at it. I am trying to use bonds to validate an entry on one of the indices, so the idea is that if bonds are in an up trend using a 9 day moving average, bar pattern and day of week conditions are met then the system buys at the high of the previous bar. The code will compile but when I add it to a chart I get a error OPEN NEXT BAR STRATAGIES CALCULATION IS NOT PERMITTED ON MULTIPLE DATASTREAMS. I am only using the daily data that comes with multicharts atm and do not want to auto trade in the future.
The only thing I can think of is to use intraday date which I dont have at the moment or to load the trade list to excell and kick out the trades that the other data stream would have disallowed.

Within this system I am trying to conform to principles Larry Williams teaches, if you like his work and are interested in a system I have made up that has no losses on the nasdaq and russell from the start of 2020 (which is all the data i have) then solve this riddle for me, yes there is a prize. Nasdaq 100 (used as futures data)+ Russell profit 31K, 23 trades no losses, stop loss on russell 30 nasdaq 200

condition1= dayofweek (date of tomorrow) = monday;
condition2= dayofweek (date of tomorrow ) = friday;
Condition3= close [0]< close [1] and close [0] > close [15];
condition4= Average (c,9)[0]> average (c,9)[1] data2;
value1 = Average(c,9)[0];
value2 = Average(c,9)[1] data2;
condition4 = value1 > value2;

if condition3 and condition4 and (condition1 or condition2)

then buy next bar at market;
If marketposition = 1 and openpositionprofit > 0 then sell next bar at market;

//setexitonclose;
Setstopcontract;
Setstoploss (200);

User avatar
ZaphodB
Posts: 64
Joined: 12 Feb 2019
Has thanked: 20 times
Been thanked: 2 times

Re: Open next bar strategies with multiple data streams

Postby ZaphodB » 09 Apr 2022

I think your issue is using the below part of code:

Code: Select all

condition1= dayofweek (date of tomorrow) = monday; condition2= dayofweek (date of tomorrow ) = friday;
I've never seen date/day code used the way that you did. Check out the code below. I also fixed part of your code that was redundant where you define condition4 twice using effectively identical code.

Code: Select all

condition1= dayofweek (date) = friday; //Set to Sunday if chart has Sunday bars condition2= dayofweek (date) = thursday; Condition3= close [0]< close [1] and close [0] > close [15]; //condition4= Average (c,9)[0]> average (c,9)[1] data2; //Removed due below code being same value1 = Average(c,9)[0]; value2 = Average(c,9)[1] data2; condition4 = value1 > value2; if condition3 and condition4 and (condition1 or condition2) then buy next bar at market; If marketposition = 1 and openpositionprofit > 0 then sell next bar at market; //setexitonclose; Setstopcontract; Setstoploss (200);

User avatar
ZaphodB
Posts: 64
Joined: 12 Feb 2019
Has thanked: 20 times
Been thanked: 2 times

Re: Open next bar strategies with multiple data streams

Postby ZaphodB » 09 Apr 2022

I was able to get that above code to work. Also, when you post code use the </> icon in the post editor to mark it as code, or people will say something every time (like I'm doing right now haha)

pmathews
Posts: 3
Joined: 07 Apr 2022

Re: Open next bar strategies with multiple data streams

Postby pmathews » 09 Apr 2022

The reason that you has never seen date/day code done like that before is because I have never coded before. My apologies, I had been playing with the code before posting and yes parts of it were redundant. Looks like the day/date correction you have given has fixed the issue, give me a few days and I will get back to you as I need to look into it properly, thanks.

pmathews
Posts: 3
Joined: 07 Apr 2022

Re: Open next bar strategies with multiple data streams

Postby pmathews » 13 Apr 2022

Both (date)= Thursday and (date of tomorrow) work fine on a code that has just one data set but only (date) works on a code with 2 data sets for some strange reason. I would prefer to use (date of tomorrow) when possible that way public holidays don`t cause problems. Thanks for your help.

User avatar
ZaphodB
Posts: 64
Joined: 12 Feb 2019
Has thanked: 20 times
Been thanked: 2 times

Re: Open next bar strategies with multiple data streams

Postby ZaphodB » 13 Apr 2022

Hmm, I checked and it worked for me with 1 dataset too. I assume it's due to the fact that different symbols can have different holidays. You could try going through quote manager and making sure they have the same sessions and holidays. However, that may be a waste of time if (date of tomorrow) is prevented by MC at a higher level. Someone more experienced than me may be able to help with that question or maybe send an email to support. I'm going to send a PM in a minute too

albevier
Posts: 24
Joined: 13 Nov 2005
Has thanked: 5 times
Been thanked: 3 times

Re: Open next bar strategies with multiple data streams

Postby albevier » 15 Jun 2022

If you're still working on this, I've found the all programming languages refuse to work with ambiguity. Seems to me that anything not specifically labeled as to which datastream is to be used is ambiguous (i.e. Value1) . Maybe try pointing everything to the specific datastream it uses -- data1 or data0.... or two or three; however many data streams you are using.

Just a passing thought. I'm re-learning datastreams so if I have another "great idea" I'll post here again.


Return to “MultiCharts”