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 Mindset, 04-21-2026, 06:46 AM
      0 responses
      108 views
      0 likes
      Last Post Mindset
      by Mindset
       
      Started by M4ndoo, 04-20-2026, 05:21 PM
      0 responses
      154 views
      0 likes
      Last Post M4ndoo
      by M4ndoo
       
      Started by M4ndoo, 04-19-2026, 05:54 PM
      0 responses
      74 views
      0 likes
      Last Post M4ndoo
      by M4ndoo
       
      Started by cmoran13, 04-16-2026, 01:02 PM
      0 responses
      125 views
      0 likes
      Last Post cmoran13  
      Started by PaulMohn, 04-10-2026, 11:11 AM
      0 responses
      79 views
      0 likes
      Last Post PaulMohn  
      Working...
      X