Announcement

Collapse
No announcement yet.

Coding A Stop Loss Into Efs

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

  • Coding A Stop Loss Into Efs

    STOP LOSS

    Incorporating a value stop; from the open trade price into EFS for, trading the SPOT FOREX Market.

    Currently the EFS code calls for all open positions to close and reverse when the opposite signal occurs within the EFS file.

    However, incorporating some conditional EFS code to, have all open positions close if a value stop is reached prior to an opposite signal occurring would be preferred.

    Therefore, what conditional EFS code would exit all open long or short positions based on a negative value from the opening price of that open position. Long example; close this position if the market price is less than the open price minus 50 pips or close this position if a short entry signal is triggered. Short example; close this position if the market price is greater than the open price plus 50 pips or close this position if a long entry signal is triggered.

    Several attempts have been made to modify the ”BtDonchian_FixedStops.efs” file that can be found on this site. However, none of these attempts produce the results needed.

    In the meantime, below is the EFS code from the EFS Action Section of the EFS file that, opens both long and short position after all conditions are met on both Action 1 and Action 2.

    //{{EFS_Action_1
    function onAction1() {
    drawTextRelative(0, low(-1), "A", Color.RGB(0,0,255), Color.RGB(255,255,255), Text.BOLD, "Arial", 12);
    Strategy.doLong("AN", Strategy.CLOSE, Strategy.THISBAR, Strategy.DEFAULT, 0);
    vLastAlert = 1;
    }
    //}}EFS_Action_1

    //{{EFS_Action_2
    function onAction2() {
    drawTextRelative(0, high(-1), "A", Color.RGB(255,0,0), Color.RGB(255,255,255), Text.BOLD, "Arial", 12);
    Strategy.doShort("AS", Strategy.CLOSE, Strategy.THISBAR, Strategy.DEFAULT, 0);
    vLastAlert = 1;
    }
    //}}EFS_Action_2

  • #2
    Hello AAMDLB,

    The Strategy object in back testing will only allow you to track one position. When your stop condition occurs, if you enter a reversing position with Strategy.doLong() or Strategy.doShort() they will automatically close the current position before recording the reversing trade. You cannot be both long and short at the same time. If you only want to close the position you have to do so with Strategy.doSell() or Strategy.doCover().
    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
      Jason-

      It’s understood that the back testing process can only track one open position at a time.

      Can that open position contain a fixed valued stop loss?

      Can the stop loss be conditioned to test for the current market value has not exceeded the open price of the position by more than a fixed amount?

      Once completing that test, the position would close if true or not close if false?

      If so, what would be the EFS code to attach to that open position once it is in the trade?

      Again, the objective is limit the max draws for any open position to a fixed value.

      Thanks!

      Comment


      • #4
        Hello AAMDLB,

        For a detailed example of how to code fixed stops into back testing formulas please review Back Testing Tutorial 2: How to Close Positions with Profit Targets and Stops.
        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