Looking for Linear Regression Indicator code that display up and down trend - EasyLanguage Programming | futures io social day trading
futures io futures trading


Notices

Looking for Linear Regression Indicator code that display up and down trend
Updated: Views / Replies:1,184 / 13
Created: by Dvdkite Attachments:1

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 100,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
 1  
 
Thread Tools Search this Thread
 

Looking for Linear Regression Indicator code that display up and down trend

  #1 (permalink)
Trading for Fun
Trieste Italy
 
Futures Experience: Beginner
Platform: Multichart
Broker/Data: Dtn Iqfeed
Favorite Futures: Mini dax
 
Posts: 101 since Feb 2018
Thanks: 101 given, 13 received

Looking for Linear Regression Indicator code that display up and down trend

First of all HELLO TO EVERYONE, this is my first post here :-D

I'm Looking for a Linear Regression Indicator code that display up and down trend with two different colors to use in multichart to test a strategy based on entries made where the color is changing (means the trend is supposed to invert) and in different time frame of the day.

I'm very new to easy language programming so any suggestion are appreciated.

Thanks in advance.

REgards,

David

Reply With Quote
 
  #2 (permalink)
Quick Summary
Quick Summary Post

Quick Summary is created and edited by users like you... Add FAQ's, Links and other Relevant Information by clicking the edit button in the lower right hand corner of this message.

 
  #3 (permalink)
Trading for Fun
Trieste Italy
 
Futures Experience: Beginner
Platform: Multichart
Broker/Data: Dtn Iqfeed
Favorite Futures: Mini dax
 
Posts: 101 since Feb 2018
Thanks: 101 given, 13 received


Hi Again ...

I tried to modify the standar LINEAR REGRESSION CURVE provided by multichart in order to use 2 different colors in order to show the UP and DOWN trends... here's what I've done:

 
Code
inputs:
	Price( Close ),
	Length( 9 ),
	Displace( 0 ) ;

variables:
	var0( 0 ) ,
	colorOfRegLin(yellow);

condition1 = Displace >= 0 or CurrentBar > AbsValue( Displace ) ;
if condition1 then 
	begin
	var0 = LinearRegValue( Price, Length, 0 ) ;
	Plot1[Displace]( var0, "LinReg",colorOfRegLin,2 ) ;

	                  
	if Displace <= 0 then 
		begin
		condition1 = Price > var0 and var0 > var0[1] and var0[1] <= var0[2] ;
		if condition1 then
			colorOfRegLin = white 
		else 
		begin 
		condition1 = Price < var0 and var0 < var0[1] and var0[1] >= var0[2];
		if condition1 then
			colorOfRegLin = blue ;
		end ;
		end;
	end ;
Actually it seems to work ...
But I'm not sure if it is working ALWAYS CORRECLTY. By setting the Chart with 100 ticks and 131 value for the linear regression I can see the most of the trends... but Sometimes it doesn't change color where it is supposed to do that..

Please register on futures.io to view futures trading content such as post attachment(s), image(s), and screenshot(s).


Can you see in the image that almost in the middle of the graphic there's a big UPtrend STILL in BLUE?? it shouls be white!

Anyone can try it? Maybe with the FDAX so we can compare it?

Thanks

Reply With Quote
 
  #4 (permalink)
 Vendor: www.abctradinggroup.com 
Hamburg Germany
 
Futures Experience: Advanced
Platform: Multicharts, Tradestation
Broker/Data: DTN IQ
Favorite Futures: ES
 
Posts: 1,846 since Apr 2013
Thanks: 301 given, 1,130 received
Forum Reputation: Legendary

Dvdkite,

your conditions for setting the color are very restrictive i.e. if the price doesn't match your Price > var0 or Price < var0 condition on the exact bar where the slope of the regression changes, the color wouldn't be changed.

Apart from that you might want to set the color before you plot the value, so the new color can be used right away.

Regards,

ABCTG

Reply With Quote
The following user says Thank You to ABCTG for this post:
 
  #5 (permalink)
Trading for Fun
Trieste Italy
 
Futures Experience: Beginner
Platform: Multichart
Broker/Data: Dtn Iqfeed
Favorite Futures: Mini dax
 
Posts: 101 since Feb 2018
Thanks: 101 given, 13 received


ABCTG View Post
Dvdkite,

your conditions for setting the color are very restrictive i.e. if the price doesn't match your Price > var0 or Price < var0 condition on the exact bar where the slope of the regression changes, the color wouldn't be changed.

Apart from that you might want to set the color before you plot the value, so the new color can be used right away.

Regards,

ABCTG

HIT ABCTG thanks for the answer. As I said I'm very new to strategies programming. My code was a simple modifications of the Linear Reg Curve indicator included in the power language editor.. I saw the row with the Alert ("trend is turning Up") and I simply changed it into the color modifications (same thing for the Dw trend alert).
So How would you modify this code in order to make it function correctly?
Thanks again :-D

Reply With Quote
 
  #6 (permalink)
 Vendor: www.abctradinggroup.com 
Hamburg Germany
 
Futures Experience: Advanced
Platform: Multicharts, Tradestation
Broker/Data: DTN IQ
Favorite Futures: ES
 
Posts: 1,846 since Apr 2013
Thanks: 301 given, 1,130 received
Forum Reputation: Legendary

Dvdkite,

it would depend a bit on your exact condition for the color change. You can for example use the reserved words "crosses over" and "crosses under" to check for a change in the slope of the linear regression.
This check should be performed before (i.e. above in the code) your call "Plot1", so it can use this changed color already. Otherwise you might have a delay of one bar.

If you want to make your programming life easier in the long run, I would suggest to start using meaningful variable names and not generic ones (like var0 or Condition1). This will make your code easier to read and in turn save you time.

Regards,

ABCTG

Reply With Quote
The following user says Thank You to ABCTG for this post:
 
  #7 (permalink)
Trading for Fun
Trieste Italy
 
Futures Experience: Beginner
Platform: Multichart
Broker/Data: Dtn Iqfeed
Favorite Futures: Mini dax
 
Posts: 101 since Feb 2018
Thanks: 101 given, 13 received


ABCTG View Post
Dvdkite,

it would depend a bit on your exact condition for the color change. You can for example use the reserved words "crosses over" and "crosses under" to check for a change in the slope of the linear regression.
This check should be performed before (i.e. above in the code) your call "Plot1", so it can use this changed color already. Otherwise you might have a delay of one bar.

If you want to make your programming life easier in the long run, I would suggest to start using meaningful variable names and not generic ones (like var0 or Condition1). This will make your code easier to read and in turn save you time.

Regards,

ABCTG

Hi ABCTG and thanks again for your suggestion.
As suggested from a friend I was able to obtain the correct linear reg curve with the up and down trend simply removing some restrictions from the conditions... It seems to work correctly.

 
Code
inputs:
	Price( Close ),
	Length( 131 ),
	Displace( 0 ) ;

variables:
	var0( 0 ) ,
	colorOfRegLin(yellow);

condition1 = Displace >= 0 or CurrentBar > AbsValue( Displace ) ; 
if condition1 then 
	begin
	var0 = LinearRegValue( Price, Length, 0 ) ;
	Plot1[Displace]( var0, "LinReg",colorOfRegLin,2 ) ;
		                  
	if Displace <= 0 then 
	     begin
   	 	if condition1= var0 > var0[1] then begin

          	 //Alert( "Indicator turning up" ) 
    		  SetPlotColor[1](1, cyan);  // con questo settaggio cambia colore una candela prima(credo corretto)
    		 //colorOfRegLin = cyan 
     		   		 
        	end
   	else begin 
       if condition1=var0<var0[1] then
               //Alert( "Indicator turning down" ) ;
                SetPlotColor[1](1, yellow);
               //colorOfRegLin = yellow; 
      		end;
		end;
	end;
Now I'm doing some test to better understand how the entries work in MC. I'm trying to buy when the indicator is supposed to turning up and I was tryng to create an OCO order that, If I'm not wrong, here at MC it should be coded by this way:

 
Code
if (marketposition = 0) then begin 
	buy 1 contract next bar at market;
	setstoploss(EntryPrice - 20);
	setprofittarget(Entryprice + 20); 
end
actually I'm totally confused because when I applied this signal to the FDAX 03 ( I only have something like 4 or 5 tick days of quotation (webank with t3 open give you only 1 day tick data.... ) at the first run it said that the MaxBarBack was to low(50) to calculate strategy.. then I went to the property strategy and changed it to 100.. nothing.. then 10000..nothing... then with 1000 I was able to see a lot (a hundred in 2 days) of "wrong operations"... with 2000 I can only see 1 Operation...

so what is the correct value for MaxBarsBack? what does it really mean? I (of course) checked documentation but it cannot explain to me the difference in the result....

Let me explane better: If I wanto to back test a strategy over 1 YEAR of Future tick by tick, what kind of value shall I set? I don't think that the system is requiring the total number of hystoric bars to analyze....

Regards,

David

Reply With Quote
The following user says Thank You to Dvdkite for this post:
 
  #8 (permalink)
 Vendor: www.abctradinggroup.com 
Hamburg Germany
 
Futures Experience: Advanced
Platform: Multicharts, Tradestation
Broker/Data: DTN IQ
Favorite Futures: ES
 
Posts: 1,846 since Apr 2013
Thanks: 301 given, 1,130 received
Forum Reputation: Legendary

David,

the Maximum Number of bars a study will reference are the number of bars that your studies require to be computed.
Assuming you have an average with the length of 100, this would require 100 bars to be on the chart. Consequently a strategy with an average with the length of 100 will raise the error message when you set Max Bars back lower than 100. In your case the regression requires at least "Length" number of bars before it will be computed.

It's best to use SetStopLoss and SetProfitTarget unconditionally. In your code they actually wouldn't be placed when you are in a position, because at that moment MarketPosition is different than zero.

Regards,

ABCTG

P.S.: By the way, you can use the "Thanks" button next to a post on futures.io to show your appreciation for a post.

Reply With Quote
The following 2 users say Thank You to ABCTG for this post:
 
  #9 (permalink)
Trading for Fun
Trieste Italy
 
Futures Experience: Beginner
Platform: Multichart
Broker/Data: Dtn Iqfeed
Favorite Futures: Mini dax
 
Posts: 101 since Feb 2018
Thanks: 101 given, 13 received


ABCTG View Post
David,

the Maximum Number of bars a study will reference are the number of bars that your studies require to be computed.
Assuming you have an average with the length of 100, this would require 100 bars to be on the chart. Consequently a strategy with an average with the length of 100 will raise the error message when you set Max Bars back lower than 100. In your case the regression requires at least "Length" number of bars before it will be computed.

It's best to use SetStopLoss and SetProfitTarget unconditionally. In your code they actually wouldn't be placed when you are in a position, because at that moment MarketPosition is different than zero.

Regards,

ABCTG

P.S.: By the way, you can use the "Thanks" button next to a post on futures.io to show your appreciation for a post.


Thanks againg (also with all buttons :-D), I understand how MaxBarsBack is working.

About the stop loss I changed the set up using this form (and the entry position is on another place with its proper condititions):

 
Code
if marketposition = 1 then begin

	Sell("TargetLong") 1 contract Next  Bar at (entryprice + TakeProfit) limit;
	Sell("StopLong") 1 contract Next Bar at (entryprice - StopLoss) stop;

end;
	
if marketposition = -1 then begin

	buytocover("TargetShort") 1 contract Next  Bar at (entryprice - TakeProfit) limit;
	buytocover("StopShort") 1 contract Next Bar at (entryprice + StopLoss) stop;

end;
By building a code like this it should work as an "emulated" OCO...

Regards,

David

Reply With Quote
The following user says Thank You to Dvdkite for this post:
 
  #10 (permalink)
 Vendor: www.abctradinggroup.com 
Hamburg Germany
 
Futures Experience: Advanced
Platform: Multicharts, Tradestation
Broker/Data: DTN IQ
Favorite Futures: ES
 
Posts: 1,846 since Apr 2013
Thanks: 301 given, 1,130 received
Forum Reputation: Legendary


Dvdkite,

the only thing to keep in mind that unless you are working with intra bar order generation, your stop and target won't be placed during the entry bar with the code you posted.

Regards,

ABCTG

Reply With Quote

Reply



futures io > > > > > Looking for Linear Regression Indicator code that display up and down trend




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

Fundraiser: Feeding Families in Need

December
 

How to use the Footprint Tool to Execute Trades w/Brannigan Barrett

Elite only
 

Ask Me Anything (Brokers & Platforms) w/Ilan Levy Mayer @ Cannon Trading

Dec 13
 

Battlestations! Show us your trading desks w/GFF Brokers ($750 in Prizes)

January
     

Similar Threads
Thread Thread Starter Forum Replies Last Post
Plot a Linear Regression Channel on the TSI Indicator TornadoES EasyLanguage Programming 5 October 12th, 2016 07:11 AM
Code To Program Esignals Linear Regression Channel In Trade Station dr0832 EasyLanguage Programming 2 May 16th, 2016 10:01 PM
Linear Regression Reversal Indicator zeller4 NinjaTrader 10 November 18th, 2011 11:08 PM
Painted Linear Regression Indicator essiar NinjaTrader 3 May 3rd, 2011 07:42 PM
Linear Regression Reversal Indicator shodson The Elite Circle 2 September 17th, 2009 12:06 PM


Tags
abc, average, back test, code, data, dow, easy language, easy language programming, easylanguage, es, fdax, futures, indicator, indicators, information, intra bar, intrabar, intrabarordergeneration, linreg, marketposition, maxbarsback, multichart, multicharts, neoticker, oco order, programming, regression, setstoploss, signal, slope, stop loss, stoploss, strategies, strategy, switch, t3, take profit, tick data, tradestation, trend, trends, variable, white

All times are GMT -4. The time now is 05:14 AM. (this page content is cached, log in for real-time version)

Copyright © 2018 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 2018-12-11 in 0.16 seconds with 15 queries on phoenix