Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

This strat does great until cancel and then goes idle.

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

    This strat does great until cancel and then goes idle.

    This is the code, the part in red cancels the orders, but then script stops.

    Code:
     
    protected override void OnBarUpdate()
    {
    if (Historical)return;
    if (CurrentBar < 1)return;
    #region Seek Type
    if (Trend().TrendSlopeLong > 0 && Trend().TrendSlopeShort > .0025 && SeekType != true)
    {
    SeekType = true;
    Print("Seek = Long, " + Trend().TrendSlopeShort);
    }
    else SeekType = null;
    if (Trend().TrendSlopeLong < 0 && Trend().TrendSlopeShort < -.0025 && SeekType != false)
    {
    SeekType = false;
    Print("Seek = Short, " + Trend().TrendSlopeShort);
    }
    if (SeekType == null)Print("Trend weak, " + Trend().TrendSlopeShort);
    #endregion
    #region Entry Triggers
    Lower = Fibs().CurrentChannelLower;
    Upper = Fibs().CurrentChannelUpper;
    Status = MACDBBLines(period,Fast,Slow,Smooth,numStdDev).Status;
    if (Status == true)Print("Status = Long");
    if (Status == false)Print("Status = Short");
    if (Upper - Lower > ((Hide + .5) * TickSize))
    {
    if (MACDBBLines(period,Fast,Slow,Smooth,numStdDev).Status == null)
    {
    if (Clear != true)Print("Clear = true");
    Clear = true;
    }
    if (Status == true && Position.MarketPosition == MarketPosition.Flat && OrderPending == null && SeekType == true && Clear == true)
    {
    StopLong = Lower - (Hide * TickSize);
    EntryPriceLong = Lower + (2 * TickSize);
    SetProfitTarget("LongBank",CalculationMode.Price,EntryPriceLong + (Bank * TickSize));
    SetStopLoss(CalculationMode.Price,StopLong);
    LongRunner = EnterLongLimit(0,true,1,EntryPriceLong,"LongRunner");
    LongBank = EnterLongLimit(0,true,2,EntryPriceLong,"LongBank");
    OrderPending = true;
    Clear = false;
    }
    if (Status == false && Position.MarketPosition == MarketPosition.Flat && OrderPending == null && SeekType == false && Clear == true)
    {
    StopShort = Upper + (Hide * TickSize);
    EntryPriceShort = Upper - (2 * TickSize);
    SetProfitTarget("ShortBank",CalculationMode.Price,EntryPriceShort - (Bank * TickSize));
    SetStopLoss(CalculationMode.Price,StopShort);
    ShortRunner = EnterShortLimit(0,true,1,EntryPriceShort,"ShortRunner");
    ShortBank = EnterShortLimit(0,true,2,EntryPriceShort,"ShortBank");
    OrderPending = false;
    Clear = false;
    }
    }
    #endregion
    #region Order Maintenance
    if ((Position.MarketPosition == MarketPosition.Flat && OrderPending == true && Input[0] > EntryPriceLong + (Chase * TickSize)))
    {
    [COLOR=red]Print("Cancel, No retrace");[/COLOR]
    [COLOR=red]CancelOrder(LongRunner);[/COLOR]
    [COLOR=red]CancelOrder(LongBank);[/COLOR]
    [COLOR=red]OrderPending = null;[/COLOR]
    [COLOR=red]}[/COLOR]
    [COLOR=red]if ((Position.MarketPosition == MarketPosition.Flat && OrderPending == false && Input[0] < EntryPriceShort - (Chase * TickSize)))[/COLOR]
    [COLOR=red]{[/COLOR]
    [COLOR=red]Print("Cancel, No retrace");[/COLOR]
    [COLOR=red]CancelOrder(ShortRunner);[/COLOR]
    [COLOR=red]CancelOrder(ShortBank);[/COLOR]
    [COLOR=red]OrderPending = null;[/COLOR]
    [COLOR=red]}[/COLOR]
    if(Position.MarketPosition == MarketPosition.Long && StopLong < Lower - (Hide * TickSize))
    {
    StopLong = Lower - (Hide * TickSize);
    SetStopLoss(CalculationMode.Price,StopLong);
    }
    if(Position.MarketPosition == MarketPosition.Short && StopShort > Upper + (Hide * TickSize))
    {
    StopShort = Upper + (Hide * TickSize);
    SetStopLoss(CalculationMode.Price,StopShort);
    }
    #endregion
    }
    protected override void OnOrderUpdate(IOrder order) 
    { 
    if (LongBank != null && LongBank.Token == order.Token) 
    { 
    if (LongBank.OrderState == OrderState.Filled)
    {
    OrderPending = null;
    }
    } 
    if (ShortBank != null && ShortBank.Token == order.Token) 
    { 
    if (ShortBank.OrderState == OrderState.Filled)
    {
    OrderPending = null;
    }
    }
    }

    #2
    Hi Sleeping Troll,

    Can you clarify what you mean by "goes idle"

    Are your Print() statements being executed?

    Are you using TraceOrders?
    TimNinjaTrader Customer Service

    Comment


      #3
      Hmmm... The first time it cancelled an order it quit printing to output, since I restarted the strategy it has not occured again...

      I guess I will standby until I have more evidence, thx.

      Yes I am using trace, last activity was a print() that immediately precedes the cancel.

      Aha!, I have a reference error in log!
      Must be a "FirstTick" issue, I think if(FirstTickOfBar)return; should do it.
      Last edited by Sleeping Troll; 05-03-2010, 02:14 PM.

      Comment


        #4
        Hi Sleeping Troll,

        Thanks for the update. Let me know what you find.
        TimNinjaTrader Customer Service

        Comment


          #5
          Must be a "FirstTick" issue, I think "if(FirstTickOfBar)return;" should do it.

          Comment


            #6
            Hi Sleeping Troll,

            Thank you for the update.
            TimNinjaTrader Customer Service

            Comment

            Latest Posts

            Collapse

            Topics Statistics Last Post
            Started by charlesugo_1, 05-26-2026, 05:03 PM
            0 responses
            59 views
            0 likes
            Last Post charlesugo_1  
            Started by DannyP96, 05-18-2026, 02:38 PM
            1 response
            143 views
            0 likes
            Last Post NinjaTrader_ChelseaB  
            Started by CarlTrading, 05-11-2026, 05:56 AM
            0 responses
            161 views
            0 likes
            Last Post CarlTrading  
            Started by CarlTrading, 05-10-2026, 08:12 PM
            0 responses
            97 views
            0 likes
            Last Post CarlTrading  
            Started by Hwop38, 05-04-2026, 07:02 PM
            0 responses
            276 views
            0 likes
            Last Post Hwop38
            by Hwop38
             
            Working...
            X