Announcement

Collapse
No announcement yet.

converting a DLL indcator to a serial object in EFS2

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • converting a DLL indcator to a serial object in EFS2

    This is the EFS1 code for the DLL.
    PHP Code:
    // load our DLL in global space.
    var mydll = new DLL("C:\\Program Files\\Kwik POP for eSignal\\kpesignal.dll");

    mydll.addFunction("E_CREATESTATE"DLL.INTDLL.STDCALL"E_CREATESTATE"DLL.STRINGDLL.INT);
    mydll.addFunction("E_CHECKSTATE"DLL.INTDLL.STDCALL"E_CHECKSTATE"DLL.INT);
    mydll.addFunction("E_BARVALUES"DLL.INTDLL.STDCALL"E_BARVALUES"DLL.INTDLL.INTDLL.INTDLL.INTDLL.DOUBLEDLL.DOUBLEDLL.DOUBLEDLL.DOUBLEDLL.DOUBLE);

    mydll.addFunction("E_TSKPA900"DLL.DOUBLEDLL.STDCALL"E_TSKPA900"DLL.INT);

    var 
    DFLAG 0;

    function 
    preMain()
    {
      
        
    setPriceStudy(true);
        
    setStudyTitle("TSKPa900");
        
    setCursorLabelName("TSKPa900",0);
        
    setDefaultBarFgColor(Color.lime,0);
    }

    var 
    stateID 0;
    var 
    cum1 0;

    function 
    longdate()
    {
        var 
    ldate getYear() * 10000;
        
    ldate += getMonth() * 100;
        
    ldate += getDay();
        
        return 
    ldate;  
    }

    function 
    longtime()
    {
        var 
    ltime getHour() * 10000;
        
    ltime += getMinute() * 100;
        
    ltime += getSecond();
        
        return 
    ltime;
    }



    function 
    main()
    {
        
    //first thing we're going to plot is TSKPa900
            
          
        
    var tskpa900 0;
      
        var 
    nBarState getBarState();
        if ( 
    nBarState == BARSTATE_ALLBARS)
        {
            
    cum1 0;
            
    stateID 0;
            
    // make it create a new state when it starts up.
        
    }
        else if( 
    nBarState == BARSTATE_NEWBAR)
        {
            
    cum1++;
        }
      
        if( 
    stateID != )
        {
            var 
    check mydll.call("E_CHECKSTATE"stateID);
            
            if( 
    check == )
            {
                
    // We have to recalculate from the first bar.
                
    reloadEFS();
                
    stateID 0;
            }
        }
        
        
        if( 
    stateID == )
        {
            
    stateID mydll.call("E_CREATESTATE",getUserName(),1); // the 1 tells it to use garbage collection.
        
    }
        
        if( 
    stateID )
        {
            
            
    // we actually have gotten this far, we can go ahead and try to do something.
            // mydll.addFunction("E_BARVALUES", DLL.INT, DLL.CDECL, "E_BARVALUES", DLL.INT, DLL.INT, DLL.INT, DLL.INT, DLL.DOUBLE, DLL.DOUBLE, DLL.DOUBLE, DLL.DOUBLE, DLL.DOUBLE);

            
    var bv mydll.call("E_BARVALUES",stateID,cum1longdate(), longtime(), open(), high(), low(), close(), volume());
            if( 
    bv != )
            {
              
                
    // they actually seem to have a license.
                // this is where we calculate an actual indicator value.
                
                // of the function in the DLL it still crashes.
                
    tskpa900 mydll.call("E_TSKPA900"stateID);
                
            }
            
        }
        
        return (
    tskpa900);

    I took the guts of the DLL and put into an efslib. Here is that code.
    PHP Code:
    //  Kwik Pop Function Library
    // load our DLL in global space.
    var KPdll = new DLL("C:\\Program Files\\Kwik POP for eSignal\\kpesignal.dll");
    //common to all KP indicators
    KPdll.addFunction("E_CREATESTATE"DLL.INTDLL.STDCALL"E_CREATESTATE"DLL.STRINGDLL.INT);
    KPdll.addFunction("E_CHECKSTATE"DLL.INTDLL.STDCALL"E_CHECKSTATE"DLL.INT);
    KPdll.addFunction("E_BARVALUES"DLL.INTDLL.STDCALL"E_BARVALUES"DLL.INTDLL.INTDLL.INTDLL.INTDLL.DOUBLEDLL.DOUBLEDLL.DOUBLEDLL.DOUBLEDLL.DOUBLE);
    // specific KP indicators
    KPdll.addFunction("E_TSKPA900"DLL.DOUBLEDLL.STDCALL"E_TSKPA900"DLL.INT); 
    function 
    initLib()
    {
     
     
    }

    var 
    stateID 0;
    var 
    cum1 0;
    var 
    vSymbol null;

    function 
    longdate()
    {
        var 
    ldate getYear(0,sym(vSymbol)) * 10000;
        
    ldate += getMonth(0,sym(vSymbol)) * 100;
        
    ldate += getDay(0,sym(vSymbol));
        
        return 
    ldate;  
    }

    function 
    longtime()
    {
        var 
    ltime getHour(0,sym(vSymbol)) * 10000;
        
    ltime += getMinute(0,sym(vSymbol)) * 100;
        
    ltime += getSecond(0,sym(vSymbol));
        
        return 
    ltime;
    }



    function 
    A900(symbolinterval)
    {
        var 
    tskpa900 0;
        var 
    nBarState getBarState();
        

            if(
    symbol == nullsymbol getSymbol();
            if(
    interval == nullinterval getInterval();
            
    vSymbol symbol "," interval;
     
        if ( 
    nBarState == BARSTATE_ALLBARS)
        {
            
    cum1 0;
            
    stateID 0;
            
    // make it create a new state when it starts up.
        
    }
        else if( 
    nBarState == BARSTATE_NEWBAR)
        {
            
    cum1++;
        }
      
        if( 
    stateID != )
        {
            var 
    check KPdll.call("E_CHECKSTATE"stateID);
            
            if( 
    check == )
            {
                
    // We have to recalculate from the first bar.
                
    reloadEFS();
                
    stateID 0;
            }
        }
        
        
        if( 
    stateID == )
        {
            
    stateID KPdll.call("E_CREATESTATE",getUserName(),1); // the 1 tells it to use garbage collection.
        
    }
        
        if( 
    stateID )
        {
            
            
    // we actually have gotten this far, we can go ahead and try to do something.
            // mydll.addFunction("E_BARVALUES", DLL.INT, DLL.CDECL, "E_BARVALUES", DLL.INT, DLL.INT, DLL.INT, DLL.INT, DLL.DOUBLE, DLL.DOUBLE, DLL.DOUBLE, DLL.DOUBLE, DLL.DOUBLE);

            
    var bv KPdll.call("E_BARVALUES",stateID,cum1longdate(), longtime(), open(0,sym(vSymbol)), high(0,sym(vSymbol)), low(0,sym(vSymbol)), close(0,sym(vSymbol)), volume(0,sym(vSymbol)));
            if( 
    bv != )
            {
                
    // this is where we calculate an actual indicator value.
                
    tskpa900 KPdll.call("E_TSKPA900"stateID);
            }
            
        }
        
        return (
    tskpa900);

    And here is the new indicator in EFS2.
    PHP Code:
    // Plot ESKPa900 on the price chart
    function preMain()
    {
        
    setPriceStudy(true);
        
    setStudyTitle("ESKPa900A");
        
    setCursorLabelName("ESKPa900",0);
        
    setDefaultBarFgColor(Color.lime,0);

        
    //Formula Parameters
        
    fp1 = new FunctionParameter("Symbol"FunctionParameter.STRING);
        
    with(fp1) {
            
    setDefault("");
        }
        
    fp2 = new FunctionParameter("Interval"FunctionParameter.NUMBER);
        
    with(fp2) {
            
    setDefault("");
        }
    }

    // global variables
    var KPLib addLibrary("KPFunctions.efsLib")    
    var 
    bInit false;  //initialization flag
    var xa900 null;   //a900 


    function main(SymbolInterval)
    {
        
    // one time initialization
        
    if(bInit == false){
            if(
    Symbol == nullSymbol getSymbol();
            if(
    Interval == nullInterval getInterval();
             
    bInit true;
        }   
        
        
    xa900 KPLib.A900(SymbolInterval);
        return 
    xa900;

    I have no idea if this is the correct/best way to convert a DLL to EFS2. Any suggestions or comments would be appreciated.

    There are also DLL indicators that return an array of values that I will have to worry about.

    Thanks

  • #2
    Hi I try to create the followin efs but not working not mistakes shown as well.

    .........
    function preMain()
    {
    setPriceStudy(true);
    setStudyTitle("TSKPRESISTANCESWINGLINE");
    setCursorLabelName("TSKPRESISTANCESWINGLINE",0);
    setDefaultBarFgColor(Color.aqua,0);

    //Formula Parameters
    fp1 = new FunctionParameter("Symbol", FunctionParameter.STRING);
    with(fp1) {
    setDefault("");
    }
    fp2 = new FunctionParameter("Interval", FunctionParameter.NUMBER);
    with(fp2) {
    setDefault("");
    }

    }

    // global variables
    var KPLib = addLibrary("KPFunctions2.efsLib")
    var bInit = false; //initialization flag
    var resistanceswingline = null; //resistanceswingline



    function main(Symbol, Interval)
    {
    // one time initialization
    if(bInit == false){
    if(Symbol == null) Symbol = getSymbol();
    if(Interval == null) Interval = getInterval();
    bInit = true;

    }
    resistanceswingline = KPLib.resistanceswingline(Symbol, Interval);
    return (resistanceswingline);
    }

    .............
    I made an extra efslib
    the KPFunction2.efslib as following.
    // Kwik Pop Function Library
    // load our DLL in global space.
    var KPdll = new DLL("C:\\Program Files\\Kwik POP for eSignal\\kpesignal.dll");
    //common to all KP indicators
    KPdll.addFunction("E_CREATESTATE", DLL.INT, DLL.STDCALL, "E_CREATESTATE", DLL.STRING,

    DLL.INT);
    KPdll.addFunction("E_CHECKSTATE", DLL.INT, DLL.STDCALL, "E_CHECKSTATE", DLL.INT);
    KPdll.addFunction("E_BARVALUES", DLL.INT, DLL.STDCALL, "E_BARVALUES", DLL.INT, DLL.INT,

    DLL.INT, DLL.INT, DLL.DOUBLE, DLL.DOUBLE, DLL.DOUBLE, DLL.DOUBLE, DLL.DOUBLE);
    // specific KP indicators
    KPdll.addFunction("E_TSKPA900", DLL.DOUBLE, DLL.STDCALL, "E_TSKPA900", DLL.INT);
    KPdll.addFunction("E_TSKPSWINGLINE", DLL.DOUBLE, DLL.STDCALL, "E_TSKPSWINGLINE", DLL.INT);

    function initLib()
    {


    }

    var stateID = 0;
    var cum1 = 0;
    var vSymbol = null;

    function longdate()
    {
    var ldate = getYear(0,sym(vSymbol)) * 10000;
    ldate += getMonth(0,sym(vSymbol)) * 100;
    ldate += getDay(0,sym(vSymbol));

    return ldate;
    }

    function longtime()
    {
    var ltime = getHour(0,sym(vSymbol)) * 10000;
    ltime += getMinute(0,sym(vSymbol)) * 100;
    ltime += getSecond(0,sym(vSymbol));

    return ltime;
    }


    function resistanceswingline (symbol, interval);
    {
    var resistanceswingline = 0;
    var nBarState = getBarState();

    if(symbol == null) symbol = getSymbol();
    if(interval == null) interval = getInterval();
    vSymbol = symbol + "," + interval;


    if ( nBarState == BARSTATE_ALLBARS)
    {
    cum1 = 0;
    stateID = 0;
    // make it create a new state when it starts up.
    }
    else if( nBarState == BARSTATE_NEWBAR)
    {
    cum1++;
    }


    if( stateID != 0 )
    {
    var check = KPdll.call("E_CHECKSTATE", stateID);

    if( check == 0 )
    {
    // We have to recalculate from the first bar.
    reloadEFS();
    stateID = 0;
    }
    }


    if( stateID == 0 )
    {
    stateID = KPdll.call("E_CREATESTATE",getUserName(),1); // the 1 tells it to use

    garbage collection.
    }

    if( stateID )
    {

    // we actually have gotten this far, we can go ahead and try to do something.
    // mydll.addFunction("E_BARVALUES", DLL.INT, DLL.CDECL, "E_BARVALUES", DLL.INT,

    DLL.INT, DLL.INT, DLL.INT, DLL.DOUBLE, DLL.DOUBLE, DLL.DOUBLE, DLL.DOUBLE, DLL.DOUBLE);

    var bv = KPdll.call("E_BARVALUES",stateID,cum1, longdate(), longtime(), open(),

    high(), low(), close(), volume());
    if( bv != 0 )
    {

    // they actually seem to have a license.
    // this is where we calculate an actual indicator value.

    KPdll.call("E_TSKPSWINGLINE", stateID);

    resistanceswingline = KPdll.call("E_GETRETURN",stateID,2); // 3rd return

    }

    }

    return (resistanceswingline);
    }
    .............
    Any Ideas?

    Comment

    Working...
    X