help with multiple position strategy - NinjaTrader Programming | futures io social day trading
futures io futures trading


help with multiple position strategy
Updated: Views / Replies:272 / 1
Created: by maggtrading Attachments:0

Welcome to futures io.

(If you already have an account, login at the top of the page)

futures io is the largest futures trading community on the planet, with over 90,000 members. At futures io, our goal has always been and always will be to create a friendly, positive, forward-thinking community where members can openly share and discuss everything the world of trading has to offer. The community is one of the friendliest you will find on any subject, with members going out of their way to help others. Some of the primary differences between futures io and other trading sites revolve around the standards of our community. Those standards include a code of conduct for our members, as well as extremely high standards that govern which partners we do business with, and which products or services we recommend to our members.

At futures io, our focus is on quality education. No hype, gimmicks, or secret sauce. The truth is: trading is hard. To succeed, you need to surround yourself with the right support system, educational content, and trading mentors – all of which you can find on futures io, utilizing our social trading environment.

With futures io, you can find honest trading reviews on brokers, trading rooms, indicator packages, trading strategies, and much more. Our trading review process is highly moderated to ensure that only genuine users are allowed, so you don’t need to worry about fake reviews.

We are fundamentally different than most other trading sites:
  • We are here to help. Just let us know what you need.
  • We work extremely hard to keep things positive in our community.
  • We do not tolerate rude behavior, trolling, or vendors advertising in posts.
  • We firmly believe in and encourage sharing. The holy grail is within you, we can help you find it.
  • We expect our members to participate and become a part of the community. Help yourself by helping others.

You'll need to register in order to view the content of the threads and start contributing to our community.  It's free and simple.

-- Big Mike, Site Administrator

Reply
 
Thread Tools Search this Thread
 

help with multiple position strategy

  #1 (permalink)
Trading Apprentice
méxico df, méxico
 
Futures Experience: Advanced
Platform: ninjatrader, tradestation
Broker/Data: demo so far
Favorite Futures: stocks, fdax, fdxm, fesx, rb, ho, ng, cl, tf, nq, bp, ec, jy
 
Posts: 46 since Mar 2013
Thanks: 115 given, 21 received

help with multiple position strategy

hello everyone,



i have been trying to code some simple strategies in nt and so far have not had much problem if i use just one single position. if i try to have multiple positions in the same direction, i am having trouble with the code to manage those positions.


i have emailed nt's ninjascript support staff and for the most part they know their stuff and are quite helpful. some days ago one of these ninjascript support people helped me put an idea into code, but it is still incomplete. i would greatly appreciate if more advanced programmers could tell me how should i structure a strategy so that it did the following:



as long as uptrend condition is true do the following, as soon as uptrend condition is no longer true, exit all long positions. [how could i bracket or condition all this code so that all long positions and their respective stops are closed as soon as the uptrend condition is no longer true?]

as soon as uptrend condition becomes true, open one long position. [the entries would look like these and are ok, that's not where i'm having trouble]

 
Code
if  uptrend = true
{
EnterLong("first entry");
}

if uptrend = true and given number of bars later and no new lower lows
{
EnterLong("second entry");
}
if uptrend = true and given number of bars later and no new lower lows
{
EnterLong("third entry");
}

[the position management section the people at nt have helped me with is what is incomplete]



 
Code
.....
        private IOrder firstEntry = null;
        private IOrder secondEntry = null;
.....
 
    if(Close[0] > Open[0] && Position.MarketPosition == MarketPosition.Flat && firstEntry == null)
            {
                firstEntry = EnterLong("first entry");
                SetStopLoss("first entry", CalculationMode.Ticks, 10, false);
            }
            if(Close[0] > Open[0] && Position.MarketPosition == MarketPosition.Long && Position.Quantity == 1 && secondEntry == null)
            {
                secondEntry = EnterLong("second entry");//This is the entry order for our second position. Our Stop will be submitted in the OnExecution() method
                SetStopLoss("second entry", CalculationMode.Ticks, 10, false);
            }
            if(positionOnePrice != 0 && Close[0] - positionOnePrice > 10 * TickSize)//This checks that the first entry has been executed and then compares if the difference from the current Close and our Entry price for Position One is greater than 10 ticks
                SetStopLoss("first entry", CalculationMode.Ticks, 0, false); // This moves our stop to 0
            if(positionTwoPrice != 0 && Close[0] - positionTwoPrice > 10 * TickSize)//This checks that the first entry has been executed and then compares if the difference from the current Close and our Entry price for Position One is greater than 10 ticks
                SetStopLoss("second entry", CalculationMode.Ticks, 0, false); // This moves our stop to 0
            if(positionOnePrice != 0 && Close[0] - positionOnePrice > 20 *TickSize)
                SetStopLoss("first entry" , CalculationMode.Ticks, -10, false);// This will move our stop to be 10 ticks behind the current price which would be +10 above our initial entry
            if(positionTwoPrice != 0 && Close[0] - positionTwoPrice > 20 *TickSize)
                SetStopLoss("second entry" , CalculationMode.Ticks, -10, false);// This will move our stop to be 10 ticks behind the current price which would be +10 above our initial entry
            
            
        }
        protected override void OnExecution(IExecution execution)
        {
            if(firstEntry != null && firstEntry == execution.Order)
                positionOnePrice = execution.Price;
            
            if(secondEntry != null && secondEntry == execution.Order)
                positionTwoPrice = execution.Price;
                
        }
.....

the idea is for the strategy to set a stoploss order for each position and if price moves in my favor, move each stop first to break even and then to lock profit. it seems like it would be necessary to use iorder objects and onexecution() methods, so the strategy knows how many positions it has opened and at what price each. the guys at nt helped me with the above code, but if i try to test it on a chart, it will only take a long position once (my guess is that all variables need to be reset to their starting values after the positions are closed because the uptrend condition stopped being true or a stop was hit. i just don't know how to do that).


so, i have a position management system that causes the strategy to open positions only the first time the uptrend condition is true in a chart, but i would like the strategy to open those positions every time the condition is true, shut everything down if uptrend stops being true, otherwise manage the positions and then reset everything after the positions were closed.


i would greatly appreciate it if anyone can help me complete this code so that it is more functional. thanks in advance.

Reply With Quote
 
  #2 (permalink)
Quick Summary
Quick Summary Post

Quick Summary is created and edited by users like you... Add FAQ's, Links and other Relevant Information by clicking the edit button in the lower right hand corner of this message.


Reply



futures io > > > > > help with multiple position strategy

Thread Tools Search this Thread
Search this Thread:

Advanced Search



Upcoming Webinars and Events (4:30PM ET unless noted)

Jigsaw Trading: TBA

Elite only

FuturesTrader71: TBA

Elite only

NinjaTrader: TBA

Jan 18

RandBots: TBA

Jan 23

GFF Brokers & CME Group: Futures & Bitcoin

Elite only

Adam Grimes: TBA

Elite only

Ran Aroussi: TBA

Elite only
     

Similar Threads
Thread Thread Starter Forum Replies Last Post
Call ATM Strategy on an automated strategy to control position jsengxx NinjaTrader Programming 7 May 31st, 2016 05:51 PM
Strategy Position and Account Position spinnybobo NinjaTrader 15 February 13th, 2015 10:00 PM
print strategy Position list avivi TradeStation 0 November 26th, 2014 01:26 PM
Backtest multiple instruments w. one position? diamondfish Platforms and Indicators 5 January 28th, 2014 08:23 AM
1 strategy with 3 long position giger2000 NinjaTrader Programming 1 October 14th, 2013 05:33 AM


All times are GMT -4. The time now is 06:23 AM.

Copyright © 2017 by futures io, s.a., Av Ricardo J. Alfaro, Century Tower, Panama, +507 833-9432, info@futures.io
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.
no new posts
Page generated 2017-12-17 in 0.08 seconds with 19 queries on phoenix via your IP 54.82.81.154