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

Using Market.Position in indicator from addon

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

    Using Market.Position in indicator from addon

    Im working on an indicator that submits orders when conditions are met, i currently use an add on to get ATM Insturment QTY and Account from chart trader, the indicator takes the trade, but the problem is that it calculates on each tick so i wanted to use this to take only one trade if flat or reverse when long, is there anyway i can get around this? could i pass it as a string value from an event?

    #2
    code im using

    if(Position.MarketPosition == MarketPosition.Flat)
    {
    Order mar****rder = account.CreateOrder(Instrument, OrderAction.Buy, OrderType.Market, OrderEntry.Automated, TimeInForce.Day, 1, 0, 0, string.Empty, "Long conditional", new DateTime(), null);
    account.Submit(new Order[] { mar****rder });
    }
    else if(Position.MarketPosition == MarketPosition.Short)
    {
    Order mar****rder = account.CreateOrder(Instrument, OrderAction.BuyToCover, OrderType.Market, OrderEntry.Automated, TimeInForce.Day, 1, 0, 0, string.Empty, "Long conditional", new DateTime(), null);
    account.Submit(new Order[] { mar****rder });
    }
    else
    {
    }​

    Comment


      #3
      i found a work around but its only registering long or short, i can close them but cant enter a new position when flat, any suggestions would be greatly appreciated


      int marketPosition = 0;

      lock (Account.All)
      account = Account.All.FirstOrDefault(a => a.Name == acct);

      if (account != null)
      {

      lock (account.Positions)
      {
      foreach (Position position in account.Positions)
      {
      if (position.MarketPosition == MarketPosition.Long)
      {
      marketPosition = 1;
      Print("LONG");
      }
      else if (position.MarketPosition == MarketPosition.Short)
      {
      marketPosition = 2;
      Print("SHORT");
      }
      else if(position.MarketPosition == MarketPosition.Flat)
      {
      marketPosition = 3;
      Print("FLAT");
      }​

      Comment


        #4
        I solved it, new here, not sure how to delete this post, so if an admin see this you can get rid of it

        Comment

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by RubenCazorla, 08-30-2022, 06:36 AM
        3 responses
        77 views
        0 likes
        Last Post PaulMohn  
        Started by f.saeidi, Yesterday, 12:14 PM
        9 responses
        23 views
        0 likes
        Last Post f.saeidi  
        Started by Tim-c, Today, 03:54 AM
        0 responses
        3 views
        0 likes
        Last Post Tim-c
        by Tim-c
         
        Started by FrancisMorro, Today, 03:24 AM
        0 responses
        4 views
        0 likes
        Last Post FrancisMorro  
        Started by Segwin, 05-07-2018, 02:15 PM
        10 responses
        1,772 views
        0 likes
        Last Post Leafcutter  
        Working...
        X