Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

multipe entries and SetStopLoss

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

    multipe entries and SetStopLoss

    I have looked over the SampleScaleOut strategy and it answers some, but not all of my questions.

    I have looked thru these forums extensively to no avail.

    I would like to have two separate entries, each with separate profit targets and stoploss. so in Intialize i declare
    SetStopLoss("Long1", CalculationMode.Ticks, _longStoplossTicks, false);
    SetStopLoss(
    "Long2", CalculationMode.Ticks, _longStoplossTicks, false);
    SetProfitTarget(
    "Long1", CalculationMode.Ticks, _myLProfitTarget);
    SetProfitTarget(
    "Long2", CalculationMode.Ticks, _myLProfitTarget2);

    Then in OnBarUpdate I enter the positions with
    EnterLong(_contracts, "Long1");
    EnterLong(_contracts,
    "Long2");

    Here is where I am stuck
    I need to move the stoploss "Long2", after the Long1 target is hit, to the price that the "Long1" was placed at.
    In other words, I would like to enter both Long1 and Long2 at the same price. When Long1 target is hit, move the stop on Long2 to Breakeven.

    I can do this in OnExecution to get the price for the Long1 entry
    if (execution.Order != null && execution.Order.Name == "Long1")
    MyStopLossLong = execution.Price;

    but may I do this as well in OnExecution?

    SetStopLoss("Long2", CalculationMode.Price, execution.Price, false);

    or does this need to be resubmitted for every tick In OnBarUpdate?






    Last edited by Laserdan; 02-04-2012, 09:48 PM.

    #2
    so i figured out i do need to resubmit it in the OnBarUpdate

    My OnExecute looks like this:
    protectedoverridevoid OnExecution(IExecution execution)
    {
    // Remember to check the underlying IOrder object for null before trying to access its properties
    if (execution.Order != null && execution.Order.Name == "Long2")
    {
    // Print(execution.ToString());
    MyStopLossLong = execution.Price;
    Target2Hit =
    true;
    }
    }

    and then I added in OnBarUpdate this check
    if (Target2Hit)
    {
    SetStopLoss(
    "Long1", CalculationMode.Price, MyStopLossLong, false);
    Print(
    "setting stoploss @ " + MyStopLossLong);
    }

    Now i just need to figure out where to reset the flag...
    Last edited by Laserdan; 02-04-2012, 09:49 PM.

    Comment


      #3
      still struggling.

      How do i determine which order was filled since the entry and the stop and targets all have the same name?
      execution.Order.Name == "Long2"
      isn't this the same for all three orders? entry, stop and target?


      This should be pretty easy, but for some reason I am just not getting it...
      Last edited by Laserdan; 02-04-2012, 09:49 PM.

      Comment


        #4
        GM Laserdan, the Set's dont provider IOrder returns, as such you could not check the fillstates explicitly per default. One option is working with the Exit() methods and the IOrder objects, or to capture the IOrder returns of the Set() methods, for which we have provided a reference sample here -

        Comment


          #5
          Thanks Bertrand. I will relook over the example, again. I will let you know if I am still having issues.

          Comment


            #6
            So if I name my entries:
            EnterLong(_contracts, "Long1");
            EnterLong(_contracts,
            "Long2");

            Are not the stops and targets named as well?

            the output does not reflect this:
            The order name Stop loss stop price is currently 1200.25
            The order name Stop loss stop price is currently 1200.25
            The order name Stop loss stop price is currently 1200.25
            The order name Profit target limit price is currently 1217.75
            The order name Profit target limit price is currently 1217.75
            The order name Profit target limit price is currently 1217.75
            The order name Profit target limit price is currently 1223.25
            The order name Profit target limit price is currently 1223.25
            The order name Profit target limit price is currently 1223.25


            Entry Long1 target is 1223.25 and entry Long2 is 1217.75
            Both share the same stop @ 1200.25

            So how do I distiguish between the two entries? I tried changing this line
            if (order.Name == "Profit target")
            profitTargetOrders.Add(order);

            to order.Name == "Long1"

            but it does not appear to work correctly.

            Comment


              #7
              but using the order propery fromEntrySignal does exactly what i want.

              Thanks for leading me in the correct direction!

              Comment


                #8
                Declare your orders as IOrder objects, so that you can access the properties of the IOrders.

                Comment

                Latest Posts

                Collapse

                Topics Statistics Last Post
                Started by Geovanny Suaza, 02-11-2026, 06:32 PM
                0 responses
                648 views
                0 likes
                Last Post Geovanny Suaza  
                Started by Geovanny Suaza, 02-11-2026, 05:51 PM
                0 responses
                369 views
                1 like
                Last Post Geovanny Suaza  
                Started by Mindset, 02-09-2026, 11:44 AM
                0 responses
                108 views
                0 likes
                Last Post Mindset
                by Mindset
                 
                Started by Geovanny Suaza, 02-02-2026, 12:30 PM
                0 responses
                572 views
                1 like
                Last Post Geovanny Suaza  
                Started by RFrosty, 01-28-2026, 06:49 PM
                0 responses
                573 views
                1 like
                Last Post RFrosty
                by RFrosty
                 
                Working...
                X