Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

double / triple breakeven in the builder and a final takeprofit

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

    double / triple breakeven in the builder and a final takeprofit

    hi, I am not a programmer and I would like if possible some suggestions on how to set up a double / triple breakeven in the builder and a final takeprofit starting from your example in which we have a single breakeven. thank you so much

    #2
    Hello matrix74,

    Welcome to the NinjaTrader forums!

    While I am not able to write the code on your behalf, I can answer any questions you may have if you are getting stuck.

    Are you wanting to have multiple entry orders and each has different logic for when the stop is moved the entry price?

    Are you wanting custom trailing logic to move a single stop multiple times?

    I have an example of custom trailing logic which I am linking below.
    Chelsea B.NinjaTrader Customer Service

    Comment


      #3

      361/5000
      I cannot understand where I am wrong, my idea is to move the initial stop when the market is in my favor by 5 ticks (stop at +1) and when it reaches 9 ticks the stop should move to +4. I had also added the canons stop and profit, but so the strategy does not work. Can you suggest where I'm wrong? thank you so much

      public class BreakEvenBuilderExample : Strategy
      {
      private double StopPrice;
      private double TriggerPrice;
      private int TriggerState;
      private double TriggerPrice1;


      protected override void OnStateChange()
      {
      if (State == State.SetDefaults)
      {
      Description = @"";
      Name = "BreakEvenBuilderExample";
      Calculate = Calculate.OnEachTick;
      EntriesPerDirection = 1;
      EntryHandling = EntryHandling.AllEntries;
      IsExitOnSessionCloseStrategy = true;
      ExitOnSessionCloseSeconds = 30;
      IsFillLimitOnTouch = false;
      MaximumBarsLookBack = MaximumBarsLookBack.TwoHundredFiftySix;
      OrderFillResolution = OrderFillResolution.Standard;
      Slippage = 0;
      StartBehavior = StartBehavior.WaitUntilFlat;
      TimeInForce = TimeInForce.Gtc;
      TraceOrders = false;
      RealtimeErrorHandling = RealtimeErrorHandling.StopCancelClose;
      StopTargetHandling = StopTargetHandling.PerEntryExecution;
      BarsRequiredToTrade = 20;
      // Disable this property for performance gains in Strategy Analyzer optimizations
      // See the Help Guide for additional information
      IsInstantiatedOnEachOptimizationIteration = true;
      BreakEvenTrigger = 5;
      InitialStopDistance = -10;
      BreakEvenTrigger9 = 9;
      MoveTicks1BE = 1;
      MoveTicks2BE = 4;
      TakeProfit = 15;
      StopLoss = 14;
      StopPrice = 0;
      TriggerPrice = 0;
      TriggerState = 0;
      TriggerPrice1 = 0;
      }
      else if (State == State.Configure)
      {
      SetProfitTarget("", CalculationMode.Ticks, TakeProfit);
      SetStopLoss("", CalculationMode.Ticks, StopLoss, false);
      }
      }

      protected override void OnBarUpdate()
      {
      if (BarsInProgress != 0)
      return;

      // Set 1
      if ((TriggerState >= 3)
      && (Position.MarketPosition == MarketPosition.Flat))
      {
      TriggerState = 0;
      }

      if (CurrentBars[0] < 1)
      return;

      // Set 2
      if ((TriggerState == 1)
      && (Position.MarketPosition == MarketPosition.Long))
      {
      TriggerState = 2;
      StopPrice = (Position.AveragePrice + (InitialStopDistance * TickSize)) ;
      TriggerPrice = (Position.AveragePrice + (BreakEvenTrigger * TickSize)) ;
      }

      // Set 3
      if (Position.MarketPosition == MarketPosition.Flat)
      {
      TriggerState = 1;
      EnterLong(Convert.ToInt32(DefaultQuantity), @"entry");
      }

      // Set 4
      if ((TriggerState == 2)
      && (Close[0] >= TriggerPrice))
      {
      TriggerState = 3;
      StopPrice = (Position.AveragePrice + (MoveTicks1BE * TickSize)) ;
      Draw.Diamond(this, @"BreakEvenBuilderExample Diamond_1", true, 0, (High[0] + (2 * TickSize)) , Brushes.DarkCyan);
      }

      // Set 5
      if (TriggerState >= 3)
      {
      ExitLongStopMarket(Convert.ToInt32(DefaultQuantity ), StopPrice, @"exit", @"entry");
      }

      // Set 6
      if ((TriggerState == 3)
      && (Close[0] >= TriggerPrice1))
      {
      TriggerState = 4;
      StopPrice = (Position.AveragePrice + (MoveTicks2BE * TickSize)) ;
      Draw.Diamond(this, @"BreakEvenBuilderExample Diamond_1", true, 0, (High[0] + (2 * TickSize)) , Brushes.DarkCyan);
      }

      }

      Comment

      Latest Posts

      Collapse

      Topics Statistics Last Post
      Started by ghoul, Today, 06:02 PM
      0 responses
      7 views
      0 likes
      Last Post ghoul
      by ghoul
       
      Started by Barry Milan, Yesterday, 10:35 PM
      6 responses
      18 views
      0 likes
      Last Post Barry Milan  
      Started by DanielSanMartin, Yesterday, 02:37 PM
      2 responses
      13 views
      0 likes
      Last Post DanielSanMartin  
      Started by DJ888, 04-16-2024, 06:09 PM
      4 responses
      13 views
      0 likes
      Last Post DJ888
      by DJ888
       
      Started by terofs, Today, 04:18 PM
      0 responses
      12 views
      0 likes
      Last Post terofs
      by terofs
       
      Working...
      X