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 SalmaTrader, 07-07-2026, 10:26 PM
    0 responses
    47 views
    0 likes
    Last Post SalmaTrader  
    Started by CarlTrading, 07-05-2026, 01:16 PM
    0 responses
    22 views
    0 likes
    Last Post CarlTrading  
    Started by CaptainJack, 06-17-2026, 10:32 AM
    0 responses
    15 views
    0 likes
    Last Post CaptainJack  
    Started by kinfxhk, 06-17-2026, 04:15 AM
    0 responses
    21 views
    0 likes
    Last Post kinfxhk
    by kinfxhk
     
    Started by kinfxhk, 06-17-2026, 04:06 AM
    0 responses
    23 views
    0 likes
    Last Post kinfxhk
    by kinfxhk
     
    Working...
    X