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

Entry logic. Bars

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

    Entry logic. Bars

    Hi Ninjatrader Support,

    I have an issue with my entry trigger.

    I would like to set a entry trigger when 2 candles above the high of the Low bar, the entry trigger it is active.

    It can also happen that there are several candles above or in the Range, then the trigger also should be activated.

    It can be for example 10 candles, how can I put it in code?

    For better understanding look at the attached picture.

    specific example in the attached picture:

    //Trigger
    ((Low[1] > Low[4] && Low[2] > Low[4]) && (High[1] > High[4] && High[2] > High[4]))

    //Entry
    if (CurrentBid() < Low[4])
    {
    EnterShort()
    }

    Click image for larger version  Name:	Logic 2 Reaktionskerzen.JPG Views:	0 Size:	98.5 KB ID:	1098583
    Last edited by Tradeer; 05-07-2020, 04:28 AM.

    #2
    Hello Tradeer,

    Thanks for your post.

    When you determine the low bar point, save the bar number into a variable that you create and save the low price into a variable you create.

    You can then use these to to test/limit how many bars have occurred since the low bar and if a particular bar is less than the low bar.

    if (CurrentBar - mySavedBar < 10 && CurrentBid() < mySavedPrice)
    {
    EnterShort();
    }

    You may also want to add a bool variable to prevent subsequent orders if you have for example two down bars in row that would be less than mySavedPrice.
    Paul H.NinjaTrader Customer Service

    Comment


      #3
      Hi Paul,

      thanks for your reply.


      I found a good way that fits the logic. But unfortunatly it doesn't work.

      I'm using the EZ indiactor to identify the price for the entry.

      The condition of the entry trigger is already given by the indicator.

      The signal should therfore only be if the CurrentBar falls below pv1(// Lowprice) and the dir is < 0(// direction is short)

      No entries are made I couldn't fix the error.

      I wanted to test it historically first, therefore the OnBarClose() method and CurrentBar for the entry.

      Can you help me? Maybe you can find the mistake.
      The script is attached

      regards
      Tradeer




      public class EMACross : Strategy
      {
      private EMA EMA1;
      private EMA EMA2;

      private EZ EZ1;




      protected override void OnStateChange()
      {
      if (State == State.SetDefaults)
      {
      Description = @"15min DowJones";
      Name = "EMACross";
      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)
      {
      }
      else if (State == State.DataLoaded)
      {
      EMA1 = EMA(Close, 6);
      EMA2 = EMA(Close, 20);
      SetStopLoss("", CalculationMode.Ticks, 50, false);
      SetProfitTarget("", CalculationMode.Ticks, 150);


      EMA1.Plots[0].Brush = Brushes.Red;
      EMA2.Plots[0].Brush = Brushes.Blue;
      AddChartIndicator(EMA1);
      AddChartIndicator(EMA2);



      EZ1 = EZ(false, 2, 3);
      AddChartIndicator(EZ1);
      }
      }


      /*
      dir = current pivot direction(positive = high, negative = low)
      pb1, pb2 = bar numbers of the last two confirmed pivots
      pb3 = bar number of possible new pivot, not yet confirmed
      pv1, pv2 = price values of the last two confirmed pivots
      pv3 = price of the possible new pivot, not yet confirmed
      */

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



      if (CurrentBars[0] < 2)
      return;




      //Short

      if (Position.MarketPosition != MarketPosition.Long && CrossBelow(EMA1, EMA2, 1))
      {
      if(EZ1.dir < 0 && CurrentBar < EZ1.pv1)
      {
      EnterShort(Convert.ToInt32(DefaultQuantity), "");
      }



      }


      // Long

      if (Position.MarketPosition != MarketPosition.Short && CrossAbove(EMA1, EMA2, 1))
      {
      if (EZ1.dir > 0 && CurrentBar > EZ1.pv1)
      {
      EnterLong(Convert.ToInt32(DefaultQuantity), "");
      }



      }





      }



      }
      Last edited by Tradeer; 05-07-2020, 02:11 PM.

      Comment


        #4
        Hello Tradeer,

        Thanks for your reply.

        It looks like you are only evaluating the EZ indicator at the same time you have a cross condition.

        If the strategy compile successfully and no errors are shown in the Log tab of the control center, I would add a print statement that prints the values of the EZ indicator when the cross occurs. this way you can see what values are actually being produced.


        Paul H.NinjaTrader Customer Service

        Comment


          #5
          Hi Paul,

          tested it for some reason pv1 Value = 0

          Comment


            #6
            Hello Tradeer,

            Thanks for your reply.

            You might want to also print out the other variables such pb1 and pb2, perhaps your code is checking for a pivot value when there is no pivot value yet determined.

            Looking at your conditions of && CurrentBar > EZ1.pv1 && CurrentBar < EZ1.pv1 you are comparing the current bar number to what earlier you listed as pv1, pv2 = price values of the last two confirmed pivots, so your conditions likely would not work even if pv1 was returning a legitimate price level.



            Paul H.NinjaTrader Customer Service

            Comment

            Latest Posts

            Collapse

            Topics Statistics Last Post
            Started by inanazsocial, Today, 01:15 AM
            1 response
            6 views
            0 likes
            Last Post NinjaTrader_Jason  
            Started by rocketman7, Today, 02:12 AM
            0 responses
            10 views
            0 likes
            Last Post rocketman7  
            Started by dustydbayer, Today, 01:59 AM
            0 responses
            2 views
            0 likes
            Last Post dustydbayer  
            Started by trilliantrader, 04-18-2024, 08:16 AM
            5 responses
            23 views
            0 likes
            Last Post trilliantrader  
            Started by Davidtowleii, Today, 12:15 AM
            0 responses
            3 views
            0 likes
            Last Post Davidtowleii  
            Working...
            X