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