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


bool switch... simple..
Updated: Views / Replies:3,253 / 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..

  #1 (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

bool switch... simple..

I'm having trouble with a simple bool type switch... can anyone see the problem with this code? Here is a piece of sample code -


variables: BoolExitLong(False);
....

//exit code

if marketposition[0] = 1 then begin

if close[0] < average(close,20)[0] then
BoolExitLong = True;

if BoolExitLong = True and close[0] > average(close,50)[0] then
sell ("boolexL") next bar at market;
BoolExitLong = False;

//some more code

end;

What I'm trying to achieve here is "if a certain low level is hit, then sell at next opportunity at a higher level". Everything else works, but this doesn't... when I do get it to work its just constantly stopping out long trades - so clearly not shutting off properly. But also not really working in the first place...

Thanks in advance.

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

Answer
This post has been selected as an answer to the original posters question Answer


Hard to say at this point. The algorithm at least appears to be functional [at least according to a quick comparison of output of the following test indicator with close price in a 240 minute chart of spot EUR.USD (i.e., it appears to be generating a sell signal when close lies between the 20 and 50 SMAs and 20MA > 50MA)]

Assuming there are no errors in the rest of the code logically the go-long algorithm may be entering trades after 20 MA rises above 50 but while the close is still between them, in which case the trade would be immediately stopped out. In the chart below there are a few places this might occur (points where one might go long between the 20MA and 50MA when 20 > 50), but this does not appear to be the rule.

Code
 
Code
variables:

BoolExitLong(false),
l20Closes(0),
l50Closes(0)
;

l20Closes = average(close,20)[0];
if close[0] < l20Closes then 
BoolExitLong = True;

l50Closes = average(close,50)[0];
if BoolExitLong = True and close[0] > l50Closes  then 
Print(D," ",T," Close ",close:1:6," < average 20 closes = ",l20Closes:1:6," and > last 50 closes = ",l50Closes:1:6," sell (boolexL) next bar at market")
else
Print(D," ",T," Close ",close:1:6," average 20 closes = ",l20Closes:1:6," last 50 closes = ",l50Closes:1:6," no sell");

BoolExitLong = False;

Output
 
Code
1120614.00 1330.00 Close 1.259200 average 20 closes = 1.253040 last 50 closes = 1.252679 no sell
1120614.00 1700.00 Close 1.263400 average 20 closes = 1.253435 last 50 closes = 1.253001 no sell
1120614.00 2130.00 Close 1.262100 average 20 closes = 1.254033 last 50 closes = 1.253274 no sell
1120615.00  130.00 Close 1.263800 average 20 closes = 1.254808 last 50 closes = 1.253550 no sell
1120615.00  530.00 Close 1.263400 average 20 closes = 1.255563 last 50 closes = 1.253751 no sell
1120615.00  930.00 Close 1.261150 average 20 closes = 1.256137 last 50 closes = 1.253936 no sell
1120615.00 1330.00 Close 1.264150 average 20 closes = 1.256802 last 50 closes = 1.254354 no sell
1120615.00 1700.00 Close 1.264000 average 20 closes = 1.257560 last 50 closes = 1.254742 no sell
1120617.00 2130.00 Close 1.268600 average 20 closes = 1.258500 last 50 closes = 1.255231 no sell
1120618.00  130.00 Close 1.270600 average 20 closes = 1.259510 last 50 closes = 1.255737 no sell
1120618.00  530.00 Close 1.263950 average 20 closes = 1.260230 last 50 closes = 1.256095 no sell
1120618.00  930.00 Close 1.259150 < average 20 closes = 1.260710 and > last 50 closes = 1.256287 sell (boolexL) next bar at market
1120618.00 1330.00 Close 1.257200 < average 20 closes = 1.260825 and > last 50 closes = 1.256415 sell (boolexL) next bar at market
1120618.00 1700.00 Close 1.257600 < average 20 closes = 1.261050 and > last 50 closes = 1.256627 sell (boolexL) next bar at market
1120618.00 2130.00 Close 1.259800 < average 20 closes = 1.261058 and > last 50 closes = 1.256705 sell (boolexL) next bar at market
1120619.00  130.00 Close 1.260650 < average 20 closes = 1.261303 and > last 50 closes = 1.256755 sell (boolexL) next bar at market
1120619.00  530.00 Close 1.261100 < average 20 closes = 1.261553 and > last 50 closes = 1.256841 sell (boolexL) next bar at market
1120619.00  930.00 Close 1.264450 average 20 closes = 1.261840 last 50 closes = 1.256993 no sell
1120619.00 1330.00 Close 1.272200 average 20 closes = 1.262680 last 50 closes = 1.257272 no sell
1120619.00 1700.00 Close 1.268550 average 20 closes = 1.263253 last 50 closes = 1.257408 no sell
1120619.00 2130.00 Close 1.267200 average 20 closes = 1.263653 last 50 closes = 1.257538 no sell
1120620.00  130.00 Close 1.267650 average 20 closes = 1.263865 last 50 closes = 1.257769 no sell
1120620.00  530.00 Close 1.270300 average 20 closes = 1.264275 last 50 closes = 1.258117 no sell
1120620.00  930.00 Close 1.269850 average 20 closes = 1.264578 last 50 closes = 1.258463 no sell
1120620.00 1330.00 Close 1.270750 average 20 closes = 1.264945 last 50 closes = 1.258941 no sell
1120620.00 1700.00 Close 1.270800 average 20 closes = 1.265428 last 50 closes = 1.259465 no sell
1120620.00 2130.00 Close 1.266750 average 20 closes = 1.265558 last 50 closes = 1.259801 no sell
1120621.00  130.00 Close 1.267500 average 20 closes = 1.265733 last 50 closes = 1.260113 no sell
1120621.00  530.00 Close 1.268500 average 20 closes = 1.265728 last 50 closes = 1.260201 no sell
1120621.00  930.00 Close 1.265150 < average 20 closes = 1.265455 and > last 50 closes = 1.260221 sell (boolexL) next bar at market
1120621.00 1330.00 Close 1.256250 average 20 closes = 1.265070 last 50 closes = 1.260147 no sell
1120621.00 1700.00 Close 1.254200 average 20 closes = 1.264823 last 50 closes = 1.260121 no sell
1120621.00 2130.00 Close 1.256300 average 20 closes = 1.264778 last 50 closes = 1.260244 no sell
1120622.00  130.00 Close 1.255550 average 20 closes = 1.264675 last 50 closes = 1.260389 no sell
1120622.00  530.00 Close 1.254700 average 20 closes = 1.264420 last 50 closes = 1.260517 no sell
1120622.00  930.00 Close 1.257650 average 20 closes = 1.264270 last 50 closes = 1.260677 no sell
1120622.00 1330.00 Close 1.256450 average 20 closes = 1.264038 last 50 closes = 1.260789 no sell
1120622.00 1700.00 Close 1.257100 average 20 closes = 1.263670 last 50 closes = 1.260954 no sell
1120624.00 2130.00 Close 1.253000 average 20 closes = 1.262710 last 50 closes = 1.261018 no sell
1120625.00  130.00 Close 1.253050 average 20 closes = 1.261935 last 50 closes = 1.261071 no sell
1120625.00  530.00 Close 1.248950 average 20 closes = 1.261023 last 50 closes = 1.261059 no sell
1120625.00  930.00 Close 1.249100 average 20 closes = 1.260095 last 50 closes = 1.261050 no sell
1120625.00 1330.00 Close 1.250050 average 20 closes = 1.259083 last 50 closes = 1.260953 no sell
1120625.00 1700.00 Close 1.250450 average 20 closes = 1.258113 last 50 closes = 1.260900 no sell
1120625.00 2130.00 Close 1.252100 average 20 closes = 1.257180 last 50 closes = 1.260749 no sell
1120626.00  130.00 Close 1.250000 average 20 closes = 1.256140 last 50 closes = 1.260634 no sell
1120626.00  530.00 Close 1.248600 average 20 closes = 1.255233 last 50 closes = 1.260484 no sell
1120626.00  930.00 Close 1.247850 average 20 closes = 1.254250 last 50 closes = 1.260267 no sell
1120626.00 1330.00 Close 1.248500 average 20 closes = 1.253250 last 50 closes = 1.260129 no sell
1120626.00 1700.00 Close 1.249200 average 20 closes = 1.252453 last 50 closes = 1.259971 no sell
1120626.00 2130.00 Close 1.248500 average 20 closes = 1.252065 last 50 closes = 1.259757 no sell
1120627.00  130.00 Close 1.250250 average 20 closes = 1.251868 last 50 closes = 1.259494 no sell
1120627.00  530.00 Close 1.248900 average 20 closes = 1.251498 last 50 closes = 1.259230 no sell
1120627.00  930.00 Close 1.247850 average 20 closes = 1.251113 last 50 closes = 1.258911 no sell
1120627.00 1330.00 Close 1.247500 average 20 closes = 1.250753 last 50 closes = 1.258593 no sell
1120627.00 1700.00 Close 1.246950 average 20 closes = 1.250218 last 50 closes = 1.258309 no sell
1120627.00 2130.00 Close 1.249150 average 20 closes = 1.249853 last 50 closes = 1.258009 no sell
1120628.00  130.00 Close 1.251900 average 20 closes = 1.249592 last 50 closes = 1.257767 no sell
1120628.00  530.00 Close 1.243400 average 20 closes = 1.249113 last 50 closes = 1.257263 no sell
1120628.00  930.00 Close 1.243550 average 20 closes = 1.248638 last 50 closes = 1.256722 no sell
1120628.00 1330.00 Close 1.242600 average 20 closes = 1.248320 last 50 closes = 1.256295 no sell
1120628.00 1700.00 Close 1.244400 average 20 closes = 1.248085 last 50 closes = 1.256000 no sell
1120628.00 2130.00 Close 1.244950 average 20 closes = 1.247830 last 50 closes = 1.255755 no sell
1120629.00  130.00 Close 1.257900 average 20 closes = 1.248202 last 50 closes = 1.255761 no sell
1120629.00  530.00 Close 1.257250 average 20 closes = 1.248460 last 50 closes = 1.255710 no sell
1120629.00  930.00 Close 1.268050 average 20 closes = 1.249362 last 50 closes = 1.255858 no sell
1120629.00 1330.00 Close 1.266300 average 20 closes = 1.250248 last 50 closes = 1.255962 no sell
1120629.00 1700.00 Close 1.266850 average 20 closes = 1.251198 last 50 closes = 1.256010 no sell
1120701.00 2130.00 Close 1.263500 average 20 closes = 1.251948 last 50 closes = 1.255836 no sell
1120702.00  130.00 Close 1.262450 average 20 closes = 1.252610 last 50 closes = 1.255714 no sell
1120702.00  530.00 Close 1.264650 average 20 closes = 1.253417 last 50 closes = 1.255663 no sell
1120702.00  930.00 Close 1.260100 average 20 closes = 1.253910 last 50 closes = 1.255512 no sell
1120702.00 1330.00 Close 1.258550 average 20 closes = 1.254393 last 50 closes = 1.255277 no sell
1120702.00 1700.00 Close 1.257900 average 20 closes = 1.254895 last 50 closes = 1.255038 no sell
1120702.00 2130.00 Close 1.258300 average 20 closes = 1.255435 last 50 closes = 1.254789 no sell
1120703.00  130.00 Close 1.259650 average 20 closes = 1.256070 last 50 closes = 1.254566 no sell
1120703.00  530.00 Close 1.258700 average 20 closes = 1.256547 last 50 closes = 1.254405 no sell
1120703.00  930.00 Close 1.256700 < average 20 closes = 1.256787 and > last 50 closes = 1.254189 sell (boolexL) next bar at market
1120703.00 1330.00 Close 1.260750 average 20 closes = 1.257655 last 50 closes = 1.254034 no sell
1120703.00 1700.00 Close 1.260850 average 20 closes = 1.258520 last 50 closes = 1.253948 no sell
1120703.00 2130.00 Close 1.259250 < average 20 closes = 1.259352 and > last 50 closes = 1.254008 sell (boolexL) next bar at market
1120704.00  130.00 Close 1.259250 < average 20 closes = 1.260095 and > last 50 closes = 1.254109 sell (boolexL) next bar at market
1120704.00  530.00 Close 1.258500 < average 20 closes = 1.260773 and > last 50 closes = 1.254153 sell (boolexL) next bar at market
1120704.00  930.00 Close 1.256050 < average 20 closes = 1.260680 and > last 50 closes = 1.254163 sell (boolexL) next bar at market
1120704.00 1330.00 Close 1.253650 average 20 closes = 1.260500 last 50 closes = 1.254142 no sell
1120704.00 1700.00 Close 1.252800 average 20 closes = 1.259738 last 50 closes = 1.254045 no sell
1120704.00 2130.00 Close 1.253650 average 20 closes = 1.259105 last 50 closes = 1.253989 no sell
1120705.00  130.00 Close 1.252350 average 20 closes = 1.258380 last 50 closes = 1.253894 no sell
1120705.00  530.00 Close 1.250650 average 20 closes = 1.257738 last 50 closes = 1.253847 no sell
1120705.00  930.00 Close 1.238350 average 20 closes = 1.256533 last 50 closes = 1.253553 no sell
...

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


Last edited by bnichols; December 6th, 2012 at 09:20 PM.
Reply With Quote
The following user says Thank You to bnichols for this post:
 
  #4 (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

Hi bnichols,
I really appreciate the help. That was terrific - however, I'm still stuck on why it won't work for me.

how can I be seeing output like this…

1121107.00 557.00Bool was TRUE and EXIT level reached
1121107.00 557.00Turning Bool OFF
1121107.00 618.00Bool was TRUE and EXIT level reached
1121107.00 618.00Turning Bool OFF
1121106.00 1957.00Initial Bool ON
1121106.00 1957.00Turning Bool OFF
1121107.00 824.00Initial Bool ON
1121107.00 824.00Turning Bool OFF


with the following code blocks:

if marketposition(0) = 1 then begin

if close[0] < KeltnerChannelLower(close,Kexitlen,KeltWidex)[0] then begin
Print(D," ",T,"Initial Bool ON");
BoolExitLong = 1;
end;


if BoolExitLong = 1 then begin
if close[0] > KeltnerChannelLower(close,Keltlen,keltwid)[0] then
Print(D," ",T,"Bool was TRUE and EXIT level reached");
sell ("bool was true exit") next bar at market;
Print(D," ",T,"Turning Bool OFF");
BoolExitLong = 0;
end;
...
end;


How is it running through that last block of code and acting on the last part but not the middle part? Doesn't it only execute the two actions (and two print statements) if the first two were true? How is it only executing one of the actions?

Referring to this part of the output:
1121106.00 1957.00Initial Bool ON
1121106.00 1957.00Turning Bool OFF
1121107.00 824.00Initial Bool ON
1121107.00 824.00Turning Bool OFF

Reply With Quote
 
  #5 (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

Here is an image of whats happening as well - it appears to be closing the position on the "Bool was true exit level reached" exit - so selling at market right there, however it's not fulfilling the the second requirement of that block of code:

Close must be greater than KeltnerChannelLower
"if close[0] > KeltnerChannelLower(close,20,1.5)[0] then"

As you can see its closing below the Keltner Channel Lower, its only supposed to close when it retraces back up to the kelt band. The KeltnerChannelLower function normally works so that shouldn't be the issue...

Am i missing something... ?

Attached Thumbnails
bool switch... simple..-strange.jpg  
Reply With Quote
 
  #6 (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


toddma View Post
Here is an image of whats happening as well - it appears to be closing the position on the "Bool was true exit level reached" exit - so selling at market right there, however it's not fulfilling the the second requirement of that block of code:

Close must be greater than KeltnerChannelLower
"if close[0] > KeltnerChannelLower(close,20,1.5)[0] then"

As you can see its closing below the Keltner Channel Lower, its only supposed to close when it retraces back up to the kelt band. The KeltnerChannelLower function normally works so that shouldn't be the issue...

Am i missing something... ?

While I don't see any issues with the output versus the code snippet in post #4 (i.e., it appears to be doing exactly what it's told to do), the comment in post #5 (" it's not fulfilling the the second requirement of that block of code: Close must be greater than KeltnerChannelLower") suggests that you might be missing a begin/end block.

Right now the code will exit the position as soon as price drops below the lower Keltner boundary because the lines

 
Code
if close[0] > KeltnerChannelLower(close,Keltlen,keltwid)[0] then
Print(D," ",T,"Bool was TRUE and EXIT level reached");
simply prints out some text if the test is true, rather than controlling the exit.

You may intend the following:

 
Code
if BoolExitLong = 1 then begin
if close[0] > KeltnerChannelLower(close,Keltlen,keltwid)[0] then begin
Print(D," ",T,"Bool was TRUE and EXIT level reached");
sell ("bool was true exit") next bar at market;
Print(D," ",T,"Turning Bool OFF"); 
BoolExitLong = 0;
end;
end;

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

Answer
This post has been selected as an answer to the original posters question Answer

You seem to want to do 2 things when if BoolExitLong=True AND etc ...

Combine them in a begin end statement so they belong to that If statement
otherwise the BoolExitLong will always reset to False.
e.g.

 
Code
if BoolExitLong = True and close[0] > average(close,50)[0] then 
begin
	sell ("boolexL") next bar at market;
	BoolExitLong = False;
end;



toddma View Post
I'm having trouble with a simple bool type switch... can anyone see the problem with this code? Here is a piece of sample code -


variables: BoolExitLong(False);
....

//exit code

if marketposition[0] = 1 then begin

if close[0] < average(close,20)[0] then
BoolExitLong = True;

if BoolExitLong = True and close[0] > average(close,50)[0] then
sell ("boolexL") next bar at market;
BoolExitLong = False;

//some more code

end;

What I'm trying to achieve here is "if a certain low level is hit, then sell at next opportunity at a higher level". Everything else works, but this doesn't... when I do get it to work its just constantly stopping out long trades - so clearly not shutting off properly. But also not really working in the first place...

Thanks in advance.


Reply With Quote
 
  #8 (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

BTW, I wrote a signal to test the exit policy you describe and it appears to have a fairly robust expectancy, which means while it might be improved it may make money as is once optimized for your instrument, more money with more investment, so good luck with it

Edited to add: Which is a warning it will probably lose money trading micro lots with realistic slippage and commission


Last edited by bnichols; December 9th, 2012 at 03:58 AM.
Reply With Quote
 
  #9 (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

Hi Bnichols and Ehlaban, thank you very much for your help. Much appreciated!
I tried both of these suggestions:

 
Code
if BoolExitLong = 1 then begin
if close[0] > KeltnerChannelLower(close,Keltlen,keltwid)[0] then begin
Print(D," ",T,"Bool was TRUE and EXIT level reached");
sell ("bool was true exit") next bar at market;
Print(D," ",T,"Turning Bool OFF"); 
BoolExitLong = 0;
end;
end;

 
Code
if BoolExitLong = True and close[0] > average(close,50)[0] then 
begin
	sell ("boolexL") next bar at market;
	BoolExitLong = False;
end;
However, I was still getting a million improper exits >> as compared to what I was trying to achieve. So I started to think that it might be something else that's causing the issue.

I decided to start over with this section of code so that it is very simple and all parts of the code can be seen. I am only looking at the long side of the code to make this even simpler.

So I'll try to explain again what I am trying to do:

The entry is not important here. The exit is what I am trying to get right. The idea is that once the price closes below a certain level then an exit signal is generated (the bool turning to TRUE, no trades taking place). This means that the price is lower than the KeltnerChannel (in this case - could be a bollinger band etc) - now we're looking for a retracement to get out of the long position. I have the retracement level required set as an 18 period moving average which should always be in between the keltners.

So the bool can only be turned on when we're in a long position and when we're below the lower keltner and it will always exit once we retrace up to the moving average. It should not continue holding beyond that level...
I also have the bool being turned off after any other type of exit so that the bool is only True just before an exit takes place.

I have it acting fairly well now (as I had intended) However, I still can't account why it will only exit half of the time when "it is supposed to" - according to my intent.

Here is my current simple code (all of it):

 
Code
[IntrabarOrderGeneration = True]

inputs: Num1(40), Num2(60);
variables: CloseTrade(false);


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

// Long signal (basic)
if Average(close,Num1)[0] > Average(close,Num2)[0] then begin
buy ("long") next bar at market;
CloseTrade = False;
end;

// Turns ON CloseTrade bool
if marketposition = 1 then begin
if close[0] <= keltnerchannellower(close,25,2.5)[0] then begin
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") next bar at market;
CloseTrade = False;
end;

This issue remaining is shown below - As you can see the code has us in a long trade coming into the section shown - then price drops below the keltnerchannel lower bound around 18:45 which should have turned on the bool exit (CloseTrade = True) - it should have then been looking for price to close above the 18 period moving average. It moves above the average but nothing happens. Same thing further along at 7/11/2012 7:00-11:00 and then moves back above and through the moving average - but no exit once it gets to that level. And then for some reason the CloseTrade trade happens later on after another move below the lower keltner....

Any thoughts here? I'm really stuck...
Thanks again for all of the help.

Attached Thumbnails
bool switch... simple..-problem.gif  
Reply With Quote
 
  #10 (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


It may be time to revisit our assumptions, since my implementation of your code works 100% as expected with Multicharts

First, are you using MC or TS?

Second, I'm assuming my homebrew implementation of keltnerchannellower in the following code snippet

 
Code
KeltnerChannelMid = AverageFC(Close,Keltlen);
KeltnerChannelLower = KeltnerChannelMid  - keltwid * AvgTrueRange(Keltlen);
KeltnerChannelUpper = KeltnerChannelMid  + keltwid * AvgTrueRange(Keltlen);

(where Keltlen = 25 and keltwid = 2.5 in this case)
is essentially the same as the implementation you are using. Can you confirm what you are using for the keltnerchannellower() function ?

Finally, is the Keltner Channel you display on the chart using the same parameter values as the strategy?

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 08:43 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-13 in 0.15 seconds with 38 queries on phoenix via your IP 54.160.245.121