logo
Welcome Guest! To enable all features please Login or Register.

Notification

Icon
Error

Options
Go to last post Go to first unread
roymadhavi  
#1 Posted : Thursday, December 15, 2005 4:17:41 PM(UTC)
roymadhavi

Rank: Member

Groups: Registered, Registered Users
Joined: 12/15/2005(UTC)
Posts: 13

I have written a ExtFml function that plays either a "BUY" or "SELL" wav file. It works fine. I want to call the function with "BUY" only when the C>O and "SELL" when C<O. However, no matter what I do, it calls and plays both "BUY" and "SELL" on every bar. Please help.
StorkBite  
#2 Posted : Friday, December 16, 2005 6:05:14 AM(UTC)
StorkBite

Rank: Advanced Member

Groups: Registered, Registered Users
Joined: 3/19/2005(UTC)
Posts: 2,995

Was thanked: 14 time(s) in 10 post(s)
What is the function and how are you calling it?
roymadhavi  
#3 Posted : Friday, December 16, 2005 3:21:41 PM(UTC)
roymadhavi

Rank: Member

Groups: Registered, Registered Users
Joined: 12/15/2005(UTC)
Posts: 13

Hi, Thanks for the reply.... I am using following formulaes for the buy B1 := LastValue(If(C>O, 2,0)); ExtFml( "MSXDll.MakeMyPosition", "MSFT",B1,"Test MSFT") For Sell If(O>C, ExtFml( "MSXDll.MakeMyPosition", "MSFT", -1, "Test MSFT"), 0) ; If(O>C,1,0); Thanks Madhavi
Ricci  
#4 Posted : Friday, December 16, 2005 8:26:56 PM(UTC)
Ricci

Rank: Member

Groups: Registered, Registered Users
Joined: 11/28/2005(UTC)
Posts: 12
Location: Salt Lake City

Hi Madhavi, Let me just first say that I hope you're not appying this to real-time data, because you'll have sound files being played nearly everytime a tick comes in. That could get really annoying! The next thing I need to say is that it doesn't look like we're getting the entire picture here. Your question seems pretty clear, but your formulae seem to reference things and perform a lot more functionality than you expressed in the first post. For example, what are all the references to MSFT? Why are you using a formula to test if close > open when you've already written an MSX DLL that could compute that kind of thing hundreds or thousands of times faster? Needless to say, I'm a little confused by your problem. In order to overcome that confusion, I'm just going to address your first post and assume that you want a function in an MSX DLL to play a wave file (like Buy.wav perhaps) when close > open and another one (like Sell.wav) when close < open. Hopefully that will help. If not, post again! :) Your formula that calls the external function can be very simple. You don't even need one for buy and one for sell. Just use the following formula: [code:1:0aeae01c1a]ExtFml( "MSXDll.MakeMyPosition" )[/code:1:0aeae01c1a] The function in your MSX DLL doesn't need to take any parameters, unless you want to pass the wave file names or something like that. One thing you want to be careful to do is only look at the last bar. Every time your MSX function is called, it is given all the data. You certainly don't want to play a sound for every bar, just the last one. Here is some example code: [code:1:0aeae01c1a] BOOL __stdcall MakeMyPosition(const MSXDataRec *a_psDataRec, const MSXDataInforRecArgsArray *a_psDataInfoArgs, const MSXNumericArgsArray *a_psNumericArgs, const MSXStringArgsArray *a_psCustomArgs, const MSXCustomArgsArray *a_psCustomArgs, MSXResultRec *a_psResultRec) { // First, we're going to play a sound, not return any results, so zero // out a_psResultRec via the iFirstValid and iLastValid fields in a_psResultRec. a_psResultRec->psResultArray->iFirstValid = 0; a_psResultRec->psResultArray->iLastValid = -1; // Second, get the open and close value from the last bar in the input data. // (You'll want to do some error checking here, like making sure that there is // actually any data in the record, and making sure that the open and close // data both end on the same record. For the sake of brevity and clarity, I // haven't included that kind of error checking for this example.) float open = a_psDataRec->sOpen.pfValue[a_psDataRec->sOpen.iLastValid]; float close = a_psDataRec->sClose.pfValue[a_psDataRec->sClose.iLastValid]; // Third, compare the open and close and play the appropriate file. // (Note that there are three possibilities here. Open could be greater than // close, open could be less than close, or open could be equal to close. You // didn't say anything about doing something if they are equal, so here I test // for the greater than and less than conditions, and do nothing for the equal // condition.) if(open > close) { // Insert your code to play Sell.wav here! } else if(open < close) { // Insert your code to play Buy.wav here! } // We're done, return return MSX_SUCCESS; } [/code:1:0aeae01c1a] You didn't specify a programming language, so I hope C is ok. I hope this helps. If it doesn't meet your requirements, it's because you didn't give them all. :P Just post again if you still have problems. Good luck, Rich
roymadhavi  
#5 Posted : Monday, December 19, 2005 9:11:54 PM(UTC)
roymadhavi

Rank: Member

Groups: Registered, Registered Users
Joined: 12/15/2005(UTC)
Posts: 13

Hi Rich, Thanks for the reply. I am doing this with MS reat time only. I want to call this external function every minute instead of every tick with buy and sell signals. In general, I want to call my function with buy signal when buy signal is displayed on the MS chart and sell signal when the sell signal is displayed on the MS chart. Plz help. Thanks Madhavi Roy
Branden Russell  
#6 Posted : Monday, December 19, 2005 10:47:56 PM(UTC)
Branden Russell

Rank: Advanced Member

Groups: Registered, Registered Users
Joined: 11/28/2005(UTC)
Posts: 276
Location: Salt Lake City, UT

I'm not sure I understand what you're doing. It is built into MetaStock (in an Expert Advisor) to be able to play a sound file based on a formula. Is this what you want? MSX DLL functions need to be passed all data, not just one data point. It will then do anything you have the function do (play sounds, calculations, etc) and then return an array of data to be plotted on the chart.
roymadhavi  
#7 Posted : Tuesday, December 20, 2005 7:19:02 PM(UTC)
roymadhavi

Rank: Member

Groups: Registered, Registered Users
Joined: 12/15/2005(UTC)
Posts: 13

Hi, This is what I need. I want to call my dll function whenever MS chart shows buy/sell. That is, if the MS shows buy, then for that tick, I want to call my external function with the buy signal and same for sell. This should remain same for whatever MS formulae is used in the experts advisor. In general i want to pass on the sell/buy tick to the dll function whenevr they occur. Hope now the question is much more clearer. Thanks Madhavi Roy
Branden Russell  
#8 Posted : Wednesday, December 21, 2005 4:52:53 PM(UTC)
Branden Russell

Rank: Advanced Member

Groups: Registered, Registered Users
Joined: 11/28/2005(UTC)
Posts: 276
Location: Salt Lake City, UT

roymadhavi wrote:
Hi, This is what I need. I want to call my dll function whenever MS chart shows buy/sell. That is, if the MS shows buy, then for that tick, I want to call my external function with the buy signal and same for sell. This should remain same for whatever MS formulae is used in the experts advisor. In general i want to pass on the sell/buy tick to the dll function whenevr they occur. Hope now the question is much more clearer. Thanks Madhavi Roy
That's not how it works. MSX DLL functions need to be passed all data, not just one data point. It will then do anything you have the function do (play sounds, calculations, etc) and then return an array of data to be plotted on the chart. You will have to pass it all the data. You could have it look at just the last value, but it has to know what makes the data a buy or sell signal. You could pass that information in as one of the parameters.
Ricci  
#9 Posted : Wednesday, December 21, 2005 6:03:11 PM(UTC)
Ricci

Rank: Member

Groups: Registered, Registered Users
Joined: 11/28/2005(UTC)
Posts: 12
Location: Salt Lake City

Another thing to consider is that the expert advisor will play sound files. Have you looked into that functionality? Is there something you need that it does not do? -Rich
roymadhavi  
#10 Posted : Wednesday, December 21, 2005 6:09:19 PM(UTC)
roymadhavi

Rank: Member

Groups: Registered, Registered Users
Joined: 12/15/2005(UTC)
Posts: 13

Ok, I understand this. Actually what is happening now is that my function is getting called for every tick. No doubt that all the data is passed to this function. My requirement is to call this function only when either a buy signal or a sell signal is generated/shown on the MS chart. I am new to MS development, so I have no idea if this is at all possible. Plz let me knoe if it is really possible and if yes than how?? Thanks Madhavi Roy
Patrick  
#11 Posted : Wednesday, December 21, 2005 6:18:14 PM(UTC)
Patrick

Rank: Advanced Member

Groups: Registered, Registered Users, Subscribers
Joined: 9/8/2004(UTC)
Posts: 2,266

Was thanked: 1 time(s) in 1 post(s)
What don't you keep it simple .... IF (condition,ExtFml( "MSXDll.MakeMyPosition"),0) I don't understand what the issue is here ... If I understood poperly your function only calls up a sound file, that's all it does right? Patrick :mrgreen:
roymadhavi  
#12 Posted : Wednesday, December 21, 2005 6:46:41 PM(UTC)
roymadhavi

Rank: Member

Groups: Registered, Registered Users
Joined: 12/15/2005(UTC)
Posts: 13

Sorry for bothering u again..... Now instead of playing the sound file, i am writing the data sent to the dll in a file, just to learn how MS works and how the external functions are called. If(Cross(C,O), ExtFml("MSXDll.MakeMyPosition"), 0); Cross(C,O); I am using the above formulae to call my function. Now this shows the buy signal on the chart and calls my external function. So the number of times my function is called and this buy signal is displayed on the MS chart should be same, but I find that my function is called more number of times than the buy signal displayed on the MS chart screen. I just want to synchronize these two.[/list]
Ricci  
#13 Posted : Wednesday, December 21, 2005 7:14:08 PM(UTC)
Ricci

Rank: Member

Groups: Registered, Registered Users
Joined: 11/28/2005(UTC)
Posts: 12
Location: Salt Lake City

Originally Posted by: MSXDll.MakeMyPosition"), 0) Go to Quoted Post
The problem that you are running into here is that there is no "short circuiting" in the MetaStock formula language. This means that if you have a formula like [code:1:9bd6267b9e]if(O>C, ExtFml( "MSXDll.MakeMyPosition" ), 0);[/code:1:9bd6267b9e] your external formula will be called every time, not just when O>C. The point of the if statement is not to keep something from being called, but to select which results will be returned by the if statement. So, in the above formula, the external function is called every time, as is anything in the other case of the if statement, but the results of the external function are used for the results of the if statement only when O>C. It is important to remember that a formula does not calculate on a row-by-row basis. The above code is evaluated in only three steps, not three steps per row. This allows some huge performance gains. Here's what happens: 1. O>C is evaluated. 2. ExtFml( "MSXDll.MakeMyPosition" ) is evalualted. 3. 0 is evaluated. In this case (where we're dealing with a constant), that means that an array the size of the input data is filled with the constant, or zero. 4. The if statement results are produced, choosing at each data point either the results from step 2 or from step 3, depending on the results of step 1. Hope this helps. By the way, it's not a bother. This is a common question, and it's discussion here should benefit many. So, please keep posting your questions. -Rich
roymadhavi  
#14 Posted : Wednesday, December 21, 2005 7:56:15 PM(UTC)
roymadhavi

Rank: Member

Groups: Registered, Registered Users
Joined: 12/15/2005(UTC)
Posts: 13

Ok then from the data passed to the external function, how can i figure out that buy signal is sent...Probably i will need to check the condition in the function itself...Am I right??
Ricci  
#15 Posted : Wednesday, December 21, 2005 8:06:41 PM(UTC)
Ricci

Rank: Member

Groups: Registered, Registered Users
Joined: 11/28/2005(UTC)
Posts: 12
Location: Salt Lake City

Quote:
Ok then from the data passed to the external function, how can i figure out that buy signal is sent...Probably i will need to check the condition in the function itself...Am I right??
You can either check the condition in the function, or you can check the condition in the formula language and pass that in to the function, like so: [code:1:4d3da6d438]ExtFml( "MSXDll.MakeMyPosition", C>O )[/code:1:4d3da6d438] This is the simplest way to write it. Checking for the condition in the function itself is more efficient though, if you want to do it that way. -Rich
roymadhavi  
#16 Posted : Wednesday, December 21, 2005 8:34:17 PM(UTC)
roymadhavi

Rank: Member

Groups: Registered, Registered Users
Joined: 12/15/2005(UTC)
Posts: 13

when i call this way, it says "This variable or expression must contain only constant data.". Am I missing something... Thanks
Ricci  
#17 Posted : Wednesday, December 21, 2005 9:39:44 PM(UTC)
Ricci

Rank: Member

Groups: Registered, Registered Users
Joined: 11/28/2005(UTC)
Posts: 12
Location: Salt Lake City

You know, after attempting to implement this myself, I have come to the conclusion that not only is it more efficient to calculate the BUY/SELL condition in the DLL, it is simpler also, because you don't have to pass a parameter to the DLL, and you don't have to determine if you are looking for a BUY signal or a SELL signal or write two seperate functions or any of that. Here's the formula I'd use: [code:1:bd7b5ee67c]ExtFml( "MSXDll.MakeMyPosition" )[/code:1:bd7b5ee67c] Here is the MSXNthFunction function: [code:1:bd7b5ee67c]BOOL __stdcall MSXNthFunction(int a_iNthFunc, MSXFuncDef* a_psFuncDef) { BOOL l_bRtrn = MSX_SUCCESS; switch(a_iNthFunc) { case 0: strcpy(a_psFuncDef->szFunctionName, "MakeMyPosition"); strcpy(a_psFuncDef->szFunctionDescription, "MakeMyPosition Description"); a_psFuncDef->iNArguments = 0; break; default: l_bRtrn = MSX_ERROR; break; } return l_bRtrn; }[/code:1:bd7b5ee67c] Here's the MSXNthArg function: [code:1:bd7b5ee67c]BOOL __stdcall MSXNthArg(int a_iNthFunc, int a_iNthArg, MSXFuncArgDef *a_psFuncArgDef) { // There are no args, this shouldn't be called return MSX_ERROR; }[/code:1:bd7b5ee67c] This doesn't require any custom strings, so your MSXNthCustomString function can just always return MSX_ERROR, just like the MSXNthArg function. Finally, your MakeMyPosition function as I posted some time ago: [code:1:bd7b5ee67c]BOOL __stdcall MakeMyPosition(const MSXDataRec *a_psDataRec, const MSXDataInforRecArgsArray *a_psDataInfoArgs, const MSXNumericArgsArray *a_psNumericArgs, const MSXStringArgsArray *a_psCustomArgs, const MSXCustomArgsArray *a_psCustomArgs, MSXResultRec *a_psResultRec) { // First, we're going to play a sound, not return any results, so zero // out a_psResultRec via the iFirstValid and iLastValid fields in a_psResultRec. a_psResultRec->psResultArray->iFirstValid = 0; a_psResultRec->psResultArray->iLastValid = -1; // Second, get the open and close value from the last bar in the input data. // (You'll want to do some error checking here, like making sure that there is // actually any data in the record, and making sure that the open and close // data both end on the same record. For the sake of brevity and clarity, I // haven't included that kind of error checking for this example.) float open = a_psDataRec->sOpen.pfValue[a_psDataRec->sOpen.iLastValid]; float close = a_psDataRec->sClose.pfValue[a_psDataRec->sClose.iLastValid]; // Third, compare the open and close and play the appropriate file. // (Note that there are three possibilities here. Open could be greater than // close, open could be less than close, or open could be equal to close. You // didn't say anything about doing something if they are equal, so here I test // for the greater than and less than conditions, and do nothing for the equal // condition.) if(open > close) { // Insert your code to play Sell.wav here! } else if(open < close) { // Insert your code to play Buy.wav here! } // We're done, return return MSX_SUCCESS; }[/code:1:bd7b5ee67c] Hope that helps, Rich
StorkBite  
#18 Posted : Thursday, December 22, 2005 2:39:47 AM(UTC)
StorkBite

Rank: Advanced Member

Groups: Registered, Registered Users
Joined: 3/19/2005(UTC)
Posts: 2,995

Was thanked: 14 time(s) in 10 post(s)
Is this whole issue just a matter of suppressing multiple signals? If so, you might check the FAQ or search the forum for some remedies. It sounds like you are calling your dll fine, but can't control when it is being called. Look for flip-flop control (training video on latches) or use of the Alert() function.
Patrick wrote:
MetaStock sends a message every time the alert conditions is tested and found to be true. Normally, the alerts are tested for each tick that comes in. You can change it to be tested only after a bar is completed by changing the following option: TOOLS | OPTIONS, under the real-time tab, uncheck the ‘Recalcualate Expert Live’ option.
Apart from precise control, a dirtier method might be to control it from the tool/ options as Patrick posted eons ago. HTH, George
wabbit  
#19 Posted : Thursday, December 22, 2005 2:52:28 AM(UTC)
wabbit

Rank: Advanced Member

Groups: Registered, Registered Users, Subscribers, Unverified Users
Joined: 10/28/2004(UTC)
Posts: 3,111
Location: Perth, Western Australia

Was thanked: 16 time(s) in 16 post(s)
I might not have read this thread correctly, so forgive me if I am wrong in my assumptions: I am assuming the goal is to play a .wav file iff (if and only if) a particular condition is met. Isn't that what the MS expert advisor alerts are for? If the alert keeps triggering when the condition is met earlier in the history, like it does, and you dont feel clicking the "skip all remaining alerts" checkbox each time, just add to your condition: soundAlert:=myBuyCondition and cum(1)=LastValue(cum(1)); soundAlert; so the alert will only sound on the latest bar. This might be the simple solution, or my simplistic view of the problem, but the I am a firm believer in Occam. wabbit :D
Users browsing this topic
Guest (Hidden)
Forum Jump  
You cannot post new topics in this forum.
You cannot reply to topics in this forum.
You cannot delete your posts in this forum.
You cannot edit your posts in this forum.
You cannot create polls in this forum.
You cannot vote in polls in this forum.