NexusFi: Find Your Edge


Home Menu

 





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


Discussion in MultiCharts

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




 
 

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

 
Dvdkite
Trieste Italy
 
Posts: 162 since Feb 2018
Thanks Given: 131
Thanks Received: 25

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


Can you help answer these questions
from other members on NexusFi?
NT7 Indicator Script Troubleshooting - Camarilla Pivots
NinjaTrader
Trade idea based off three indicators.
Traders Hideout
REcommedations for programming help
Sierra Chart
ZombieSqueeze
Platforms and Indicators
How to apply profiles
Traders Hideout
 
Best Threads (Most Thanked)
in the last 7 days on NexusFi
Spoo-nalysis ES e-mini futures S&P 500
45 thanks
Just another trading journal: PA, Wyckoff & Trends
31 thanks
Bigger Wins or Fewer Losses?
24 thanks
Tao te Trade: way of the WLD
24 thanks
GFIs1 1 DAX trade per day journal
22 thanks
 
Dvdkite
Trieste Italy
 
Posts: 162 since Feb 2018
Thanks Given: 131
Thanks Received: 25

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;

Thanked by:
 
Kharmaz
Orlando, FL
 
Posts: 34 since Jun 2014
Thanks Given: 14
Thanks Received: 4


Will this Linrig work on NT8? Thanks.


 



Last Updated on February 27, 2022


© 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