bool switch... simple.. - futures io
futures io futures trading



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 5,603 views
    2. thumb_up 5 thanks given
    3. group 3 followers
    1. forum 37 posts
    2. attach_file 10 attachments




Welcome to futures io: the largest futures trading community on the planet, with well over 125,000 members
  • 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 and simple.

-- Big Mike, Site Administrator

(If you already have an account, login at the top of the page)

 
Search this Thread
 

bool switch... simple..

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

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.

Started this thread Reply With Quote

Can you help answer these questions
from other members on futures io?
ZigZag with Depth and Backstep
EasyLanguage Programming
Automatic pattern research with NT
Elite Algorithmic NinjaTrader Trading
Webinar: Finding your own way in trading w/Adam Grimes
The Elite Circle
Tools for backtesting?
Platforms and Indicators
NT8 indicator to simulate a Funding Evaluation where to …
NinjaTrader
 
 
(login for full post details)
  #3 (permalink)
Dartmouth NS
 
Experience: Intermediate
Platform: MC, MC.Net, NT, TWS
Broker: IB / IQFeed / Kids
Trading: Forex, stocks
 
bnichols's Avatar
 
Posts: 638 since Feb 2010
Thanks: 64 given, 460 received


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:

Visit my futures io Trade Journal Reply With Quote
 
(login for full post details)
  #4 (permalink)
vancouver canada
 
Experience: Intermediate
Platform: multicharts, ninjatrader
Trading: 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

Started this thread Reply With Quote
 
(login for full post details)
  #5 (permalink)
vancouver canada
 
Experience: Intermediate
Platform: multicharts, ninjatrader
Trading: 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
Click image for larger version

Name:	strange.jpg
Views:	49
Size:	102.5 KB
ID:	96668  
Started this thread Reply With Quote
 
(login for full post details)
  #6 (permalink)
Dartmouth NS
 
Experience: Intermediate
Platform: MC, MC.Net, NT, TWS
Broker: IB / IQFeed / Kids
Trading: Forex, stocks
 
bnichols's Avatar
 
Posts: 638 since Feb 2010
Thanks: 64 given, 460 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;

Visit my futures io Trade Journal Reply With Quote
 
(login for full post details)
  #7 (permalink)
Netherlands
 
Experience: Advanced
Platform: Ensign, Multicharts
Trading: SP500
 
Posts: 92 since Nov 2009
Thanks: 66 given, 57 received

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

Visit my futures io Trade Journal Reply With Quote
 
(login for full post details)
  #9 (permalink)
vancouver canada
 
Experience: Intermediate
Platform: multicharts, ninjatrader
Trading: 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
Click image for larger version

Name:	problem.gif
Views:	45
Size:	16.5 KB
ID:	96847  
Started this thread Reply With Quote
 
(login for full post details)
  #10 (permalink)
Dartmouth NS
 
Experience: Intermediate
Platform: MC, MC.Net, NT, TWS
Broker: IB / IQFeed / Kids
Trading: Forex, stocks
 
bnichols's Avatar
 
Posts: 638 since Feb 2010
Thanks: 64 given, 460 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?

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

Agreed
Your KeltnerChannelLower is the same as mine. I am using MultiCharts.

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

Rgr.

All that leaves is to double check you've parameterized the Keltner indicator on the chart and the function in the signal the same way....

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

I use that keltner function in other signals and plot the keltner indicator separately and they always seem to match up. I don't imagine that is the issue. I think I did even try taking it out and using a different requirement for that part. I think I tried RSI, if RSI was below a certain level then it was supposed to turn the TradeClose bool to True. Same issue though.

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

Alrighty then. When assumption checking fails time to put on our thinking caps.

Can you post 2 things:

1. a screenshot of the entire chart containing the offending trade compressed so that the image contains both the entry and the exit if possible (but not so compressed numbers on the axes are not discernible), but of main interest is the exit, the time axis at the bottom and price axis at the right; and,

2. the instrument your're working with?

I love a puzzle.

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

Definitely. Thanks a lot!

Started this thread Reply With Quote
 
(login for full post details)
  #16 (permalink)
vancouver canada
 
Experience: Intermediate
Platform: multicharts, ninjatrader
Trading: forex
 
toddma's Avatar
 
Posts: 53 since Jul 2012
Thanks: 14 given, 6 received

The second chart is further back - you can see another 2 instances where it should have triggered the exit.
One around the beginning of the 30th and one on the 25th. The asset is AUDJPY and the timeframe was a 21 minute chart.

*The entry related to the exit we were looking at is on the 29th.

Attached Thumbnails
Click image for larger version

Name:	111.gif
Views:	38
Size:	58.5 KB
ID:	96860   Click image for larger version

Name:	2222.gif
Views:	45
Size:	63.8 KB
ID:	96861  
Started this thread Reply With Quote
 
(login for full post details)
  #17 (permalink)
Dartmouth NS
 
Experience: Intermediate
Platform: MC, MC.Net, NT, TWS
Broker: IB / IQFeed / Kids
Trading: Forex, stocks
 
bnichols's Avatar
 
Posts: 638 since Feb 2010
Thanks: 64 given, 460 received

Aha.

The first thing to notice is that the trade spanned not one but many session boundaries which (given my experience with Interactive Brokers and NT) probably means all bets are off for automated strategies running on platforms designed for retail traders.

I'm a day trader (at least don't leave strategies running overnight because of my experience with IB and NT ) and still learning MC so would have to discover if MC has issues similar to NT, assuming we can rule out IB as the common factor.

In any event clearly it seems the trade should have exited around 4 AM on the 30th of October, soon after the trade was entered (in swing trading terms).

I can understand your confusion but I'm curious why it exited at all since it makes no sense to me unless it was a live trade--in which case it's my experience 3rd party retail platforms tend to fall apart.

Can you confirm it exited automatically (confirm you did not kill it to make the exit) and that this is a backtesting result rather than an actual live trade?

While I assume it's a backtest, if a live trade for the record can you confirm 2 things:

1. whether you tinkered with the signal or the chart or even turned your computer off and back on between Oct 29 (entry) and Dec 8 (exit)?
2. whether your broker is IB?

Tough puzzle. I already know your answer is that it was a backtest

At this point should probably post the....

Disclaimer

All my tests have been on bar intervals likely to give an intraday exit rather than a 21 minute bar interval--the assumption I missed-- and this is probably the key. Should confess I may not be able to help you with this if the strat runs past session close and if so there are 2 choices: close at end of session or wait for someone better informed than I (your future self perhaps!) to parachute in.

If it's a backtest it may be a bug in MC, in which case have to ask are you running 8 or 8.5 (beta). NT at least can handle backtests (screws up in real time). Otherwise I've learned not to trust a retail broker/platform pair for strategies overnight exactly because of insoluble swing trade issues of this sort :-/

Edited to add: That's one reason I use IB's interface (TWS) for swing trades.

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

Hmmm interesting..

This was a backtest in MC using IQFeed data. If/when trading live I use MC with IB as my data and broker. I haven't had any issues with multi-day trades in a live environment with MC and IB though.

I just took a look back through the data and found a situation where the entry, the exit trigger (bool) was triggered and the price retraced to the moving average all within the same day and the trade did not exit as it should have (I will post that below).

Yeah it's really quite confusing to me why it exits when it does - it seems to ignore other situations that seem to be equivalent in all respects...

Thanks again for your help on this - maybe I should just try approaching this from a different angle?

Attached Thumbnails
Click image for larger version

Name:	SameDay.gif
Views:	37
Size:	16.0 KB
ID:	96865  
Started this thread Reply With Quote
 
(login for full post details)
  #19 (permalink)
Dartmouth NS
 
Experience: Intermediate
Platform: MC, MC.Net, NT, TWS
Broker: IB / IQFeed / Kids
Trading: Forex, stocks
 
bnichols's Avatar
 
Posts: 638 since Feb 2010
Thanks: 64 given, 460 received

I'm not gone yet...just out of quick solutions

Keep us posted.

Edited to add: perhaps my last words didn't express the passion I feel for a puzzle I can't solve

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

For the record here is what I'm seeing (in this case a 21 minute AUD.JPY chart with the signal applied, data courtesy of IB). The entry is slightly different presumably because of the different feed, given the signal MAs (cyan and magenta) are intertwined around the point of entry, but the exit is as expected :-/


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

Really?! With the same code?

Started this thread Reply With Quote
 
(login for full post details)
  #22 (permalink)
Netherlands
 
Experience: Advanced
Platform: Ensign, Multicharts
Trading: SP500
 
Posts: 92 since Nov 2009
Thanks: 66 given, 57 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
 
(login for full post details)
  #23 (permalink)
Dartmouth NS
 
Experience: Intermediate
Platform: MC, MC.Net, NT, TWS
Broker: IB / IQFeed / Kids
Trading: Forex, stocks
 
bnichols's Avatar
 
Posts: 638 since Feb 2010
Thanks: 64 given, 460 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;	
}

Visit my futures io Trade Journal Reply With Quote
 
(login for full post details)
  #24 (permalink)
Dartmouth NS
 
Experience: Intermediate
Platform: MC, MC.Net, NT, TWS
Broker: IB / IQFeed / Kids
Trading: Forex, stocks
 
bnichols's Avatar
 
Posts: 638 since Feb 2010
Thanks: 64 given, 460 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.

Visit my futures io Trade Journal Reply With Quote
 
(login for full post details)
  #25 (permalink)
vancouver canada
 
Experience: Intermediate
Platform: multicharts, ninjatrader
Trading: 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
Click image for larger version

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

Name:	mess.gif
Views:	44
Size:	47.1 KB
ID:	96914  
Started this thread Reply With Quote
 
(login for full post details)
  #26 (permalink)
Dartmouth NS
 
Experience: Intermediate
Platform: MC, MC.Net, NT, TWS
Broker: IB / IQFeed / Kids
Trading: Forex, stocks
 
bnichols's Avatar
 
Posts: 638 since Feb 2010
Thanks: 64 given, 460 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.




Visit my futures io Trade Journal Reply With Quote
 
(login for full post details)
  #27 (permalink)
Dartmouth NS
 
Experience: Intermediate
Platform: MC, MC.Net, NT, TWS
Broker: IB / IQFeed / Kids
Trading: Forex, stocks
 
bnichols's Avatar
 
Posts: 638 since Feb 2010
Thanks: 64 given, 460 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

Visit my futures io Trade Journal Reply With Quote
 
(login for full post details)
  #28 (permalink)
Dartmouth NS
 
Experience: Intermediate
Platform: MC, MC.Net, NT, TWS
Broker: IB / IQFeed / Kids
Trading: Forex, stocks
 
bnichols's Avatar
 
Posts: 638 since Feb 2010
Thanks: 64 given, 460 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;

Visit my futures io Trade Journal Reply With Quote
 
(login for full post details)
  #29 (permalink)
vancouver canada
 
Experience: Intermediate
Platform: multicharts, ninjatrader
Trading: 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...

Started this thread Reply With Quote
 
(login for full post details)
  #30 (permalink)
Dartmouth NS
 
Experience: Intermediate
Platform: MC, MC.Net, NT, TWS
Broker: IB / IQFeed / Kids
Trading: Forex, stocks
 
bnichols's Avatar
 
Posts: 638 since Feb 2010
Thanks: 64 given, 460 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.

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

Ohhh! Clever...


That was just the "long signal basic" though correct? Does that resolve the issue seen in that close up image for you?

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

Thanks but in my case not clever so much as persevering :-/ I couldn't see the error until I could duplicate the problem--funny how the mind works.

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

Indeed.

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


toddma View Post
That was just the "long signal basic" though correct? Does that resolve the issue seen in that close up image for you?

You're getting multiple intrabar orders at exits likely because

1. bar magnifier is on
2. entry conditions exist at the time (i.e., fast MA > slow MA); and
3. Your profit exit*** is causing the trade to close very quickly--you might want to confirm you have the symbol settings (scale, movement and bigpointvalue) configured properly.

***
 
Code
// Just a long target
if positionprofit > 4000 then begin
sell ("target") quantity Contracts next bar at market;
CloseTrade = False;
end;
In general (i.e., even with bar magnifier off and no profit exit) new orders will be generated when the last trade closes if entry conditions exist.

Visit my futures io Trade Journal Reply With Quote
 
(login for full post details)
  #35 (permalink)
Netherlands
 
Experience: Advanced
Platform: Ensign, Multicharts
Trading: SP500
 
Posts: 92 since Nov 2009
Thanks: 66 given, 57 received

Yes, depending on what the entry signal is perhaps you better can use
Cross Above or Cross Below with the MA's

Also all the CloseTrade switches is rather confusing make a condition
and check it rather then switching it on or off

condition1 = close <= keltnerchannellower(close,25,2.5)

if marketposition = 1 AND condition1 then
etc etc



bnichols View Post
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
The following user says Thank You to ehlaban for this post:
 
(login for full post details)
  #36 (permalink)
vancouver canada
 
Experience: Intermediate
Platform: multicharts, ninjatrader
Trading: forex
 
toddma's Avatar
 
Posts: 53 since Jul 2012
Thanks: 14 given, 6 received

bnichols -
I have bar magnifier on, but it doesn't seem to be an issue with other scripts I use. I have that profit target turned off for simplicity and all of the exits that follow the entries are "CloseTrade" exits. So it must still have something to do with the CloseTrade code...
If you think about the order of events in the code the CloseTrade exit is last and the last thing in that block is to turn the CloseTrade variable to False. So how could the next bar after re-entering (which also has a CloseTrade = False in it) still execute the CloseTrade Exit further down the code (which requires CloseTrade = True)?

ehlaban -
I don't see how using conditions would replace using the bool variable we have- is that what you are suggesting? I agree it would be simpler and clearer but I don't think the same end goal can be achieved.. ? unless I am missing something?

Started this thread Reply With Quote
 
(login for full post details)
  #37 (permalink)
Netherlands
 
Experience: Advanced
Platform: Ensign, Multicharts
Trading: SP500
 
Posts: 92 since Nov 2009
Thanks: 66 given, 57 received

I now understand the logic about the CloseTrade better. It indeed is a switch.

A thing i noticed is that when exiting a trade next bar at market
it is possible that another buy is given in the same next bar due to the
IntrabarOrder etc etc. You could use sell this bar at close but this code works for me:

 
Code
[IntrabarOrderGeneration = True]

inputs: Num1(40), Num2(60), Num3(18), profitamount(4000);
variables: CloseTrade(false);



If marketposition = 0 then
begin
	CloseTrade = False;

	if Average(close, Num1) Cross Above Average(close, Num2) then 
	buy ("long") next bar at market;
end;

if marketposition = 1 AND CloseTrade = False then
begin
	if Close <= keltnerchannellower(Close, 25, 2.5) then CloseTrade = true;
end;


if marketposition = 1 AND CloseTrade = True then
begin
 	if Close > Average(Close, Num3) then sell ("CloseTrade") next bar at market;
end;


SetStopContract;
SetProfitTarget(profitamount);

Reply With Quote
The following user says Thank You to ehlaban for this post:
 
(login for full post details)
  #38 (permalink)
vancouver canada
 
Experience: Intermediate
Platform: multicharts, ninjatrader
Trading: forex
 
toddma's Avatar
 
Posts: 53 since Jul 2012
Thanks: 14 given, 6 received

Hi Ehlaban - I think you've solved this puzzle! I haven't had a chance to take a close look yet, but initially all seems to be functioning as it "should" even with intrabarorder gen!
Great job.
Thanks for your help!

Started this thread Reply With Quote


futures io Trading Community Platforms and Indicators EasyLanguage Programming > bool switch... simple..


Last Updated on December 12, 2012


Upcoming Webinars and Events
 

NinjaTrader Indicator Challenge!

Ongoing
 

Battlestations! Show us your trading desk - $1,500 in prizes!

March
 

Importance of Finding Your Own Way w/Adam Grimes

Elite only
 

Journal Challenge w/Jigsaw

April
     



Copyright © 2021 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