ChartHelper in a Strategy - NinjaTrader Programming | futures io social day trading
futures io futures trading


ChartHelper in a Strategy
Updated: Views / Replies:6,741 / 27
Created: by sam028 Attachments:5

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 dont 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
 5  
 
Thread Tools Search this Thread
 

ChartHelper in a Strategy

  #21 (permalink)
Elite Member
London, UK
 
Futures Experience: Beginner
Platform: NinjaTrader, IB TWS
Broker/Data: IB, Kinetic
Favorite Futures: Stocks, Forex
 
Posts: 97 since Nov 2011
Thanks: 47 given, 16 received


Traderji View Post
You could have your code remove the horizontal line(s) from the chart if the instrument changes or once it has obtained the price (and replace it with a text marker).

Hello Traderji,

Sorry I was not able to reply sooner. Been working for a living and doing some unsociable hours Thanks for your reply and suggestion. I am not too sure how to do this, as my NTScript/C# skills are limited to just nicking snippets of codes here and there and trial and error If you do have the time to come up with a sample code to do what you have suggested above, I would be most grateful. If you can't, no problem, I am still very grateful for your assistance so far.

Many thanks
Dan

Reply With Quote
 
  #22 (permalink)
Elite Member
Australia
 
Futures Experience: Advanced
Platform: NinjaTrader, Multicharts
Favorite Futures: Spot Forex, Gold, Silver
 
Posts: 176 since Oct 2010
Thanks: 114 given, 114 received


danjuma View Post
Hello Traderji,

Sorry I was not able to reply sooner. Been working for a living and doing some unsociable hours Thanks for your reply and suggestion. I am not too sure how to do this, as my NTScript/C# skills are limited to just nicking snippets of codes here and there and trial and error If you do have the time to come up with a sample code to do what you have suggested above, I would be most grateful. If you can't, no problem, I am still very grateful for your assistance so far.

Many thanks
Dan


I have basic C# skills, just enough to be dangerous. But I'll point you in the right direction.

This code should remove all the user drawn horizontal lines if the instrument changes. I haven't tried to run it or compile it and it might be all horribly wrong so good luck.


 
Code
//Variables
string chartInstrument;

// On Bar Update
protected override void OnBarUpdate()
{
     if (chartInstrument == null)
     {
          chartInstrument = Instrument.FullName;
      }
      else
      {
          if ( chartInstrument != Instrument.FullName)
          {
                foreach (IDrawObject draw in DrawObjects)
               {
	            if (draw.DrawType == DrawType.HorizontalLine && draw.UserDrawn)
	            {
		            IHorizontalLine hLine = (IHorizontalLine) draw;
		            RemoveDrawObject(hLine);
	            }
                }
                chartInstrument = Instrument.FullName;
            }
      }
  }

Reply With Quote
 
  #23 (permalink)
Elite Member
London, UK
 
Futures Experience: Beginner
Platform: NinjaTrader, IB TWS
Broker/Data: IB, Kinetic
Favorite Futures: Stocks, Forex
 
Posts: 97 since Nov 2011
Thanks: 47 given, 16 received



Traderji View Post
I have basic C# skills, just enough to be dangerous. But I'll point you in the right direction.

This code should remove all the user drawn horizontal lines if the instrument changes. I haven't tried to run it or compile it and it might be all horribly wrong so good luck.


 
Code
//Variables
string chartInstrument;

// On Bar Update
protected override void OnBarUpdate()
{
     if (chartInstrument == null)
     {
          chartInstrument = Instrument.FullName;
      }
      else
      {
          if ( chartInstrument != Instrument.FullName)
          {
                foreach (IDrawObject draw in DrawObjects)
               {
                if (draw.DrawType == DrawType.HorizontalLine && draw.UserDrawn)
                {
                    IHorizontalLine hLine = (IHorizontalLine) draw;
                    RemoveDrawObject(hLine);
                }
                }
                chartInstrument = Instrument.FullName;
            }
      }
  }

Hi Traderji,

Thanks for the reply. I have tried your code above, but it didn't seem to work. I am switching instruments via Market Analyser, if that makes any difference. Thanks
Dan

Reply With Quote
 
  #24 (permalink)
Elite Member
Australia
 
Futures Experience: Advanced
Platform: NinjaTrader, Multicharts
Favorite Futures: Spot Forex, Gold, Silver
 
Posts: 176 since Oct 2010
Thanks: 114 given, 114 received


danjuma View Post
Hi Traderji,

Thanks for the reply. I have tried your code above, but it didn't seem to work. I am switching instruments via Market Analyser, if that makes any difference. Thanks
Dan


I just realised that when I change instruments on my charts NT does not carry over any drawing objects from the previous instrument to the new instrument. So if I have a marker in EURUSD and I switch to AUDUSD that marker will go away automatically. So I don't know how come your horizontal line objects are persisting even after you have changed instruments on the chart.

Reply With Quote
 
  #25 (permalink)
Elite Member
London, UK
 
Futures Experience: Beginner
Platform: NinjaTrader, IB TWS
Broker/Data: IB, Kinetic
Favorite Futures: Stocks, Forex
 
Posts: 97 since Nov 2011
Thanks: 47 given, 16 received


Traderji View Post
I just realised that when I change instruments on my charts NT does not carry over any drawing objects from the previous instrument to the new instrument. So if I have a marker in EURUSD and I switch to AUDUSD that marker will go away automatically. So I don't know how come your horizontal line objects are persisting even after you have changed instruments on the chart.

Hi Traderji
Thanks for your reply. Below is my code. The only thing I have added is your suggested code for getting the price under protected override void OnStartUp(). Basically, my code without your suggested code does not seem to have this problem, so not sure what the problem might be. I am using NT version 7.0.1000.8
Anyway, I am still grateful for your code and assistance, and I will just have to live with having to manually remove the horizontal lines anytime I change instruments, if I can't come up with a solution.

Thanks
Dan




Quoting 
protected override void Initialize()
{
Overlay = false;


}
protected override void OnStartUp()
{

foreach (IDrawObject draw in DrawObjects)
{
if (draw.DrawType == DrawType.HorizontalLine && draw.UserDrawn)
{
IHorizontalLine hLine = (IHorizontalLine) draw;
yvalue = Math.Round(hLine.Y, 2); // This is Price value
}

}


}

protected override void OnBarUpdate()
{

if (CurrentBar < 1)
return;

double StopLossP, StopLossPATR, StopLossP2, StopLossPATR2, SharesMxS, SharesMxS2, SharesATR, SharesATR2, SharesPC, SharesPC2;


if (yvalue > Close[0])
{
StopLossP = yvalue - LossPerUnit;
StopLossPATR = Math.Round(yvalue - ATR(14)[0],2);
SharesATR = Math.Round(Math.Abs(LossPerTrade/(yvalue - StopLossPATR)),2);
SharesPC = Math.Round(Math.Abs(LossPerTrade/(yvalue - Low[0])),2);
SharesMxS = Math.Round(Math.Abs(LossPerTrade/(yvalue - StopLossP)),2);
DrawHorizontalLine("Previous candle stop", true, Low[0], Color.Yellow, DashStyle.Dot, 2);
DrawHorizontalLine("Maximum stop", true, StopLossP, Color.Silver, DashStyle.Solid, 2);
DrawHorizontalLine("ATR stop", true, StopLossPATR, Color.Silver, DashStyle.Dash, 2);
DrawTextFixed("Stop Values", "MaxStop " + StopLossP + " (" + SharesMxS + ")" + " ATRStop " + StopLossPATR + " (" + SharesATR + ")" + " Prior CandleStop " + Low[0] + " (" + SharesPC + ")" + " Entry Price " + yvalue, TextPosition.BottomLeft);

}
if (yvalue < Close[0])
{
StopLossP2 = yvalue + LossPerUnit;
StopLossPATR2 = Math.Round(yvalue + ATR(14)[0],2);
SharesATR2 = Math.Round(Math.Abs(LossPerTrade/(yvalue - StopLossPATR2)),2);
SharesPC2 = Math.Round(Math.Abs(LossPerTrade/(yvalue - High[0])),2);
SharesMxS2 = Math.Round(Math.Abs(LossPerTrade/(yvalue - StopLossP2)),2);
DrawHorizontalLine("Previous candle stop", true, High[0], Color.Yellow, DashStyle.Dot, 2);
DrawHorizontalLine("Maximum stop", true, StopLossP2, Color.Silver, DashStyle.Solid, 2);
DrawHorizontalLine("ATR stop", true, StopLossPATR2, Color.Silver, DashStyle.Dash, 2);
DrawTextFixed("Stop Values", "MaxStop " + StopLossP2 + " (" + SharesMxS2 + ")" + " ATRStop " + StopLossPATR2 + " (" + SharesATR2 + ")" + " Prior Candle Stop " + High[0] + " (" + SharesPC2 + ")" + " Entry Price " + yvalue, TextPosition.BottomLeft);

}


Reply With Quote
 
  #26 (permalink)
Elite Member
London, UK
 
Futures Experience: Beginner
Platform: NinjaTrader, IB TWS
Broker/Data: IB, Kinetic
Favorite Futures: Stocks, Forex
 
Posts: 97 since Nov 2011
Thanks: 47 given, 16 received

Ok, I think it's probably to do with with calculations in my formula, as even when I manually remove the horizontal lines, same thing happens. I think it's to do with my price value defaulting to 0, if the price range of the new instrument is not within the price range of the last instrument on the chart when the horizontal line was drawn and from which the price value got.

Cheers
Dan

Reply With Quote
 
  #27 (permalink)
Elite Member
Australia
 
Futures Experience: Advanced
Platform: NinjaTrader, Multicharts
Favorite Futures: Spot Forex, Gold, Silver
 
Posts: 176 since Oct 2010
Thanks: 114 given, 114 received


danjuma View Post
Ok, I think it's probably to do with with calculations in my formula, as even when I manually remove the horizontal lines, same thing happens. I think it's to do with my price value defaulting to 0, if the price range of the new instrument is not within the price range of the last instrument on the chart when the horizontal line was drawn and from which the price value got.

Cheers
Dan


quite easy to fix. Move my code to OnBarUpdate instead of OnStartUp. Also add something to the horizontallines you are drawing in your calculation code so that it does not grab yvalues from those. For example

 
Code
DrawHorizontalLine("DONOTUSEPrevious candle stop", true, Low[0], Color.Yellow, DashStyle.Dot, 2);
This way you can check and exclude any hline which has been drawn by your calculations


 
Code
foreach (IDrawObject draw in DrawObjects)
{
if (draw.DrawType == DrawType.HorizontalLine && draw.UserDrawn && !(draw.Tag.Contains("DONOTUSE")) {
IHorizontalLine hLine = (IHorizontalLine) draw; yvalue = Math.Round(hLine.Y, 2); // This is Price value RemoveDrawObject(hLine);
}
}


Last edited by Traderji; March 17th, 2012 at 06:45 PM.
Reply With Quote
 
  #28 (permalink)
Elite Member
London, UK
 
Futures Experience: Beginner
Platform: NinjaTrader, IB TWS
Broker/Data: IB, Kinetic
Favorite Futures: Stocks, Forex
 
Posts: 97 since Nov 2011
Thanks: 47 given, 16 received

Hi Traderji,

Thank you for your response, time and efforts, I am most grateful. I tried your suggestion above (first code below), but it didn't seem to make any difference. So working on my theory that the cause is probably due to the price value defaulting to zero when I change instruments, and getting some ideas from your previous codes, I came up with the following code (second code below), and it seems to work.

First code

Quoting 
protected override void Initialize()
{
Overlay = false;


}
protected override void OnStartUp()
{


}

protected override void OnBarUpdate()
{

if (CurrentBar < 1)
return;

foreach (IDrawObject draw in DrawObjects)
{
if (draw.DrawType == DrawType.HorizontalLine && draw.UserDrawn && !draw.Tag.Contains("DONOTUSE"))
{
IHorizontalLine hLine = (IHorizontalLine) draw;
yvalue = Math.Round(hLine.Y, 2); // This is Price value
RemoveDrawObject(hLine);
}

}

double StopLossP, StopLossPATR, StopLossP2, StopLossPATR2, SharesMxS, SharesMxS2, SharesATR, SharesATR2, SharesPC, SharesPC2;


if (yvalue > Close[0])
{
StopLossP = yvalue - LossPerUnit;
StopLossPATR = Math.Round(yvalue - ATR(14)[0],2);
SharesATR = Math.Round(Math.Abs(LossPerTrade/(yvalue - StopLossPATR)),2);
SharesPC = Math.Round(Math.Abs(LossPerTrade/(yvalue - Low[0])),2);
SharesMxS = Math.Round(Math.Abs(LossPerTrade/(yvalue - StopLossP)),2);
DrawHorizontalLine("DONOTUSEPrevious candle stop", true, Low[0], Color.Yellow, DashStyle.Dot, 2);
DrawHorizontalLine("DONOTUSEMaximum stop", true, StopLossP, Color.Silver, DashStyle.Solid, 2);
DrawHorizontalLine("DONOTUSEATR stop", true, StopLossPATR, Color.Silver, DashStyle.Dash, 2);
DrawTextFixed("Stop Values", "MaxStop " + StopLossP + " (" + SharesMxS + ")" + " ATRStop " + StopLossPATR + " (" + SharesATR + ")" + " Prior CandleStop " + Low[0] + " (" + SharesPC + ")" + " Entry Price " + yvalue, TextPosition.BottomLeft);

}
if (yvalue < Close[0])
{
StopLossP2 = yvalue + LossPerUnit;
StopLossPATR2 = Math.Round(yvalue + ATR(14)[0],2);
SharesATR2 = Math.Round(Math.Abs(LossPerTrade/(yvalue - StopLossPATR2)),2);
SharesPC2 = Math.Round(Math.Abs(LossPerTrade/(yvalue - High[0])),2);
SharesMxS2 = Math.Round(Math.Abs(LossPerTrade/(yvalue - StopLossP2)),2);
DrawHorizontalLine("DONOTUSEPrevious candle stop", true, High[0], Color.Yellow, DashStyle.Dot, 2);
DrawHorizontalLine("DONOTUSEMaximum stop", true, StopLossP2, Color.Silver, DashStyle.Solid, 2);
DrawHorizontalLine("DONOTUSEATR stop", true, StopLossPATR2, Color.Silver, DashStyle.Dash, 2);
DrawTextFixed("Stop Values", "MaxStop " + StopLossP2 + " (" + SharesMxS2 + ")" + " ATRStop " + StopLossPATR2 + " (" + SharesATR2 + ")" + " Prior Candle Stop " + High[0] + " (" + SharesPC2 + ")" + " Entry Price " + yvalue, TextPosition.BottomLeft);

}

Second code

Quoting 
protected override void Initialize()
{
Overlay = false;


}
protected override void OnStartUp()
{

if (chartInstrument == null)
{
chartInstrument = Instrument.FullName;
yvalue = Close[0];
}

foreach (IDrawObject draw in DrawObjects)
{
if (draw.DrawType == DrawType.HorizontalLine && draw.UserDrawn)
{
IHorizontalLine hLine = (IHorizontalLine) draw;
yvalue = Math.Round(hLine.Y, 2); // This is Price value
}

}

}

protected override void OnBarUpdate()
{

if (CurrentBar < 1)
return;


double StopLossP, StopLossPATR, StopLossP2, StopLossPATR2, SharesMxS, SharesMxS2, SharesATR, SharesATR2, SharesPC, SharesPC2;


if (yvalue > Close[0])
{
StopLossP = yvalue - LossPerUnit;
StopLossPATR = Math.Round(yvalue - ATR(14)[0],2);
SharesATR = Math.Round(Math.Abs(LossPerTrade/(yvalue - StopLossPATR)),2);
SharesPC = Math.Round(Math.Abs(LossPerTrade/(yvalue - Low[0])),2);
SharesMxS = Math.Round(Math.Abs(LossPerTrade/(yvalue - StopLossP)),2);
DrawHorizontalLine("Previous candle stop", true, Low[0], Color.Yellow, DashStyle.Dot, 2);
DrawHorizontalLine("Maximum stop", true, StopLossP, Color.Silver, DashStyle.Solid, 2);
DrawHorizontalLine("ATR stop", true, StopLossPATR, Color.Silver, DashStyle.Dash, 2);
DrawTextFixed("Stop Values", "MaxStop " + StopLossP + " (" + SharesMxS + ")" + " ATRStop " + StopLossPATR + " (" + SharesATR + ")" + " Prior CandleStop " + Low[0] + " (" + SharesPC + ")" + " Entry Price " + yvalue, TextPosition.BottomLeft);

}
if (yvalue < Close[0])
{
StopLossP2 = yvalue + LossPerUnit;
StopLossPATR2 = Math.Round(yvalue + ATR(14)[0],2);
SharesATR2 = Math.Round(Math.Abs(LossPerTrade/(yvalue - StopLossPATR2)),2);
SharesPC2 = Math.Round(Math.Abs(LossPerTrade/(yvalue - High[0])),2);
SharesMxS2 = Math.Round(Math.Abs(LossPerTrade/(yvalue - StopLossP2)),2);
DrawHorizontalLine("Previous candle stop", true, High[0], Color.Yellow, DashStyle.Dot, 2);
DrawHorizontalLine("Maximum stop", true, StopLossP2, Color.Silver, DashStyle.Solid, 2);
DrawHorizontalLine("ATR stop", true, StopLossPATR2, Color.Silver, DashStyle.Dash, 2);
DrawTextFixed("Stop Values", "MaxStop " + StopLossP2 + " (" + SharesMxS2 + ")" + " ATRStop " + StopLossPATR2 + " (" + SharesATR2 + ")" + " Prior Candle Stop " + High[0] + " (" + SharesPC2 + ")" + " Entry Price " + yvalue, TextPosition.BottomLeft);

}


Reply With Quote

Reply



futures io > > > > > ChartHelper in a 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
Utility To Transpose Optimized Strategy Values From Excel Output to Actual Strategy mercuryfx NinjaTrader 5 April 7th, 2012 04:59 PM
Ninjatrader7 ATM Strategy combine with Strategy Wizard Ninja Script schuster21 NinjaTrader Programming 4 July 4th, 2011 05:39 PM
Ninja Strategy multi-timeframe issue/Strategy to indicator nw123 NinjaTrader Programming 2 December 20th, 2009 07:24 PM


All times are GMT -4. The time now is 02:55 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-16 in 0.17 seconds with 20 queries on phoenix via your IP 54.163.209.109