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

Ninjatrader Strategy builder Prior Day Close Script Problem

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

    Ninjatrader Strategy builder Prior Day Close Script Problem

    Hello Team
    Can you please help me understand why I can't get my "Prior Day Close" script to work ,I am trying to short when the price cross the Prior day close.But the Strategy analyzer isn't giving any output. Below is my actual script :

    //This namespace holds Strategies in this folder and is required. Do not change it.
    namespace NinjaTrader.NinjaScript.Strategies
    {
    public class PDAYCLOSE : Strategy
    {
    private PriorDayOHLC PriorDayOHLC1;

    protected override void OnStateChange()
    {
    if (State == State.SetDefaults)
    {
    Description = @"Enter the description for your new custom Strategy here.";
    Name = "PDAYCLOSE";
    Calculate = Calculate.OnPriceChange;
    EntriesPerDirection = 1;
    EntryHandling = EntryHandling.UniqueEntries;
    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 = 5;
    // Disable this property for performance gains in Strategy Analyzer optimizations
    // See the Help Guide for additional information
    IsInstantiatedOnEachOptimizationIteration = true;
    }
    else if (State == State.Configure)
    {
    }
    else if (State == State.DataLoaded)
    {
    PriorDayOHLC1 = PriorDayOHLC(Close);
    SetStopLoss(@" ", CalculationMode.Ticks, 100, false);
    SetProfitTarget("", CalculationMode.Ticks, 200);
    }
    }

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

    if (CurrentBars[0] < 1)
    return;

    // Set 1
    if (CrossBelow(PriorDayOHLC1.PriorClose, PriorDayOHLC1.PriorClose, 0))
    {
    EnterShort(Convert.ToInt32(DefaultQuantity), @"");
    }

    }
    }
    }

    #region Wizard settings, neither change nor remove

    Thanks in Advance


    #2
    Hello Behungr101,

    Thanks for your post.

    In your entry condition you have the priordayclose crossing below the priordayclose and 0 bar lookback. This will never trigger.

    What you want to to see if the Close price series crosses below the prior day close and I would suggest a 1 bar look back.

    In the strategy builder conditions, select Price folder then Close price, center is Crossbelow (1 bar look back), and on the right would be PriorDay as you have it.

    Paul H.NinjaTrader Customer Service

    Comment


      #3
      Hello Paul
      Thanks a million for the quick reply and for your suggestion ,now the script is working.But I still have a little problem .The script isn't respecting my stop lost when the trade goes against me .What am I doing wrong ? I have attached the screenshot .

      Thanks again
      Attached Files

      Comment


        #4
        Hello Behungr101,

        Thanks for your reply.

        Looking back at the code produced for the stop loss I see this line: SetStopLoss(@" ", CalculationMode.Ticks, 100, false); If you contrast that with the profit target: SetProfitTarget("", CalculationMode.Ticks, 200); take note that the stop loss shows " " where the profit target shows "", in other words, it appears that the stop loss has an entry in the "signal name" field which is only a space character. So this means the stop loss is only going to work for an entry signal that has a single space for the entry name.

        I would suggest removing the stop loss and then recreate it, without an entry in the signal name field.
        Paul H.NinjaTrader Customer Service

        Comment


          #5
          Hi Paul,
          Thanks a million! It's working! You Guys really know your stuff.

          Best regards

          Comment


            #6
            Hello Behungr101,

            Thanks for your reply and glad you are making progress!

            Here are links to education resources for the Startegy Builder that you might want to review if you haven't already:

            Free live webinar every other Thursday at 4:00 PM EST, through this link to all webinars: https://ninjatrader.com/PlatformTraining
            Previous recording of the Strategy Builder 301 webinar: https://youtu.be/HCyt90GAs9k?list=PL...auWXkWe0Nf&t=2
            Help guide for the strategy builder: https://ninjatrader.com/support/help...gy_builder.htm
            Tutorial using the Strategy Builder (Titled "Creating the Strategy by the Wizard): https://ninjatrader.com/support/help..._cross_ove.htm

            Paul H.NinjaTrader Customer Service

            Comment

            Latest Posts

            Collapse

            Topics Statistics Last Post
            Started by traderqz, Yesterday, 09:06 AM
            3 responses
            20 views
            0 likes
            Last Post NinjaTrader_ThomasC  
            Started by f.saeidi, Today, 10:19 AM
            1 response
            4 views
            0 likes
            Last Post NinjaTrader_BrandonH  
            Started by kujista, Today, 06:23 AM
            5 responses
            15 views
            0 likes
            Last Post kujista
            by kujista
             
            Started by traderqz, Today, 12:06 AM
            3 responses
            6 views
            0 likes
            Last Post NinjaTrader_Gaby  
            Started by RideMe, 04-07-2024, 04:54 PM
            5 responses
            28 views
            0 likes
            Last Post NinjaTrader_BrandonH  
            Working...
            X