Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Strategy with Crossing EMA's

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

    Strategy with Crossing EMA's

    Hi,

    I'm trying to develop a strategy using the yellow and blue lines in the attached file. Basically, when the yellow line crosses above the blue line, execute long trades. When crossing down, enter short trades. I guess there are certain times when the yellow line takes awhile to decide if it's going to cross up or down and NT keeps executing and cancelling trades in these spots and loses alot of money. Is there a filter I can add to prevent NT from entering trades during these times? This is trading one contract. Thanks for your help!
    Attached Files

    #2
    Hello alnghiem,

    Thanks for your post.

    A bool could be used to control when trades are made by the strategy. You could create a bool named something like OkToTrade (initially set to false). You would create your order entry condition and set the bool to true. Then you would check if the bool is true and call your entry order method and set the bool to false.

    By doing this, the order entry method will only be called to place an order when the bool is true. When the bool is false, the order entry condition will not be called so the strategy will stop placing trades until the bool becomes true. See the attached example script demonstrating this.

    Ultimately, To understand why the script is behaving as it is, such as placing orders or not placing orders or drawing objects when expected, it is necessary to add prints to the script that print the values used for the logic of the script to understand how the script is evaluating.

    In the strategy add prints (outside of any conditions) that print the values of every variable used in every condition that places an order along with the time of that bar. Prints will appear in the NinjaScript Output window (New > NinjaScript Output window).

    Below is a link to a forum post that demonstrates how to use prints to understand behavior.
    https://ninjatrader.com/support/foru...121#post791121

    Let us know if we may assist further.
    Attached Files
    <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 CarlTrading, 03-31-2026, 09:41 PM
    1 response
    61 views
    0 likes
    Last Post NinjaTrader_ChelseaB  
    Started by CarlTrading, 04-01-2026, 02:41 AM
    0 responses
    32 views
    0 likes
    Last Post CarlTrading  
    Started by CaptainJack, 03-31-2026, 11:44 PM
    0 responses
    44 views
    1 like
    Last Post CaptainJack  
    Started by CarlTrading, 03-30-2026, 11:51 AM
    0 responses
    58 views
    0 likes
    Last Post CarlTrading  
    Started by CarlTrading, 03-30-2026, 11:48 AM
    0 responses
    47 views
    0 likes
    Last Post CarlTrading  
    Working...
    X