NexusFi: Find Your Edge


Home Menu

 





Need to code - Ninjatrader/C++


Discussion in NinjaTrader

Updated
      Top Posters
    1. looks_one nemeis45 with 9 posts (2 thanks)
    2. looks_two Tasker_182 with 3 posts (4 thanks)
    3. looks_3 wldman with 3 posts (0 thanks)
    4. looks_4 Quick Summary with 1 posts (0 thanks)
      Best Posters
    1. looks_one Tasker_182 with 1.3 thanks per post
    2. looks_two yosef with 1 thanks per post
    3. looks_3 larosacristian with 1 thanks per post
    4. looks_4 nemeis45 with 0.2 thanks per post
    1. trending_up 7,259 views
    2. thumb_up 8 thanks given
    3. group 5 followers
    1. forum 17 posts
    2. attach_file 0 attachments




 
Search this Thread

Need to code - Ninjatrader/C++

  #11 (permalink)
 
Tasker_182's Avatar
 Tasker_182 
Cedar Rapids, iowa
Legendary Market Wizard
 
Experience: Intermediate
Platform: Ninjatrader
Broker: Ninjatrader - Continuum
Posts: 716 since Aug 2009
Thanks Given: 476
Thanks Received: 1,401


nemeis45 View Post
Thanks Tasker,
I went through the help file

The Dll will be very helpful for order execution.

Ninjascript based on C#, which i can used to code.

However there are a couple of questions.

I can set bar period to tick - this will provide me the data for every print?
No it doesnt seem to work that way.
it provides me data for every change in tick i guess.

All i need is price and volume data for every print , along with bid/ask , basically tick data.
and put them into variables, which i can then process.

Eg. i have a live data feed from which i might want to do this, or stored historical data from NT

I dont need to use tick bars or time bars, also the strategy doesnt use charts but price action, which is why i need only this data.

From what i read, i think itll be hard if not impossible to do it in Ninjascript.
i would rather code it in C# then use the dll for order execution?


If you are familiar with C# and if you read the NinjaTrader help manual, already, then you would have observed the methods to acquire the information you need, IE:

GetCurrentBid(int barSeriesIndex)

GetCurrentBidVolume(int barSeriesIndex)

GetCurrentAsk(int barSeriesIndex)

GetCurrentAskVolume(int barSeriesIndex)

VOL()[int barsAgo]

Close[int barsAgo]

Basically you want to write a strategy within NinjaScript that gets those data points, then within the strategy that you write, perform your magic using C#

You can continue to ask basic questions here and on NinjaTrader forum but it comes down to you doing your investigative work of the tool you are using (NinjaScript). There are webinars here on futures.io (formerly BMT) that show you how to write ninjascripts for strategy or indicators. There are also plenty of examples of strategies and indicators that will help your learning.

You have a lot to learn and I wish you well on your journey.

Be yourself; everyone else is already taken. Oscar Wilde
Reply With Quote
Thanked by:

Can you help answer these questions
from other members on NexusFi?
My NT8 Volume Profile Split by Asian/Euro/Open
NinjaTrader
ZombieSqueeze
Platforms and Indicators
The space time continuum and the dynamics of a financial …
Emini and Emicro Index
Exit Strategy
NinjaTrader
NT7 Indicator Script Troubleshooting - Camarilla Pivots
NinjaTrader
 
  #12 (permalink)
nemeis45
delhi, delhi, india
 
Posts: 59 since Dec 2013
Thanks Given: 10
Thanks Received: 14


Tasker_182 View Post
If you are familiar with C# and if you read the NinjaTrader help manual, already, then you would have observed the methods to acquire the information you need, IE:

GetCurrentBid(int barSeriesIndex)

GetCurrentBidVolume(int barSeriesIndex)

GetCurrentAsk(int barSeriesIndex)

GetCurrentAskVolume(int barSeriesIndex)

VOL()[int barsAgo]

Close[int barsAgo]

Basically you want to write a strategy within NinjaScript that gets those data points, then within the strategy that you write, perform your magic using C#

You can continue to ask basic questions here and on NinjaTrader forum but it comes down to you doing your investigative work of the tool you are using (NinjaScript). There are webinars here on futures.io (formerly BMT) that show you how to write ninjascripts for strategy or indicators. There are also plenty of examples of strategies and indicators that will help your learning.

You have a lot to learn and I wish you well on your journey.

VOL()[int barsAgo] returns the indicator value of the referenced bar.
so VOL()[0], will provide total volume in the current bar with a set timeframe, but i want volume at last print.
i have to use Add() to add a bar object.

and specify a timeframe.

I dont want to use bars at all, just current price and volume will do at every print.
Well i would in algo refresh info at some x seconds so i can use x second bars,
Never mind, let me put some thought and time into Ninjascript and come back with what i can learn


I am sorry if the questions are basic, i will go through a few seminars on ninjascript.

Reply With Quote
  #13 (permalink)
nemeis45
delhi, delhi, india
 
Posts: 59 since Dec 2013
Thanks Given: 10
Thanks Received: 14


I wrote a sample program to get this data
protected override void Initialize()
{
CalculateOnBarClose = false;
Add("CL 04-14",PeriodType.Tick,1);
Print("Hello World");
}
protected override void OnBarUpdate()
{
if(CurrentBar <= 100)
{
Print(CurrentBar);
Print("Current Bid Price="+GetCurrentBid());
Print("Current Bid Volume="+GetCurrentBidVolume());
Print("Current Ask Price="+GetCurrentAsk());
Print("Current Ask Volume="+GetCurrentAskVolume());
Print("Last Traded Price= " +Close[0]);
Print("Last Traded Volume="+VOL()[0]);
Print("Time Stamp="+Time[0]);


}
else
{
return;
}
}

This is the sample output i received.
on output window
Current Bid Price=101.98
Current Bid Volume=11
Current Ask Price=101.98
Current Ask Volume=11
Last Traded Price= 101.98
Last Traded Volume=11
,, when DataSeries= second
Why are the current bid price and current ask price always the same
and all volume is equal , this is in all the cases of CurrentBar
If i backtest using Dataseries= Tick,1 , it says
Current Bid Price=102.02
Current Bid Volume=2
Current Ask Price=102.02
Current Ask Volume=2
Last Traded Price= 102.02
Last Traded Volume=2
Time Stamp=2/26/2014 4:38:01 AM

I think i am getting the volume traded, not sure why Current Bid volume and current ask volume are the same too
Could you please also tell me how to get level 2 data, its not essentially required for algo, but would help in some cases.

I have downloaded past data for CL 04-14 both Bid, Ask and Last, tick data
will try it with live data if i can on monday, maybe some problem with my backtest or historical data

Please also tell me , how to get the TimeStamp down to the last millisecond ( or the finest resolution)

I think i would rather do this with the DLL,

It would be great if i could have a complete list of functions for the DLL,
or tell me if there is a way to add functions to the DLL,

I just want to get the mentioned data from my Rthmic Data connection or Historical data into variables.

Thanks a lot

Reply With Quote
  #14 (permalink)
 
Tasker_182's Avatar
 Tasker_182 
Cedar Rapids, iowa
Legendary Market Wizard
 
Experience: Intermediate
Platform: Ninjatrader
Broker: Ninjatrader - Continuum
Posts: 716 since Aug 2009
Thanks Given: 476
Thanks Received: 1,401


nemeis45 View Post
I wrote a sample program to get this data
protected override void Initialize()
{
CalculateOnBarClose = false;
Add("CL 04-14",PeriodType.Tick,1);
Print("Hello World");
}
protected override void OnBarUpdate()
{
if(CurrentBar <= 100)
{
Print(CurrentBar);
Print("Current Bid Price="+GetCurrentBid());
Print("Current Bid Volume="+GetCurrentBidVolume());
Print("Current Ask Price="+GetCurrentAsk());
Print("Current Ask Volume="+GetCurrentAskVolume());
Print("Last Traded Price= " +Close[0]);
Print("Last Traded Volume="+VOL()[0]);
Print("Time Stamp="+Time[0]);


}
else
{
return;
}
}

This is the sample output i received.
on output window
Current Bid Price=101.98
Current Bid Volume=11
Current Ask Price=101.98
Current Ask Volume=11
Last Traded Price= 101.98
Last Traded Volume=11
,, when DataSeries= second
Why are the current bid price and current ask price always the same
and all volume is equal , this is in all the cases of CurrentBar
If i backtest using Dataseries= Tick,1 , it says
Current Bid Price=102.02
Current Bid Volume=2
Current Ask Price=102.02
Current Ask Volume=2
Last Traded Price= 102.02
Last Traded Volume=2
Time Stamp=2/26/2014 4:38:01 AM

I think i am getting the volume traded, not sure why Current Bid volume and current ask volume are the same too
Could you please also tell me how to get level 2 data, its not essentially required for algo, but would help in some cases.

I have downloaded past data for CL 04-14 both Bid, Ask and Last, tick data
will try it with live data if i can on monday, maybe some problem with my backtest or historical data

Please also tell me , how to get the TimeStamp down to the last millisecond ( or the finest resolution)

I think i would rather do this with the DLL,

It would be great if i could have a complete list of functions for the DLL,
or tell me if there is a way to add functions to the DLL,

I just want to get the mentioned data from my Rthmic Data connection or Historical data into variables.

Thanks a lot

In the NinjaTrader help guide:

NinjaScript > Educational Resources > Tips >

Using Historical Bid/Ask Series:
New to NinjaTrader 7 is the ability to use historical bid and ask price series in your NinjaScript instead of only being able to use a last price series. The following outlines the intricacies of this capability:

· You can have multiple bid/ask/last series in your NinjaScript indicator/strategy. Please use the Add() method to add these series to your script.

· The historical bid/ask series holds all bid/ask events sent out by the exchange. This would not be equivalent to the bid/ask at a specific time a trade went off.

· When processing your NinjaScript, the historical bid/ask series would have the historical portion triggered in the OnBarUpdate() method only. OnMarketData() method events for the historical bid/ask series would only be triggered in real-time.

· When using a Market Replay, the series are synced by their timestamp. These timestamps are synced only to a 1-second level of tolerance.

· In real-time, the events from the various series would be received in whichever sequence was sent out by the exchange

What this means is that:

- The exact sequence of a mix of bid/ask/last events will not be maintained while processing the historical data from multiple series.

- The exact sequence of the bid/ask/last events in relation to themselves individually will be maintained while processing the historical data from multiple series.

Be yourself; everyone else is already taken. Oscar Wilde
Reply With Quote
Thanked by:
  #15 (permalink)
nemeis45
delhi, delhi, india
 
Posts: 59 since Dec 2013
Thanks Given: 10
Thanks Received: 14

Thanks a lot Tasker
I believe i have most of what i need now.

Also,
OnMarketData() seems to fit into what i need for live data perfectly, also giving me finer resolution on the time stamps.

Reply With Quote
Thanked by:
  #16 (permalink)
nemeis45
delhi, delhi, india
 
Posts: 59 since Dec 2013
Thanks Given: 10
Thanks Received: 14

ok so quick update.
I didnt do any coding the last month. Didnt find any prop firms here , so back to coding again , have a lot of spare time.

I basically used OnMarketUpdate() to get all the data , in the required format.

Now, the catch is that i dont think i should put all my logic in this method, since it can be called quite frequently, even as bid/ask changes .

I have used it just to extract relevant information.

Now, I want a loop to run , every second which contains the core logic (evaluates this data, an generate signals)

One way to do this is to use OnBarUpdate(), add a series object of timeframe 1 second, on the required contract and then go ahead.

I just want to know

1). If calculate on Bar close is set to false, is OnBarUpdate(), gets called for every change in tick?(every tick movement?)
2.) I just need a parallel thread running, which evaluates the data generated by onmarketdata(), it should run every second - that is the resolution i have set.

I dont like using OnBarUpdate(), for this, there is no void main(), in ninjascript. Is there any convenient way to do this?

Reply With Quote
Thanked by:
  #17 (permalink)
 yosef 
Melilla spain
 
Experience: Advanced
Platform: TOS| JIGSAW | TICKSTRIKE
Broker: AMP
Trading: emini
Posts: 1 since Nov 2019
Thanks Given: 0
Thanks Received: 1

Hi, good afternoon
I need a development with experience in C++ for NJT8 to create a ratio advance.

If any person are interesting,please send me a note.

See you soon.

Follow me on Twitter Reply With Quote
Thanked by:
  #18 (permalink)
larosacristian
italia
 
Posts: 1 since Feb 2019
Thanks Given: 0
Thanks Received: 1


nemeis45 View Post
Thanks a lot Tasker
I believe i have most of what i need now.

Also,
OnMarketData() seems to fit into what i need for live data perfectly, also giving me finer resolution on the time stamps.

Hi, can you post for me an example please. Thanks

Reply With Quote
Thanked by:




Last Updated on December 16, 2019


© 2024 NexusFi™, s.a., All Rights Reserved.
Av Ricardo J. Alfaro, Century Tower, Panama City, Panama, Ph: +507 833-9432 (Panama and Intl), +1 888-312-3001 (USA and Canada)
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.
About Us - Contact Us - Site Rules, Acceptable Use, and Terms and Conditions - Privacy Policy - Downloads - Top
no new posts