Dark Theme
Light Theme
Trading Articles
Article Categories
Article Tools
Welcome to NexusFi: the best trading community on the planet, with over 150,000 members Sign Up Now for Free
Genuine reviews from real traders, not fake reviews from stealth vendors
Quality education from leading professional traders
We are a friendly, helpful, and positive community
We do not tolerate rude behavior, trolling, or vendors advertising in posts
We are here to help, just let us know what you need
You'll need to
register in order to view the content of the threads and start contributing to our community.
It's free for basic access, or support us by becoming an Elite Member -- see if you qualify for a discount below.
-- Big Mike, Site Administrator
(If you already have an account, login at the top of the page)
Updated December 12, 2012
Top Posters
looks_one
bnichols
with 17 posts (3 thanks)
looks_two
toddma
with 16 posts (0 thanks)
looks_3
ehlaban
with 4 posts (2 thanks)
looks_4
Quick Summary
with 1 posts (0 thanks)
trending_up
12,387 views
thumb_up
5 thanks given
group
3 followers
forum
37 posts
attach_file
10 attachments
December 11th, 2012, 01:31 PM
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?
Can you help answer these questions from other members on NexusFi?
Best Threads (Most Thanked) in the last 7 days on NexusFi
December 11th, 2012, 01:40 PM
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
December 11th, 2012, 01:42 PM
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;
}
December 11th, 2012, 02:01 PM
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.
December 11th, 2012, 02:02 PM
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
December 11th, 2012, 02:07 PM
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.
December 11th, 2012, 02:14 PM
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
December 11th, 2012, 02:32 PM
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;
December 11th, 2012, 02:32 PM
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...
December 11th, 2012, 02:36 PM
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
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.
Last Updated on December 12, 2012