Announcement

Collapse
No announcement yet.

switch for esignal paper trade

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

  • switch for esignal paper trade

    i have attached esignal paper trade to one of my formulas so that it will automatically paper trade the formula in real time, and that is working fine.

    i am now trying to put a switch into the formula so i can turn the paper trade on & off,

    these are my workings for the switch


    var vBrokerType=0; //0=none, 1= esignal paper trade

    if(vBrokerType==1){
    var PTtrade = new PaperTradeBroker;
    }
    if (vBrokerType==0){
    var PTtrade = null;
    }


    the efs runs with the switch off until it trys to execute a trade then i get a syntax error , "PTtrade has no properties" what do i need to do to make it work,

    thanks

  • #2
    Hello shogun,

    You could check to see if PTtrade is null before each line of code that executes a trade or create a boolean flag based on your switch.


    if (PTtrade != null) {
    // allow trade
    }
    Jason K.
    Project Manager
    eSignal - an Interactive Data company

    EFS KnowledgeBase
    JavaScript for EFS Video Series
    EFS Beginner Tutorial Series
    EFS Glossary
    Custom EFS Development Policy

    New User Orientation

    Comment


    • #3
      thanks jason,

      i have now got the switch to work ,what i did was add a "trade function" after the "function main" and made it so the "trade function" would not run unless the switch was on.

      now what i want to try and do is make the switch operate in the edit studies window, instead of opening the efs editor, how is that done .

      this is what i currently have


      var vBrokerType=1; //0=none, 1= esignal paper trade

      if(vBrokerType==1){
      var PTtrade = new PaperTradeBroker;
      }
      if (vBrokerType==0){
      var PTtrade = null;
      }



      function Trade(TradeType) {

      if (vBrokerType == 1){

      if (TradeType== x ){
      PTtrade.Buy(getSymbol(),(Contracts),PaperTradeBrok er.MARKET);
      }

      Comment


      • #4
        Hello shogun,

        Here's a code example of what you'll need to do below. Setting this up with the FunctionParameter class in preMain isn't necessary but it helps with basic error checking. You could alternatively just define the input parameter for the Edit Studies option within the parentheses of the main( ... here ... ) function.

        PHP Code:
        function preMain() {
            
        setStudyTitle("test");
            
        setPriceStudy(true);

            var 
        fp1 = new FunctionParameter("bBroker"FunctionParameter.STRING);
            
        fp1.setName("Enable Trading");
            
        fp1.addOption("true");
            
        fp1.addOption("false");
            
        fp1.setDefault("false");
        }

        var 
        vBrokerType 0;
        var 
        bEdit true;

        function 
        main(bBroker) {

            if (
        bEdit == true) {    // only runs after Edit Studies change
                
        if (bBroker == "false"vBrokerType 0;
                if (
        bBroker == "true"vBrokerType 1;
                
        bEdit false;
            }

            
        // your formula code
            
            
        return;

        Jason K.
        Project Manager
        eSignal - an Interactive Data company

        EFS KnowledgeBase
        JavaScript for EFS Video Series
        EFS Beginner Tutorial Series
        EFS Glossary
        Custom EFS Development Policy

        New User Orientation

        Comment

        Working...
        X