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,969 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)
  #31 (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

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

Can you help answer these questions
from other members on NexusFi?
Futures Close-Out Policy
Commodities
The space time continuum and the dynamics of a financial …
Emini and Emicro Index
Request for MACD with option to use different MAs for fa …
NinjaTrader
NT7 Indicator Script Troubleshooting - Camarilla Pivots
NinjaTrader
Looking for an MQL4 MetaTrader programmer/coder
The Elite Circle
 
Best Threads (Most Thanked)
in the last 7 days on NexusFi
Just another trading journal: PA, Wyckoff & Trends
33 thanks
Daytrading ES & NQ
32 thanks
Battlestations: Show us your trading desks!
30 thanks
Spoo-nalysis ES e-mini futures S&P 500
28 thanks
Retail Trading As An Industry
25 thanks

(login for full post details)
  #32 (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

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 NexusFi Trade Journal Reply With Quote
(login for full post details)
  #33 (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


Indeed.

Started this thread Reply With Quote
(login for full post details)
  #34 (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


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 NexusFi Trade Journal Reply With Quote
(login for full post details)
  #35 (permalink)
 ehlaban 
Netherlands
 
Experience: Advanced
Platform: Ensign, Multicharts
Trading: SP500
Posts: 91 since Nov 2009
Thanks Given: 66
Thanks Received: 57

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)
 
toddma's Avatar
 toddma 
vancouver canada
 
Experience: Intermediate
Platform: multicharts, ninjatrader
Trading: forex
Posts: 53 since Jul 2012
Thanks Given: 14
Thanks Received: 6

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)
 ehlaban 
Netherlands
 
Experience: Advanced
Platform: Ensign, Multicharts
Trading: SP500
Posts: 91 since Nov 2009
Thanks Given: 66
Thanks Received: 57

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)
 
toddma's Avatar
 toddma 
vancouver canada
 
Experience: Intermediate
Platform: multicharts, ninjatrader
Trading: forex
Posts: 53 since Jul 2012
Thanks Given: 14
Thanks Received: 6

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





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