Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Help moving Stops to BE+-5 in Strategy

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

    Help moving Stops to BE+-5 in Strategy

    My wizard code is below. Set 3 and 4 is the issue I have yet to unlock it but I will if need be. I am trying to have the stop move to breakeven +-5 once I have >= or <=14 ticks. I tested this Long in simulator data and it did nothing and it's late so I'm looking for help.

    Thanks lots guys.
    HTML Code:
    #region Variables
    // Wizard generated variables
    private int hMAperiod = 21; // Default setting for HMAperiod
    private int stoploss1 = 20; // Default setting for Stoploss1
    private int profitraget3 = 20; // Default setting for Profitraget3
    private int profitraget1 = 7; // Default setting for Profitraget1
    private int profitraget2 = 15; // Default setting for Profitraget2
    private int positionsize1 = 3; // Default setting for Positionsize1
    private int positionsize2 = 2; // Default setting for Positionsize2
    private int positionsize3 = 1; // Default setting for Positionsize3
    // User defined variables (add any user defined variables below)
    #endregion
    /// <summary>
    /// This method is used to configure the strategy and is called once before any strategy method is called.
    /// </summary>
    protected override void Initialize()
    {
    Add(RCHMASlope(21));
    SetProfitTarget("Enter at market1", CalculationMode.Ticks, Profitraget1);
    SetProfitTarget("Enter at market2", CalculationMode.Ticks, Profitraget2);
    SetStopLoss("Enter at market1", CalculationMode.Ticks, Stoploss1, false);
    SetStopLoss("Enter at market2", CalculationMode.Ticks, Stoploss1, false);
    SetStopLoss("Enter at market3", CalculationMode.Ticks, Stoploss1, false);
    SetProfitTarget("Enter at market3", CalculationMode.Ticks, Profitraget3);
    CalculateOnBarClose = false;
    }
    /// <summary>
    /// Called on each bar update event (incoming tick)
    /// </summary>
    protected override void OnBarUpdate()
    {
    // Condition set 1
    if (CrossAbove(RCHMASlope(21).HMAslope, 0, 1))
    {
    DrawArrowUp("My up arrow" + CurrentBar, false, 0, Low[0] + -1 * TickSize, Color.Lime);
    EnterLongLimit(Positionsize1, GetCurrentAsk(), "Enter at market1");
    EnterLongLimit(Positionsize2, GetCurrentAsk(), "Enter at market2");
    EnterLongLimit(Positionsize3, GetCurrentAsk(), "Enter at market3");
    }
    // Condition set 2
    if (CrossBelow(RCHMASlope(21).HMAslope, 0, 1))
    {
    DrawArrowDown("My down arrow" + CurrentBar, false, 0, High[0] + 1 * TickSize, Color.Red);
    EnterShortLimit(Positionsize1, GetCurrentBid(), "Enter at market1");
    EnterShortLimit(Positionsize2, GetCurrentBid(), "Enter at market2");
    EnterShortLimit(Positionsize3, GetCurrentBid(), "Enter at market3");
    }
    // Condition set 3
    if (Close[0] >= Position.AvgPrice + 14 * TickSize)
    {
    ExitLongStop(Position.AvgPrice + 5 * TickSize, "Breakeven+5 Stop", "Enter at market3");
    }
    // Condition set 4
    if (Close[0] <= Position.AvgPrice + -14 * TickSize)
    {
    ExitShortStop(Position.AvgPrice + -5 * TickSize, "Breakeven-5 Stop", "Enter at market3");
    }
    }

    #2
    blash, you would need to unlock the code and add TraceOrders = true in your Initialize() to debug further, you're likely running into the Internal Order Handling Rules here as there's a Set() method working and you try to submit an additional exit stoploss order here.

    BertrandNinjaTrader Customer Service

    Comment

    Latest Posts

    Collapse

    Topics Statistics Last Post
    Started by tkaboris, Today, 05:13 PM
    0 responses
    2 views
    0 likes
    Last Post tkaboris  
    Started by GussJ, 03-04-2020, 03:11 PM
    16 responses
    3,281 views
    0 likes
    Last Post Leafcutter  
    Started by WHICKED, Today, 12:45 PM
    2 responses
    19 views
    0 likes
    Last Post WHICKED
    by WHICKED
     
    Started by Tim-c, Today, 02:10 PM
    1 response
    10 views
    0 likes
    Last Post NinjaTrader_ChelseaB  
    Started by Taddypole, Today, 02:47 PM
    0 responses
    5 views
    0 likes
    Last Post Taddypole  
    Working...
    X