Register Login
Forums    February 9, 2012
TradersStudio Forums
Use of Gvalue1 in a DLL?
Last Post 09-05-2007 08:02 PM by mur ang. 5 Replies.
Printer Friendly
  •  
  •  
  •  
  •  
  •  
Sort:
PrevPrev NextNext
You are not authorized to post a reply.
Author Messages
Tom Himel
New Member
New Member
Posts:14

--
09-04-2007 04:42 PM

    I've written a DLL in VB .NET that is called by TradersStudio.  It appears that the object that contains the routines in the DLL is reinstantiated every time a new market is started.  This means that no data can easily be passed on from the analysis of one market to the analysis of another.

    First of all, am I right that this is what happens?

    Secondly, is there a way to pass such data?  Within TradersStudio Basic, Gvalue1 etc. could be used.  Is there a way to use them here or some other way to retain data?

    Thanks.

    mur ang
    Advanced Member
    Advanced Member
    Posts:525

    --
    09-04-2007 05:34 PM

    Yes, you are correct. Each Market is independent. We do this for other reasons when we get to real time.

    I will need to check on it, I have not tried it. You can try to use Script.Eval("GValue1="&cstr(myval)) , if that does not work I have other Ideas.

    Tom Himel
    New Member
    New Member
    Posts:14

    --
    09-05-2007 03:17 AM

    I now have the following code to my DLL:

     

    Public Sub attachScript(ByRef script As Object)

    'this is called early on by TradersStudio to pass a pointer to the script object to us.

    'It contains the price series etc. Just save the pointer.

    m_script = script

    test = script.eval("GValue1")

    test = test + 1

    script.Eval("GValue1=" & CStr(test))

    End Sub

    Test is declared as in Integer earlier.  Test always gets a value of 0 from the first call to script.eval.  Hence, it looks like this method doesn't work.  I would appreciate your other ideas.  (I suppose if all else fails I can save my data in the registry.)

    By-the-way, I notice that if I run a sesssion that contains n markets that attachScript and attachMarket are each called alternately n+1 times before the function I explictly call from my indicator is called.  They are each then called once again before my function is called for each new market.  This is not a significant problem for me, but I'm curious as to the reason.

    mur ang
    Advanced Member
    Advanced Member
    Posts:525

    --
    09-05-2007 10:25 AM

    This is the low level function GValueXX is created from try the LangSub and LangFunc API call to use these.

     

     

    SetBuiltInVar -- Subroutine

     

    Sets the value of a built-in Variable.  Passes the variable number '0' to '254' and the value of the variable as a variant.


    There are 255 built-in variables that that can be set using this function. They will remain set for the duration of a backtesting session.  The variable is stored between runs of the 'mom series'.


    Return type


    A Variant value

     

    Syntax

    SetBuiltInVar(Num as Integer,Value as Variant )


    This code shows a good example of using this function with GetBuiltInVar  to write a custom report that outputs a row to the custom report when a 10-day momentum crosses to positive from negative.

    Sub Scanner(SLen)

    Dim CellRow as Integer

    If Close>Close[9] amd Close[1]  then

    CellRow=GetBuiltInVar(0)+1

    SetTextValue(GetActiveSymbol(0),CellRow,1,30)

    SetTextValue(FormatDateTime(date),CellRow,2,10)

    SetTextValue("Uptrend for tomorrows trade ",CellRow,3,40)

    SetBuiltInVar(0,CellRow)

    End if

    End sub

    Tom Himel
    New Member
    New Member
    Posts:14

    --
    09-05-2007 03:28 PM

    I'm afraid this one is being resistant to solution.  I first tried implement your solution above.  It didn't work.  It looked like the call to GetBuiltInVar didn't via LangFunc didn't return a value.

    I then tried a simpler example using the function max3.  Here is the code which is inside a function called from an indicator:

    Dim args3(2)

    args3(0) = 5

    args3(1) = 7

    args3(2) = 9

    test = 99 'set test to something non-zero so we can see if max3 fills it in.

    Dim answer As Integer = m_script.langfunc("max3", args3, test)

    If Not m_script.langfunc("max3", args3, test) Then 'get the value of test

         MsgBox("Error calling max3: " & m_script.error, MsgBoxStyle.OkOnly)

    End If

    Watching this from the debugger, no errors occur. The call to MsgBox does not occur.  Answer is -1 (true) and test keeps its value of 99 instead of being set to max3(5,7,9) = 9.

    I tried varients of this code, introducing things that should cause errors.   I changed the dimension for args3 from 2 to 3 and to 1.  I changed "max3" to "max4". I both added and removed an argument to the langfunc routine.  All of the above gave reasonable error messages leading me to believe that I really am calling max3.  The mystery is why I don't get an answer filled into my variable named test.

    Can you see what I am doing wrong?  Remember that this is VB .NET (2005) I am using, whose TradersStudio interface is only a beta right now.  Any chance it is the difference between VB 6.0 which has a type of variant and VB .NET which has a type of object instead?

    Thanks

    mur ang
    Advanced Member
    Advanced Member
    Posts:525

    --
    09-05-2007 08:02 PM

    I will look into it for you.

    You are not authorized to post a reply.


     TradersStudio, Inc. ® Copyright 2004-2012 All Rights Reserved   Terms Of Use  Privacy Statement