Announcement

Collapse
No announcement yet.

Multiple orders

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

  • Multiple orders

    My trading system is running great on my screen, but I just tryed to connect my system with IB.

    The proble is, that the symbol on the sheet only makes one signal and now it has buyed several times until I have logged off.

    Could you help me?

  • #2
    Hello mautz,

    If you are using an EFS, please attach your formula and I'll take a look at your conditions.
    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
      here is it ...only want to trade 200 shares of each symbol

      //{{EFSWizard_Description
      //
      // This formula was generated by the Alert Wizard
      //
      //}}EFSWizard_Description


      //{{EFSWizard_Declarations
      var vEMA14 = new MAStudy(14, 0, "Close", MAStudy.EXPONENTIAL);
      var vEMA39 = new MAStudy(39, 0, "Close", MAStudy.EXPONENTIAL);
      var vBollinger22 = new BollingerStudy(22, "Close", 20);
      var vLastAlert = -1;
      //}}EFSWizard_Declarations


      function preMain() {
      /**
      * This function is called only once, before any of the bars are loaded.
      * Place any study or EFS configuration commands here.
      */
      //{{EFSWizard_PreMain
      setPriceStudy(true);
      setStudyTitle("");
      //}}EFSWizard_PreMain

      }

      function main() {
      /**
      * The main() function is called once per bar on all previous bars, once per
      * each incoming completed bar, and if you don't have 'setComputeOnClose(true)'
      * in your preMain(), it is also called on every tick.
      */

      //{{EFSWizard_Expressions
      //{{EFSWizard_Expression_1
      if (
      vEMA14.getValue(MAStudy.MA) >= vEMA39.getValue(MAStudy.MA) &&
      high(0) >= vBollinger22.getValue(BollingerStudy.BASIS)
      ) onAction1()
      //}}EFSWizard_Expression_1

      //{{EFSWizard_Expression_2
      else if (
      low(0) < vBollinger22.getValue(BollingerStudy.BASIS)
      ) onAction2();
      //}}EFSWizard_Expression_2

      //}}EFSWizard_Expressions


      //{{EFSWizard_Return
      return null;
      //}}EFSWizard_Return

      }

      function postMain() {
      /**
      * The postMain() function is called only once, when the EFS is no longer used for
      * the current symbol (ie, symbol change, chart closing, or application shutdown).
      */
      }

      //{{EFSWizard_Actions
      //{{EFSWizard_Action_1
      function onAction1() {
      if (vLastAlert != 1) drawShapeRelative(0, low(), Shape.UPARROW, "", Color.RGB(0,128,0), Shape.LEFT);
      if (vLastAlert != 1) Strategy.doLong("", Strategy.MARKET, Strategy.THISBAR, Strategy.DEFAULT, 0);
      if (vLastAlert != 1) buyMarket( getSymbol(), 200 );

      vLastAlert = 1;
      }
      //}}EFSWizard_Action_1

      //{{EFSWizard_Action_2
      function onAction2() {
      if (vLastAlert != 2) drawShapeRelative(0, low(), Shape.DOWNARROW, "", Color.RGB(155,0,0), Shape.LEFT);
      if (vLastAlert != 2) Strategy.doSell("", Strategy.MARKET, Strategy.THISBAR, Strategy.DEFAULT, 0);
      if (vLastAlert != 2) sellShortMarket( getSymbol(), 200 );
      vLastAlert = 2;
      }
      //}}EFSWizard_Action_2

      //}}EFSWizard_Actions

      Comment


      • #4
        Hello mautz,

        Thanks for posting your code. However, real time trading formulas can not be created with the Formula Wizard. You will need to add some addition logic that requires some custom variables, which the Formula Wizard does not currently allow you to create. To get you started in the right direction, here are a few suggestions.

        First, if you aren't already, I strongly suggest that you paper trade your formulas before using them with your broker. Next, you need to prevent the Generic Broker functions from being executed on historical bars while the formula is loading. Otherwise, unwanted trades will be sent to your broker. Add a global variable in the EFS Editor called bRealTime and set it's initial value to false.



        This variable will be used in your conditional statements to make sure that the formula is processing data on the real time bar (bar 0) before submitting a trade. At the top of main() you will check for the bar index of 0 and set bRealTime to true.



        Then in your OnAction functions, modify the if() statements to prevent GB trades from executing unless you're on bar 0. Likewise, it's a good idea to prevent the Strategy functions, which are only used for back testing, from executing on the real time bar.



        You should also consider that your formula logic will be evaluated differently in real time vs back testing. In back testing the formula only evaluates the conditions on completed bars where as in real time they get evaluated on a tick by tick bases. In real time you will get intrabar signals that will differ from the back testing logic. The real time signals that your formula currently produces could become false signals by the time the bar closes. It's up to you to decide how your signals will be evaluated. If you want to duplicate the logic of the back test and only evaluate the trade conditions when the bars complete you will need to place all your trade conditions inside a check for BARSTATE_NEWBAR and then look at bar-1 values in the conditions. If the condition is true, which will be a the open of the real time bar, then execute your market orders. This will ensure that you avoid the intrabar false signals that will occur.
        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


        • #5
          think it´s getting to an end

          ok here are now the three parts...am I right now`?

          **************************************************
          function main( Period, ATRs, RatchInc, longColor, shortColor, lineThick ) {
          var x;
          var nV1, nV2, nV3;
          var nTrToday;
          var nTmp;
          var nVal;

          //script is initializing
          if (getCurrentBarIndex() == 0) bRealTime = true;
          if ( getBarState() == BARSTATE_ALLBARS ) {
          return null;
          }

          if ( bInitialized == false ) {

          nRatchetInc = RatchInc;
          setDefaultBarThickness( Math.round( lineThick ), 0 );

          bInitialized = true;
          }

          //called on each new bar
          if ( getBarState() == BARSTATE_NEWBAR )

          **************************************************
          if ( Strategy.isShort() == false &&
          vEMA39.getValue(MAStudy.MA) > vEMA14.getValue(MAStudy.MA) ) {
          onAction2();
          }

          if ( Strategy.isLong() == false &&
          vEMA14.getValue(MAStudy.MA) > vEMA39.getValue(MAStudy.MA)
          ) {
          onAction1();
          **************************************************
          function onAction1() {
          if (vLastAlert != 1) drawTextRelative(0, low(-2), "Kauf", Color.RGB(0,128,0), Color.RGB(255,255,255), Text.LEFT, "Arial", 9);
          if (vLastAlert != 1 && !bRealtime) Strategy.doLong("", Strategy.MARKET, Strategy.THISBAR, Strategy.DEFAULT, 0);
          if (vLastAlert != 1 && bRealtime) buyMarket( getSymbol(), 200 );
          if (vLastAlert != 1) drawShapeRelative(0, low(0), Shape.UPARROW, "", Color.RGB(0,128,0), Shape.LEFT);
          vLastAlert = 1;
          nDir = 1;
          }

          function onAction2() {
          if (vLastAlert != 2) drawShapeRelative(0, high(), Shape.DOWNARROW, "", Color.RGB(255,0,0), Shape.LEFT);
          if (vLastAlert != 2 && !bRealtime) Strategy.doShort("", Strategy.MARKET, Strategy.THISBAR, Strategy.DEFAULT, 0);
          if (vLastAlert != 2 && bRealtime) sellShortMarket( getSymbol(), 200 );
          if (vLastAlert != 2) drawTextRelative(-1, high(-2), "Verkauf", Color.RGB(155,0,0), Color.RGB(255,255,255), Text.LEFT, "Arial", 9);
          vLastAlert = 2;
          nDir = 0;
          }

          Comment


          • #6
            Hello mautz,

            No, it doesn't appear so. Please post your new version as a complete working formula and I'll look it over. You can also test it with some real time data and the eSignal Paper Broker to determine if it performs to your satisfaction.
            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


            • #7
              here is is

              *****thanks for checking in advance*******
              Code:
              //Global Variables
              var grID                = 0;
              var nBarCounter			= 0;
              var nBarsInTrade		= 0;
              var nRatchetInc			= 0.005;
              var nStatus				= 1;
              var nDir				= 0;
              var nStopPrice			= null;
              var nATR				= null;
              var nATR_1				= null;
              var aFPArray			= new Array();
              var bInitialized		= false;
              
              var vEMA90 = new MAStudy(90, 0, "Close", MAStudy.EXPONENTIAL);
              var vEMA200 = new MAStudy(200, 0, "Close", MAStudy.EXPONENTIAL);
              var vBollinger30 = new BollingerStudy(30, "Close", 20);
              var vLastAlert = -1;
              var bRealTime = false;
              
              
              
              //== PreMain function required by eSignal to set things up
              function preMain() {
              var x;
              
                  setPriceStudy(true);
                  setStudyTitle("ATR Stop w/Ratchet");
                  setCursorLabelName("Stop", 0);
                  setDefaultBarFgColor( Color.blue, 0 );
                  setShowTitleParameters( false );
                  
                  setPlotType( PLOTTYPE_FLATLINES, 0 );
                  setDefaultBarThickness( 2, 0 );    
                 
                  grID = 0;
                  
                  //initialize formula parameters
              	x=0; 
              	aFPArray[x] = new FunctionParameter( "Period", FunctionParameter.NUMBER);
              	with( aFPArray[x] ) {
              		setName( "ATR Period" );
              		setLowerLimit( 1 );
              		setUpperLimit( 125 );
              		setDefault( 10 );
              	}  
              	x++; 
              	aFPArray[x] = new FunctionParameter( "ATRs", FunctionParameter.NUMBER);
              	with( aFPArray[x] ) {
              		setName( "# ATRs" );
              		setLowerLimit( 1 );
              		setUpperLimit( 20 );
              		setDefault( 2 );
              	}  
              	x++; 
              	aFPArray[x] = new FunctionParameter( "RatchInc", FunctionParameter.NUMBER);
              	with( aFPArray[x] ) {
              		setName( "Ratchet %" );
              		setLowerLimit( 0 );
              		setUpperLimit( 1 );
              		setDefault( 0.005 );
              	}  
              	x++; 
              	aFPArray[x] = new FunctionParameter( "longColor", FunctionParameter.COLOR);
              	with( aFPArray[x] ) {
              		setName( "Long Stop Color" );
              		setDefault( Color.blue );
              	}  	
              	x++; 
              	aFPArray[x] = new FunctionParameter( "shortColor", FunctionParameter.COLOR);
              	with( aFPArray[x] ) {
              		setName( "Short Stop Color" );
              		setDefault( Color.red );
              	} 
              	x++; 
              	aFPArray[x] = new FunctionParameter( "lineThick", FunctionParameter.NUMBER);
              	with( aFPArray[x] ) {
              		setName( "Plot Thickness" );
              		setLowerLimit( 0 );
              		setUpperLimit( 10 );
              		setDefault( 2 );
              	}  	 	
              
              }
              
              //== Main processing function
              function main( Period, ATRs, RatchInc, longColor, shortColor, lineThick ) {
              var x;
              var nV1, nV2, nV3;
              var nTrToday;
              var nTmp;
              var nVal;
              
              	
              	//script is initializing
              	if (getCurrentBarIndex() == 0) bRealTime = true;
                  if ( getBarState() == BARSTATE_ALLBARS ) {
                      return null;
                  }
              
              	if ( bInitialized == false ) {
              	
              		nRatchetInc = RatchInc;
              		setDefaultBarThickness( Math.round( lineThick ), 0 );
              	
              		bInitialized = true;
              	}
              
              	//called on each new bar
              	if ( getBarState() == BARSTATE_NEWBAR ) {
              	
              		//save the prior ATR value
              		nATR_1  = nATR;
              		
              		//calculate the Average True Range
              		nV1 = Math.abs( high(-1)-low(-1) );
              		nV2 = Math.abs( close(-2)-high(-1) );
              		nV3 = Math.abs( close(-2)-low(-1) );
              	
              		nTrToday = Math.max( nV1, nV2, nV3 );
              	
              		nATR  = ( ( Period-1 ) * nATR_1 + nTrToday ) / Period;
              		
              		//determine the ratchet, if any
              		nRatchet = 1.0 - ( nBarsInTrade * nRatchetInc );
              		
              		//adjust long stop
              		if ( nStatus == 1 ) {
              			nVal = ATRs * nATR;
              			nTmp = close(-1) - ( nVal * nRatchet );
              			if (nTmp>nStopPrice) nStopPrice = nTmp;
              		}
              		
              		//adjust short stop
              		if ( nStatus == -1 ) {
              			nVal = ATRs * nATR;
              			nTmp = close(-1) + ( nVal * nRatchet );
              			if (nTmp<nStopPrice) nStopPrice = nTmp;
              		}	
              		
              		//increment our counters
              		nBarCounter++;
              		nBarsInTrade++;
              		
              	}
              	
              	
              	//Reverse the stop if stop was hit
              	if ( nStopPrice != null ) {
              		if ( nStatus==1 ) {
              			if ( low(0) <= nStopPrice ) {
              				nStatus = -1;
              				nBarsInTrade = 0;
              				nVal = ATRs * nATR;
              				nStopPrice = close(-1) + nVal;
              			}
              		}
              		else if ( nStatus==-1 ) {
              			if ( high(0) >= nStopPrice ) {
              				nStatus = 1;
              				nBarsInTrade = 0;
              				nVal = ATRs * nATR;
              				nStopPrice = close(-1) - nVal;
              			}
              		}
              	}
              			
              
              	//set color based on current stop direction
              	if ( nStatus == 1 ) {
              		setDefaultBarFgColor( longColor, 0 );
              	}
              	else {
              		setDefaultBarFgColor( shortColor, 0 );		 
              	}
              	
              	if ( nDir==1 && nStatus<0 && 
                     Strategy.isShort() == false ) 
              {
              		onAction2();
              	}
              
              	if ( nStatus==1 && nDir<1 &&
                      Strategy.isLong() == false &&
              		vEMA90.getValue(MAStudy.MA) > vEMA200.getValue(MAStudy.MA)
                       ) {
                      onAction1();
              	}
              
              	//return current stop value to be displayed
              	if ( nDir==1 ) {
              		return( nStopPrice );
              	}
              
              }
              
              
              /*************************************************
                           SUPPORT FUNCTIONS                    
              **************************************************/    
                  
              //== gID function assigns unique identifier to graphic/text routines
              function gID() {
                  grID ++;
                  return( grID );
              }
              
              function onAction1() {
              	    if (vLastAlert != 1 && !bRealTime) Strategy.doLong("", Strategy.MARKET, Strategy.THISBAR, Strategy.DEFAULT, 0);
                      if (vLastAlert != 1 &&  bRealTime) buyMarket( getSymbol(), 200 ); 
                      vLastAlert = 1;
                  nDir = 1;
              }
              
              function onAction2() {
              	if (vLastAlert != 2 && !bRealTime) Strategy.doShort("", Strategy.MARKET, Strategy.THISBAR, Strategy.DEFAULT, 0);    
                  if (vLastAlert != 2 &&  bRealTime) sellShortMarket( getSymbol(), 200 );     
                  vLastAlert = 2;
                  nDir = 0;
              }

              Comment


              • #8
                Hi mautz,

                Here is a list of efs consultants that can be contacted to provide support.


                Originally posted by mautz
                Can someone help me?

                Comment


                • #9
                  efs consultant

                  i realy don´t want to bother someone...

                  the only thing I want is to put my trading system (see below) to trade now at IB...

                  the problem is it works on backtesting but not in real!

                  I think that is only a small problem and would be great if you could have a look on it

                  Comment


                  • #10
                    Hi mautz,

                    So what you are after is the free help... Assistance of that nature is commonplace on this board. It usually takes more time than what you have alotted though. Please be patient and respectful of other people's time. I am sure you understand that those willing to provide their time may have other responsibilities, which either prevents jumping right onto your request, or alternately, expending significant time on request(s) for help.


                    Originally posted by mautz
                    i realy don´t want to bother someone...

                    the only thing I want is to put my trading system (see below) to trade now at IB...

                    the problem is it works on backtesting but not in real!

                    I think that is only a small problem and would be great if you could have a look on it

                    Comment


                    • #11
                      mautz
                      As Jason indicated in an earlier reply the Strategy Object is intended for back testing only. When processing real time data and/or using Broker functions you need to replace the Strategy calls with your own global variables that you will use to keep track of the position status of the system.
                      Also you need to consider that the results returned by the back test will be unrealstic since you are entering trades on the Open (ie. Strategy.MARKET) of the bar that triggers the trade instead of at the price at which the trade is triggered.
                      Alex

                      Comment


                      • #12
                        Real Time Trading

                        The only things I can find for real time trading are the buy, sell and other market and limit orders.

                        The problem is, that I want to start trading with the system at the bottom.

                        There are several things what Jason f.e. wrote about bRealTime and other things, but I hardly can find any codes how to fit my system now for real time trading with IB....

                        Would be nice if someone could help.

                        Comment


                        • #13
                          mautz
                          The reason your script is not working properly in real time is because you are using Strategy Object calls to check for the status of your strategy (such as for example Strategy.isLong() and Strategy.isShort()) and not with the buy/sell orders.
                          Add some debugPrintln() statements to check the the status of the strategy in the conditions that are supposed to trigger the trades and you will see that it is not changing from long to short or vice versa.
                          For the scriipt to work correctly in real time you need to create your own variables that you will use to keep track of the status of the strategy.
                          You can find examples on how to write strategies for use in real time in the Help Guides in the EFS KnowledgeBase and specifically the Guide to Developing eSignal Strategies
                          If you are unable to program this yourself and the script is important to your trading then I would suggest that you contact one of the EFS Consultants and have them develop the script for you.
                          Alex

                          Comment


                          • #14
                            EFS Functions

                            I have read through the EFS funcitons but I can´t find things like bRealTime .

                            How shall I trade with an efs system when I can´t find the proper funtioncs to trade with IB?

                            Comment


                            • #15
                              mautz
                              bRealTime is not an efs function but a user defined variable.
                              Alex


                              Originally posted by mautz
                              I have read through the EFS funcitons but I can´t find things like bRealTime .

                              How shall I trade with an efs system when I can´t find the proper funtioncs to trade with IB?

                              Comment

                              Working...
                              X