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

Trailing stop gets cancelled upon reversal

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

    Trailing stop gets cancelled upon reversal

    Hi,

    I run a simple reversal strategy. It appears that trailing stop works incorrectly.

    CL 12-12, 2min chart, Replay Mode 11/2/2012 8:12:ish AM

    protected override void Initialize()
    {
    SetTrailStop(CalculationMode.Ticks, 6.0);
    TraceOrders = true;

    CalculateOnBarClose = true;
    Add(PeriodType.Minute, 1);
    }
    protected override void OnBarUpdate()
    {
    if (Historical)
    {
    return;
    }

    if (BarsInProgress == 0)
    {
    bool longCond = GetCurrentBid() > High[1]
    && Position.MarketPosition==MarketPosition.Flat
    && CONDITION1);
    if (longCond)
    {
    EnterLong(1, 1, "Long");
    }

    bool shortCond = GetCurrentAsk() < Low[1]
    && Position.MarketPosition==MarketPosition.Flat
    && CONDITION2);
    if (shortCond)
    {
    EnterShort(1, 1, "Short");
    }
    }
    }
    Here is the chart
    Free online storage and sharing with Screencast.com. 2 GB of storage and 2 GB of bandwidth per month for free. We won't compress, alter or take ownership of your content.


    Here are the traces:
    11/2/2012 8:16:08 AM Entered internal PlaceOrder() method at 11/2/2012 8:16:08 AM: BarsInProgress=1 Action=SellShort OrderType=Market Quantity=1 LimitPrice=0 StopPrice=0 SignalName='Short' FromEntrySignal=''
    11/2/2012 8:30:00 AM Entered internal PlaceOrder() method at 11/2/2012 8:30:00 AM: BarsInProgress=1 Action=Buy OrderType=Market Quantity=1 LimitPrice=0 StopPrice=0 SignalName='Long' FromEntrySignal=''
    11/2/2012 8:31:00 AM Amended trail stop order: Order='cf7bb64dee8441e9bb67f794aabdb9da/Replay101' Name='Trail stop' State=Accepted Instrument='CL 12-12' Action=Sell Limit price=0 Stop price=86.81 Quantity=1 Strategy='HeikenAshi1' Type=Stop Tif=Gtc Oco='b97a62d6b60b4dc0bcbd17cace4788f2-1725' Filled=0 Fill price=0 Token='cf7bb64dee8441e9bb67f794aabdb9da' Gtd='12/1/2099 12:00:00 AM'
    11/2/2012 8:31:00 AM Cancelled expired order: BarsInProgress=0: Order='cf7bb64dee8441e9bb67f794aabdb9da/Replay101' Name='Trail stop' State=Accepted Instrument='CL 12-12' Action=Sell Limit price=0 Stop price=86.81 Quantity=1 Strategy='HeikenAshi1' Type=Stop Tif=Gtc Oco='b97a62d6b60b4dc0bcbd17cace4788f2-1725' Filled=0 Fill price=0 Token='cf7bb64dee8441e9bb67f794aabdb9da' Gtd='12/1/2099 12:00:00 AM'


    What am I doing wrong?

    Thanks.

    #2
    Hello alex.nt,
    Thanks for your note.

    You are submitting the orders on the secondary series. The Set() method works only for orders submitted on the primary series and not on the secondary series.

    Please use the Exit() codes to exit the strategy if you are using a Multi series strategy and submitting the orders on the secondary series.
    JoydeepNinjaTrader Customer Service

    Comment


      #3
      In fact, I changed the code so now (everything else remained the same)
      if (longCond)
      {
      EnterLong(PositionSize);
      }
      if (shortCond)
      {
      EnterShort(PositionSize);
      }
      The result remains the same!

      Any ideas?

      Comment


        #4
        Hello alex.nt,
        To assist you further may I know the exact scenario you are facing. Can you please let me know the exact steps to replicate the scenario.

        I look forward to assisting you further.
        JoydeepNinjaTrader Customer Service

        Comment

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by andrewtrades, Today, 04:57 PM
        1 response
        10 views
        0 likes
        Last Post NinjaTrader_Manfred  
        Started by chbruno, Today, 04:10 PM
        0 responses
        6 views
        0 likes
        Last Post chbruno
        by chbruno
         
        Started by josh18955, 03-25-2023, 11:16 AM
        6 responses
        436 views
        0 likes
        Last Post Delerium  
        Started by FAQtrader, Today, 03:35 PM
        0 responses
        9 views
        0 likes
        Last Post FAQtrader  
        Started by rocketman7, Today, 09:41 AM
        5 responses
        20 views
        0 likes
        Last Post NinjaTrader_Jesse  
        Working...
        X