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

[code included] simple strategy development assistance

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

    [code included] simple strategy development assistance

    Greetings to all, I hope you are doing well!

    I am not a programmer nor a coder.
    I have tried to read the docs and use the help of ChatGPT 4 and Google Bard but I feel like I am nearing the end of my rope.

    The strategy is simple.

    Take one trade or zero trades per day based on the following conditions:
    eg. utilizing the 5m chart of $NQ
    If price goes above the high of the 17th 5m candle open a long position with a SL/TP of 60 ticks (15 points)
    If price goes below the low of the 17th 5m candle open a short position with a SL/TP of 60 ticks (15 points)
    If price does not go above or below the 17th candle, do nothing for the day.

    I tried using AI, following its instructions or copy pasting its code... but to no avail.
    Here's the link https://chat.openai.com/share/b2b838...6-d8af75d3ca2c

    Thank you for taking the time to take a look at my issue ^_^
    Last edited by deafhorse; 10-21-2023, 01:55 PM.

    #2
    Originally posted by jhkghjk
    ​If price goes above the high of the 17th 5m candle open a long position with a SL/TP of 60 ticks (15 points)
    If price goes below the low of the 17th 5m candle open a short position with a SL/TP of 60 ticks (15 points)
    If price does not go above or below the 17th candle, do nothing for the day.
    I am not sure how to interpret that
    Last edited by deafhorse; 10-21-2023, 04:25 PM.

    Comment


      #3
      A quick update:
      I made the code work, but I'm not sure it executes as I imagined it... and ends up slightly profitable or unprofitable.
      In my mind while executing it live & manually, I would follow a different procedure.

      Comment


        #4
        Hello deafhorse,

        Thanks for your post.

        You could consider creating a class-level int variable, checking if IsFirstBarOfSession is true, and assigning CurrentBar to the int variable. Then, you could create a condition that checks if CurrentBar is equal to the variable + 17 to detect the 17th bar since the open of the session.

        Within the condition that detects the 17th bar of the session, you could save the High[0] price to a double variable and save the Low[0] price to a double variable. Those variables could then be used later in your script for comparisons.

        Next, you could create a condition that checks if Close[0] price is greater than the variable saving the High[0] price of the 17th bar, and call EnterLong() within this condition to place a Long order.

        A condition could be created that checks if the Close[0] price is less than the variable saving the Low[0] price of the 17th bar, and call EnterShort() to within this condition to place a Short order.

        SetProfitTarget() and SetStopLoss() could be defined in OnStateChange() when the State == State.Configure to have the strategy submit a profit target and stop loss order when you enter a position.

        Bool variables could be used to control the logic of your script. For example, you could create a bool variable (initially set to true) in your script. In your conditions to place an order, you could also check if the bool is true. After calling either EnterLong() or EnterShort() you could set the variable to false so no further trades are placed. Then, in your condition that checks if IsFirstBarOfSession you could set the bool back to true to reset it.

        See the help guide documentation below for more information.

        IsFirstBarOfSession: https://ninjatrader.com/support/help...rofsession.htm
        PriceSeries (Close, High, Low, etc): https://ninjatrader.com/support/help...riceseries.htm
        CurrentBar: https://ninjatrader.com/support/help...currentbar.htm
        EnterLong(): https://ninjatrader.com/support/help.../enterlong.htm
        EnterShort(): https://ninjatrader.com/support/help...entershort.htm
        SetProfitTarget(): https://ninjatrader.com/support/help...ofittarget.htm
        SetStopLoss(): https://ninjatrader.com/support/help...etstoploss.htm

        Below is a link to a forum post with helpful information about getting started with NinjaScript.
        https://ninjatrader.com/support/foru...040#post786040
        Brandon H.NinjaTrader Customer Service

        Comment


          #5
          Originally posted by NinjaTrader_BrandonH View Post
          Hello deafhorse,

          Thanks for your post.
          thank you for the reply (taking the time to write all of this!)!

          I'll probably give up on coding the strategy, because the more I looked back on the data (past days and weeks) the more evident it became that this strategy needs discretion.
          I also didn't take into consideration red-folder days etc.

          It needs more analysis, on what kind of market conditions/structure it works best...
          and I need to go by the data manually (charts, news on each specific date etc)
          maybe I'll find a more efficient way to gather the data
          Attached Files
          Last edited by deafhorse; 10-22-2023, 04:18 PM.

          Comment

          Latest Posts

          Collapse

          Topics Statistics Last Post
          Started by burtoninlondon, Today, 12:38 AM
          0 responses
          10 views
          0 likes
          Last Post burtoninlondon  
          Started by AaronKoRn, Yesterday, 09:49 PM
          0 responses
          14 views
          0 likes
          Last Post AaronKoRn  
          Started by carnitron, Yesterday, 08:42 PM
          0 responses
          11 views
          0 likes
          Last Post carnitron  
          Started by strategist007, Yesterday, 07:51 PM
          0 responses
          14 views
          0 likes
          Last Post strategist007  
          Started by StockTrader88, 03-06-2021, 08:58 AM
          44 responses
          3,983 views
          3 likes
          Last Post jhudas88  
          Working...
          X