Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

My First Indicator Update

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

    My First Indicator Update

    This post updates the post now closed by support at http://ninjatrader.com/support/forum...EastLondonKiwi

    Ok first of all a big thank you to Paul from the Ninja support team, he has replied to about 40 emails I sent him on this subject, and his guidance is greatly appreciated.

    As a summary what I was doing and why is this. I am very new to coding c sharp, and Ninja Script. So I wanted to start dipping my toe into the scripting arena by writing a simple indictor that achieved some basic goals, and set up a base of knowledge I will use to build on with more complex exercises I want to build.

    The basic premise of this indicator is as an example of a 2 target trade setup. I am using 4 lines to represent each of the 4 orders (and entry at market, a limit as target1, a second limit as target2, and finally a stop limit). I have hard coded the line colours, but feel free to down load the code and try and code in the line colours to the properties so the User can change the line colours when the indicator is loaded. That said I strong recommend you try this exercise from scratch.

    The next objective was to identify as price crossed each of the 4 lines. and then cause specific actions to happen. This is represented in this indicator by the dots which are drawn. The Pink dot appears as a marker for the stop placement. As price moves past the target1 line, the pink dot is removed and a new blue dot appears at the entry line, representing a breakeven setup. Once price moves to the Target2 line the blue dot is removed and a new orange dot appears at the target1 line, representing a trailing stop.

    If prices crosses the stop line all other dots currently on the chart are removed, and a new red dot is drawn at the stop line representing the trade being stopped out.

    Why not leave the previous dot on the chart you may ask. The answer to that is I wanted in this exercise to make sure the bar that is moving the dot is only ever the most recent bar. Eventually I will code a custom ATM for my own trade plans. and I did not want to ever have the circumstance, historic bars could cause an automatic stop manager to place a stop order in an unintended position at an unintended time.

    However if you want all the previous dots on the chart, there is scope for you to edit the code for that purpose.

    Attached is the code as it currently stands. download it if you want to start from a basic framework.

    I learnt a lot by starting from scratch, but I also got stuck a lot, I found the Ninja Trader help guide useful but not always intuitive enough for a beginner like me to find the syntax I needed, as a result Paul at ninja support as fielded a number of emails and giving me the required guidance to find the solutions to problems I just could not find answers to.

    My hope is as I get better my reliance on such help will diminish.

    Could this code be improved. without doubt and I suggest you have a go, and post any additions or improvements here for others to enjoy.

    I have heavily commented the code some it is easy for a novice to work out what any block of code is doing.

    I have also (to Pauls dismay) used a lot of methods outside of the main OnBarUpdate method. The reason I did this was two fold, I wanted to isolate specific actions into blocks of code. So when trouble shooting it was obvious which section I needed to focus on (Paul also suggested print statements which I have now also started using and found very helpful). The second reason to create lots of method blocks, is that a lot of these actions are useful in their own right, and I wanted a clear block of code I can copy into new projects without having to make sure I am leaving out lines that relate to other actions. Paul's personal preference appears to be to have a lot more of the code within the OnBarUpdate. As I become more experience I may revert to this position, but for now I am using a lot of methods.

    What are the next steps for me. So my next challenge with this code is to have the indicator placed on the chart. And then allow the User to draw the 4 lines with the drawing tool. then and only then have the dots appear as they do now.

    after that I am going to have a go at printing messages to the screen. setting of alerts and starting to move across into n actual ATM strategy I will use on some of my pattern trade set ups.

    I hope you enjoy this code and find new and interesting ways to use it.

    Take care

    Duncan
    Attached Files

    #2
    If I may comment.

    Your more modular method of writing code is the exact idea behind OOP. It is by far the better way to write OOP code. If anything, I, too often, put too much of my code directly into the OnBarUpdate() method, often to my later chagrin, thus causing me to refactor the code into a more modular structure.

    Stick with the modularity!

    Comment

    Latest Posts

    Collapse

    Topics Statistics Last Post
    Started by asd32, Today, 11:45 AM
    2 responses
    15 views
    0 likes
    Last Post asd32
    by asd32
     
    Started by GonzaloTradingSystems, Today, 05:30 AM
    1 response
    19 views
    0 likes
    Last Post GonzaloTradingSystems  
    Started by styvenrutchell, Today, 12:42 PM
    0 responses
    5 views
    0 likes
    Last Post styvenrutchell  
    Started by tkaboris, Today, 11:09 AM
    1 response
    7 views
    0 likes
    Last Post NinjaTrader_Jesse  
    Started by marco231, 03-20-2024, 03:56 PM
    5 responses
    159 views
    0 likes
    Last Post bnoisette  
    Working...
    X