NexusFi: Find Your Edge


Home Menu

 





VLookup value from a CSV File within NT8 Strategy


Discussion in NinjaTrader

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




 
Search this Thread

VLookup value from a CSV File within NT8 Strategy

  #1 (permalink)
venkatv
Chennai + India
 
Posts: 3 since Jan 2019
Thanks Given: 0
Thanks Received: 1

Hi Folks,

Im a Newbie to this forum and also for Ninjascript programming and i need a help from senior folks for a typical scenario, i m encountering.

Basically i do trade in indian stock market on Stock futures where every contracts do have specified in lot sizes and due to which when i place a order i have to place for a particular stock future instrument, i have to place in mutiple of lot sizes.

NT8 at the intrument level i have no provision to enter this info and if at all i wanted to run a stategy on a particular symbol then somehow at the NT code level i have to manipulate this info and take care while placing the order.

from initial findings i came to know somewhere at OnStateChange under State.DataLoaded i have to write a code and get this lotsize info for the intrument i happen to trade

i did create a CSV file for the entire symbols with its lot size e.g will look like something below.
RELIANCE 09-19,500
AXISBANK 09-19,200
YESBANK 09-19,1800
Here the first field is my stock instrument with its expiry, and the second field after the comma is its lot size.

Now on my OnStateChange under State.DataLoaded, I have to vlookup the master instrument name and get the lot size and i contructed my Ninja code as indicated below,

However im struckup to figure it out on getting the Try code block and appreciate if could i get a help from you.

----Here is the code i came up so far----------------------------------------

else if (State == State.DataLoaded)
{
path = NinjaTrader.Core.Globals.UserDataDir + "NFO_SEP19.txt"; //file path indicates Text file where the lotsizes of my Stock Future Instrument are saved
MyInstrument= Instrument.FullName // Which Instrument full name (including contract month) of the configured instrument
// Checks to see if the file exists
if (!File.Exists(path))
{
// If file does not exist, let the user know
Print("File does not exist.");
return;
}
// Code to Vookup Master Instrument Name and return the Lot Size.
try
{


}
catch (Exception e)
{
// Outputs the error to the log
Log("Could not get the info you have requested", NinjaTrader.Cbi.LogLevel.Error);
Print(e.ToString());
}

}

Cheers!!
Venkatesh V

Reply With Quote

Can you help answer these questions
from other members on NexusFi?
ZombieSqueeze
Platforms and Indicators
NT7 Indicator Script Troubleshooting - Camarilla Pivots
NinjaTrader
How to apply profiles
Traders Hideout
Cheap historycal L1 data for stocks
Stocks and ETFs
MC PL editor upgrade
MultiCharts
 
  #3 (permalink)
 
sam028's Avatar
 sam028 
Site Moderator
 
Posts: 3,765 since Jun 2009
Thanks Given: 3,825
Thanks Received: 4,629


It's a text file so don't use vlookup and try with some split() and a dictionary.

Check https://stackoverflow.com/questions/1852200/how-to-split-string-into-a-dictionary .

Success requires no deodorant! (Sun Tzu)
Follow me on Twitter Reply With Quote
  #4 (permalink)
venkatv
Chennai + India
 
Posts: 3 since Jan 2019
Thanks Given: 0
Thanks Received: 1

Dear Sam,

Many thanks for your reply.

i have gone through the link you have given, however still struck up to figure it out how exactly to achieve it.

Here when I run a strategy on instrument RELIANCE 09-19, I expect my try catch block code

1) must open the text file NFO_SEP19.txt
2) look for the instrument RELIANCE 09-19
3) Return its lot size i.e. 500. i.e the data next to the instrument

Appreciate if could you guide with an closest example some thing similar to this.

Many thanks in advance.

regards
Venkatesh

Reply With Quote




Last Updated on September 1, 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