Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

GetUnrealizedProfitLoss Issue

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

    GetUnrealizedProfitLoss Issue

    Hi Everyone,

    I'm having some issue with using the below for getting the unrealized profit/loss. I'm using the below code, but for some reason, it decides not to obey the target all the time. It will work correctly for a number of trades, then just decide to go for something like 10x my target. Not sure what I'm doing or if there are some ideas of what I can look at.

    if (Position.MarketPosition == MarketPosition.Long && (Position.GetUnrealizedProfitLoss(PerformanceUnit. Percent, Close[0])) >= PercentGain/100)
    {
    ExitLong("Exit Profit Target", "Long Position");
    Draw.ArrowDown(this, "Exit Long Profit Target" + CurrentBar, false, 0, High[0] - 4*TickSize, Brushes.Red);
    Print("EXIT LONG PROFIT TARGET " + " " + Time[0].Date);
    Print(Position.GetUnrealizedProfitLoss(Performance Unit.Percent, Close[0]) + " Unrealized Profit " + Time[0].Date);
    }


    I have all my entries using Position.MarketPosition == MarketPosition.Flat as a requirement before entry. I'm also using SetProfitTarget("Long Position", CalculationMode.Percent, PercentGain/100, true) as a check on this, but I have them set conditionally using a bool to where only one or the other can be utilized during the strategy. And I have a Stop Loss enabled using SetStopLoss.

    Any help or recommendations would be appreciated.

    Thanks,
    Ray





    #2
    I think the best thing for you to do to figure out why it's not working out consistently would be to add prints to make sure the values you are using are being assigned properly/as you intend them. For example, does PercentageGain/100 give you number you expect it to? Does Position.GetUnrealizedProfitLoss(PerformanceUnit. Percent, Close[0]))?

    Comment


      #3
      Hi Rockmanx00,

      I have added the prints and looked at the results. The results as far as the numbers look correct. The issue I'm having is that its just not triggering at the specified %. So if there is no trigger, then I'm not sure how I can determine the problem as there is no output. But I can clearly see in the Print results the Target (PercentGain/100) set at 1% and the Unrealized Profit at just over 1% once it triggers for certain ones. For others, I can see the target at 1% and exit at 1.0565% for example. So it seems to work for some, but just not triggering for others.

      Ray

      Comment


        #4
        It may be a lot of prints, depending on how you loop it, but I would print each of the conditions: Position.MarketPosition, Position.GetUnrealizedProfitLoss(PerformanceUnit. Percent, Close[0] & PercentGain/100 BEFORE the if statement, maybe include a timestamp. Then you can evaluate all the conditions and make sure they are matching and supposed to cause what's in the if statement to trigger. Do you have a timestamp when it exits? Is it perhaps exiting because it's the end of day?

        Comment

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by NullPointStrategies, Today, 05:17 AM
        0 responses
        41 views
        0 likes
        Last Post NullPointStrategies  
        Started by argusthome, 03-08-2026, 10:06 AM
        0 responses
        124 views
        0 likes
        Last Post argusthome  
        Started by NabilKhattabi, 03-06-2026, 11:18 AM
        0 responses
        64 views
        0 likes
        Last Post NabilKhattabi  
        Started by Deep42, 03-06-2026, 12:28 AM
        0 responses
        41 views
        0 likes
        Last Post Deep42
        by Deep42
         
        Started by TheRealMorford, 03-05-2026, 06:15 PM
        0 responses
        46 views
        0 likes
        Last Post TheRealMorford  
        Working...
        X