Announcement

Collapse
No announcement yet.

Automated Trading

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

  • #16
    Button ?

    Hi Doji and Alexis....

    Ok....so my understanding is that it is NOT possible to scale out of positions while in automation mode.

    As a kind of workaround. Is it possible to create a button that can turn the efs off and on easily ?

    The idea is that if the need arose to scale out, I could just disable/turn off the EFS and manage it manually. Then turn it back on for the next signal.

    I know the efs can be removed and reloaded by right clicking....but a button written into the efs that does this on one click would be great !


    Thanks a lot !

    BlueNote

    Comment


    • #17
      Blue,

      Sure you can scale out of a position (in any way you want). There is no real limit as to the complexity of your trading system with EFS - you just have to control all the logic correctly.

      Here, let me show you how you would use a scaling system (with stops and one PT level - as well as the buttons...

      This code includes 2 PT levels, one STOP level, an ONOFF button and a STATUS button (for display purposes). It is all developed within EFS to use the IBBroker feature - for automated trading.

      As you can see, it is not super difficult to accomplish these things. I have a set type of parameters that I use to control the actions of my systems. This is a great example of how I do it.

      B

      PHP Code:
      var DefEntryContracts 50;
      var 
      OpenContracts 0;

      var 
      PTLevel1 0.25;
      var 
      PTLevel2 0.50;

      var 
      ExitContracts1 25;
      var 
      ExitContracts2 25;

      //  System Variables - DO NOT CHANGE!
      var nStopPrice 0;
      var 
      nPTStage 0;
      var 
      nEntryPrice null;


      function 
      preMain() {
      }


      function 
      main() {

      if (
      getCurrentBarIndex() == 0) {  //  current RT bar

      //  Buy Signal Entry Triggers
      if ((!StrategyisLong) && (BuySignalNow)) {
          if (
      StrategyisShort) {
            
      IBtrade.Buy(getSymbol(), (DefEntryContracts+OpenContracts), IBBroker.MARKET); 
          } else {
            
      IBtrade.Buy(getSymbol(), (DefEntryContracts), IBBroker.MARKET); 
         }
          
      StrategyisLong true;
          
      StrategyisShort false;
          
      StrategyisInTrade true;
          
      nStopPrice Math.min(low(-1),low(-2),low(-3));
          
      nPTStage 0;
          
      nEntryPrice close();
          
      OpenContracts DefEntryContracts;
      }

      //  Sell Signal Entry Triggers
      if ((!StrategyisShort) && (SellSignalNow)) {
         if (
      StrategyisLong) {
           
      IBtrade.Sell(getSymbol(), (DefEntryContracts+OpenContracts), IBBroker.MARKET); 
         } else {
           
      IBtrade.Sell(getSymbol(), (DefEntryContracts), IBBroker.MARKET); 
         }
          
      StrategyisLong false;
          
      StrategyisShort true;
          
      StrategyisInTrade true;
          
      nStopPrice Math.max(high(-1),high(-2),high(-3));
          
      nPTStage 0;
          
      nEntryPrice close();
          
      OpenContracts DefEntryContracts;
      }



      //  Test for stops....
      if ((StrategyisLong) && (close() < nStopPrice)) {
           
      IBtrade.Sell(getSymbol(), OpenContractsIBBroker.MARKET); 
          
      StrategyisLong false;
          
      StrategyisShort false;
          
      StrategyisInTrade false;
          
      OpenContracts 0;
      }
      if ((
      StrategyisShort) && (close() > nStopPrice)) {
           
      IBtrade.Buy(getSymbol(), OpenContractsIBBroker.MARKET); 
          
      StrategyisLong false;
          
      StrategyisShort false;
          
      StrategyisInTrade false;
          
      OpenContracts 0;
      }


      //  Test for PT Level 1 hit
      if ((StrategyisLong) && (close() >= (nEntryPrice+PTLevel1)) && (nPTStage == 0)) {
           
      IBtrade.Sell(getSymbol(), ExitContracts1 IBBroker.MARKET); 
          
      nPTStage += 1;
          
      OpenContracts -= ExitContracts1 ;
      }
      if ((
      StrategyisShort) && (close() <= (nEntryPrice-PTLevel1)) && (nPTStage == 0)) {
           
      IBtrade.Buy(getSymbol(), ExitContracts1IBBroker.MARKET); 
          
      nPTStage += 1;
          
      OpenContracts -= ExitContracts1 ;
      }

      //  Test for PT Level 2 hit
      if ((StrategyisLong) && (close() >= (nEntryPrice+PTLevel2)) && (nPTStage == 1)) {
           
      IBtrade.Sell(getSymbol(), ExitContracts2 IBBroker.MARKET); 
          
      nPTStage += 1;
          
      OpenContracts -= ExitContracts2 ;
      }
      if ((
      StrategyisShort) && (close() <= (nEntryPrice-PTLevel2)) && (nPTStage == 1)) {
           
      IBtrade.Buy(getSymbol(), ExitContracts2IBBroker.MARKET); 
          
      nPTStage += 1;
          
      OpenContracts -= ExitContracts2 ;
      }

      // Catcher for closing all contracts/shares
      if (OpenContracts == 0) {
          
      StrategyisLong false;
          
      StrategyisShort false;
          
      StrategyisInTrade false;
      }

      //  Draw Buttons....
        
      DrawButtons();

      }  
      //  end of getCurrentBarIndex()

      // end of main()


      function DrawButtons() {
         
      // status code
          
      if (StrategyisLong) {
            
      drawTextPixel(165,35" + LONG "+OpenContracts+" + " Color.blackColor.RGB(0xE00xFF0xE0), Text.FRAME Text.ONTOP Text.RELATIVETOLEFT Text.RELATIVETOBOTTOMnullnull"Status");
          } else if (
      StrategyisShort) {
            
      drawTextPixel(165,35" - SHORT "+OpenContracts+" - " Color.blackColor.RGB(0xFF0xE00xE0), Text.FRAME Text.ONTOP Text.RELATIVETOLEFT Text.RELATIVETOBOTTOMnullnull"Status");
          } else {
            
      drawTextPixel(165,35" = FLAT = " Color.blackColor.RGB(0xE00xE00xFF), Text.FRAME Text.ONTOP Text.RELATIVETOLEFT Text.RELATIVETOBOTTOMnullnull"Status");
          }
          
         
      //  trading system code
           
      if (TradingSystemONOFF) {
            
      drawTextPixel(165,15" System ON ""@URL=EFS:ONOFFButton" Color.blackColor.RGB(0xE00xFF0xE0), Text.FRAME Text.ONTOP Text.RELATIVETOLEFT Text.RELATIVETOBOTTOMnullnull"Stats11");
           } else {
            
      drawTextPixel(165,15" System OFF ""@URL=EFS:ONOFFButton" Color.blackColor.RGB(0xFF0xE00xE0), Text.FRAME Text.ONTOP Text.RELATIVETOLEFT Text.RELATIVETOBOTTOMnullnull"Stats11");
           }
      }


      function 
      ONOFFButton()
      {
            
      Alert.playSound("tap1.wav");
           if (
      TradingSystemONOFF) { TradingSystemONOFF false; }
         else { 
      TradingSystemONOFF true; }
           if (
      TradingSystemONOFF) {
           
      drawTextPixel(165,15" System ON ""@URL=EFS:ONOFFButton" Color.blackColor.RGB(0xE00xFF0xE0), Text.FRAME Text.ONTOP Text.RELATIVETOLEFT Text.RELATIVETOBOTTOMnullnull"Stats11");
           } else {
           
      drawTextPixel(165,15" System OFF ""@URL=EFS:ONOFFButton" Color.blackColor.RGB(0xFF0xE00xE0), Text.FRAME Text.ONTOP Text.RELATIVETOLEFT Text.RELATIVETOBOTTOMnullnull"Stats11");
           }

      Brad Matheny
      eSignal Solution Provider since 2000

      Comment

      Working...
      X