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 argusthome, Yesterday, 10:06 AM
      0 responses
      20 views
      0 likes
      Last Post argusthome  
      Started by NabilKhattabi, 03-06-2026, 11:18 AM
      0 responses
      18 views
      0 likes
      Last Post NabilKhattabi  
      Started by Deep42, 03-06-2026, 12:28 AM
      0 responses
      14 views
      0 likes
      Last Post Deep42
      by Deep42
       
      Started by TheRealMorford, 03-05-2026, 06:15 PM
      0 responses
      9 views
      0 likes
      Last Post TheRealMorford  
      Started by Mindset, 02-28-2026, 06:16 AM
      0 responses
      38 views
      0 likes
      Last Post Mindset
      by Mindset
       
      Working...
      X