Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

SetStopLoss/SetProfitTarget in forex

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

    SetStopLoss/SetProfitTarget in forex

    Hi everyone

    I'm trying to set a simple stop loss in a strategy on a spot forex ($EURUSD) chart.

    In Variables, I've put:

    private int stop1 = 20;
    private int target1 = 40;


    In Initialize:

    SetStopLoss("LongStopLoss", CalculationMode.Ticks, Stop1, false);
    SetProfitTarget("LongProfitTarget1", CalculationMode.Ticks, Target1);


    My strategy compiles but it doesn't seem to be working right on the chart.

    I'd be very grateful for an explanation of how to set these properly on a forex chart.

    #2
    Hello arbuthnot,

    Thank you for your post.

    Can you provide further details on what is not occurring?

    I look forward to your response.

    Comment


      #3
      Thanks very much for your reply, Patrick.

      I was convinced there was a syntax error in the code I quoted, but from your reply, I realised this wasn't the case so I looked further for the problem and I'm sure I've found it. I hadn't linked the tags in SetStopLoss and SetProfitTarget with the order entries.

      However, I do have a somewhat related question from the same strategy I'm working on in relation to a breakeven condition..

      Part of my amended code in Initialize is now:

      SetStopLoss("Long1", CalculationMode.Ticks, Stop1, false);
      SetProfitTarget("Long1", CalculationMode.Ticks, Target1);
      SetProfitTarget("Long1", CalculationMode.Ticks, Target2);

      SetStopLoss("Long2", CalculationMode.Ticks, Stop1, false);
      SetProfitTarget("Long2", CalculationMode.Ticks, Target1);
      SetProfitTarget("Long2", CalculationMode.Ticks, Target2);


      In OnBarUpdate:

      if( ...conditions... )

      {
      EnterLong(Quantity1, "Long1");
      EnterLong(Quantity2, "Long2");
      }

      if (
      Position.MarketPosition == MarketPosition.Long
      && Close[0] >= Position.AvgPrice + ProfitTrigger1 * TickSize
      )


      SetStopLoss(CalculationMode.Price, (Position.AvgPrice + BreakEvenPlus1) * TickSize);


      My questions are:

      a) Do the conditions in blue work as a 'breakeven'?

      b) with the strategy entering two profit targets, there's a problem with this breakeven condition applying to both orders. Is there a way of adding a line to the condition so that it applies only to, say, the first order 'tag'? If so, I can repeat these lines with a reference to the other tag.

      If not, would the solution be to set up two strategies, each one referring to separate profit targets?

      I hope I've expressed the situation well.

      Much obliged in advance for your further assistance, Patrick.

      Comment


        #4
        Hello arbuthnot,

        Thank you for your response.

        For A, yes this would effectively be a breakeven.
        For B, you would use the fromEntrySignalName. Below is the syntax you would use:
        Code:
        SetStopLoss(string fromEntrySignal, CalculationMode mode, double value, bool simulated)
        Please let me know if I may be of further assistance.

        Comment

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by Geovanny Suaza, 02-11-2026, 06:32 PM
        0 responses
        601 views
        0 likes
        Last Post Geovanny Suaza  
        Started by Geovanny Suaza, 02-11-2026, 05:51 PM
        0 responses
        347 views
        1 like
        Last Post Geovanny Suaza  
        Started by Mindset, 02-09-2026, 11:44 AM
        0 responses
        103 views
        0 likes
        Last Post Mindset
        by Mindset
         
        Started by Geovanny Suaza, 02-02-2026, 12:30 PM
        0 responses
        559 views
        1 like
        Last Post Geovanny Suaza  
        Started by RFrosty, 01-28-2026, 06:49 PM
        0 responses
        558 views
        1 like
        Last Post RFrosty
        by RFrosty
         
        Working...
        X