NexusFi: Find Your Edge


Home Menu

 





bool switch... simple..


Discussion in EasyLanguage Programming

Updated
      Top Posters
    1. looks_one bnichols with 17 posts (3 thanks)
    2. looks_two toddma with 16 posts (0 thanks)
    3. looks_3 ehlaban with 4 posts (2 thanks)
    4. looks_4 Quick Summary with 1 posts (0 thanks)
    1. trending_up 9,839 views
    2. thumb_up 5 thanks given
    3. group 3 followers
    1. forum 37 posts
    2. attach_file 10 attachments




 
Search this Thread

bool switch... simple..

(login for full post details)
  #21 (permalink)
 
toddma's Avatar
 toddma 
vancouver canada
 
Experience: Intermediate
Platform: multicharts, ninjatrader
Trading: forex
Posts: 53 since Jul 2012
Thanks Given: 14
Thanks Received: 6

Really?! With the same code?

Started this thread Reply With Quote

Can you help answer these questions
from other members on NexusFi?
NT7 Indicator Script Troubleshooting - Camarilla Pivots
NinjaTrader
Wicked Renko Bars
Traders Hideout
Request for MACD with option to use different MAs for fa …
NinjaTrader
Searching for CurrentMonthOHL Indicator
NinjaTrader
ISO Equity Curve Indicator
NinjaTrader
 
Best Threads (Most Thanked)
in the last 7 days on NexusFi
Tao te Trade: way of the WLD
37 thanks
Deaddogs Stock Trading
27 thanks
GFIs1 1 DAX trade per day journal
26 thanks
Supertradersams Thread Journal on NQ/MNQ
24 thanks
Leaving CFD trading and learning futures
11 thanks

(login for full post details)
  #22 (permalink)
 ehlaban 
Netherlands
 
Experience: Advanced
Platform: Ensign, Multicharts
Trading: SP500
Posts: 91 since Nov 2009
Thanks Given: 66
Thanks Received: 57

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
(login for full post details)
  #23 (permalink)
 
bnichols's Avatar
 bnichols 
Dartmouth NS
 
Experience: Intermediate
Platform: MC, MC.Net, NT, TWS
Broker: IB / IQFeed / Kids
Trading: Forex, stocks
Posts: 637 since Feb 2010
Thanks Given: 64
Thanks Received: 460


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;	
}

Visit my NexusFi Trade Journal Reply With Quote
(login for full post details)
  #24 (permalink)
 
bnichols's Avatar
 bnichols 
Dartmouth NS
 
Experience: Intermediate
Platform: MC, MC.Net, NT, TWS
Broker: IB / IQFeed / Kids
Trading: Forex, stocks
Posts: 637 since Feb 2010
Thanks Given: 64
Thanks Received: 460

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.

Visit my NexusFi Trade Journal Reply With Quote
(login for full post details)
  #25 (permalink)
 
toddma's Avatar
 toddma 
vancouver canada
 
Experience: Intermediate
Platform: multicharts, ninjatrader
Trading: forex
Posts: 53 since Jul 2012
Thanks Given: 14
Thanks Received: 6

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
Click image for larger version

Name:	closeup.gif
Views:	196
Size:	19.7 KB
ID:	96913   Click image for larger version

Name:	mess.gif
Views:	203
Size:	47.1 KB
ID:	96914  
Started this thread Reply With Quote
(login for full post details)
  #26 (permalink)
 
bnichols's Avatar
 bnichols 
Dartmouth NS
 
Experience: Intermediate
Platform: MC, MC.Net, NT, TWS
Broker: IB / IQFeed / Kids
Trading: Forex, stocks
Posts: 637 since Feb 2010
Thanks Given: 64
Thanks Received: 460

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.




Visit my NexusFi Trade Journal Reply With Quote
(login for full post details)
  #27 (permalink)
 
bnichols's Avatar
 bnichols 
Dartmouth NS
 
Experience: Intermediate
Platform: MC, MC.Net, NT, TWS
Broker: IB / IQFeed / Kids
Trading: Forex, stocks
Posts: 637 since Feb 2010
Thanks Given: 64
Thanks Received: 460

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

Visit my NexusFi Trade Journal Reply With Quote
(login for full post details)
  #28 (permalink)
 
bnichols's Avatar
 bnichols 
Dartmouth NS
 
Experience: Intermediate
Platform: MC, MC.Net, NT, TWS
Broker: IB / IQFeed / Kids
Trading: Forex, stocks
Posts: 637 since Feb 2010
Thanks Given: 64
Thanks Received: 460

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;

Visit my NexusFi Trade Journal Reply With Quote
(login for full post details)
  #29 (permalink)
 
toddma's Avatar
 toddma 
vancouver canada
 
Experience: Intermediate
Platform: multicharts, ninjatrader
Trading: forex
Posts: 53 since Jul 2012
Thanks Given: 14
Thanks Received: 6

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...

Started this thread Reply With Quote
(login for full post details)
  #30 (permalink)
 
bnichols's Avatar
 bnichols 
Dartmouth NS
 
Experience: Intermediate
Platform: MC, MC.Net, NT, TWS
Broker: IB / IQFeed / Kids
Trading: Forex, stocks
Posts: 637 since Feb 2010
Thanks Given: 64
Thanks Received: 460


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.

Visit my NexusFi Trade Journal Reply With Quote





Last Updated on December 12, 2012


© 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