Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

can someone help me . i want the entry on 20 ticks pullback from the close of candle

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

    can someone help me . i want the entry on 20 ticks pullback from the close of candle

    can someone help me i have try it with chatgpt but dont work .

    i want the entry on a pullback of 20 ticks from the closed candle

    Attached Files

    #2
    Hello nadire.adiki60,

    Thanks for your post.

    To clarify, you are wanting to submit a buy order when the current market price is 20 ticks below the previous close price. Is that correct?

    If so, you could create a condition that checks if the current market price (Close[0]) is Less than or Equal to the previous Close price (Close[1]) offset by 20 ticks. Then, call your EnterLong() method within that condition to place the order.

    The code for this might look something like this.

    if (Close[0] <= Close[1] - 20 * TickSize)
    {
    EnterLong();
    }


    See the help guide documentation below for more information and sample code.

    Close: https://ninjatrader.com/support/help.../nt8/close.htm
    TickSize: https://ninjatrader.com/support/help...8/ticksize.htm

    The best way to begin learning NinjaScript is to use the Strategy Builder. With the Strategy Builder, you can set up conditions and variables and then see the generated code in the NinjaScript Editor by clicking the View Code button.

    Here is a link to our publicly available training videos, 'Strategy Builder 301' and 'NinjaScript Editor 401', for you to view at your own convenience.

    Strategy Builder 301 — https://www.youtube.com/watch?v=_KQF2Sv27oE&t=13s

    NinjaScript Editor 401 - https://youtu.be/H7aDpWoWUQs?list=PL...We0Nf&index=14

    I am also linking you to the Educational Resources section of the Help Guide to help you get started with NinjaScript:
    https://ninjatrader.com/support/help..._resources.htm

    If you are new to C#, to get a basic foundation for the concepts and syntax used in NinjaScript I would recommend this section of articles in our help guide first:
    https://ninjatrader.com/support/help...g_concepts.htm

    And the MSDN (Microsft Developers Network) C# Language Reference.
    https://ninjatrader.com/support/help...erence_wip.htm

    Note that ChatGPT is not supported for creating custom NinjaScripts. The resources above could be used to learn how to create your own custom NinjaScript strategies.

    Let me know if I may assist further.
    <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
      i have now this . but something is wrong and i dont know what . he only take shorts. and if he must take longs he take also shorts.

      and pullback dont work.

      anybody know how to solve this issue ??
      Attached Files

      Comment


        #4
        Hello nadire.sadiki60,

        Thanks for your note.

        I see in the code you shared that you do not have any Using declarations in your script. You would need to add Using declarations in your script. In addition to this, I see you are missing the 'namespace NinjaTrader.NinjaScript.Strategies' in your code as well which wraps around all other code in the script.

        Open a New > Strategy Builder window and click the 'View code' button to see how the Using declarations should be added to the strategy as well as how the namespace should be added to the script.

        The 'private bool enableReversalTrade' should be added to the section of code containing the other class-level variables in the script, not between OnStateChange() and OnBarUpdate()

        You could remove the base.OnStateChange() call and base.OnBarUpdate() call from your script as these are not needed.

        All user-defined Properties could be created at the end of the script after OnBarUpdate(). See the SampleMACrossOver strategy that comes with NinjaTrader for how these properties are added to the script. To view the script, open a New > NinjaScript Editor window, open the Strategies folder, and double-click on the SampleMACrossOver file.

        To check what your current strategy position is, you would need to create a condition that checks if Position.MarketPosition == MarketPosition.Long or Position.MarketPosition == MarketPosition.Short instead of using your 'PositionType' enum.

        View this help guide page about using Position.MarketPosition in a NinjaScript strategy to check what the current strategy position is: https://ninjatrader.com/support/help...etposition.htm

        Set methods (SetProfitTarget/SetStopLoss) should be called before the Entry order method since the Set methods prep NinjaTrader to submit protective orders for the Entry order. For example:

        SetStopLoss(CalculationMode.Ticks, StopLossTicks);
        SetProfitTarget(CalculationMode.Ticks, TargetTicks);

        EnterLong();

        When using Set methods in OnBarUpdate(), you should always reset the stop loss price/offset value when your strategy is flat otherwise, the last price/offset value set will be used to generate your stop loss order on your next open position This is noted in the Set method help guide documentation.

        See the help guide pages below for information about using Set methods.

        SetStopLoss(): https://ninjatrader.com/support/help...etstoploss.htm
        SetProfitTarget(): https://ninjatrader.com/support/help...ofittarget.htm

        Ultimately, if the strategy is not behaving as expected, such as placing trades or not placing trades, debugging prints need to be added to the script that prints out each value in conditions being used to place orders along with the time of the bar.

        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​​

        Note that it is not suggested that you use ChatGPT to create the script as this causes necessary NinjaScript code to be left out of the script most of the time.

        Let me know if I may assist further.
        <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 NullPointStrategies, Yesterday, 05:17 AM
        0 responses
        64 views
        0 likes
        Last Post NullPointStrategies  
        Started by argusthome, 03-08-2026, 10:06 AM
        0 responses
        139 views
        0 likes
        Last Post argusthome  
        Started by NabilKhattabi, 03-06-2026, 11:18 AM
        0 responses
        75 views
        0 likes
        Last Post NabilKhattabi  
        Started by Deep42, 03-06-2026, 12:28 AM
        0 responses
        45 views
        0 likes
        Last Post Deep42
        by Deep42
         
        Started by TheRealMorford, 03-05-2026, 06:15 PM
        0 responses
        50 views
        0 likes
        Last Post TheRealMorford  
        Working...
        X