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,
    BertrandNinjaTrader Customer Service

    Comment


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

      Alex

      Comment

      Latest Posts

      Collapse

      Topics Statistics Last Post
      Started by pvincent, 06-23-2022, 12:53 PM
      14 responses
      238 views
      0 likes
      Last Post Nyman
      by Nyman
       
      Started by TraderG23, 12-08-2023, 07:56 AM
      9 responses
      383 views
      1 like
      Last Post Gavini
      by Gavini
       
      Started by oviejo, Today, 12:28 AM
      0 responses
      1 view
      0 likes
      Last Post oviejo
      by oviejo
       
      Started by pechtri, 06-22-2023, 02:31 AM
      10 responses
      125 views
      0 likes
      Last Post Leeroy_Jenkins  
      Started by judysamnt7, 03-13-2023, 09:11 AM
      4 responses
      59 views
      0 likes
      Last Post DynamicTest  
      Working...
      X