NexusFi: Find Your Edge


Home Menu

 





Automated Trading Need Some Help


Discussion in EasyLanguage Programming

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




 
Search this Thread

Automated Trading Need Some Help

  #1 (permalink)
jpthegreek1
Charlotte North Carolina
 
Posts: 11 since Sep 2019
Thanks Given: 3
Thanks Received: 0

 
Code
inputs:  
  Price( Close ),
  Length( 53 ),
  upcolor( Green ),
  downcolor( Red );
   
var:
  HullAvg( 0 ),
  IntraBarPersist color( 0 );
   
HullAvg = HMA( Price, Length );
 
//plot1 [Displace](HullAvg);  
 
if HullAvg > hullAvg[1] then begin
	//SetPlotColor(1, upcolor);
	color = upcolor;
end else begin
	//SetPlotColor(1, downcolor);
	color = downcolor;
end;

{buy sell Criteria}

if color[1] <> color then
	if color = upcolor then
		Buy ("B") next bar at market
	else
		if color = downcolor then
			Sell ("S") next bar at market;

Reply With Quote

Can you help answer these questions
from other members on NexusFi?
ZombieSqueeze
Platforms and Indicators
Better Renko Gaps
The Elite Circle
Trade idea based off three indicators.
Traders Hideout
Exit Strategy
NinjaTrader
Increase in trading performance by 75%
The Elite Circle
 
Best Threads (Most Thanked)
in the last 7 days on NexusFi
Just another trading journal: PA, Wyckoff & Trends
36 thanks
Tao te Trade: way of the WLD
24 thanks
Bigger Wins or Fewer Losses?
19 thanks
GFIs1 1 DAX trade per day journal
16 thanks
Spoo-nalysis ES e-mini futures S&P 500
15 thanks
  #2 (permalink)
 
Fu510n's Avatar
 Fu510n 
Suffield, CT
 
Experience: Advanced
Platform: MC, TS, Python, Rust
Broker: IB, IQFeed, TS, Kraken
Trading: ES, NQ, RTY, YM, CL, RB, 6E
Frequency: Several times daily
Duration: Seconds
Posts: 144 since Oct 2009
Thanks Given: 902
Thanks Received: 143


jpthegreek1 View Post
[/CODE]

Looks like you commented out the code for some reason - either way, welcome to the adventure...

Your code as was wouldn't compile on MultiCharts for a variety of reasons; tweaked variant below at least now compiles (for starters you can't/shouldn't mix indicator calls with signal code):
 
Code
inputs:  
  Price( Close ),
  Length( 53 ),
  upcolor( Green ),
  downcolor( Red );
   
var:
  HullAvg( 0 ),
  IntraBarPersist color( 0 );
   
HullAvg = HMA( Price, Length );
 
//plot1 [Displace](HullAvg);  
 
if HullAvg > HullAvg[1] then begin
	//SetPlotColor(1, upcolor);
	color = upcolor;
end else begin
	//SetPlotColor(1, downcolor);
	color = downcolor;
end;

{buy sell Criteria}

if MarketPosition = 0 then begin

	if color[1] <> color then
		if color = upcolor then
			Buy ("LE") next bar at market
		else
			if color = downcolor then
				SellShort ("SE") next bar at market;

end else begin

	if MarketPosition = 1 and color = downcolor then
		Sell ("SX") next bar at market
	else
		if MarketPosition = -1 and color = upcolor then
			BuyToCover ("LX") next bar at market;

end;

...but I'm not sure exactly what you're trying to accomplish (exactly), i.e.
  • do you want to always be "in the market" but keep flipping buy/sell whenever the color changes?
  • is it safe to assume you're willing to wait until a bar closes before making buy/sell decisions? (i.e. intrabar, the color may change multiple times in either direction in whipsaw fashion)
  • not sure if the above was meant to be "entry-only" signals in which case you need additional code for managing exits (i.e. check for "MarketPosition = 0")
  • the above is long-only entry-wise - will need a bit more tweaking depending on what you're actually trying to accomplish
My .02...backtesting the above with a single NQM0 contract for the past month netted $110k ($977k GP, -$867 GL; not my cup of tea as W/L ratio is only 34% but I suppose you could technically live on $1M+/year)

Follow me on Twitter Reply With Quote
  #3 (permalink)
jpthegreek1
Charlotte North Carolina
 
Posts: 11 since Sep 2019
Thanks Given: 3
Thanks Received: 0



Fu510n View Post
Looks like you commented out the code for some reason - either way, welcome to the adventure...

Your code as was wouldn't compile on MultiCharts for a variety of reasons; tweaked variant below at least now compiles (for starters you can't/shouldn't mix indicator calls with signal code):
 
Code
inputs:  
  Price( Close ),
  Length( 53 ),
  upcolor( Green ),
  downcolor( Red );
   
var:
  HullAvg( 0 ),
  IntraBarPersist color( 0 );
   
HullAvg = HMA( Price, Length );
 
//plot1 [Displace](HullAvg);  
 
if HullAvg > hullAvg[1] then begin
	//SetPlotColor(1, upcolor);
	color = upcolor;
end else begin
	//SetPlotColor(1, downcolor);
	color = downcolor;
end;

{buy sell Criteria}

if color[1] <> color then
	if color = upcolor then
		Buy ("B") next bar at market
	else
		if color = downcolor then
			Sell ("S") next bar at market;

...but I'm not sure exactly what you're trying to accomplish (exactly), i.e.
  • do you want to always be "in the market" but keep flipping buy/sell whenever the color changes?
  • is it safe to assume you're willing to wait until a bar closes before making buy/sell decisions? (i.e. intrabar, the color may change multiple times in either direction in whipsaw fashion)
  • not sure if the above was meant to be "entry-only" signals in which case you need additional code for managing exits (i.e. check for "MarketPosition = 0")
  • the above is long-only entry-wise - will need a bit more tweaking depending on what you're actually trying to accomplish
My .02...backtesting the above with a single NQM0 contract for the past month netted $110k ($977k GP, -$867 GL; not my cup of tea as W/L ratio is only 34% but I suppose you could technically live on $1M+/year)

I am not sure how I did that. I was trying to add more comments. I will fix it. Thank you for the help. Also I am on tradestation will this work there?

Reply With Quote
  #4 (permalink)
 
Fu510n's Avatar
 Fu510n 
Suffield, CT
 
Experience: Advanced
Platform: MC, TS, Python, Rust
Broker: IB, IQFeed, TS, Kraken
Trading: ES, NQ, RTY, YM, CL, RB, 6E
Frequency: Several times daily
Duration: Seconds
Posts: 144 since Oct 2009
Thanks Given: 902
Thanks Received: 143


jpthegreek1 View Post
I am not sure how I did that. I was trying to add more comments. I will fix it. Thank you for the help. Also I am on tradestation will this work there?

No worries - we all have to start somewhere . I've spent 30+ years in IT (and about 20 trading) so I had the advantage of a Computer Science background to start with.

FYI, MultiCharts was written by some of the developers that wrote TradeStation hence the parallels with EasyLanguage syntax so most code should be interchangeable (TS does support OO which I with MC had). TradeStation is better in some ways, not so much in others, but either is easier to code strategies and indicators on than having to write something object oriented in C# or Java IMHO (e.g. NinjaTrader, etc.). I've been doing more coding of late in Python...

That being said, just don't get caught chasing the holy grail - backtesting strategies is only one part of a workable system (and be wary of results using if Heikin-Ashi, Renko, etc. bar types). Also, the operational side of having to deal with "hiccups" can take up as much code as the strategies themselves (done properly anyway) so there's value with testing against demo/paper accounts before losing (I mean making) real $$$ .

Best of luck!

Follow me on Twitter Reply With Quote
Thanked by:
  #5 (permalink)
jpthegreek1
Charlotte North Carolina
 
Posts: 11 since Sep 2019
Thanks Given: 3
Thanks Received: 0


Fu510n View Post
No worries - we all have to start somewhere . I've spent 30+ years in IT (and about 20 trading) so I had the advantage of a Computer Science background to start with.

FYI, MultiCharts was written by some of the developers that wrote TradeStation hence the parallels with EasyLanguage syntax so most code should be interchangeable (TS does support OO which I with MC had). TradeStation is better in some ways, not so much in others, but either is easier to code strategies and indicators on than having to write something object oriented in C# or Java IMHO (e.g. NinjaTrader, etc.). I've been doing more coding of late in Python...

That being said, just don't get caught chasing the holy grail - backtesting strategies is only one part of a workable system (and be wary of results using if Heikin-Ashi, Renko, etc. bar types). Also, the operational side of having to deal with "hiccups" can take up as much code as the strategies themselves (done properly anyway) so there's value with testing against demo/paper accounts before losing (I mean making) real $$$ .

Best of luck!

LOL thanks.

Is there anyway to make it execute a trade multiple times in a candle if the color keeps changing? Like when the hull line would start to flicker I want it to execute the sell or buy.

Reply With Quote
  #6 (permalink)
 
Fu510n's Avatar
 Fu510n 
Suffield, CT
 
Experience: Advanced
Platform: MC, TS, Python, Rust
Broker: IB, IQFeed, TS, Kraken
Trading: ES, NQ, RTY, YM, CL, RB, 6E
Frequency: Several times daily
Duration: Seconds
Posts: 144 since Oct 2009
Thanks Given: 902
Thanks Received: 143


jpthegreek1 View Post
LOL thanks.

Is there anyway to make it execute a trade multiple times in a candle if the color keeps changing? Like when the hull line would start to flicker I want it to execute the sell or buy.

Technically - yes, though I wouldn't recommend it. Look up "Intrabar Order Generation" on either TradeStation or MultiCharts; typically signals are generated only at the close/end of each bar though that can be adjusted (either at compilation or run-time) to be tick-by-tick-based.

The issue you'll run into though is order fill time (i.e. slippage) which you need to assume can/will eat up 50ms-5s (or worse) depending on broker, trading server co-location near exchange (or not), etc. I've done some studies in the past where I generated signals based on "commitment level"; i.e. trades within a bar heading predominantly in one direction vs. a continuous "battle" between bulls & bears. Didn't really amount to much from what I recall, at least not with any constancy. Might be something where Machine Learning can be applied with better success but I haven't done enough with ML yet (and integrating ML with retail trading platforms isn't a small task).

Simple tends to work "better" (i.e. more consistently) with the caveat that you also need to understand (and have coded for) market context, money management and general broker/internet-induced gremlins along with whatever signal you're looking for (HMA or otherwise).

Follow me on Twitter Reply With Quote
  #7 (permalink)
jpthegreek1
Charlotte North Carolina
 
Posts: 11 since Sep 2019
Thanks Given: 3
Thanks Received: 0

I can't get the code to execute in the same bar on tradestation nor multi charts

Reply With Quote




Last Updated on July 25, 2020


© 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