Announcement

Collapse

Looking for a User App or Add-On built by the NinjaTrader community?

Visit NinjaTrader EcoSystem and our free User App Share!

Have a question for the NinjaScript developer community? Open a new thread in our NinjaScript File Sharing Discussion Forum!
See more
See less

Partner 728x90

Collapse

Setting Stop at Each Percentage of Open Profit

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

    Setting Stop at Each Percentage of Open Profit

    Hi I am trying to just set a simple profit stop after I have 2% of open profit in a position. The following code works fine for when I have 1% open profit but if I change it to anything over 1% it doesn't work.


    if ((InLong == true)
    && (High[0] > (Position.AveragePrice * 1.01) ))
    {
    ExitLongStopMarket(Convert.ToInt32(DefaultQuantity ), (Position.AveragePrice * 1.0075) , @"1%ProfitProtect", "");
    }



    This doesn't work:


    if ((InLong == true)
    && (High[0] > (Position.AveragePrice * 1.02) ))
    {
    ExitLongStopMarket(Convert.ToInt32(DefaultQuantity ), (Position.AveragePrice * 1.0075) , @"2%ProfitProtect", "");
    }


    Thanks

    #2
    Hello prescottbph,

    Thank you for the post.

    I wanted to check, are you currently using Prints or any other type of way to see the value you are calculating?

    Nothing looks out of place in what you provided, however, the value you are calculating may be the problem. Have you tried using a Print like the following before the condition to see what values it is reporting?

    Code:
    Print("InLong: " + InLong + " High[0]: " + High[0] + " Position.AveragePrice * 1.02: " + (Position.AveragePrice * 1.02));
    
    if ((InLong == true) && (High[0] > (Position.AveragePrice * 1.01) ))
    This would likely be the easiest way to see what is happening here.



    I look forward to being of further assistance.
    JesseNinjaTrader Customer Service

    Comment

    Latest Posts

    Collapse

    Topics Statistics Last Post
    Started by timko, Today, 06:45 AM
    2 responses
    12 views
    0 likes
    Last Post NinjaTrader_ChristopherJ  
    Started by habeebft, Today, 07:27 AM
    0 responses
    4 views
    0 likes
    Last Post habeebft  
    Started by Tim-c, Today, 03:54 AM
    1 response
    7 views
    0 likes
    Last Post NinjaTrader_BrandonH  
    Started by rocketman7, Today, 01:00 AM
    1 response
    10 views
    0 likes
    Last Post NinjaTrader_ChelseaB  
    Started by wzgy0920, 04-23-2024, 09:53 PM
    3 responses
    76 views
    0 likes
    Last Post NinjaTrader_BrandonH  
    Working...
    X