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

Multiple EnterLongStops

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

    Multiple EnterLongStops

    I have developed a strategy that generates multiple price levels to enter at.

    All of these will not get hit on the next bar

    So here are my questions:

    1. How can i store these levels so i can use them later (should i use a dataseries object) because if i submit all these enterLongStops, i am afraid my broker wont accept because of margin...lol
    2. how do i determine which price is closest to market so i can submit orders? one may be short and another long
    3. how do i tell if order filled so i can remove it from (dataseries?) because each level gets used once

    Not sure if I made myself clear, but anyone who is really good at programming this should be a no brainer for ya!

    I guess i would ike a framework to store levels
    execute orders on those levels
    confirm fills
    then delete levels

    Thanks

    #2
    Originally posted by Laserdan View Post
    I have developed a strategy that generates multiple price levels to enter at.

    All of these will not get hit on the next bar

    So here are my questions:

    1. How can i store these levels so i can use them later (should i use a dataseries object) because if i submit all these enterLongStops, i am afraid my broker wont accept because of margin...lol
    2. how do i determine which price is closest to market so i can submit orders? one may be short and another long
    3. how do i tell if order filled so i can remove it from (dataseries?) because each level gets used once

    Not sure if I made myself clear, but anyone who is really good at programming this should be a no brainer for ya!

    I guess i would ike a framework to store levels
    execute orders on those levels
    confirm fills
    then delete levels

    Thanks

    Hi LaserDan


    I have done a similiar thing ...I'm not saying this is perfect (as i just typed it in- probably some typo's etc) but it should give you the basis on which to add some code to your strategy ...

    /////////////////////
    /// variables
    /////////////////////

    static int LONG =1;
    static in SHORT = -1;

    List<double>listLongOrderLevels = new List<double>();
    List<double>listShortOrderLevels = new List<double>();
    List<IOrder>listOpenOrders = new List<IOrder>();

    //////////////////////
    //////////////////////
    //////////////////////

    1. Add your long/short levels to the long order list => AddToOrderLevels(double prc, int LS)
    3. Find And Remove your order placement levels from the Long level List => private double FindNearestLongLevel ()
    4. Find And Remove your order placement levels from the Short level List => private double FindNearestShortLevel ()
    5. Place Order = > PlaceMyOrder(double prc, int LongOrShort)
    6. Order will be removed from your open order list in the override of OnExecution


    //////////////////////
    //////////////////////
    //////////////////////

    protected override void OnExecution(IExecution execution) {
    for (int i=0;i<listOpenOrders.Count;i++) {
    if ( listOpenOrders[i].Token == execution.Order.Token) {
    listOpenOrders.RemoveAt(i);
    break;
    }
    }
    }

    //////////////////////
    //////////////////////
    //////////////////////

    private void PlaceMyOrder (double prc, int LS) {

    if (LS == LONG) listOpenOrders.Add(EnterLongLimit(.....));
    else if (LS == SHORT) listOpenOrders.Add(EnterShortLimit(.....));
    }

    //////////////////////
    //////////////////////
    //////////////////////

    private void AddToOrderLevels(double prc, int LS) {

    if (LS == LONG) listLongOrderLevels.Add(prc);
    else if (LS == SHORT) listShortOrderLevels.Add(prc);

    }

    //////////////////////
    //////////////////////
    //////////////////////

    private double FindNearestLongLevel () {

    double diff = 0;
    double d;
    int iPos = -1;


    for (int i=0; i< listLongOrderLevels.Count; i++ ) {

    d = Close[0] - listLongOrderLevels[i];

    if (d > TickSize && (d < diff || diff == 0)) iPos = i;
    }

    if (iPos > -1) {
    d = listLongOrderLevles[i];
    listLongOrderLevels.RemoveAt(i);
    return (d);
    } else return 0;

    }

    //////////////////////
    //////////////////////
    //////////////////////

    private double FindNearestShortLevel() {

    double diff = 0;
    double d;
    int iPos = -1;


    for (int i=0; i< listShortOrderLevels.Count; i++ ) {

    d = listShortOrderLevels[i] - Close[i];

    if (d > TickSize && (d < diff || diff == 0)) iPos = i;
    }

    if (iPos > -1) {
    d = listShortOrderLevels[i];
    listShortOrderLevels.RemoveAt(i);
    return (d);
    } else return 0;

    }

    Comment


      #3
      THANK YOU!!

      The List Item with the FindNearest Functions are Exactly what i was looking for. Thanks for showing me this and hopefully it will help others as well.

      Comment


        #4
        Originally posted by Laserdan View Post
        THANK YOU!!

        The List Item with the FindNearest Functions are Exactly what i was looking for. Thanks for showing me this and hopefully it will help others as well.
        u r welcome!

        Comment

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by ETFVoyageur, Today, 12:52 AM
        0 responses
        2 views
        0 likes
        Last Post ETFVoyageur  
        Started by Board game geek, Yesterday, 02:20 AM
        2 responses
        21 views
        0 likes
        Last Post Board game geek  
        Started by jackiegils, Yesterday, 11:05 PM
        0 responses
        5 views
        0 likes
        Last Post jackiegils  
        Started by cre8able, 05-09-2024, 09:15 PM
        2 responses
        17 views
        0 likes
        Last Post cre8able  
        Started by Trader146, Yesterday, 09:17 PM
        0 responses
        10 views
        0 likes
        Last Post Trader146  
        Working...
        X