bool switch... simple.. - EasyLanguage Programming | futures io social day trading
futures io futures trading


bool switch... simple..
Updated: Views / Replies:3,266 / 37
Created: by toddma Attachments:10

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 90,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
 10  
 
Thread Tools Search this Thread
 

bool switch... simple..

  #21 (permalink)
Elite Member
vancouver canada
 
Futures Experience: Intermediate
Platform: multicharts, ninjatrader
Favorite Futures: forex
 
toddma's Avatar
 
Posts: 53 since Jul 2012
Thanks: 14 given, 6 received

Really?! With the same code?

Reply With Quote
 
  #22 (permalink)
Elite Member
Netherlands
 
Futures Experience: Advanced
Platform: Ensign, Multicharts
Favorite Futures: SP500
 
Posts: 95 since Nov 2009
Thanks: 66 given, 56 received

For me to test your code can you tell what timeframe
and can you give the exact code you are using for: keltnerchannellower

Reply With Quote
 
  #23 (permalink)
Elite Member
Dartmouth NS
 
Futures Experience: Intermediate
Platform: MC, MC.Net, NT, TWS
Broker/Data: IB / IQFeed / Kids
Favorite Futures: Forex, stocks
 
bnichols's Avatar
 
Posts: 638 since Feb 2010
Thanks: 64 given, 459 received


Well....identical entry and exit code but not quite the same code because of the permutations it has been through [note much of it is commented out with {} brackets] but the changes don't affect the outcome no matter what I try.

Edited to add: Perhaps the major difference is testing for flat before entry, but removing that condition does not change the outcome.

 
Code
[IntrabarOrderGeneration = True]

inputs: Keltlen(25),
keltwid(2.5),
quantity(100000),
Num1(40), Num2(60)
;

variables:

BoolExitLong(false),
BoolExitShort(false),
isMarketPosition1(0),
isAboveKC(false),
isBelowKC(false),
isAbove(false),
isBelow(false),
isBelowMid(false),
crossesBelowUpperKC(false),
isLongBomb(false),
l20Closes(0),
l50Closes(0),
KeltWidex(1.5),
KeltnerChannelLower(0),
KeltnerChannelUpper(0),
KeltnerChannelMid(0),
isRising(false),
entryP(0),
exitP(0),
pAndL(0),
started(false),
oPS(""),
isFalling(false),
isBelowKCUpper(false),
isAboveKCUpper(false),
CloseTrade(false)
;
KeltnerChannelMid = AverageFC(Close,Keltlen);

KeltnerChannelLower = KeltnerChannelMid  - keltwid * AvgTrueRange(Keltlen);
KeltnerChannelUpper = KeltnerChannelMid  + keltwid * AvgTrueRange(Keltlen);
isRising = KeltnerChannelLower > KeltnerChannelLower [1];
isFalling = KeltnerChannelUpper < KeltnerChannelUpper [1];
isBelowKC = close[0] < KeltnerChannelLower; 
isAboveKCUpper = close[0] > KeltnerChannelUpper;// or close[0] crosses over KeltnerChannelMid or close[0] crosses over KeltnerChannelUpper   ; 
isAboveKC = close[0] crosses over KeltnerChannelLower;// or close[0] crosses over KeltnerChannelMid or close[0] crosses over KeltnerChannelUpper   ; 
isBelowKCUpper = close[0] crosses under KeltnerChannelUpper;// or close[0] crosses over KeltnerChannelMid or close[0] crosses over KeltnerChannelUpper   ; 
//isAbove = close crosses above KeltnerChannelUpper;
//isBelow = close crosses below KeltnerChannelLower;
//isBelowMid = close crosses below KeltnerChannelMid;
//crossesBelowUpperKC = close crosses below KeltnerChannelUpper;
{
if MarketPosition = 0 then begin
	if isRising and isAboveKC then begin
		Buy ("Enter long") quantity Contracts Next Bar At Market;
		Print(D:7:0," ",Time_s:6:0," Go long "); 
	end else if isFalling and isBelowKCUpper then begin
		sellshort ("Enter shot") quantity Contracts Next Bar At Market;
		Print(D:7:0," ",Time_s:6:0," Go long "); 
	end;
end;
}



// Just a long target
//if positionprofit > 4000 then begin
//sell ("target") quantity Contracts next bar at market;
//CloseTrade = False;
//end;

// Long signal (basic)
if marketposition = 0 then begin
if Average(close,Num1)[0] > Average(close,Num2)[0] then begin
buy ("long") quantity Contracts next bar at market;
Print(D," ",Time_s," buy with avg1 = ",Average(close,Num1)[0]," > avg2 =  ",Average(close,Num2)[0] );
CloseTrade = False;
end;
end; 

// Turns ON CloseTrade bool
if marketposition = 1 then begin
if close[0] <= KeltnerChannelLower then begin // (close,25,2.5)[0] then begin
Print(D," ",Time_s," close ",close," KCL ",KeltnerChannelLower);
CloseTrade = True;
end;
end;

// Just another check to make sure we're in a long position, if not CloseTrade OFF
If marketposition = 0 or marketposition = -1 then begin
CloseTrade = False;
end;

// The CloseTrade EXIT
if (marketposition = 1) and (CloseTrade = True) and (close[0] > Average(close,18)[0]) then begin
sell ("CloseTrade") quantity Contracts next bar at market;
Print(D," ",Time_s," sell with close = ",close," Avg ",Average(close,18)[0]);
CloseTrade = False;
end; 

{
		

if marketposition = 1 then begin
	if isBelowKC then begin
		Print(D:7:0," ",Time_s:6:0,"Initial Bool ON");
		BoolExitLong = true; 
	end;

 
	if BoolExitLong then begin  
		if isAboveKC then begin
			Print(D:7:0," ",Time_s:6:0," sell (bool was true exit) next bar at market");
			Print(D:7:0," ",Time_s:6:0,"Turning Bool OFF"); 
			Print(D:7:0," ",Time_s:6:0," Bool was TRUE and EXIT level reached");
			Sell ("Exit long") Next Bar quantity Contracts At Market;
			BoolExitLong = false;
		end; 
	end;	

end;	
if marketposition = -1 then begin
	if isAboveKCUpper then begin
		Print(D:7:0," ",Time_s:6:0,"Initial Bool short ON");
		BoolExitShort = true; 
	end;

 
	if BoolExitShort then begin  
		if isBelowKCUpper then begin
			Print(D:7:0," ",Time_s:6:0," sell (bool was true exit) next bar at market");
			Print(D:7:0," ",Time_s:6:0,"Turning Bool OFF"); 
			Print(D:7:0," ",Time_s:6:0," Bool was TRUE and EXIT level reached");
			buytocover ("Exit short") Next Bar quantity Contracts At Market;
			BoolExitLong = false;
		end; 
	end;	

end;	
}

Reply With Quote
 
  #24 (permalink)
Elite Member
Dartmouth NS
 
Futures Experience: Intermediate
Platform: MC, MC.Net, NT, TWS
Broker/Data: IB / IQFeed / Kids
Favorite Futures: Forex, stocks
 
bnichols's Avatar
 
Posts: 638 since Feb 2010
Thanks: 64 given, 459 received

I'm curious what happens if you replace your KeltnerChannelLower function with my definition, since it seems to be at the center of the issue.

Reply With Quote
 
  #25 (permalink)
Elite Member
vancouver canada
 
Futures Experience: Intermediate
Platform: multicharts, ninjatrader
Favorite Futures: forex
 
toddma's Avatar
 
Posts: 53 since Jul 2012
Thanks: 14 given, 6 received

ehlaban -
I am using this as a function:
inputs: PriceValue( numericseries ), Len( numericsimple ), NumATRs( numericsimple ) ;
KeltnerChannelLower = Average( PriceValue, Len ) - NumATRs * AvgTrueRange( Len ) ;

21minute bars is the timeframe


bnichols -
When I try your code I get similar results, however, if I turn on bar magnifier @ 1 minute resolution, I get a lot of weird trading right around entries and exits. I've run into this a lot, some times my charts are just a mess of in/out trading...
Any idea what is going on there? Do you see that with bar mag?

See closeup image

Attached Thumbnails
bool switch... simple..-closeup.gif   bool switch... simple..-mess.gif  
Reply With Quote
 
  #26 (permalink)
Elite Member
Dartmouth NS
 
Futures Experience: Intermediate
Platform: MC, MC.Net, NT, TWS
Broker/Data: IB / IQFeed / Kids
Favorite Futures: Forex, stocks
 
bnichols's Avatar
 
Posts: 638 since Feb 2010
Thanks: 64 given, 459 received

If I turn on bar magnifier I get your (weird) results. That is, no multiple entry/exit (although I have seen that previously) but the exit is missed--no clue why at the moment.



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

Reply With Quote
 
  #27 (permalink)
Elite Member
Dartmouth NS
 
Futures Experience: Intermediate
Platform: MC, MC.Net, NT, TWS
Broker/Data: IB / IQFeed / Kids
Favorite Futures: Forex, stocks
 
bnichols's Avatar
 
Posts: 638 since Feb 2010
Thanks: 64 given, 459 received

Furthermore, turning bar magnifier off does not fix the problem -- it is now stuck in weird mode....

Edited to add: and neither does restarting MC (fix the problem)

I suppose I should be happy I've managed to duplicate your results


Last edited by bnichols; December 11th, 2012 at 02:26 PM.
Reply With Quote
 
  #28 (permalink)
Elite Member
Dartmouth NS
 
Futures Experience: Intermediate
Platform: MC, MC.Net, NT, TWS
Broker/Data: IB / IQFeed / Kids
Favorite Futures: Forex, stocks
 
bnichols's Avatar
 
Posts: 638 since Feb 2010
Thanks: 64 given, 459 received

Fixed it by re-wrapping entry test with the marketpositionflat test:

 
Code
if marketposition = 0 then begin
if Average(close,Num1)[0] > Average(close,Num2)[0] then begin
buy ("long") quantity Contracts next bar at market;
Print(D," ",Time_s," buy with avg1 = ",Average(close,Num1)[0]," > avg2 =  ",Average(close,Num2)[0] );
CloseTrade = False;
end;
end;

Reply With Quote
The following user says Thank You to bnichols for this post:
 
  #29 (permalink)
Elite Member
vancouver canada
 
Futures Experience: Intermediate
Platform: multicharts, ninjatrader
Favorite Futures: forex
 
toddma's Avatar
 
Posts: 53 since Jul 2012
Thanks: 14 given, 6 received

haha - I suppose that is an accomplishment of sorts

The trading as seen in the close up image is the reason that I put so many CloseTrade = False snip-its throughout the code. I wanted to make sure that any time it made a trade or performed an action CloseTrade was set to False.
You can see in that close up image that we end the previous trade and the code should have turned CloseTrade bool to false, so we should not be exiting again with CloseTrade right away and yet we are. Even though we're no where near the lower KC and yet is still triggers a CloseTrade trade next bar.

I'm baffled...

Reply With Quote
 
  #30 (permalink)
Elite Member
Dartmouth NS
 
Futures Experience: Intermediate
Platform: MC, MC.Net, NT, TWS
Broker/Data: IB / IQFeed / Kids
Favorite Futures: Forex, stocks
 
bnichols's Avatar
 
Posts: 638 since Feb 2010
Thanks: 64 given, 459 received


If you do not test for flat the line

 
Code
CloseTrade = False;
will be executed every time an entry signal is generated by the MA's whether or not a new position is opened. THIS IS WHAT IS CAUSING THE HAVOC.

Edited to add: not sure why it took so long to manifest itself on my system or why turning bar magnifier on finally triggered it.

Reply With Quote

Reply



futures io > > > > > bool switch... simple..

Thread Tools Search this Thread
Search this Thread:

Advanced Search



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

Jigsaw Trading: TBA

Elite only

FuturesTrader71: TBA

Elite only

NinjaTrader: TBA

Jan 18

RandBots: TBA

Jan 23

GFF Brokers & CME Group: Futures & Bitcoin

Elite only

Adam Grimes: TBA

Elite only

Ran Aroussi: TBA

Elite only
     

Similar Threads
Thread Thread Starter Forum Replies Last Post
How often do you switch brokers? Big Mike Reviews of Brokers and Data Feeds 8 August 28th, 2012 03:17 PM
Switch Statement DonStar AmiBroker 7 August 20th, 2012 04:15 PM
Filter switch seeker NinjaTrader Programming 9 July 30th, 2012 07:22 AM
Help : Method + Switch wkmetal NinjaTrader Programming 3 October 25th, 2010 05:51 AM
CalculateOnBarClose as a bool or as a simulation within OnBarUpdate chapter SARdynamite NinjaTrader Programming 5 July 5th, 2010 02:02 AM


All times are GMT -4. The time now is 07:00 PM.

Copyright © 2017 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 2017-12-16 in 0.13 seconds with 40 queries on phoenix via your IP 54.145.16.43