Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Entering the trader 2 ticks above the close of the signal bar

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

    Entering the trader 2 ticks above the close of the signal bar

    Hello,
    I'd like to enter a long trade 2 ticks above the close of the signal bar. The challenge that I am running into are:
    1. How to create a code that helps me to enter at a price 2 ticks above the close of the signal bar
    2. At times the market may move up 2 ticks during the very next bar after the signal bar OR it may hover around for next 5 bars and then moves up in my direction. In this case, how do I make sure that NT is able to remember the long signal even though it occurred number of bars ago.

    I wrote a code after going through NT help manual, but it is not placing any trade at all. I am copying the code that I have and greatly appreciate if you can help me to figure out:
    1. How to go long at 2 ticks above the close of the signal bar
    2. In case the market does not move up by 2 ticks during the next bar after the signal bar, how to make sure NT will do so as long as long conditions are still prevailing and will enter a trade if the market continues to move higher after 3 or 4 or 5 bars after the signal bar

    protected override void Initialize()
    {
    EntriesPerDirection = 1;
    SetProfitTarget(CalculationMode.Ticks, profittargetticks1);
    SetStopLoss(CalculationMode.Ticks, stoplossticks);
    Add(PeriodType.Minute, higherperiod);
    CalculateOnBarClose = true;
    }
    protected override void OnBarUpdate()
    {
    //Long Entry
    if (VsTWPColor(wave).Power5[0] >= 1

    && (VsTWPColor(wave).Power5[0] <= 2
    && AAATS_TrendWithPower(wave).TrendUp.ContainsValue(0 )
    && AAATS_TrendWithPower(BarsArray[1],highertimewave).TrendTicksCount[0]>=1
    && AAATS_TrendWithPower(BarsArray[1],highertimewave).TrendTendance[0]>=1


    && (ToTime(Time[0]) >= 83000 && ToTime(Time[0]) <= 150000)
    && entryOrder == null))
    {
    entryOrder = SubmitOrder(1, OrderAction.Buy, OrderType.StopLimit, 1, Close[0] + 2*TickSize, Close[0] + 2*TickSize, "", "Long 1");
    }

    #2
    Hello,

    Thank you for the code snippet. One thing I've noticed is that an unmanaged method type is being used to enter your position however this is a managed strategy.

    In stead of using SubmitOrder you'll want to use EnterLongStopLimit: http://www.ninjatrader.com/support/h...gstoplimit.htm

    If you're condition remains true the order will remain active. If you want the order to stay active even if the condition is no longer true you will want to use the final overload listed in the above link that looks like this:

    EnterLongStopLimit(int barsInProgressIndex, bool liveUntilCancelled, int quantity, double limitPrice, double stopPrice, string signalName)

    This way you can set liveUntilCancelled to true.

    A final note, depending on your desired logic you may need to add BarsInProgess filtering. Otherwise you'll be getting duplicate calls from each of your data series: http://www.ninjatrader.com/support/h...nstruments.htm

    Let me know if I can further assist.
    LanceNinjaTrader Customer Service

    Comment


      #3
      Hi Pandyav,

      I suggest printing individual conditions in your code to review their value at runtime. Whether all of time are True at runtime or not.

      Also its easier to use EnterLongLimit() to test the strategy using Managed approach, and then branch into unmanaged order approach.

      For the second question you had, you can use a one-time boolean flag for your code to remember when the last order was sent, and hence not modifying or re-entering the order at different price, few bars later.

      Hope this helps,
      Cheers!

      Comment

      Latest Posts

      Collapse

      Topics Statistics Last Post
      Started by Max238, Today, 01:28 AM
      5 responses
      42 views
      0 likes
      Last Post Max238
      by Max238
       
      Started by giulyko00, Yesterday, 12:03 PM
      3 responses
      12 views
      0 likes
      Last Post NinjaTrader_BrandonH  
      Started by habeebft, Today, 07:27 AM
      1 response
      14 views
      0 likes
      Last Post NinjaTrader_ChristopherS  
      Started by AveryFlynn, Today, 04:57 AM
      1 response
      12 views
      0 likes
      Last Post NinjaTrader_Erick  
      Started by r68cervera, Today, 05:29 AM
      1 response
      10 views
      0 likes
      Last Post NinjaTrader_ChelseaB  
      Working...
      X