Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Stop strategy

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

    Stop strategy

    Hi, i am triyng to put a stop strategy in my code but it does not seem to work, in the test i get strange results like the suggestion (if optimized) to put lvl3 = 2 lvl3move= 10, and lvl4 = 5 lvl4move= 1, i really cant realize why this is happening. I have more then 40 key levels where i usually move my stop and for me would be a great thing have the possibility to backtest them. The calculation is on bar close. Thanks. Here's a part of the code:

    if (Position.MarketPosition == MarketPosition.Flat)
    {
    SetStopLoss(CalculationMode.Ticks, stopLoss);
    Variable1 = 0;
    }

    else if (Position.MarketPosition == MarketPosition.Long)
    {

    if (Close[0] >= Position.AvgPrice + mbreakEven * TickSize
    && Variable1 == 0)
    {
    SetStopLoss(CalculationMode.Price, Position.AvgPrice);
    Variable1 = 1;
    }

    if (Close[0] >= Position.AvgPrice + lvl1 * TickSize
    && Variable1 < 2)
    {
    SetStopLoss(CalculationMode.Price, Position.AvgPrice + lvl1move * TickSize);
    Variable1 = 2;
    }

    if (Close[0] >= Position.AvgPrice + lvl2 * TickSize
    && Variable1 < 3)
    {
    SetStopLoss(CalculationMode.Price, Position.AvgPrice + lvl2move * TickSize);
    Variable1 = 3;
    }

    if (Close[0] >= Position.AvgPrice + lvl3 * TickSize
    && Variable1 < 4)
    {
    SetStopLoss(CalculationMode.Price, Position.AvgPrice + lvl3move * TickSize);
    Variable1 = 4;

    .............................+37

    #2
    Welcome to our forums here Alex, I would suggest you simplify and debug your strategy script using Prints and TraceOrders, this will help you to understand what's happening to your orders and stoploss levels -





    Thanks,

    Comment


      #3
      Thank you Bertrand, i found out what was wrong.

      Alex

      Comment

      Latest Posts

      Collapse

      Topics Statistics Last Post
      Started by CarlTrading, 03-31-2026, 09:41 PM
      1 response
      72 views
      0 likes
      Last Post NinjaTrader_ChelseaB  
      Started by CarlTrading, 04-01-2026, 02:41 AM
      0 responses
      39 views
      0 likes
      Last Post CarlTrading  
      Started by CaptainJack, 03-31-2026, 11:44 PM
      0 responses
      63 views
      2 likes
      Last Post CaptainJack  
      Started by CarlTrading, 03-30-2026, 11:51 AM
      0 responses
      63 views
      0 likes
      Last Post CarlTrading  
      Started by CarlTrading, 03-30-2026, 11:48 AM
      0 responses
      53 views
      0 likes
      Last Post CarlTrading  
      Working...
      X