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 Geovanny Suaza, 02-11-2026, 06:32 PM
            0 responses
            661 views
            0 likes
            Last Post Geovanny Suaza  
            Started by Geovanny Suaza, 02-11-2026, 05:51 PM
            0 responses
            376 views
            1 like
            Last Post Geovanny Suaza  
            Started by Mindset, 02-09-2026, 11:44 AM
            0 responses
            110 views
            0 likes
            Last Post Mindset
            by Mindset
             
            Started by Geovanny Suaza, 02-02-2026, 12:30 PM
            0 responses
            574 views
            1 like
            Last Post Geovanny Suaza  
            Started by RFrosty, 01-28-2026, 06:49 PM
            0 responses
            580 views
            1 like
            Last Post RFrosty
            by RFrosty
             
            Working...
            X