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 popecapllc, 08-09-2023, 07:42 PM
      8 responses
      1,346 views
      0 likes
      Last Post Johng22
      by Johng22
       
      Started by ETFVoyageur, 04-30-2024, 02:04 PM
      11 responses
      100 views
      0 likes
      Last Post ETFVoyageur  
      Started by bubblegum, 03-18-2024, 10:41 AM
      3 responses
      45 views
      0 likes
      Last Post vjsworld  
      Started by JamesK1, Today, 02:48 PM
      1 response
      13 views
      0 likes
      Last Post JamesK1
      by JamesK1
       
      Started by llanqui, Today, 03:51 PM
      0 responses
      13 views
      0 likes
      Last Post llanqui
      by llanqui
       
      Working...
      X