Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Using prior profit to signal whether to do the next trade.

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

    Using prior profit to signal whether to do the next trade.

    I want to calculate the profit I have a signal to buy when the stock goes above a moving average, and selling when it goes below the moving average. Once I have that profit calculation I use the calculation as a signal to buy or sell on the next bar. So, the next step would be to sell when the stock dips below the moving average, but only if the trade before this one made X% of profit. I don't know how to program the first calculation because we have no idea if the stock will be above the moving average for 1 bar or 50 bars.

    #2
    Hello Kevinled,

    Thank you for your post.

    Can you please clarify - what specifically is the "first calculation" you are referring to?

    You mentioned you want to calculate profit but not how you want to calculate the profit.

    Are you trying to identify when the price crosses above or below a moving average?

    Comment


      #3
      First calculation: Buy when the stock is over the moving average. So, the stock is $10 when it goes about the moving average & is $11 when it goes back below the moving average, so the profit is 10%.

      Next calculation: sell when the stock goes below the moving average, but only if the prior calculation gave you a result of 5% or more.

      So, in this case we would place the short trade, but if the stock had only gone up 4% we would not place the second trade.

      Comment


        #4
        Hello Kevinled,

        You can track when the price crosses above or below the moving average using CrossAbove and CrossBelow.





        When you detect a cross above event has occurred, use a double variable to save the current price. When you detect a cross above event has occurred, compare your saved price to the current price. Then you can calculate how much larger the new price is in comparison to the saved price.

        Please let us know if you need further assistance.

        Comment

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by Geovanny Suaza, 02-11-2026, 06:32 PM
        0 responses
        647 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