Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Hedging Profit Target

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

    Hedging Profit Target

    I am designing a simple hedging strategy but I am having trouble creating the exit strategy.


    Under the initialize shows the Data Series added


    protected override void Initialize()
    {

    CalculateOnBarClose = true;

    EntriesPerDirection = 1;
    EntryHandling = EntryHandling.AllEntries;

    Add("M6E 09-14", PeriodType.Minute, 5);
    Add("M6B 09-14", PeriodType.Day, 1);
    Add("M6B 09-14", PeriodType.Minute, 5);
    Add(PeriodType.Minute, 1);


    }


    My exit strategy attempts are shown below. What I am trying to do is when the cumulative value of my positions between the instruments used (accounting for position size) is greater than a target value then close both positions. Thanks.




    if (BarsInProgress == 0
    && ((((Positions[3].AvgPrice - Closes[3][0]) * Positions[3].Quantity * TickSize) + ((Closes[1][0] - Positions[1].AvgPrice) * Positions[1].Quantity * TickSize)) > 5
    || Positions[1].MarketPosition == MarketPosition.Flat)
    )

    {

    ExitLong("PoundLong");

    }


    if (BarsInProgress == 1

    && ((((Positions[3].AvgPrice - Closes[3][0]) * Positions[3].Quantity * TickSize) + ((Closes[1][0] - Positions[1].AvgPrice) * Positions[1].Quantity * TickSize)) > 5
    || Positions[3].MarketPosition == MarketPosition.Flat)
    )

    {

    ExitShort("EuroShort");
    }

    #2
    I have made some changes to the exits, it now includes contract multipliers. Please refer to the image. I don't understand what is happening here, almost all exit names are "exit on close", the chart shows that almost all trades exit on close, yet the exit time on the trades table says otherwise (note I am in Mountain Time). Going by what is displayed on the chart my exits strategy is apparently ignored as the spread between the instruments at the end of the session well exceed the script.



    if (BarsInProgress == 0
    && (((Closes[1][0] - Positions[1].AvgPrice) * Positions[1].Quantity / TickSize * 1.25) + ((Positions[3].AvgPrice - Closes[3][0]) * Positions[3].Quantity / TickSize * 0.625)) > 10
    && (((Closes[1][0] - Positions[1].AvgPrice) * Positions[1].Quantity / TickSize * 1.25) + ((Positions[3].AvgPrice - Closes[3][0]) * Positions[3].Quantity / TickSize * 0.625)) < 20
    //|| Positions[1].MarketPosition == MarketPosition.Flat
    || Positions[1].Quantity == 0
    )

    {
    ExitShort("PoundShort");
    }






    if (BarsInProgress == 1

    && (((Closes[1][0] - Positions[1].AvgPrice) * Positions[1].Quantity / TickSize * 1.25) + ((Positions[3].AvgPrice - Closes[3][0]) * Positions[3].Quantity / TickSize * 0.625)) > 10
    && (((Closes[1][0] - Positions[1].AvgPrice) * Positions[1].Quantity / TickSize * 1.25) + ((Positions[3].AvgPrice - Closes[3][0]) * Positions[3].Quantity / TickSize * 0.625)) < 20
    //|| Positions[3].MarketPosition == MarketPosition.Flat
    || Positions[3].Quantity == 0
    )

    {
    ExitLong("EuroLong");
    }


    }
    Attached Files

    Comment


      #3
      in the script where it says "<20", I have corrected this to <-20. Still I get the same results

      Comment


        #4
        Sorry about all the updates. For the most part I got it working now, I caught my mistake. The code for the exits is shown below. however the condition to exit when MarketPosition.Flat at times can be delayed by numerous bars, even though the other positions are flat. Any idea what may cause this.



        if (BarsInProgress == 0
        && ((((Closes[1][0] - Positions[1].AvgPrice) * Positions[1].Quantity / TickSize * 1.25) + ((Positions[3].AvgPrice - Closes[3][0]) * Positions[3].Quantity / TickSize * 0.625)) > 20
        || (((Closes[1][0] - Positions[1].AvgPrice) * Positions[1].Quantity / TickSize * 1.25) + ((Positions[3].AvgPrice - Closes[3][0]) * Positions[3].Quantity / TickSize * 0.625)) < -10)
        || Positions[1].MarketPosition == MarketPosition.Flat
        //|| Positions[1].Quantity == 0
        )

        {
        ExitShort("PoundShort");
        }


        if (BarsInProgress == 1

        && ((((Closes[1][0] - Positions[1].AvgPrice) * Positions[1].Quantity / TickSize * 1.25) + ((Positions[3].AvgPrice - Closes[3][0]) * Positions[3].Quantity / TickSize * 0.625)) > 20
        || (((Closes[1][0] - Positions[1].AvgPrice) * Positions[1].Quantity / TickSize * 1.25) + ((Positions[3].AvgPrice - Closes[3][0]) * Positions[3].Quantity / TickSize * 0.625)) < -10)
        || Positions[3].MarketPosition == MarketPosition.Flat
        //|| Positions[3].Quantity == 0
        )

        {
        ExitLong("EuroLong");
        }

        Comment


          #5
          Hello Chris001,

          Thank you for your post.

          What are the bar series/instruments for each barsInProgress Index? i.e. 0, 1, 2, and 3

          Comment

          Latest Posts

          Collapse

          Topics Statistics Last Post
          Started by Geovanny Suaza, 02-11-2026, 06:32 PM
          0 responses
          630 views
          0 likes
          Last Post Geovanny Suaza  
          Started by Geovanny Suaza, 02-11-2026, 05:51 PM
          0 responses
          364 views
          1 like
          Last Post Geovanny Suaza  
          Started by Mindset, 02-09-2026, 11:44 AM
          0 responses
          105 views
          0 likes
          Last Post Mindset
          by Mindset
           
          Started by Geovanny Suaza, 02-02-2026, 12:30 PM
          0 responses
          566 views
          1 like
          Last Post Geovanny Suaza  
          Started by RFrosty, 01-28-2026, 06:49 PM
          0 responses
          568 views
          1 like
          Last Post RFrosty
          by RFrosty
           
          Working...
          X