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 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
      283 views
      0 likes
      Last Post Hwop38
      by Hwop38
       
      Working...
      X