Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

set profit...set stoploss

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

    set profit...set stoploss

    can't seem to get the "set profit and stop" to work


    [Description(
    "Enter the description of your strategy here")]
    publicclass forex : Strategy
    {
    #region Variables
    // Wizard generated variables
    privateint length = 10; // Default setting for Length
    privatedouble multiplier = 10; // Default setting for Multiplier
    // 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>
    protectedoverridevoid Initialize()
    {
    SetProfitTarget(
    "10000", CalculationMode.Ticks, 0);
    SetStopLoss(
    "10000", CalculationMode.Ticks, 0, false);
    CalculateOnBarClose =
    true;
    }
    ///<summary>
    /// Called on each bar update event (incoming tick)
    ///</summary>
    protectedoverridevoid OnBarUpdate()
    {
    // Condition set 1
    if (CrossAbove(Close, SuperTrend(Length, Multiplier).UpTrend, 1))
    {
    EnterLong(DefaultQuantity,
    "");
    }
    // Condition set 2
    if (CrossBelow(Close, SuperTrend(Length, Multiplier).DownTrend, 1))
    {
    EnterShort(DefaultQuantity,
    "");
    }

    #2
    Hi duck_CA, they both won't work, because they are looking for the wrong entry order name to exit from and also they are set to 0.

    Please use this code snippet below - where the 30 is your Stop / Target value.

    Code:
    SetProfitTarget([SIZE=2][COLOR=#800000]""[/COLOR][/SIZE][SIZE=2], CalculationMode.Ticks, 30[/SIZE][SIZE=2]);
    SetStopLoss([/SIZE][SIZE=2][COLOR=#800000]""[/COLOR][/SIZE][SIZE=2], CalculationMode.Ticks, 30[/SIZE][SIZE=2], [/SIZE][SIZE=2][COLOR=#0000ff]false[/COLOR][/SIZE][SIZE=2]);[/SIZE]
    [SIZE=2][/SIZE]

    Comment

    Latest Posts

    Collapse

    Topics Statistics Last Post
    Started by cmoran13, Yesterday, 01:02 PM
    0 responses
    29 views
    0 likes
    Last Post cmoran13  
    Started by PaulMohn, 04-10-2026, 11:11 AM
    0 responses
    21 views
    0 likes
    Last Post PaulMohn  
    Started by CarlTrading, 03-31-2026, 09:41 PM
    1 response
    160 views
    1 like
    Last Post NinjaTrader_ChelseaB  
    Started by CarlTrading, 04-01-2026, 02:41 AM
    0 responses
    95 views
    1 like
    Last Post CarlTrading  
    Started by CaptainJack, 03-31-2026, 11:44 PM
    0 responses
    148 views
    2 likes
    Last Post CaptainJack  
    Working...
    X