NexusFi: Find Your Edge


Home Menu

 





How to code an angled trend line???


Discussion in MultiCharts

Updated
      Top Posters
    1. looks_one Sinatra Fan with 5 posts (0 thanks)
    2. looks_two ABCTG with 4 posts (0 thanks)
    3. looks_3 DoubleDown with 1 posts (0 thanks)
    4. looks_4 trendisyourfriend with 1 posts (0 thanks)
    1. trending_up 740 views
    2. thumb_up 0 thanks given
    3. group 4 followers
    1. forum 10 posts
    2. attach_file 1 attachments




 
Search this Thread

How to code an angled trend line???

  #1 (permalink)
 
Sinatra Fan's Avatar
 Sinatra Fan 
Orlando FL
 
Experience: Intermediate
Platform: MultiCharts, Ninja
Trading: Emini ES
Posts: 67 since May 2019
Thanks Given: 7
Thanks Received: 9

I am trying to create a signal and indicator that will calculate a trend line that can be used to create entry/exit signal. Does anyone have some sample code that I can take a look at for doing this? I want to create a line based on bottoms or tops of a trend channel. Here's a pic of what I'm looking to do...

https://photos.app.goo.gl/WYPEsjEvaQ2kzoMU7


Started this thread Reply With Quote

Can you help answer these questions
from other members on NexusFi?
Footprint for strategy Builder
NinjaTrader
Quantum physics & Trading dynamics
The Elite Circle
MC PL editor upgrade
MultiCharts
Pivot Indicator like the old SwingTemp by Big Mike
NinjaTrader
Legends Trading: Ask Me Anything (AMA) w/Greg Khojikian CEO
Trading Reviews and Vendors
 
Best Threads (Most Thanked)
in the last 7 days on NexusFi
ApexTraderFunding.com experience and review
27 thanks
System Performance Stats Comparison
13 thanks
GFIs1 1 DAX trade per day journal
10 thanks
Favorite High Probability Setup
9 thanks
Spoo-nalysis ES e-mini futures S&P 500
8 thanks
  #2 (permalink)
 
trendisyourfriend's Avatar
 trendisyourfriend 
Quebec Canada
Market Wizard
 
Experience: Intermediate
Platform: NinjaTrader
Broker: AMP/CQG
Trading: ES, NQ, YM
Frequency: Daily
Duration: Minutes
Posts: 4,529 since Oct 2009
Thanks Given: 4,183
Thanks Received: 6,028

I did one for Ninjatrader, you can look at the code though it is developed in Ninjascript which is an extention of the "C Sharp" language.

 
Code
/// indicator name : tiyfSlopeInterceptor
/// *** Descrition ***
/// Its mission is to move any selected Horizontal Line to the common point (x,y coordinate axes) between a Ray and the current bar.
/// This indicator updates the y-location of any selected Horizontal Line 
/// to the common point (x,y coordinate axes) between a Ray and the current bar.
///
/// How to use:
/// 1- a Ray must be drawn anywhere on the chart. There can be many Rays on the chart but only one single Ray can be active.
/// 2- A ray gets activated when the user simultaneously presses the left control key (left Ctrl) and clicks on the Ray. Doing this repeatedly will flip the state of the Ray between active/inactive.
/// 3- Once the user selects an Horizontal Line, the line will start to follow the Ray (trend line) at the current bar as long as the h. line stays selected.
/// 4- to detach the Horizontal Line from the Ray. The user can unselect the Horizontal Line or flip the state of the Ray to inactive.
The interesting part of the code is located in this method:
private LineCalculation calculate_YIntercept( string lineTagName )

See attached text file with extention .cs

Attached Files
Elite Membership required to download: tiyfSlopeInterceptor.cs
Reply With Quote
  #3 (permalink)
 
Sinatra Fan's Avatar
 Sinatra Fan 
Orlando FL
 
Experience: Intermediate
Platform: MultiCharts, Ninja
Trading: Emini ES
Posts: 67 since May 2019
Thanks Given: 7
Thanks Received: 9


OK, so I started experimenting and created the following indicator just to see if it will plot a trend line on a flexrenko chart. It would plot a trend line with the starting point being on bar number 165 at 4185.00 and the end point being at bar number 1051 at 4180.50.

It did successfully plot the line, but it taxed the hell out of my processor. And when I say taxing, I opened the task manager and the CPU usage for MC went from 0.1% to 9%. And I have a robust system. Do all plotting codes do this?



Vars:
TL_ID(0), StartBar(165), EndBar(1051), StartPrice(4185.00), EndPrice(4180.50);

TL_ID = TL_New_BN(StartBar, StartPrice, EndBar, EndPrice);
TL_SetExtRight(TL_ID, True);
TL_SetSize(TL_ID, 4);
TL_SetColor(TL_ID, Blue);

Started this thread Reply With Quote
  #4 (permalink)
 ABCTG   is a Vendor
 
Posts: 2,436 since Apr 2013
Thanks Given: 484
Thanks Received: 1,629

Sinatra Fan,

no, but your code "asks" for this. Think about what it does exactly and how many trendlines it potentially creates.

Regards,

ABCTG


Sinatra Fan View Post
OK, so I started experimenting and created the following indicator just to see if it will plot a trend line on a flexrenko chart. It would plot a trend line with the starting point being on bar number 165 at 4185.00 and the end point being at bar number 1051 at 4180.50.

It did successfully plot the line, but it taxed the hell out of my processor. And when I say taxing, I opened the task manager and the CPU usage for MC went from 0.1% to 9%. And I have a robust system. Do all plotting codes do this?



Vars:
TL_ID(0), StartBar(165), EndBar(1051), StartPrice(4185.00), EndPrice(4180.50);

TL_ID = TL_New_BN(StartBar, StartPrice, EndBar, EndPrice);
TL_SetExtRight(TL_ID, True);
TL_SetSize(TL_ID, 4);
TL_SetColor(TL_ID, Blue);


Follow me on Twitter Reply With Quote
  #5 (permalink)
 
Sinatra Fan's Avatar
 Sinatra Fan 
Orlando FL
 
Experience: Intermediate
Platform: MultiCharts, Ninja
Trading: Emini ES
Posts: 67 since May 2019
Thanks Given: 7
Thanks Received: 9


ABCTG View Post
Sinatra Fan,

no, but your code "asks" for this. Think about what it does exactly and how many trendlines it potentially creates.

Regards,

ABCTG

Not sure I understand. It plotted one line. Is there a more efficient approach to this. If so, I'm all ears. I'm a complete noob to coded trend lines. Thanks

Started this thread Reply With Quote
  #6 (permalink)
 ABCTG   is a Vendor
 
Posts: 2,436 since Apr 2013
Thanks Given: 484
Thanks Received: 1,629

Sinatra Fan,

I am not sure I understand what you mean by that. Are you saying you are just seeing one line or did you actually check the number of drawings for the chart (for example by looking at all drawings via -> Format Drawings)?

Regards,

ABCTG


Sinatra Fan View Post
Not sure I understand. It plotted one line. Is there a more efficient approach to this. If so, I'm all ears. I'm a complete noob to coded trend lines. Thanks


Follow me on Twitter Reply With Quote
  #7 (permalink)
 
Sinatra Fan's Avatar
 Sinatra Fan 
Orlando FL
 
Experience: Intermediate
Platform: MultiCharts, Ninja
Trading: Emini ES
Posts: 67 since May 2019
Thanks Given: 7
Thanks Received: 9


ABCTG View Post
Sinatra Fan,

I am not sure I understand what you mean by that. Are you saying you are just seeing one line or did you actually check the number of drawings for the chart (for example by looking at all drawings via -> Format Drawings)?

Regards,

ABCTG

OK, so let me answer....

1) I only see 1 trend line.
2) I just checked and saw 499K drawings. This would obviously explain the draw on the CPU.

So, why is this happening and what can I do to stop this. Thanks

Started this thread Reply With Quote
  #8 (permalink)
 ABCTG   is a Vendor
 
Posts: 2,436 since Apr 2013
Thanks Given: 484
Thanks Received: 1,629

Sinatra Fan,

you need to keep in mind how your code is evaluated. It is called on every bar/tick and since you are drawing the trendline unconditionally, every call will result in a new trendline using the same values.
This is also the solution to you problem i.e. you will probably want to add a condition to ensure the trendline is only drawn once. What you use here is up to you.

Regards,

ABCTG


Sinatra Fan View Post
OK, so let me answer....

1) I only see 1 trend line.
2) I just checked and saw 499K drawings. This would obviously explain the draw on the CPU.

So, why is this happening and what can I do to stop this. Thanks


Follow me on Twitter Reply With Quote
  #9 (permalink)
 
Sinatra Fan's Avatar
 Sinatra Fan 
Orlando FL
 
Experience: Intermediate
Platform: MultiCharts, Ninja
Trading: Emini ES
Posts: 67 since May 2019
Thanks Given: 7
Thanks Received: 9


ABCTG View Post
Sinatra Fan,

you need to keep in mind how your code is evaluated. It is called on every bar/tick and since you are drawing the trendline unconditionally, every call will result in a new trendline using the same values.
This is also the solution to you problem i.e. you will probably want to add a condition to ensure the trendline is only drawn once. What you use here is up to you.

Regards,

ABCTG

So let's say I put a condition in there to calculate it once right at the point where the second (end) point is identified. What happens when I tell it to extend right? will it extend right even if it calculates one time?

Started this thread Reply With Quote
  #10 (permalink)
 ABCTG   is a Vendor
 
Posts: 2,436 since Apr 2013
Thanks Given: 484
Thanks Received: 1,629


I would suggest testing this. Any drawing attribute should remain as set until changed.


Sinatra Fan View Post
So let's say I put a condition in there to calculate it once right at the point where the second (end) point is identified. What happens when I tell it to extend right? will it extend right even if it calculates one time?


Follow me on Twitter Reply With Quote




Last Updated on December 3, 2023


© 2024 NexusFi™, s.a., All Rights Reserved.
Av Ricardo J. Alfaro, Century Tower, Panama City, Panama, Ph: +507 833-9432 (Panama and Intl), +1 888-312-3001 (USA and Canada)
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.
About Us - Contact Us - Site Rules, Acceptable Use, and Terms and Conditions - Privacy Policy - Downloads - Top
no new posts