Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

"The Strat" strategy. Using Failed 2ups/2downs on the 1 minute chart.

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

    "The Strat" strategy. Using Failed 2ups/2downs on the 1 minute chart.

    The title says the majority of what I am after.


    //This namespace holds Strategies in this folder and is required. Do not change it.
    namespace NinjaTrader.NinjaScript.Strategies
    {
    public class Scalping : Strategy
    {
    protected override void OnStateChange()
    {
    if (State == State.SetDefaults)
    {
    Description = @"I will be using this to go long on failed 2 downs that close green and failed 2ups that close red above or below the 10EMA respectively. ";
    Name = "Scalping";
    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.Day;
    TraceOrders = false;
    RealtimeErrorHandling = RealtimeErrorHandling.StopCancelClose;
    StopTargetHandling = StopTargetHandling.ByStrategyPosition;
    BarsRequiredToTrade = 1;
    // Disable this property for performance gains in Strategy Analyzer optimizations
    // See the Help Guide for additional information
    IsInstantiatedOnEachOptimizationIteration = true;
    EMAPeriod = 10;
    }
    else if (State == State.Configure)
    {
    AddDataSeries("NQ DEC23", Data.BarsPeriodType.Minute, 1, Data.MarketDataType.Last);
    SetProfitTarget(@"12", CalculationMode.Ticks, 12);
    }
    }

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

    if (CurrentBars[0] < 1)
    return;

    // Set 1
    if ((Low[0] < Low[0])
    && (High[0] < High[1])
    && (Close[0] > Open[0])
    && (Times[0][0].TimeOfDay >= new TimeSpan(9, 31, 0))
    && (Times[0][0].TimeOfDay <= new TimeSpan(16, 29, 0))
    && (CurrentBars[0] >= EMAPeriod))
    {
    EnterLongStopMarket(10, (GetCurrentAsk(0) + (1 * TickSize)) , @"2D green long");
    }

    // Set 2
    if ((High[0] > High[1])
    && (Low[0] > Low[1])
    && (Close[0] < Open[0])
    && (Times[0][0].TimeOfDay >= new TimeSpan(9, 31, 0))
    && (Times[0][0].TimeOfDay <= new TimeSpan(16, 29, 0))
    && (CurrentBars[0] <= EMAPeriod))
    {
    EnterShortStopMarket(10, (GetCurrentBid(0) + (1 * TickSize)) , @"ShortEntry");
    }

    }​

    This is what I have so far. I cannot seem to populate any data when I backtest it.

    #2
    Hello slade3789,

    Thanks for your post.

    I see you added a secondary data series to the script but you are not checking if there are enough bars processed for the added series. A CurrentBars check should be added to the script to make sure you have enough bars for all series.

    See the help guide page below for more information.
    CurrentBars: https://ninjatrader.com/support/help...urrentbars.htm
    Make sure you have enough bars: https://ninjatrader.com/support/help...nough_bars.htm
    Working with Multi-timeframe/Multi-instrument NinjaScripts: https://ninjatrader.com/support/help...nstruments.htm

    CurrentBars[0] returns the bar index of the current bar of the primary data series the script is running on. This condition (CurrentBars[0] >= EMAPeriod) would mean that the condition would only become true if the bar index is greater than 10. This condition would not return true if the bar index is before bar 10.

    This condition (CurrentBars[0] <= EMAPeriod) would only become true if the bar index is 0-10. After bar 10, this condition would not become true.

    If the expected trade(s) are not appearing, this would indicate that the condition to place the order is not evaluating as true or the order is being ignored for other reasons.

    To understand why the script is behaving as it is, such as placing orders or not placing orders or drawing objects when expected, it is necessary to add prints to the script that print the values used for the logic of the script to understand how the script is evaluating.

    In the strategy add prints (outside of any conditions) that print the values of every variable used in every condition that places an order along with the time of that bar.​

    Prints will appear in the NinjaScript Output window (New > NinjaScript Output window).

    Below is a link to a forum post that demonstrates how to use prints to understand the behavior of a script.
    https://ninjatrader.com/support/foru...121#post791121
    Last edited by NinjaTrader_BrandonH; 10-10-2023, 07:38 AM.
    <span class="name">Brandon H.</span><span class="title">NinjaTrader Customer Service</span><iframe name="sig" id="sigFrame" src="/support/forum/core/clientscript/Signature/signature.php" frameborder="0" border="0" cellspacing="0" style="border-style: none;width: 100%; height: 120px;"></iframe>

    Comment


      #3
      Hey slade did you ever get this working?

      Do you have or know of an indicator that highlights the patterns on the chart?

      Comment


        #4
        Hey Innovatoin88 you can go here and use the NQ scalper [redacted]​

        Comment


          #5
          Hello slade3789,

          Thanks for your input.
          Unfortunately, I've had to remove the link from your post.
          To ensure a fair forum environment that isn't filled with advertisement, our policy is to remove links to third party sites that are not educational.
          It can helpful to discuss a vendor product, however if you have links to non-educational material such as product sites please consider sending these as a private message to the recipient.
          If this is an open source script you have created, you may also consider submitting the script to the User App Share.
          https://forum.ninjatrader.com/forum/...app-submission
          Chelsea B.NinjaTrader Customer Service

          Comment

          Latest Posts

          Collapse

          Topics Statistics Last Post
          Started by NullPointStrategies, Yesterday, 05:17 AM
          0 responses
          56 views
          0 likes
          Last Post NullPointStrategies  
          Started by argusthome, 03-08-2026, 10:06 AM
          0 responses
          132 views
          0 likes
          Last Post argusthome  
          Started by NabilKhattabi, 03-06-2026, 11:18 AM
          0 responses
          73 views
          0 likes
          Last Post NabilKhattabi  
          Started by Deep42, 03-06-2026, 12:28 AM
          0 responses
          45 views
          0 likes
          Last Post Deep42
          by Deep42
           
          Started by TheRealMorford, 03-05-2026, 06:15 PM
          0 responses
          49 views
          0 likes
          Last Post TheRealMorford  
          Working...
          X