Here is my Linear Regression 2 colors code - How can I anticipate the color switch? - futures io
futures io



Here is my Linear Regression 2 colors code - How can I anticipate the color switch?


Discussion in MultiCharts

Updated
    1. trending_up 738 views
    2. thumb_up 2 thanks given
    3. group 2 followers
    1. forum 2 posts
    2. attach_file 1 attachments




Welcome to futures io: the largest futures trading community on the planet, with well over 150,000 members
  • Genuine reviews from real traders, not fake reviews from stealth vendors
  • Quality education from leading professional traders
  • We are a friendly, helpful, and positive community
  • We do not tolerate rude behavior, trolling, or vendors advertising in posts
  • We are here to help, just let us know what you need
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

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

 
Search this Thread
 

Here is my Linear Regression 2 colors code - How can I anticipate the color switch?

(login for full post details)
  #1 (permalink)
Dvdkite
Trieste Italy
 
 
Posts: 162 since Feb 2018
Thanks: 131 given, 23 received

Hello Everyone,

I'm using the following code for the Linear Regression but it change its color a bar late for...

 
Code
inputs:
  Price( Close),
  Length( 89),
  Displace( 0),
  UpColor( green),
  DnColor (red),
  PaintInBarLRCLine ("Yes");

variables:
   LinReg( 0 ),Trend (0),Transition (0) ;

if Displace >= 0 or CurrentBar > AbsValue( Displace ) then  
  begin
    LinReg = LinearRegValue( Price, Length, 0 ) ; 
  If LinReg > LinReg [1] then
    Begin
      If Trend = -1 then Transition = 1;
     If PaintInBarLRCLine = "Yes" then Plot1[Displace]( LinReg, "LinReg", UpColor );
      Trend = 1;
    End
  Else
    Begin
      If Trend = 1 then Transition = 1;
      If PaintInBarLRCLine = "Yes" then Plot1 [Displace] ( LinReg, "LinReg",DnColor ) ;
      Trend = -1;
    End;
  End;
Let me explane with an example over the FDAX...
Let's suppose we have an uptrend linear regression (LR) line yellow and then it is approching to switch direction and we came to the point where LR[4] is 12349,70, LR[3] is 12350,80 , LR[2] is 12350,68 and then LR[1] is 12350,49.

Ok so this is the situation that I actually see on my chart:

I have the UpColor between LR4 and LR3, // correct because LR4 12349,70 < LR3 12350,80
I have the UpColor between LR3 and LR2, // wrong because LR3 12350,80 > LR2 12350,68
I have the DownColor between LR2 and LR1, //correct because LR2 12350,68 > LR1 12350,49

So basically the indicator is switching color a bar late and I honestly can't find a way to change it!
... Also I would like to see the last piece of line to change color (if the condition are met) on every tick untill the bar end and its value is definitive so I know that I'm approching the switch...
How can I achive that?

HERE you have a grafic example of what I mean




Any help would be appreciated.

Thanks

Reply With Quote

Can you help answer these questions
from other members on futures io?
NT8 - Footprint Chart adding on code
NinjaTrader
 
 
(login for full post details)
  #2 (permalink)
Dvdkite
Trieste Italy
 
 
Posts: 162 since Feb 2018
Thanks: 131 given, 23 received

UPDATE: SOLVED by adding 2 rows to the code.

This is the final version for anyone who needs them:

 
Code
inputs:
  Price( Close),
  Length( 20),
  Displace( 0),
  UpColor( green),
  DnColor (red),
  PaintInBarLRCLine ("Yes");

variables:
   LinReg( 0 ),Trend (0),Transition (0) ;

if Displace >= 0 or CurrentBar > AbsValue( Displace ) then  
  begin
    LinReg = LinearRegValue( Price, Length, 0 ) ; 
  If LinReg > LinReg [1] then
    Begin
      If Trend = -1 then Transition = 1;
     If PaintInBarLRCLine = "Yes" then Plot1[Displace]( LinReg, "LinReg", UpColor );
     SetPlotColor[Displace+1]( 1, UpColor );
      Trend = 1;
    End
  Else
    Begin
      If Trend = 1 then Transition = 1;
      If PaintInBarLRCLine = "Yes" then Plot1 [Displace] ( LinReg, "LinReg",DnColor ) ;
      SetPlotColor[Displace+1]( 1, DnColor );
      Trend = -1;
    End;
  End;

Reply With Quote
The following 2 users say Thank You to Dvdkite for this post:
 
(login for full post details)
  #3 (permalink)
Kharmaz
Orlando, FL
 
 
Posts: 18 since Jun 2014
Thanks: 10 given, 2 received


Will this Linrig work on NT8? Thanks.

Reply With Quote


futures io Trading Community Platforms and Indicators MultiCharts > Here is my Linear Regression 2 colors code - How can I anticipate the color switch?


Last Updated on February 27, 2022


Upcoming Webinars and Events
 

NinjaTrader Indicator Challenge!

Ongoing
     



Copyright © 2022 by futures io, s.a., Av Ricardo J. Alfaro, Century Tower, Panama, Ph: +507 833-9432 (Panama and Intl), +1 888-312-3001 (USA and Canada), 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