Announcement

Collapse
No announcement yet.

End of Day

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

  • End of Day

    Morning Everybody !

    Can somebody please tell me why (on 6e #f), does the following code not *always* close my open positions at the end of the day ? :

    if (getHour(0)>=21){
    if (Strategy.isLong){
    Strategy.doSell("End of Day", Strategy.CLOSE, Strategy.THISBAR);
    }
    if (Strategy.isShort){
    Strategy.doCover("End of Day", Strategy.CLOSE, Strategy.THISBAR);
    }
    }

    It only seems to work about 50% of the time which is weird.

    Many Thanks

    Roger

  • #2
    Roger
    What is the interval of the 6E #F chart in which you are running the efs?
    What is the Time Template set to (including Time Zone)?
    Alex

    Comment


    • #3
      Hi Alex,

      I am running it on a 15 min chart, with a 24hour template (default 24 hour template in E-Signal).

      30 Days loaded.

      Hope that helps.

      Thanks

      Roger

      Comment


      • #4
        Oops, on GMT time zone.

        Comment


        • #5
          Roger
          Check the syntax in your conditions. You are missing the parenthesis in if(Strategy.isLong) and if(Strategy.isShort) which should be if(Strategy.isLong()) and if(Strategy.isShort())
          This should fix the problem you are having
          Alex

          Comment


          • #6
            It most certainly did.

            Thanks very much indeed Alex, have a good day.

            Comment


            • #7
              Actually Alex, I am afraid it didn't please see attached. Trade 19 is an example of what I am talking about.

              The other strange thing when I add brackets to the whole 'Strategy.isLong() and Short() in the below code it just messes things up.

              All I am trying to do at the moment is if the indicators are all 1 go long (closing out a short if it exists), the opposite if all the indicators are all 2.

              Exit conditions is either end of day, profit target of 10 ticks or reversal. There are more exits to come but since I am stuck already I didn;t want to cloud the issue.

              I would be very grateful indeed if you could shed some light on where it is going wrong:

              if (getBarState()==BARSTATE_NEWBAR){
              Counter++
              if (Counter > 1000){
              Counter = 0
              }
              }
              //Trade Entry//


              if (fast==2 && DMIBias==2 && ComboBias==2){
              if (Strategy.isLong){
              Strategy.doSell("Exit Long", Strategy.CLOSE, Strategy.THISBAR);
              }

              Strategy.doShort("Enter Short", Strategy.CLOSE, Strategy.THISBAR);
              TradeEntry = close().toFixed(4)
              StopLoss = (close().toFixed(4) + 0.0035)
              TradeMark = Counter}
              }

              if (fast==1 && DMIBias==1 && ComboBias==1){
              if (Strategy.isShort){
              Strategy.doCover("Exit Short", Strategy.CLOSE, Strategy.THISBAR);
              }

              Strategy.doLong("Enter Long", Strategy.CLOSE, Strategy.THISBAR);
              TradeEntry = close()
              StopLoss = (close() - 0.0035)
              TradeMark = Counter}

              }


              // Profit Target //

              if (Strategy.isLong && (TradeMark != Counter)){
              if ((high().toFixed(4)-TradeEntry) >= 0.0010){
              Strategy.doSell("Target Met", Strategy.LIMIT, Strategy.THISBAR, null, (TradeEntry+0.0010));
              }
              }
              if (Strategy.isShort && (TradeMark != Counter)){
              if ((TradeEntry-low().toFixed(4)) >= 0.0010){
              Strategy.doCover("Target Met", Strategy.LIMIT, Strategy.THISBAR, null, (TradeEntry-0.0010));
              }
              }

              /* Stop Loss //

              if (Strategy.isLong){
              if (low(0) <= StopLoss){
              Strategy.doSell("Stopped Out", Strategy.LIMIT, Strategy.THISBAR, null, StopLoss);
              }
              }

              if (Strategy.isShort()){
              if (high(0) >= StopLoss){
              Strategy.doCover("Stopped Out", Strategy.LIMIT, Strategy.THISBAR, null, StopLoss);
              }
              }
              */

              // Close Trades at End of Day //

              if (getHour(0)>=21){
              if (Strategy.isLong()){
              Strategy.doSell("End of Day", Strategy.CLOSE, Strategy.THISBAR);
              }
              if (Strategy.isShort()){
              Strategy.doCover("End of Day", Strategy.CLOSE, Strategy.THISBAR);
              }
              }
              Attached Files

              Comment


              • #8
                Roger
                In the section of code you posted I see several other instances of Strategy.isShort or Strategy.isLong with missing parenthesis.
                Also in the logic you will need to insert a condition that does not allow for new trades to be executed between 21:00 and whatever starting time you want
                Alex

                Comment


                • #9
                  Hi Alex,

                  I appreciate that, however if I put the parenthesis in, it really messes everything up, targets don't get met, mutliple positions are opened, and no reversals take place.

                  Honestly I am totally confused.

                  I have tried it but to no avail, and would I be right in saying that with the parenthesis in the end of day exit, events such as the trade 19 shouldn't happen ?

                  Thanks for your patience Alex.

                  Roger

                  Comment


                  • #10
                    Roger
                    All I can tell you is what I believe to be the correct syntax. If you are having problems with the strategy then it is possible that there is a flaw elsewhere in the logic.
                    As to trade 19 it could be that there is no bar time stamped 21:00 (or later) on 5/27 which would also explain why the trade is closed at 23:00 on 5/29 which is the first bar on Sunday (ie when the market started trading again).
                    Alex

                    Comment


                    • #11
                      OK Alex, I will persevere. Sometimes when I get as confused as this its better to strip it out and start again.

                      I sincerely appreciate your patience, and advice.

                      Thanks again.

                      Comment

                      Working...
                      X