Announcement

Collapse

Looking for a User App or Add-On built by the NinjaTrader community?

Visit NinjaTrader EcoSystem and our free User App Share!

Have a question for the NinjaScript developer community? Open a new thread in our NinjaScript File Sharing Discussion Forum!
See more
See less

Partner 728x90

Collapse

Enter long position at 6:00PM

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

    Enter long position at 6:00PM

    So I'm trying to get a strategy that will do something simple, which is enter a long position at 6:00PM every day.

    I've backtest this code on Playback and it doesn't seem to enter a position at 6:00PM for some reason. Advice would be welcome.

    Here is the code (which goes long 4 contracts):

    --

    #region Using declarations
    using System;
    using System.Collections.Generic;
    using System.ComponentModel;
    using System.ComponentModel.DataAnnotations;
    using System.Linq;
    using System.Text;
    using System.Threading.Tasks;
    using System.Windows;
    using System.Windows.Input;
    using System.Windows.Media;
    using System.Xml.Serialization;
    using NinjaTrader.Cbi;
    using NinjaTrader.Gui;
    using NinjaTrader.Gui.Chart;
    using NinjaTrader.Gui.SuperDom;
    using NinjaTrader.Gui.Tools;
    using NinjaTrader.Data;
    using NinjaTrader.NinjaScript;
    using NinjaTrader.Core.FloatingPoint;
    using NinjaTrader.NinjaScript.Indicators;
    using NinjaTrader.NinjaScript.DrawingTools;
    #endregion

    //This namespace holds Strategies in this folder and is required. Do not change it.
    namespace NinjaTrader.NinjaScript.Strategies
    {
    public class TimeLong : Strategy
    {
    protected override void OnStateChange()
    {
    if (State == State.SetDefaults)
    {
    Description = @"Enter the description for your new custom Strategy here.";
    Name = "TimeLong";
    Calculate = Calculate.OnBarClose;
    EntriesPerDirection = 1;
    EntryHandling = EntryHandling.AllEntries;
    IsExitOnSessionCloseStrategy = true;
    ExitOnSessionCloseSeconds = 30;
    IsFillLimitOnTouch = false;
    MaximumBarsLookBack = MaximumBarsLookBack.TwoHundredFiftySix;
    OrderFillResolution = OrderFillResolution.Standard;
    Slippage = 0;
    StartBehavior = StartBehavior.WaitUntilFlat;
    TimeInForce = TimeInForce.Gtc;
    TraceOrders = false;
    RealtimeErrorHandling = RealtimeErrorHandling.StopCancelClose;
    StopTargetHandling = StopTargetHandling.PerEntryExecution;
    BarsRequiredToTrade = 20;
    // Disable this property for performance gains in Strategy Analyzer optimizations
    // See the Help Guide for additional information
    IsInstantiatedOnEachOptimizationIteration = true;
    }
    else if (State == State.Configure)
    {
    AddDataSeries("MES 09-19", Data.BarsPeriodType.Minute, 1, Data.MarketDataType.Ask);
    SetStopLoss("", CalculationMode.Ticks, 40, false);
    }
    }

    protected override void OnBarUpdate()
    {
    if (BarsInProgress != 0)
    return;

    if (CurrentBars[0] < 1)
    return;

    // Set 1
    if (ToTime(Time[0]) >= ToTime(18, 0, 0) && ToTime(Time[0]) <= ToTime(18, 0, 1))
    {
    EnterLong(Convert.ToInt32(4), "");
    }

    }
    }
    }

Latest Posts

Collapse

Topics Statistics Last Post
Started by fx.practic, 10-15-2013, 12:53 AM
5 responses
5,404 views
0 likes
Last Post Bidder
by Bidder
 
Started by Shai Samuel, 07-02-2022, 02:46 PM
4 responses
95 views
0 likes
Last Post Bidder
by Bidder
 
Started by DJ888, Yesterday, 10:57 PM
0 responses
8 views
0 likes
Last Post DJ888
by DJ888
 
Started by MacDad, 02-25-2024, 11:48 PM
7 responses
159 views
0 likes
Last Post loganjarosz123  
Started by Belfortbucks, Yesterday, 09:29 PM
0 responses
8 views
0 likes
Last Post Belfortbucks  
Working...
X