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

Sendmail()

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

    #16
    Hi Jesse,

    Thanks for writing back so quickly. Unfortunately no I am not referring to the Tick Size; the pip cost in forex is used to calculate the value of a position in your account dollar terms (rather than in pips or ticks).

    I have attached a screenshot of forex price quotes for reference - you can see the third column from the right shows the pip cost values for each pair. The values in that column represent the cost of one pip per lot.

    So whatever the initial risk value of my trade is in ticks I want to multiply that number by the pip cost and that way the risk is converted into my account dollars (otherwise my position sizing is out).

    As per my previous post I could create an IF "pair" THEN "pip cost" but with the number of different pairs I have that amounts to a lot of IF/THEN statements. I could also create a user input variable for the pip cost, create one strategy per pair and then manually enter the pip cost for each but I was wondering whether there's a way to create say an array or table with pairs/pip costs and then perform some sort of lookup.
    Attached Files

    Comment


      #17
      Hello,

      Thank you for the clarification, in this case you would need to calculate the cost as this is not an item directly available to the script.

      You could do as you had said or use logic to determine this based on the instrument being used, or use a user input to enter the value which could later be used in the logic.

      I look forward to being of further assistance.
      JesseNinjaTrader Customer Service

      Comment


        #18
        I want to avoid using user input variables if I can. How would I go about creating an array
        (or is there a better way of doing it)?

        What I'm thinking is I would have an array or some sort of object like the attached image
        and then the script would return the value in the corresponding PipCost cell for the relevant
        instrument that has generated the alert.
        Attached Files

        Comment


          #19
          Hello,

          You could use a Dictionary or List for this, a dictionary is likely the easiest for 2 values or a key and value pair. If you needed more than 2 values, a list would likely be better.

          There are some examples here: https://www.dotnetperls.com/dictionary

          You could use the instrument name as the Key and for the value you could enter what you need. Then you can reference the dictionary's Key or the instrument name to retrieve its value.


          I look forward to being of further assistance.
          JesseNinjaTrader Customer Service

          Comment


            #20
            Hi Jesse,

            Thanks for the advice - I got the dictionary to work as follows.

            Code:
            protected override void OnBarUpdate()
            {
            Dictionary<string, double> piptable = new Dictionary<string, double>();						    
            		piptable.Add("$AUDJPY",0.13);
               {
                    double pipcost;
            	if (piptable.TryGetValue(Instrument.FullName,out pipcost))
            			{	}
               }
            }
            However, that got me thinking that I wouldn't mind adding a few more values to each instrument (talk about mission creep!) that I could then retrieve and use. Can you give me some advice or point me in the right direction on how to create a list within the dictionary and then retrieve those values?

            Say for example a list with 3 items - so each instrument has 3 different values attached to it and then I retrieve either value 1, 2 or 3 elsewhere in the code.

            Many thanks.

            Comment


              #21
              Hello,

              In that case you would likely want to make a custom Object (class) and use a List of that custom object.

              Here is a simple example:


              The first portion would be to define your custom object (class) above the indicators Class:
              Code:
              namespace NinjaTrader.Indicator
              {
                  [B]public class MyCustomClass
                  {
              	public double PointSize {get;set;}
              	public string InstrumentName {get;set;}
              	public int SomeIntValue {get;set;}
              	public bool SomeBoolValue {get;set;}
                  }[/B]
              	
                  [Description("Enter the description of your new custom indicator here")]
                  public class Test : Indicator
                  {
                      ...
                  }
              }

              Once this object is defined, you would need to make a List variable and then use it:

              Code:
              private System.Collections.Generic.List<MyCustomClass> myListOfInstruments = new System.Collections.Generic.List<MyCustomClass>();
              		
              protected override void Initialize()
              {
              	myListOfInstruments.Add(new MyCustomClass {PointSize = 1,  InstrumentName = "test", SomeIntValue = 1, SomeBoolValue = true });
              	myListOfInstruments.Add(new MyCustomClass {PointSize = 4,  InstrumentName = "test2", SomeIntValue = 3, SomeBoolValue = false });
              }
              		
              protected override void OnBarUpdate()
              {
                      foreach(MyCustomClass item in myListOfInstruments)
              	{
              		Print(string.Format("PointSize {0} InstrumentName {1} SomeIntValue {2} SomeBoolValue {3}",item.PointSize,item.InstrumentName,item.SomeIntValue,item.SomeBoolValue ));
              	}
              }
              I look forward to being of further assistance.
              Attached Files
              JesseNinjaTrader Customer Service

              Comment

              Latest Posts

              Collapse

              Topics Statistics Last Post
              Started by burtoninlondon, Today, 12:38 AM
              0 responses
              5 views
              0 likes
              Last Post burtoninlondon  
              Started by AaronKoRn, Yesterday, 09:49 PM
              0 responses
              12 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
              13 views
              0 likes
              Last Post strategist007  
              Started by StockTrader88, 03-06-2021, 08:58 AM
              44 responses
              3,982 views
              3 likes
              Last Post jhudas88  
              Working...
              X