Announcement

Collapse
No announcement yet.

EFS Help Needed

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

  • EFS Help Needed

    I am currently trying to create a sort of hedging technique but I am very unsure of how to program the EFS for this task. I am programming the strategy so that I can be run using the backtester on a 1 minute chart.
    I have set rules to enter a long position and I want to program it so after it gains a certian percentage from the entry point I want it to exit the position. Also if at anytime during the trade any loss or negative percentage happens, I want to enter a short trade (this is the moment the loss happens). And for the short trade to be covered, which must happen before I can exit the long trade, the percentage change since the entry price must either equal 0 or be positive (it cannot be a negative percentage change since the entry price).

  • #2
    swishdaddy
    Without seeing the code it is not possible to provide any specific guidance. Anyhow you can find detailed information and examples on how to set profit targets and protective stops in the Back Testing Tutorials which are available in the EFS KnbowledgeBase under Help Guides and Tutorials->Beginner Tutorials
    Alex

    Comment


    • #3
      I have posted below the EFS code for my strategy (although the actual entry conditions have been blanked out "***-blank-***". I have inserted 5 questions with this "***" beside the questions throughout the study. Ca you also please take a look over the rest of the strategy to make sure everything is in order, and if you have any suggestions please note them. This would greatly be appreciated.

      //Global Variables
      var vRSI1 = null;
      var vRSI5 = null;
      var vMACDH1 = null;
      var vPDI1 = null;
      var vPDI5 = null;
      var nStop = null;
      var bInit = false; // initialization flag


      function premain() {
      setPriceStudy(true);
      setStudyTitle("EVO IX (SELL)");
      }


      function main() {
      if (getCurrentBarIndex() == 0) return;

      if(bInit == false) {
      vRSI1 = rsi(14, inv(1));
      vRSI5 = rsi(14, inv(5));
      vMACDH1 = macdHist(30, 40, 12, inv(1));
      vPDI1 = pdi(14, 14, inv(1));
      vPDI5 = pdi(14, 14, inv(5));
      bInit = true;
      }

      var nM1P0 = vMACDH1.getValue(0);
      var nR1P0 = RSI1.getValue(0);
      var nR5P0 = RSI5.getValue(0);
      var nP1PN4 = PDI1.getValue(-4);
      var nP1PN3 = PDI1.getValue(-3);
      var nP1PN2 = PDI1.getValue(-2);
      var nP1PN1 = PDI1.getValue(-1);
      var nP1P0 = PDI1.getValue(0);
      var nP5PN1 = PDI5.getValue(-1);
      var nP5P0 = PDI5.getValue(0);

      if(nM1P0 == null || nR1P0 == null || nR5P0 == null || nP1PN4 == null || nP1PN3 == null ||
      nP1PN2 == null || nP1PN1 == null || nP1P0 == null || nP5PN1 == null || nP5P0 == null) {
      return;
      }

      if (Strategy.isInTrade() == false) {
      nStop = null;
      } *** By using 'StrategyisInTrade' is this acceptable if I want to possibly be entered in a Long and Short trade at the same time? If not how should it be written?***

      if (Strategy.isLong() == false &&
      ***-Blank-***) {
      Strategy.doLong("Long Signal", Strategy.Close, Strategy.THISBAR, Strategy.DEFAULT, 0);
      drawShapeRelative(0, close(), Shape.UPARROW, "", Color.RGB(0,255,0), Shape.LEFT);
      setBarBgColor(Color.RGB(166,202,240));
      nStop = ; ***What should be written next to 'nStop' if I want the stop loss to trigger when an increase in percentage change from the entry price occurs?***
      }

      else if (Strategy.isShort() == false &&
      Strategy.isLong() == true &&
      ) ***I want to add another Entry rule here that when a decrease in percentage change from the entry price occurs***
      {
      Strategy.doShort("Short Signal", Strategy.Close, Strategy.THISBAR, Strategy.DEFAULT, 0);
      drawShapeRelative(0, low(), Shape.DOWNARROW, "", Color.RGB(255,0,0), Shape.LEFT);
      setBarBgColor(Color.RGB(0,255,0));
      nStop = ; ***What should be written next to 'nStop' if I want the stop loss to trigger when the percentage change from the entry price is greater than or equal to zero? Also should the 'nStop' be something like 'nLimit' or 'nCover' since I would be in a short position?***
      }
      }
      ***I currently do not have any seperate exit conditions because I am relying on the percentage-change stop signals that I have inputed into the entry positions. Although I would like to have somekind of visual confirmation on the sell and cover positions, how should I go about doing this?***

      Comment


      • #4
        Hello swishdaddy,

        The strategy logic that you are trying to accomplish is not possible as you cannot hold both a long and short position simultaneously. If a long position is active when the .doShort() method is executed, the long position is automatically closed and then the short position is taken. Likewise for the .doLong() method.
        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