indicators and signals

Questions about MultiCharts and user contributed studies.
janus
Posts: 835
Joined: 25 May 2009
Has thanked: 63 times
Been thanked: 104 times

indicators and signals

Postby janus » 19 Jul 2009

Is there a way I could use the same study for both plotting indicators and generating orders? As I understand it, I have to duplicate the code for both an indicator study and a signal study, with the former doing the plotting and the latter generating the orders. Seems such a waste to me, especially if I end up using lots of memory with arrays and the like. Could I get around this by using global variables and have all the order preparation work done by the indicator study and pass the type of order and quantity of contracts to the signal study so it can generate the actual order? Is anyone doing this?

I think one downside in using GV's this way is I can't use the optimize feature. That's OK as I can live with having another version of the signal study incorporating the same code as the indicator study with all the plot statements commented out. I wish there was a compiler "if" and "include" directives that can be used to include them in indicator studies, and automatically exclude them in signal studies. Better still, why not just have the compiler ignore and skip over the plot statements when complied as a signal study?

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

Postby Marina Pashkova » 23 Jul 2009

Hi janus,

Well, as you know signals and indicators are different in their nature: signals can't draw plots and indicators can't generate orders.

If you want to keep things simple, you might want to have your logic coded as a function and then use this function from both an indicator and a signal.

Hope it helps.

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

Postby TJ » 23 Jul 2009

Hi janus,
Well, as you know signals and indicators are different in their nature: signals can't draw plots and indicators can't generate orders.
If you want to keep things simple, you might want to have your logic coded as a function and then use this function from both an indicator and a signal.
Hope it helps.

that's an idea.
I will give it a try too.
Thanks

janus
Posts: 835
Joined: 25 May 2009
Has thanked: 63 times
Been thanked: 104 times

Postby janus » 23 Jul 2009

Thanks Marina for the tip. That's what I've been doing all the time - it's a carry over of my 30 years of programming experience - the main program/study contains just a series of call statements to functions, and to break down complex code into functional blocks. This way it makes your code easier to understand..

So, my indicator studies now have a long list of plotn statements, which are selectively used depending on the outcomes of my functions. I've got all 999 plotn statements used, and I use a 2-d array to store the various attributes required to use plotn, plus a flag to control when to use the appropriate plotn. Obviously I didn't type all those statements - there are over 5,000 lines of code - I wrote in another language a program to write them into a text file, and then copied and pasted the contents into the study. I've also added logic to "free" an indicator so it can be re-used later by the code. To leave gaps in the lines, I choose either "point", "left tick", or "right tick" for all my lines. This is far more efficient than using trend lines. I use this mostly to plot support and resistance lines. The only downsides are: can't plot solid lines, can't plot vertical lines, only a limit of 999 lines crossing at any given bar.

As for the signal study, I do something similar - I have a series of different types orders that are selectively used depending on the results of the same functions used by the indicator study.

Despite all this, I still prefer to have both plots and strategy orders generated by the same study, but I can live with current way MC does things.

wegi
Posts: 124
Joined: 02 Jun 2009
Has thanked: 5 times
Been thanked: 13 times

Postby wegi » 23 Jul 2009

@Janus,

i use pushpop.dll wich provides global variables.
i calculate the values in my signal, put them into a global variable and draw them in an indicator. Look in the forum here, i dont have the u r l here at the moment.

i can´t understand why i can not draw in an signal script, where i calculate my stops and targets. i want to see them in a chart.
doing this in separate sub-functions in the signal, the code is calculated twice and i have to setup 2 inputs the same way.

janus
Posts: 835
Joined: 25 May 2009
Has thanked: 63 times
Been thanked: 104 times

Postby janus » 24 Jul 2009

I'm using the built-in global variable in MC to do something similar. My indicator study does all the work to draw the lines and creates the "signals". It passes the "strategy order" to the signal study via global variables to execute. I might go the other way like you are later, but I'm still in the development stage and started with the indicator study first, which was the obvious thing to do at the time. If I knew about this issue before, I probably would have started with the signal study and worked backward to the indicator study to display my lines. It works fine the way I have it now so I probably won't need to change it. At least the way I'm doing it now I only need to execute my functions once; in the indicator study. All the signal study is doing is picking up the appropriate order and sending it to IB. It does nothing else, at least for now. In fact, I could use this as a generic signal study for all my indicator studies.

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

Postby TJ » 24 Jul 2009

where can I find info on this MC built-in global variable ?

janus
Posts: 835
Joined: 25 May 2009
Has thanked: 63 times
Been thanked: 104 times

Postby janus » 24 Jul 2009

In the "Functions" folder you can see four of them each starting with GV. I don't think there's any documentation but they appear to use the same syntax as V2.2 of GlobalVariable.dll

wegi
Posts: 124
Joined: 02 Jun 2009
Has thanked: 5 times
Been thanked: 13 times

Postby wegi » 24 Jul 2009

Very interessting !

But there is one thing, i cant find out.
Is there any order how scripts are calculated.
Example:
Indicator 1 says at Bar No. 10 buy long and pass the value to a global variable: "G1"
Signal 1 watches G1 for a buy signal and will do the order.

How can i ensure, that at Bar 10 first the indicator calculate the value for G1 and then Signal 1 is processed ?
Can it happen, that Siganl 1 get the value at Bar No. 11 ?

In my second software (tradesignal) there is a definitiv order. The order depends on the order how the scripts are added to the chart. The First script is processed first, and so on. So, with the wrong order, it can happen that signal 1 gets the correct value at bar No. 11.

With the pushpop.dll i could not discover this problem.

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

Postby TJ » 24 Jul 2009

In the "Functions" folder you can see four of them each starting with GV. I don't think there's any documentation but they appear to use the same syntax as V2.2 of GlobalVariable.dll
thanks

I would like to learn more about this MC-built-in Global Variable.

but I wouldn't know which GVfunction is from MC and which is the 3rd party's... because I have already installed the 3rd party GV.
I have a list of 17 GV functions in my PLEditor.

Marina/Andrew: can you shed more light on this?
e.g. what can this GV do and how to use this GV?


.
Last edited by TJ on 24 Jul 2009, edited 5 times in total.

janus
Posts: 835
Joined: 25 May 2009
Has thanked: 63 times
Been thanked: 104 times

Postby janus » 24 Jul 2009

Through trail an error I found the best way is to place the indicator on a 5 minute chart (or whatever your preference), and the signal study on a tick chart. I find that way the orders are processed almost immediately after the indicator study has set the global variables. Sometimes there may be a slight delay due to low activity in the market.

janus
Posts: 835
Joined: 25 May 2009
Has thanked: 63 times
Been thanked: 104 times

Postby janus » 24 Jul 2009

The four that I have are:

GVSetNamedInt
GVSetNamedDouble
GVGetNamedInt
GVGetNamedDouble

Don't have the Boolean and string versions unlike the other dll. For now the basic ones suite me fine.

wegi
Posts: 124
Joined: 02 Jun 2009
Has thanked: 5 times
Been thanked: 13 times

Postby wegi » 24 Jul 2009

the advantage of the puspop.dll is, that you can access historical values by datetime. i always pass the datetime of the current bar.
so i think if i allow calculating by tick and not once per bar, i get the right values with the second tick.

janus
Posts: 835
Joined: 25 May 2009
Has thanked: 63 times
Been thanked: 104 times

Postby janus » 25 Jul 2009

Thanks for the idea. It reminds me of my younger days of programming in machine language using the stack pointer to share information between routines, in particular interrupt routines. It was very useful. That's another point; it would be nice if MC had a programmable interrupt or mutex interface. For example, a study could send an interrupt to trigger all other studies that are programmed to wait for it without waiting for the next tick update. Would be a nice addition to those who know how to program complex studies.

Spaceant
Posts: 254
Joined: 30 May 2009
Has thanked: 1 time
Been thanked: 3 times

Postby Spaceant » 30 Jul 2009

Can any TS Support team provide info about the usage of pre-built GV tools?

Sa

User avatar
Andrew Kirillov
Posts: 1589
Joined: 28 Jul 2005
Has thanked: 2 times
Been thanked: 31 times
Contact:

Postby Andrew Kirillov » 30 Jul 2009

This is 3d party add-on. We haven't developed it and I'm afraid we are not able to provide the requested info.


Return to “MultiCharts”