Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Add a button to chart trader and validate if there are open positions

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

    Add a button to chart trader and validate if there are open positions

    I have an indicator that paints the candles that meet parameters already established in the code and also passes the entry price to a variable. I have two queries.
    1.- I need to validate if there are running positions so that I stop painting them until the position is closed
    2.- I need to add a button to chart trader that, when clicked, enters a limit or stop order depending on where the current price is at that moment with respect to the variable with the entry price that the indicator code gives me.

    I understand that input cannot be validated or entered from an indicator. Is this correct?

    Would I have to develop a strategy to achieve the aforementioned?

    Greetings and thank you very much.​

    #2
    Hello villarroel0401,

    Thanks for your post.

    To check if there are open positions on an account, you could use the Account class Positions collection.

    See this help guide page about the Account class: https://ninjatrader.com/support/help...ount_class.htm

    See this help guide about the Account.Positions collection: https://ninjatrader.com/support/help...ns_account.htm

    The <Account>.CreateOrder() method could be used to create an order. The <Account>.Submit() method would be used to submit the created order.

    Below are the help guide documentation for <Account>.CreateOrder() and <Account>.Submit().

    <Account>.CreateOrder(): https://ninjatrader.com/support/help...reateorder.htm
    <Account>.Submit(): https://ninjatrader.com/support/help...nt8/submit.htm

    To add a button to Chart Trader, you would need to implement C# WPF modifications into your indicator.

    The reference sample linked below details adding buttons to Chart Trader using WPF Modifications.

    SampleWPFModifications: https://ninjatrader.com/support/help...ui)-modifi.htm
    <span class="name">Brandon H.</span><span class="title">NinjaTrader Customer Service</span><iframe name="sig" id="sigFrame" src="/support/forum/core/clientscript/Signature/signature.php" frameborder="0" border="0" cellspacing="0" style="border-style: none;width: 100%; height: 120px;"></iframe>

    Comment


      #3
      Good day

      It was difficult for me to validate open positions and send orders to the market from an indicator, so I had to move all the code to a strategy, from there I created the button and I achieved my goal of validating and sending orders to the market, everything perfect. (Attached Capture)

      Now please guide me how to change the color of the bullish and bearish candles in general, I currently use BarBrush to paint the candles that meet a series of parameters, but I need to paint all of them in a single color to be able to distinguish the ones that give me the parameters defined in the code.

      Greetings and thanks​​
      Attached Files

      Comment


        #4
        Hello villarroel0401,

        Thanks for your notes.

        BarBrush or BarBrushes could be used to change the color of the candle on a chart to a specific color.

        You could create if else-if else conditions to check if conditions happen and change the BarBrush color when those conditions are true else color the BarBrush a specific color.

        For example, the code might look something like this:

        if (Close[0] > Close[1])
        {
        BarBrush = Brushes.Blue;
        }
        else if (Open[0] > Open[1])
        {
        BarBrush = Brushes.Pink;
        }
        else
        BarBrush = Brushes.Yellow;



        See this help guide page for information about BarBrush and sample code: https://ninjatrader.com/support/help...arbrush​
        <span class="name">Brandon H.</span><span class="title">NinjaTrader Customer Service</span><iframe name="sig" id="sigFrame" src="/support/forum/core/clientscript/Signature/signature.php" frameborder="0" border="0" cellspacing="0" style="border-style: none;width: 100%; height: 120px;"></iframe>

        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