Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

ToTime and unwanted short trades

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

    ToTime and unwanted short trades

    Hi,

    I'm having two strange problems with a strategy I'm backtesting.

    1. I'm having trouble with ToTime. I have the following code:

    Code:
    // Long trades
                if (condition
                && ToTime(Time[0])> ToTime(08,30,00)
                && ToTime(Time[0])< ToTime(14,0,000)
                && more conditions
                );
                {
                    EnterLongStop(DefaultQuantity, High[0] + 1 * TickSize, "LongEntry1");
                    SetStopLoss("LongEntry1", CalculationMode.Price, Low[0]-1*TickSize, false);
                    SetProfitTarget("LongEntry1", CalculationMode.Price, (High[0]-Low[0])*1.55+High[0]);
                    StopMoveTriggerLong = (High[0]-Low[0])*0.9+High[0];
    
    //Move stop loss to half risk if 1.9x target is achieved
                if (High[0] >= StopMoveTriggerLong
                && Position.MarketPosition == MarketPosition.Long)
    
                {
                SetStopLoss("LongEntry1", CalculationMode.Price,Position.AvgPrice,false);
                }
    
                //Reset StopMoveTrigger if no position
                if (Position.MarketPosition == MarketPosition.Flat);
    
                {
                StopMoveTriggerLong = 0;
                }
    But the ToTime piece is just ignored by the strategy. It trades almost 24 hours a day (this is for the CME ES contract). Any ideas?

    2. As you can see, this strategy is only meant to take long trades. However, when I run a backtest and pull up the performance report, on the summary tab it shows that the strategy is taking short trades, and on the Trades tab it shows that the strategy is the strategy is treating some of my stop loss orders as short trades (see attached screenshot). I'm guessing when I dynamically move the stop loss up when a price target is hit, it's not cancelling the original stop loss (see code above)? How do I fix this?

    Thanks in advance.
    Attached Files

    #2
    Please remove the semicolon marked in RED.

    It effectively says do nothing after your if statement.


    Originally posted by PhillyD View Post
    Hi,

    I'm having two strange problems with a strategy I'm backtesting.

    1. I'm having trouble with ToTime. I have the following code:

    Code:
    // Long trades
                if (condition
                && ToTime(Time[0])> ToTime(08,30,00)
                && ToTime(Time[0])< ToTime(14,0,000)
                && more conditions
                )[B][COLOR="Red"][SIZE="7"];[/SIZE][/COLOR][/B]
                {
                    EnterLongStop(DefaultQuantity, High[0] + 1 * TickSize, "LongEntry1");
                    SetStopLoss("LongEntry1", CalculationMode.Price, Low[0]-1*TickSize, false);
                    SetProfitTarget("LongEntry1", CalculationMode.Price, (High[0]-Low[0])*1.55+High[0]);
                    StopMoveTriggerLong = (High[0]-Low[0])*0.9+High[0];
    
    //Move stop loss to half risk if 1.9x target is achieved
                if (High[0] >= StopMoveTriggerLong
                && Position.MarketPosition == MarketPosition.Long)
    
                {
                SetStopLoss("LongEntry1", CalculationMode.Price,Position.AvgPrice,false);
                }
    
                //Reset StopMoveTrigger if no position
                if (Position.MarketPosition == MarketPosition.Flat);
    
                {
                StopMoveTriggerLong = 0;
                }
    But the ToTime piece is just ignored by the strategy. It trades almost 24 hours a day (this is for the CME ES contract). Any ideas?

    2. As you can see, this strategy is only meant to take long trades. However, when I run a backtest and pull up the performance report, on the summary tab it shows that the strategy is taking short trades, and on the Trades tab it shows that the strategy is the strategy is treating some of my stop loss orders as short trades (see attached screenshot). I'm guessing when I dynamically move the stop loss up when a price target is hit, it's not cancelling the original stop loss (see code above)? How do I fix this?

    Thanks in advance.

    Comment


      #3
      Brilliant. Thank you.

      Comment

      Latest Posts

      Collapse

      Topics Statistics Last Post
      Started by CarlTrading, 03-31-2026, 09:41 PM
      1 response
      81 views
      1 like
      Last Post NinjaTrader_ChelseaB  
      Started by CarlTrading, 04-01-2026, 02:41 AM
      0 responses
      42 views
      0 likes
      Last Post CarlTrading  
      Started by CaptainJack, 03-31-2026, 11:44 PM
      0 responses
      64 views
      2 likes
      Last Post CaptainJack  
      Started by CarlTrading, 03-30-2026, 11:51 AM
      0 responses
      66 views
      0 likes
      Last Post CarlTrading  
      Started by CarlTrading, 03-30-2026, 11:48 AM
      0 responses
      54 views
      0 likes
      Last Post CarlTrading  
      Working...
      X