NT8 Ninjascript. Code to obtain the time and date of an event and display it on chart - futures io
futures io futures trading



NT8 Ninjascript. Code to obtain the time and date of an event and display it on chart


Discussion in NinjaTrader

Updated
    1. trending_up 116 views
    2. thumb_up 0 thanks given
    3. group 2 followers
    1. forum 2 posts
    2. attach_file 0 attachments




Welcome to futures io: the largest futures trading community on the planet, with well over 125,000 members
  • Genuine reviews from real traders, not fake reviews from stealth vendors
  • Quality education from leading professional traders
  • We are a friendly, helpful, and positive community
  • We do not tolerate rude behavior, trolling, or vendors advertising in posts
  • We are here to help, just let us know what you need
You'll need to register in order to view the content of the threads and start contributing to our community.  It's free and simple.

-- Big Mike, Site Administrator

(If you already have an account, login at the top of the page)

 
Search this Thread
 

NT8 Ninjascript. Code to obtain the time and date of an event and display it on chart

(login for full post details)
  #1 (permalink)
Dallas Texas
 
 
Posts: 15 since Feb 2017
Thanks: 7 given, 3 received

Hello

Having as base the NinjaTrader 8 open source indicator Position Display Indicator:
https://ninjatraderecosystem.com/user-app-share-download/position-display-indicator/


I'm making it some customizations to calculate the lower Unrealized Account Balance value that if reached then it means the trading strategy you are using has failed. Lower Unrealized Account Balance value = lower Net Liquidation value.

Now what I need is that if this described event happens, then that the indicator put a mark of this event:
- Displaying in red color the date and exact time (hh:mm:ss) it has happened.
- If possible and for better visual illustration, in addition to the previous, that the indicator also draws a vertical time line in red color showing the moment/bar the event took place.

I need a guide about how to add these 2 features to the indicator.

I need this works either in Live, in Demo, in Simulated or in Playback (Market Replay), so for Live, Demo and Simulated accounts the date and time I need to be displayed is the real-time calendar date and time, as the normal, but about the Playback the thing is different, because what it is needed is the event's date and time of the Market Replay moment, i.e. not the date and time in the computer for these cases.

For example, if today Feb 23, 2021 you are running the Market Replay of Nov 30, 2020 and the failure event happens at 11:05:42 am (on Nov 30, 2020) then I need the indicator displays something similar like:

"The strategy failed to meet the minimum necessary requirements at 11:05:42 am, on Nov 30, 2020"


Note: I have not programming backgraound but some years ago I learned the basis for programming. I started with these modifications some days ago, so as you can imagine I'm in a knowledge refreshing process and I'm noticing that to do any simple action in C# needs almost the double of code than others more simplified programming languages.


Thank you

Reply With Quote

Journal Challenge February 2021 results (so far):
Competing for $1500 in prizes from Topstep
looks_oneSBtrader82 's Trading Journalby SBtrader82
(154 thanks from 29 posts)
looks_twoJust BEING a Trader: Letting Go!!by iqgod
(111 thanks from 32 posts)
looks_3Wisdom is Emptinessby Mtype
(68 thanks from 25 posts)
looks_4Deetee’s DAX Trading Journal (time based)by Deetee
(31 thanks from 16 posts)
looks_5Journal for peanuts1956by peanuts1956
(23 thanks from 13 posts)
 
 
(login for full post details)
  #2 (permalink)
Dallas Texas
 
 
Posts: 15 since Feb 2017
Thanks: 7 given, 3 received

The indicator I mention "Position Display Indicator" draws a textbox in any chart you want showing the information pre-defined, and for this you just need to import and load the indicator as any other indicator. I need to display the failed event notification in this textbox.

to display information any extra iformation I've been using the defeult way the indicator use, for example
 
Code
DrawTextLayout(RenderTarget, ChartPanel, ChartPanel.X + HorizontalOffset, ChartPanel.Y + VerticalOffset, P&Lstring, Font, P&L < 0 ? negativeBrush : positiveBrush);
The situation I'm asking for is not mainly about how to draw the time/date, this will help but is secundary, becuase the main I need to know is how I get the time-and-date when the event happened, to then take that information and display it in screen (a chart).

For example, let's suppose a starting account balance = $1,000.00, and you have the rule that if the account balance < or = $500, either with the account unrealized balance or with the account realized balance, then it means your strategy failed to meet the minimum necessary requirements. So what I need to know is how I can get the time-and-date when the example event happens, i.e. when the account have a net liquidation < or = $500, to then draw this information in the screen, also drawing a reference vertical time line of the event.

I have a basic idea about the needed code for the example described, but seeing how C# works, I'm almost sure it won't be so simplified:


 
Code
...
private double NetLiquidation;
private double FailureLevel = 500;
private DateTime time&date_FailureLevel;  // As NinjaTrader specifies a time/date needs to be setted as 'DateTime'

...

if (NetLiquidation <= FailureLevel)
{
    // Pseudocode:
    time&date_FailureLevel = code_to_get_time_of_the_event;
    // If met the condition, then display the message: "The strategy failed to meet the minimum necessary requirements at   HH:MM:SS a/pm, on Mmm DD, YYYY"
}

else
{
    // If not met the condition, then continue doing everything as normal
}

...

string time&date_FailureLevelstring = time&date_FailureLevel.ToString("N2");

...
DrawTextLayout(RenderTarget, ChartPanel, ChartPanel.X + HorizontalOffset, ChartPanel.Y + VerticalOffset, time&date_FailureLevel, Font, time&date_FailureLevel < 0 ? negativeBrush : positiveBrush);


Finally, as far as I know the Playback runs the Market Replay at 1 second update that for my case is ok because I can obtain the time of the event with 1 second of maximum inaccuracy time distortion, either the Market Replay speed be at 1x or at 100x or at Max speed.

Reply With Quote
 
(login for full post details)
  #3 (permalink)
Urban Samurai
Chicago IL
 
Experience: None
Platform: Ninja, MT4, Matlab
Broker: CQG, AMP, MB, DTN
Trading: E/U, G/U
 
forrestang's Avatar
 
Posts: 1,194 since Jun 2010
Thanks: 290 given, 873 received



futurenow View Post

I need this works either in Live, in Demo, in Simulated or in Playback (Market Replay), so for Live, Demo and Simulated accounts the date and time I need to be displayed is the real-time calendar date and time, as the normal, but about the Playback the thing is different, because what it is needed is the event's date and time of the Market Replay moment, i.e. not the date and time in the computer for these cases.

So I may have a general idea of what you're trying to do here...

But as you want to capture TIME... there are issues with storing and capturing these values.

So... NT does not actually have an object that can be easily referenced that permantly stores the time of LIVE trades taken in real or SIM accounts(as odd as this is). So while you'll always have access to balances, you won't have access to times/dates. Actually, when you go across a session, or when you restart your PC, you will lose access to times of trades taken in live or SIM.

Now... if you run a strategy for example, and are placing trades... you can always STORE those times... but those will only be available for the life cycle of the script, so unless you write that info to a text file, it will be destroyed on a restart of the indicator.

So to recap....

For LIVE/SIM trades taken by a strategy, your access to events are limited. You would have to store those events(date/time), and you would have access to it for the life-cycle of the indicator.

If you want to store that time of strategy taking the trades, and NOT the PC time, that is standard, so no worries there. I.e., when a balance dips below your desire value, you would simply flag that event, and store that date with "Time[0]", and you would have the time that event occurred.

I actually built and indicator for someone else in THIS thread, where he wanted to have his TIME in trade, where I found out about all these pitfalls of attempting to capture times of trades placed.

The posts about that indie are interspersed throughout the thread, but you can start reading from that link, and maybe you can get a sense of what I'm trying to explain here.

This probably isn't the most thorough answer, but maybe it will get the discussion started.

Reply With Quote


futures io Trading Community Platforms and Indicators NinjaTrader > NT8 Ninjascript. Code to obtain the time and date of an event and display it on chart


Last Updated on February 25, 2021


Upcoming Webinars and Events
 

NinjaTrader Indicator Challenge!

Ongoing
 

Journal Challenge w/$1500 prizes from Topstep!

February
 

Identifying Setups & Targets Using Profile Charts w/Trevor & Tradovate

Feb 25
 

Battlestations! Show us your trading desk - $1,500 in prizes!

March
     



Copyright © 2021 by futures io, s.a., Av Ricardo J. Alfaro, Century Tower, Panama, +507 833-9432, info@futures.io
All information is for educational use only and is not investment advice.
There is a substantial risk of loss in trading commodity futures, stocks, options and foreign exchange products. Past performance is not indicative of future results.
no new posts