• If this is your first visit, you will have to register before you can post. To view messages, please scroll below and select the forum that you would like to visits. Questions? Be sure to check out the Forum FAQ.

Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Disconnecting from data interrupts strategy?

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

    Disconnecting from data interrupts strategy?

    Hi,
    I trade only between certain hours (7am to 5pm). As such, I generally connect the data feed in NT8 in the morning, and then disconnect again at night.

    If I trade on the hourly chart, and my strategy requires 60 hours to pass before a trade alert is generated, does this mean an Alert will never ever be generated?

    I/e Do I need to leave myself connected to the data feed 24/7?

    Code below:

    // Look for a trigger for the strong trade
    if (Position.MarketPosition == MarketPosition.Flat
    && Notrade
    && SMA(movav)[0]<SMA(movavshort)[0]
    )

    { Triggerbar=CurrentBar;
    Notrade=false;
    GoLong=true;
    }

    // Switch off the potential trade if the SMA short breaks below the longer term SMA

    if (Position.MarketPosition == MarketPosition.Flat
    && GoLong
    && SMA(movav)[0]>SMA(movavshort)[0]
    )

    { Triggerbar=0;
    Notrade=true;
    GoLong=false;
    }

    // Switch off the potential trade if the close breaks above the longer term SMA

    if (Position.MarketPosition == MarketPosition.Flat
    && GoLong
    && Close[0]<SMA(movav)[0]
    )

    { Triggerbar=0;
    Notrade=true;
    GoLong=false;
    }

    if (Position.MarketPosition == MarketPosition.Flat
    && ToTime(Time[0])>70000 && ToTime(Time[0])<170000
    && SMA(movav)[0]<SMA(movavshort)[0]
    && Low[0]<SMA(movavshort)[0]
    && GoLong
    && CurrentBar-Triggerbar>60

    {Enter trade;}

    #2
    Hello lancasterstephen,

    Thanks for the post.

    Note this reference sample that shows how to limit trading hours using a time filter, this does not rely on runtime variables:

    https://ninjatrader.com/support/help...to_limit_t.htm

    To use your approach, would be better to use the Time[] array to mark an epoch that can be checked later. NinjaTrader needs to be running with an active data feed for the OnBarUpdate function to be called.

    A good way to check that enough time has passed would be to write down the time in a text file, then read that file on the next run of your script to check that at least 60 hours have passed.

    This reference sample shows how to write to a text file:
    https://ninjatrader.com/support/help...o_write_to.htm

    The former approach would be recommended over this though.

    Please let me know if I can assist further.
    Chris L.NinjaTrader Customer Service

    Comment


      #3
      Hi Chris

      Sorry, I don't follow your response.

      As an example, if CurrentBar-Triggerbar = 48 at 5pm and I disconnected my data feed for the day.

      If the conditions continued to be met through the evening, at 7am the next morning when I reconnected to the data feed, CurrentBar-Triggerbar = 62 and therefore a trade should trigger.

      Would Ninjatrader recognise this and enter a trade, or because I was not connected to the datafeed for the entire 62 bars would it not enter a trade?

      Many thanks
      STeve

      Comment


        #4
        Hello Steve,

        Thanks for the reply.

        If your session template is set to something other than default 24/7, then counting the bars would not work because the bars would stop being built at the end of the session and begin again at the next session start, excluding all the hours in between. Try this idea with the default 24/7 template, that does seem like it could work even when NinjaTrader is shut down. Using the time filter example would be the recommended way of limiting your trading hours though.

        I look forward to hearing of your results.
        Chris L.NinjaTrader Customer Service

        Comment


          #5
          Hi Chris

          So, if my Session Template is set to default 24/7, then when I switch off the data feed, and reconnect in the morning, then it should take into account the fact that bars 49 through to 62 have occurred?

          How do I check my Session Template sessions please? Tools-Trading Hours-Forex looks to be set to 24 /7.

          Start End
          Sunday 1700 Monday 1700
          Monday 1700 Tues 1700


          Does this mean I'm ok for what I'm trying to achieve? Doesn't seem to be generating Alerts/Trades in real time.

          I can get results Backtesting the strategy

          Thanks for the advice on how to more appropriately limit my trading hours, I'll take a look and compare to how I've currently done it.

          Comment


            #6
            Hello Steve,

            Thanks for the reply.

            Use Print statements to output values that make your condition true, then view the output through a NinjaScript output window - this is available through the New menu. Print statements help to see why a condition is not becoming true.

            EX:

            Code:
            Print("Evaluating Alert Condition");
            Print(Position.MarketPosition);
            Print(Time[0]);
            Print(SMA(movav)[0]);
            Print(SMA(movavshort)[0]);
            Print(Low[0]);
            Print(GoLong);
            Print(CurrentBar);
            Print(Triggerbar);
            if (Position.MarketPosition == MarketPosition.Flat
            && ToTime(Time[0])>70000 && ToTime(Time[0])<170000
            && SMA(movav)[0]<SMA(movavshort)[0]
            && Low[0]<SMA(movavshort)[0]
            && GoLong
            && CurrentBar-Triggerbar>60)
            https://ninjatrader.com/support/help...-us/?print.htm - Print()

            Please let me know if I can assist further.
            Chris L.NinjaTrader Customer Service

            Comment

            Latest Posts

            Collapse

            Topics Statistics Last Post
            Started by samir, Yesterday, 11:35 PM
            0 responses
            4 views
            0 likes
            Last Post samir
            by samir
             
            Started by iceman2018, Yesterday, 09:56 PM
            2 responses
            10 views
            0 likes
            Last Post samir
            by samir
             
            Started by [email protected], Yesterday, 10:13 PM
            0 responses
            4 views
            0 likes
            Last Post garzon.javier.e@gmail.com  
            Started by iceman2018, Yesterday, 09:51 PM
            0 responses
            6 views
            0 likes
            Last Post iceman2018  
            Started by n8dogg59, Yesterday, 06:55 AM
            2 responses
            18 views
            0 likes
            Last Post n8dogg59  
            Working...
            X