Announcement

Collapse
No announcement yet.

global variables ?

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

  • global variables ?

    I'm looking to implement an EFS that could deal with pairs trading... here's what I have in mind:

    - 1 advanced chart with ratio (stock 1 / stock 2)
    - plot 2 moving average (10 days and 50 days) using this ratio value to use as a signal for entry and exit point of the trade
    - whenever entry point is received, do a trade (eg. long stock 1 and short stock 2)

    previously I was thinking that I could do this by using only 1 advanced chart, however someone point me out that I need to use additional two charts (for stock 1 and stock 2) and use global variable as a trigger for this additional charts.

    could anyone give me like an example or guide on how I could achieve this ? thanks in advanced

    cheers,
    Marlon

  • #2
    Multi Stage EFS

    Marlon,

    Before I can assist you further, I need to ask you some questions...

    Who are you using to trade?? IB or someone else??

    The reason I ask is I need to know "how" to trade the shares for you. There are a number of solutions, but some are easier than others.

    The setup is simple though....

    If you are using Dynaorder (and know the pairs you want to trade), you can do it all from one file...(EFS).

    If you are using something else, then the setup may be a bit more complex...

    I can set it up for you using esignal paper trader module - so you can see how it works, then move onto actual trading later.

    let me know what you want to do .

    B
    Brad Matheny
    eSignal Solution Provider since 2000

    Comment


    • #3
      Dynaorder

      Hi Brad...

      i'm currently testing and planning to use DynaOrder since it has the paper trading features which will come in handy for testing the strategy.

      could you give more info please ? i tried contacting eSignal support however they told me that they would not support any questions related to EFS anymore.

      thanks in advanced

      Comment


      • #4
        Re: Dynaorder

        Originally posted by smartidea
        i tried contacting eSignal support however they told me that they would not support any questions related to EFS anymore.
        What?? eSignal isn't supporting EFS anymore? Is this something new?

        Comment


        • #5
          Hello Foz,

          There must have been a misunderstanding about EFS support. We do support EFS through these forums. We do not have one-on-one phone support through the call center.
          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


          • #6
            Re: Re: Dynaorder

            Originally posted by Foz
            What?? eSignal isn't supporting EFS anymore? Is this something new?
            sorry for the misunderstanding...

            what i meant was eSignal's support would not answer any EFS-related questions anymore.

            so sorry for my english.. my bad..

            Comment


            • #7
              Example code..

              I use a function called TradeMarket with Dynaorder. This allows me to do whatever I want within this function for my trading system. So, I'll illustrate an example using my code...

              This code should give you an idea of how to accomplish this. With DO, you just issue a BUYMARKET, then SELLMARKET order for two symbols (see near the bottom of the code - within the trademarket() function). This way, you are assuming entry of the orders, there is a more complicated way to accomplish this, but for now - we'll keep it simple..

              B

              PHP Code:
              /*********************************************************
              Matheny Enterprises Â© June 2004                          
              **********************************************************/
              var dots5 = new DLL ("dots5.dll");
              var 
              AltSymbol "MSFT"
              var ExpText "";

              var 
              DefEntryContracts 200;  //  The number of contracts to trade
              var LossLimit 1;  //  the number of losses allowed in a 24 hour period
              var StopLevel 2.0//  your default stop offset (from the entry price)
              var BELevel 4.0;  //  Your default Beark-even level (for stops)
              var PTLevel1 6.0;  //  Your default Profit Target

              // system variables - DO NOT CHANGE!
              var StrategyisInTrade false;
              var 
              StrategyisShort false;
              var 
              StrategyisLong false;
              var 
              TradePending false;
              var 
              EntryOrderID 0;
              var 
              EntryOrderID2 0;
              var 
              StopOrderID 0;
              var 
              PTOrderID 0;
              var 
              CloseOrderID 0;
              var 
              OpenContracts 0;
              //---------------------------------
              var nLastRawTime 0;
              var 
              BLBarOffset 0;
              var 
              nLastvDay 0;
              var 
              LossCount 0;
              var 
              TradeCount 0;

              var 
              nEntryPrice;
              var 
              nStopPrice;
                var 
              vHour;
                var 
              vMin;
                var 
              vSec;
                var 
              vDay;
                var 
              vMonth;


              function 
              preMain() {
                  
              setPriceStudy(true);
                  
              setStudyTitle("Sample System RTDO");
                  
              doInit();
              }

              function 
              main() {
                 
                var 
              vTime = new Date();
              //---------------------------------------------------
              //  Get Time Variables 
                
              vTime getValue("Time"0);
                
              vHour vTime.getHours();
                
              vMin vTime.getMinutes();
                
              vSec vTime.getSeconds();
                
              vDay vTime.getDate();
                
              vMonth vTime.getMonth() +1;

               if (
              getValue("rawtime"0) != nLastRawTime) {
                   
              nLastRawTime getValue("rawtime"0);
                   
              BLBarOffset += 1;
                   if (
              vDay != nLastvDay) {
                     
              nLastvDay vDay;
                     
              LossCount 0;
                     
              TradeCount 0;
                   }
               }


              if (
              getCurrentBarIndex() == 0) {
              //  Entry Triggers 
               
              if ((LossCount LossLimit) && (TradeCount >= 0)) {
                if ((
              SELL ENTRY TRIGGER) && (!StrategyisShort)) {
                 
              drawShapeRelative(0high()+0.25Shape.DOWNARROWnullColor.redShape.ONTOPBLBarOffset+"3SELL");
                 
              TradeMarket(2);
                }
                if ((
              BUY ENTRY TRIGGER) ) && (!StrategyisLong)) {
                 
              drawShapeRelative(0low()-0.25Shape.UPARROWnullColor.greenShape.ONTOPBLBarOffset+"3BUY");
                 
              TradeMarket(1);
                }
               } 
              // end if losscount < losslimit
              // end if get currentbarindex == 0

                  
              return;
              }




              //  ------------  DO Functions.....
              function doInit()
              {
                  
              dots5.addFunction ("IsHostRunning" DLL.SHORT DLL.STDCALL "ISHOSTRUNNING");
                  
              dots5.addFunction ("IsHostConnected" DLL.SHORT DLL.STDCALL "ISHOSTCONNECTED");
                  
              dots5.addFunction ("BuyMarket"DLL.INTDLL.STDCALL"BUYMARKET"DLL.STRINGDLL.STRINGDLL.STRINGDLL.STRINGDLL.FLOATDLL.STRINGDLL.STRINGDLL.SHORT);
                  
              dots5.addFunction ("SellMarket"DLL.INTDLL.STDCALL"SELLMARKET"DLL.STRINGDLL.STRINGDLL.STRINGDLL.STRINGDLL.FLOATDLL.STRINGDLL.STRINGDLL.SHORT);
                  
              dots5.addFunction ("BuyLimit"DLL.INTDLL.STDCALL"BUYLIMIT"DLL.STRINGDLL.STRINGDLL.STRINGDLL.STRINGDLL.FLOATDLL.STRINGDLL.STRINGDLL.SHORTDLL.FLOAT);
                  
              dots5.addFunction ("SellLimit"DLL.INTDLL.STDCALL"SELLLIMIT"DLL.STRINGDLL.STRINGDLL.STRINGDLL.STRINGDLL.FLOATDLL.STRINGDLL.STRINGDLL.SHORTDLL.FLOAT);
                  
              dots5.addFunction ("BuyStop"DLL.INTDLL.STDCALL"BUYSTOP"DLL.STRINGDLL.STRINGDLL.STRINGDLL.STRINGDLL.FLOATDLL.STRINGDLL.STRINGDLL.SHORTDLL.FLOAT);
                  
              dots5.addFunction ("SellStop"DLL.INTDLL.STDCALL"SELLSTOP"DLL.STRINGDLL.STRINGDLL.STRINGDLL.STRINGDLL.FLOATDLL.STRINGDLL.STRINGDLL.SHORTDLL.FLOAT);
                  
              dots5.addFunction ("BuyStopLimit"DLL.INTDLL.STDCALL"BUYSTOPLIMIT"DLL.STRINGDLL.STRINGDLL.STRINGDLL.STRINGDLL.FLOATDLL.STRINGDLL.STRINGDLL.SHORTDLL.FLOATDLL.FLOAT);
                  
              dots5.addFunction ("SellStopLimit"DLL.INTDLL.STDCALL"SELLSTOPLIMIT"DLL.STRINGDLL.STRINGDLL.STRINGDLL.STRINGDLL.FLOATDLL.STRINGDLL.STRINGDLL.SHORTDLL.FLOATDLL.FLOAT);
                  
              dots5.addFunction ("BuyTrailStop"DLL.INTDLL.STDCALL"BUYTRAILSTOP"DLL.STRINGDLL.STRINGDLL.STRINGDLL.STRINGDLL.FLOATDLL.STRINGDLL.STRINGDLL.SHORTDLL.FLOAT);
                  
              dots5.addFunction ("SellTrailStop"DLL.INTDLL.STDCALL"SELLTRAILSTOP"DLL.STRINGDLL.STRINGDLL.STRINGDLL.STRINGDLL.FLOATDLL.STRINGDLL.STRINGDLL.SHORTDLL.FLOAT);
                  
              dots5.addFunction ("CancelOrder"DLL.INTDLL.STDCALL"CANCELORDER"DLL.INT);
                  
              dots5.addFunction ("StartOCAGroup"DLL.INTDLL.STDCALL"STARTOCAGROUP"DLL.STRING);
                  
              dots5.addFunction ("StopOCAGroup"DLL.INTDLL.STDCALL"STOPOCAGROUP");
                  
              dots5.addFunction ("GetOrderStatusN"DLL.SHORTDLL.STDCALL"GETORDERSTATUSN"DLL.INT);
                  
              dots5.addFunction ("GetOrderPrice"DLL.FLOATDLL.STDCALL"GETORDERPRICE"DLL.INT);
                  
              dots5.addFunction ("GetOrderFilled"DLL.INTDLL.STDCALL"GETORDERFILLED"DLL.INT);
                  
              dots5.addFunction ("GetOrderRemaining"DLL.INTDLL.STDCALL"GETORDERREMAINING"DLL.INT);
                  
              dots5.addFunction ("SetEmailDefaults",DLL.INT,DLL.STDCALL,"SETEMAILDEFAULTS"DLL.STRINGDLL.STRING,DLL.STRINGDLL.STRING);
                  
              dots5.addFunction ("EmailAlert",DLL.INT,DLL.STDCALL,"EMAILALERT",DLL.STRING,DLL.STRING,DLL.STRING);
                  
              dots5.addFunction ("PopupAlert"DLL.INTDLL.STDCALL"POPUPALERT"DLL.STRINGDLL.STRING);
                  
              dots5.addFunction ("SoundAlert",DLL.INT,DLL.STDCALL,"SOUNDALERT",DLL.STRING);
                  
              dots5.addFunction ("CancelAll"DLL.INTDLL.STDCALL"CANCELALL");
                  
              dots5.addFunction ("CancelAllFor"DLL.INTDLL.STDCALL"CANCELALLFOR"DLL.STRINGDLL.STRINGDLL.STRINGDLL.STRINGDLL.FLOATDLL.STRINGDLL.STRING);
                  
              dots5.addFunction ("GetMarketPosition"DLL.INTDLL.STDCALL"GETMARKETPOSITION"DLL.STRINGDLL.STRINGDLL.STRINGDLL.STRINGDLL.FLOATDLL.STRING);
                  
              dots5.addFunction ("ClosePositionFor"DLL.INTDLL.STDCALL"CLOSEPOSITIONFOR"DLL.STRINGDLL.STRINGDLL.STRINGDLL.STRINGDLL.FLOATDLL.STRINGDLL.STRING);
                  
              dots5.addFunction ("GetAccountCashBalance"DLL.FLOATDLL.STDCALL"GETACCOUNTCASHBALANCE");
                  
              dots5.addFunction ("GetAccountUpdateTime"DLL.SHORTDLL.STDCALL"GETACCOUNTUPDATETIME");
                  
              dots5.addFunction ("GetFirstOpenOrder",DLL.INTDLL.STDCALL,"GETFIRSTOPENORDER");
                  
              dots5.addFunction ("GetNextOpenOrder",DLL.INTDLL.STDCALL,"GETNEXTOPENORDER",DLL.INT);
                  
              dots5.addFunction ("GetAccountItem"DLL.FLOATDLL.STDCALL"GETACCOUNTITEM"DLL.SHORT);
                  
              dots5.addFunction ("SetTIF"DLL.INTDLL.STDCALL"SETTIF"DLL.STRING);
                  
              dots5.addFunction("SetSharesAllocation",DLL.INT,DLL.STDCALL"SETSHARESALLOCATION",DLL.STRING);

              }


              function 
              TradeMarket(TradeType) {
               var 
              host=dots5.call("IsHostRunning");
              // var conn=dots5.call("IsHostConnected");
              var conn 1;
              // debugPrintln("Host :"+host+"Conn :"+conn);
               
              if ((host == 1) && (conn == 1)) {
              // debugPrintln("Host/Conn/vRT Connected!");

              //  format symbol...
                
              var tsymbol getSymbol();
                 
              PosCount tsymbol.split(" ");
                  if (
              PosCount[0]) { tsymbol PosCount[0]; }
                   
              TAction+=1;
                var 
              tOCAlabel ""+TAction;
                 
              dots5.call("SetTIF""GTC");

              //-------------------------------------------------------------------  
              //--------------      New Buy Order
              //-------------------------------------------------------------------  
                
              if (TradeType == 1) {
                
              //  New Buy Order
               
              debugPrintln("Executing BUY MARKET Order");
                 if (
              StrategyisShort) {
                   
              dots5.call("CancelOrder",StopOrderID);
                   
              dots5.call("CancelOrder",PTOrderID);
                  
              EntryOrderID=dots5.call("BuyMarket",tsymbol,"STK",ExpText,"",0,"SMART","",(DefEntryContracts+OpenContracts));

                  
              EntryOrderID2=dots5.call("SellMarket",AltSymbol ,"STK",ExpText,"",0,"SMART","",(DefEntryContracts+OpenContracts));

                 } else {
                  
              EntryOrderID=dots5.call("BuyMarket",tsymbol,"FUT",ExpText,"",0,"SMART","",DefEntryContracts);

                  
              EntryOrderID2=dots5.call("SellMarket",AltSymbol ,"STK",ExpText,"",0,"SMART","",DefEntryContracts);

                 }
                 
                  
              StrategyisInTrade true;
                  
              StrategyisLong true;
                  
              StrategyisShort false;
                  
              OpenContracts DefEntryContracts;
                  
              TradeCount += 1;
                }



              //-------------------------------------------------------------------  
              //--------------      New SELL Order
              //-------------------------------------------------------------------  
                
              if (TradeType == 2) {
                
              //  New Sell Order
               
              debugPrintln("Executing SELL MARKET Order");
                 if (
              StrategyisLong) {
                   
              dots5.call("CancelOrder",StopOrderID);
                   
              dots5.call("CancelOrder",PTOrderID);
                  
              EntryOrderID=dots5.call("SellMarket",tsymbol,"STK",ExpText,"",0,"SMART","",(DefEntryContracts+OpenContracts));

                  
              EntryOrderID2=dots5.call("BuyMarket",AltSymbol ,"STK",ExpText,"",0,"SMART","",(DefEntryContracts+OpenContracts));

                 } else {
                  
              EntryOrderID=dots5.call("SellMarket",tsymbol,"FUT",ExpText,"",0,"SMART","",DefEntryContracts);

                  
              EntryOrderID2=dots5.call("BuyMarket",AltSymbol ,"STK",ExpText,"",0,"SMART","",DefEntryContracts);

                 }
                 
                  
              StrategyisInTrade true;
                  
              StrategyisLong false;
                  
              StrategyisShort true;
                  
              OpenContracts DefEntryContracts;
                  
              TradeCount += 1;
                }



              //-------------------------------------------------------------------  
              //--------------      Close all Order
              //-------------------------------------------------------------------  
                
              if (TradeType == 12) {  
                   
              dots5.call("CancelOrder",StopOrderID);
                   
              dots5.call("CancelOrder",PTOrderID);

                 
                 if (
              StrategyisLong) {
                  
              CloseOrderID=dots5.call("SellMarket",tsymbol,"STK",ExpText,"",0,"SMART","",OpenContracts);
                 }
                 if (
              StrategyisShort) {
                  
              CloseOrderID=dots5.call("BuyMarket",tsymbol,"STK",ExpText,"",0,"SMART","",OpenContracts);
                 }
                 
              debugPrintln("Executing Close - GO FLAT Order");
                  
              StrategyisInTrade false;
                  
              StrategyisLong false;
                  
              StrategyisShort false;
                  
              OpenContracts 0;
                }

              //-------------------------------------------------------------------  
              //--------------      EOD Close all Order
              //-------------------------------------------------------------------  
                
              if (TradeType == 13) {
                 
              debugPrintln("Executing Close - GO FLAT Order");

                 if (
              StrategyisLong) {
                  
              CloseOrderID=dots5.call("SellMarket",tsymbol,"STK",ExpText,"",0,"SMART","",OpenContracts);
                 }
                 if (
              StrategyisShort) {
                  
              CloseOrderID=dots5.call("BuyMarket",tsymbol,"STK",ExpText,"",0,"SMART","",OpenContracts);
                 }

                
              //  Close All Open Positions
                  
              dots5.call("CancelOrder",PTOrderID);
                  
              dots5.call("CancelOrder",StopOrderID);

                  
              StrategyisInTrade false;
                  
              StrategyisLong false;
                  
              StrategyisShort false;
                  
              OpenContracts 0;
                }



               } 
              //  End if Host & Conn are true

              Brad Matheny
              eSignal Solution Provider since 2000

              Comment

              Working...
              X