Execute trade intrabar on bar close indicator - NinjaTrader | futures io social day trading
futures io futures trading


Execute trade intrabar on bar close indicator
Updated: Views / Replies:2,557 / 3
Created: by spinnybobo 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
 

Execute trade intrabar on bar close indicator

  #1 (permalink)
Elite Member
Crete, IL/USA
 
Futures Experience: Intermediate
Platform: NinjaTrader, Mt4
Broker/Data: Tradestation/Tradestation, NinjaTrader, FXCM and Tallinex
Favorite Futures: ES, CL, EUR/USD, TF
 
spinnybobo's Avatar
 
Posts: 171 since Aug 2009
Thanks: 99 given, 48 received

Execute trade intrabar on bar close indicator

Hello
I have a programming question. I am using the Swing indicator built into NinjaTrader to go Long as soon as it is 1 tick above the swingHigh, or go Short as soon as it is 1 tick below the swingLow.

This obviously needs to be done CalculateOnBarClose = false; to enter the trade intrabar
However, now the indicator is being calculated on bar close = false;

I just wanted to know the best way to have a strategy that has the entry for OnBarUpdate when I need:
goLong/goShort-------> needs to be CalculateOnBarClose = false;
Swing(5) indicator--------->needs to be CalculateOnBarClose = true;

Do I create 2 separate methods?
 
Code
public void calculateIndicator()
{
Add(Swing(5));
CalculateOnBarClose = true;
}
public void orderEntry()
{
CalculateOnBarClose = false;
}
T

here is my code so far:
 
Code
#region Using declarations
using System;
using System.ComponentModel;
using System.Diagnostics;
using System.Drawing;
using System.Drawing.Drawing2D;
using System.Xml.Serialization;
using NinjaTrader.Cbi;
using NinjaTrader.Data;
using NinjaTrader.Indicator;
using NinjaTrader.Gui.Chart;
using NinjaTrader.Strategy;
#endregion


namespace NinjaTrader.Strategy
{
    
    [Description("CL trading strategy")]
    public class CLStrategy : Strategy
    {
        #region Variables
        private string            atmStrategyId        = string.Empty;
        private string            orderId                = string.Empty;
        
        private int                _numberOfContracts    = 2;
        private int                _strength            = 5;
        private int                _startTime            = 80000;
        private int                _endTime            = 103000;
        private string            _alertSound            = "NONE";
        private string            _atmName            = "crude";
        
        #endregion

        
        protected override void Initialize()
        {
            Add(spencerSwing(_strength)); //spencerSwing is same as Swing except different color and size of dot
                                                             //plus DisplayInDataBox    = true;   and I made some of the private members
                                                              //in the properties public just to make sure it could be used by 
                                                              //an outside strategy
            CalculateOnBarClose = true;
            EntriesPerDirection = _numberOfContracts;
            EntryHandling = EntryHandling.AllEntries;
            TraceOrders = true;
        }

       
        protected override void OnBarUpdate()
        {
            if(ToTime(Time[0])>=StartTime && ToTime(Time[0])<=EndTime)
            {
                if(Historical)
                    return;
                //for longs
                if(orderId.Length==0
                    && atmStrategyId.Length == 0
                    && (High[0]>spencerSwing(_strength).SwingHigh[0] && High[1]<spencerSwing(_strength).SwingHigh[0]))
                {
                    atmStrategyId = GetAtmStrategyUniqueId();
                    orderId = GetAtmStrategyUniqueId();
                    AtmStrategyCreate(Cbi.OrderAction.Buy, OrderType.Market, 0, 0, TimeInForce.Day, orderId, _atmName, atmStrategyId);
                }
                if(orderId.Length==0
                    && atmStrategyId.Length==0
                    && (Low[0]<spencerSwing(_strength).SwingLow[0] && Low[1] > spencerSwing(_strength).SwingLow[0]))
                {
                    atmStrategyId = GetAtmStrategyUniqueId();
                    orderId = GetAtmStrategyUniqueId();
                    AtmStrategyCreate(Cbi.OrderAction.Sell, OrderType.Market, 0, 0, TimeInForce.Day, orderId, _atmName, atmStrategyId);
                }
                if(orderId.Length > 0)
                {
                    string[] status = GetAtmStrategyEntryOrderStatus(orderId);
                    //if the status call cant find the order specified, the
                    //return array length will be zero otherwise it will hold elements
                    if(status.GetLength(0) > 0)
                    {
                        //print out some info about the order
                        Print("The entry order average fill price is: "+status[0]);
                        Print("The entry order filled amount is: " +status[1]);
                        Print("The entry order order state is: "+status[2]);
                        //if the order state is terminal, reset the order id value
                        if(status[2] == "Filled" || status[2] == "Cancelled" || status[2]=="Rejected")
                            orderId = string.Empty;
                    }
                }
                else if(atmStrategyId.Length > 0 && GetAtmStrategyMarketPosition(atmStrategyId) == Cbi.MarketPosition.Flat)
                    atmStrategyId = string.Empty;
            }//end put on trade
        }
        #region Properties
        [Description("The Number of contracts traded")]
        [Category("Parameters")]
        [Gui.Design.DisplayName("01. Number Of Contracts")]
        public int NumberOfContracts
        {
            get{return _numberOfContracts;}
            set{_numberOfContracts = Math.Max(1, value);}
        }
        [Description("The input strength of swing")]
        [Category("Parameters")]
        [Gui.Design.DisplayName("02. Swing Strength")]
        public int Strength
        {
            get{return _strength;}
            set{_strength = Math.Max(1, value);}
        }
        [Description("The time trading starts")]
        [Category("Parameters")]
        [Gui.Design.DisplayName("03. Start")]
        public int StartTime
        {
            get{return _startTime;}
            set{_startTime = Math.Max(1, value);}
        }
        [Description("The time trading ends")]
        [Category("Parameters")]
        [Gui.Design.DisplayName("04. Ends")]
        public int EndTime
        {
            get{return _endTime;}
            set{_endTime = Math.Max(1, value);}
        }
        [Description("A .wav file to play as an alert")]
        [Category("Parameters")]
        [Gui.Design.DisplayName("05. Wave File")]
        public string AlertWavFile
        {
            get{return _alertSound;}
            set{
                    _alertSound = value;
                    _alertSound = _alertSound.Trim();
                    if(_alertSound.ToUpperInvariant().CompareTo("NONE")== 0 )
                        _alertSound = "NONE";
                }
        }
        [Description("Enter the ATM strategy name")]
        [Category("Parameters")]
        [Gui.Design.DisplayName("06. Strategy Name")]
        public string ATMName
        {
            get{return _atmName;}
            set{_atmName = value;}
        }
       
        #endregion
The only other thing I can think of is use the indicator on the chart and have a FileWriter write the Swing High, Swing Low to a swingLow.txt and swingHigh.txt and then the Strategy uses these .txt files. However, I am thinking this might cause delays, but not sure, etc...
The other way can be using a data structure like ArrayList or something on an indicator page, and then the Strategy page reads the return.

 
Code
//this would be put on the indicator
public ArrayList<double> getCurrentValue()
{
ArrayList<double> currentSwingHighValue = new ArrayList<double>();
ArrayList<double> currentSwingLowValue = new ArrayList<double>();
currentSwingHighValue.add(SwingHigh);
currentSwingLowValue.add(SwingLow);
return ArrayList<double>;
}
Then the strategy can grab this
BTW, my most comfortable programming language is Java, so it is taking a little while for me to learn C#----not that bad, just trying to relate how things are done differently-----like with get, and set

thanks
Spencer

Reply With Quote
 
  #2 (permalink)
Site Administrator
Manta, Ecuador
 
Futures Experience: Advanced
Platform: My own custom solution
Favorite Futures: E-mini ES S&P 500
 
Big Mike's Avatar
 
Posts: 46,238 since Jun 2009
Thanks: 29,350 given, 83,220 received

If your "calling" indicator or strategy (the one added to your chart) is set to COBC = false, then anything other than COBC = false in all the child indicators will result in problems. The best thing is to remove COBC from #init altogether, which means it defaults to true, unless the parent is false in which case it defaults to false.

It is not possible to have the parent be different than the child and get correct results. Not in any of my experiences at least.

If you need this, you would have to simulate it yourself. Run everything COBC false, then code a function to simulate filling your dataseries or whatever based on COBC true. I've had to do this several times.

Mike

Due to time constraints, please do not PM me if your question can be resolved or answered on the forum.

Need help?
1) Stop changing things. No new indicators, charts, or methods. Be consistent with what is in front of you first.
2) Start a journal and post to it daily with the trades you made to show your strengths and weaknesses.
3) Set goals for yourself to reach daily. Make them about how you trade, not how much money you make.
4) Accept responsibility for your actions. Stop looking elsewhere to explain away poor performance.
5) Where to start as a trader? Watch this webinar and read this thread for hundreds of questions and answers.
6)
Help using the forum? Watch this video to learn general tips on using the site.

If you want
to support our community, become an Elite Member.

Reply With Quote
The following 2 users say Thank You to Big Mike for this post:
 
  #3 (permalink)
Elite Member
Crete, IL/USA
 
Futures Experience: Intermediate
Platform: NinjaTrader, Mt4
Broker/Data: Tradestation/Tradestation, NinjaTrader, FXCM and Tallinex
Favorite Futures: ES, CL, EUR/USD, TF
 
spinnybobo's Avatar
 
Posts: 171 since Aug 2009
Thanks: 99 given, 48 received


Hi Mike

thanks for the reply. yeah, I think you confirmed my suspicions that this is more complex than I originally thought. I will have to think about this more:-) thanks

Spencer

Reply With Quote
 
  #4 (permalink)
Trading Apprentice
London, UK
 
Futures Experience: Intermediate
Platform: NinjaTrader
Favorite Futures: ES, Stocks, European index futures
 
Posts: 1 since Aug 2011
Thanks: 1 given, 0 received


Big Mike View Post
If your "calling" indicator or strategy (the one added to your chart) is set to COBC = false, then anything other than COBC = false in all the child indicators will result in problems. The best thing is to remove COBC from #init altogether, which means it defaults to true, unless the parent is false in which case it defaults to false.

It is not possible to have the parent be different than the child and get correct results. Not in any of my experiences at least.

If you need this, you would have to simulate it yourself. Run everything COBC false, then code a function to simulate filling your dataseries or whatever based on COBC true. I've had to do this several times.

Mike

Hi Mike,

The million dollar question I'm trying to answer, and it seems you may be up to something already, is how exactly would I code a function to simulate filling my dataseries?
An example of that would prove very useful to me, I've been straining my brain for a reliable solution for ages...

Thanks for your help,
Dan M.

Reply With Quote

Reply



futures io > > > > Execute trade intrabar on bar close indicator

Thread Tools Search this Thread
Search this Thread:

Advanced Search



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

Linda Bradford Raschke: Reading The Tape

Elite only

Adam Grimes: TBA

Elite only

NinjaTrader: TBA

January

Ran Aroussi: TBA

Elite only
     

Similar Threads
Thread Thread Starter Forum Replies Last Post
highest bar close occuring within the last X number of bars . . . . jmejedi NinjaTrader Programming 37 October 6th, 2014 01:52 AM
Heikin Ashi indicator with bar outline same color as bar? Todd NinjaTrader 29 September 7th, 2013 08:33 AM
Close bar recognization in multi time frame strategy pinto552 NinjaTrader Programming 6 September 6th, 2011 10:07 AM
Managing Trade when Calculate on Close = True jthom NinjaTrader Programming 15 March 24th, 2010 05:49 PM
Close[0] not waiting until bar close dsraider NinjaTrader Programming 4 February 11th, 2010 06:49 PM


All times are GMT -4. The time now is 09:51 PM.

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-12 in 0.08 seconds with 19 queries on phoenix via your IP 54.221.93.187