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 Geovanny Suaza, 02-11-2026, 06:32 PM
    0 responses
    559 views
    0 likes
    Last Post Geovanny Suaza  
    Started by Geovanny Suaza, 02-11-2026, 05:51 PM
    0 responses
    324 views
    1 like
    Last Post Geovanny Suaza  
    Started by Mindset, 02-09-2026, 11:44 AM
    0 responses
    101 views
    0 likes
    Last Post Mindset
    by Mindset
     
    Started by Geovanny Suaza, 02-02-2026, 12:30 PM
    0 responses
    546 views
    1 like
    Last Post Geovanny Suaza  
    Started by RFrosty, 01-28-2026, 06:49 PM
    0 responses
    547 views
    1 like
    Last Post RFrosty
    by RFrosty
     
    Working...
    X