Announcement

Collapse
No announcement yet.

Exit issue

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

  • Exit issue

    Hi,

    I am trying to create my first strategy which is practically a direct copy of the turtle rules. Got to start somewhere!

    I think I have nearly completed a first draft however I'm having a little trouble with the exit part e.g.;

    I'm struggling with profitable exits which should exit on a 10 day high/low.

    Does any one have any ideas how i do this?

    Here is my attempt;

    PHP Code:
    if (Strategy.isLong() == true && (Strategy.isInTrade() == true));
    if (
    low() <= nStopLevelLong) ||
    if (
    low(-1) >=vDonchExitLong.getValue (DonchianStudy.LOWER, -1) && low() <vDonchExitLong.getValue (DonchianStudy.LOWER)) {

    Strategy.doSell("Sell"Strategy.LIMITStrategy.THISBARStrategy.ALLnStopPriceLong);


    Is there an error on the 2nd line after the OR symbol?

    Any help will be appreciated.

    Thanks

  • #2
    Hello thestranger,

    In your if() statement,

    PHP Code:
    if (low(-1) >=vDonchExitLong.getValue (DonchianStudy.LOWER, -1) && low() <vDonchExitLong.getValue (DonchianStudy.LOWER)) 
    the first portion, low(-1) >=vDonchExitLong.getValue (DonchianStudy.LOWER, -1), will always be true by definition. The low of any bar will never be lower than the lower Donchian channel on the same bar. The main problem here is in the second portion, low() <vDonchExitLong.getValue (DonchianStudy.LOWER), which will always be false. This causes your if() statement to always evaluate to false and its corresponding .doSell call never gets executed. I think you have misinterpreted what the turtle rule indicates. Post a description of the rule you are trying to code.
    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
      Hi JasonK,

      My copy of the rules indicates that a stop would be placed at the value of 2N (2 * ATR) from the entry price. This would then be moved by half N each time a new unit was added. Up to 4 units.

      I think i have created this part.

      It then states that one of the systems exits was a 10 day low for long positions or a 10 day high for short positions.

      Is this correct?

      I assumed that a stop loss point would be used until the trade became profitable and then a 10 day high/low exit would become effective.

      Thanks

      Comment


      • #4
        Hello thestranger,

        Is the 10 day low supposed to be the profit exit as you indicated in your first post? At any rate the way to check for a new 10 day high or low is to compare the current bar's high/low to the previous bar's Donchian channel (assuming that the Donchian study was set to a length of 10).


        PHP Code:
        // new 10-day low
        if (low(0) <= vDonchExitLong.getValue(DonchianStudy.LOWER, -1)) 

        // new 10-day high
        if (high(0) >= vDonchExitLong.getValue(DonchianStudy.UPPER, -1)) 

        I think you will also need to restructure this exit logic. Depending on how you are setting the value for the nStopPirceLong variable, this may not be the price level you want to exit on for the new 10-day high/low exits. You might want to try something like below.

        PHP Code:
        if (Strategy.isLong() == true && Strategy.isInTrade() == true) {
            if (
        low(0) <= nStopLevelLong) {
                
        Strategy.doSell("Stop Sell"Strategy.LIMITStrategy.THISBARStrategy.ALLnStopPriceLong);
            } else if (
        low(0) <= vDonchExitLong.getValue(DonchianStudy.LOWER, -1)) {
                var 
        nStop vDonchExitLong.getValue(DonchianStudy.LOWER, -1);
                if (
        open(0) < nStopnStop open(0);  // check for gap at open
                
        Strategy.doSell("10-day low Sell"Strategy.LIMITStrategy.THISBARStrategy.ALLnStop);
            }

        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
          Thanks JasonK,

          This will be a great help. Back to the drawing board but every little step helps.

          Thanks again!

          Comment

          Working...
          X