NexusFi: Find Your Edge


Home Menu

 





Problem with naming multiple entry/exits


Discussion in EasyLanguage Programming

Updated
      Top Posters
    1. looks_one Big Mike with 6 posts (1 thanks)
    2. looks_two equalizer with 6 posts (0 thanks)
    3. looks_3 NW27 with 3 posts (0 thanks)
    4. looks_4 ABCTG with 2 posts (0 thanks)
    1. trending_up 12,792 views
    2. thumb_up 2 thanks given
    3. group 8 followers
    1. forum 21 posts
    2. attach_file 0 attachments




 
Search this Thread

Problem with naming multiple entry/exits

  #1 (permalink)
 
Big Mike's Avatar
 Big Mike 
Manta, Ecuador
Site Administrator
Developer
Swing Trader
 
Experience: Advanced
Platform: Custom solution
Broker: IBKR
Trading: Stocks & Futures
Frequency: Every few days
Duration: Weeks
Posts: 50,442 since Jun 2009
Thanks Given: 33,215
Thanks Received: 101,603

I can't make this work.

The error is:
 
Code
------ Compiled with error(s): ------
syntax error, unexpected 'identificator', expecting 'string constant'
errLine 105, errColumn 7, errLineEnd 105, errColumnEnd 7
causal study:  (Function)
What I am trying to do is name each entry with a unique name, but without doing it manually.

An example of manually doing it:
 
Code
		switch (CurrentContracts)
		begin
			case 0: 	Buy ("LE # 1") 1 Contract Next Bar At MaxList(InsideAsk, MinList(sr, srskip, Lowest(Low, skiplength) + TickSize)) Limit;
			case 1: 	Buy ("LE # 2") 1 Contract Next Bar At MaxList(InsideAsk, MinList(sr, srskip, Lowest(Low, skiplength) + TickSize)) Limit;
			case 2: 	Buy ("LE # 3") 1 Contract Next Bar At MaxList(InsideAsk, MinList(sr, srskip, Lowest(Low, skiplength) + TickSize)) Limit;
			case 3: 	Buy ("LE # 4") 1 Contract Next Bar At MaxList(InsideAsk, MinList(sr, srskip, Lowest(Low, skiplength) + TickSize)) Limit;
			case 4: 	Buy ("LE # 5") 1 Contract Next Bar At MaxList(InsideAsk, MinList(sr, srskip, Lowest(Low, skiplength) + TickSize)) Limit;
			case 5: 	Buy ("LE # 6") 1 Contract Next Bar At MaxList(InsideAsk, MinList(sr, srskip, Lowest(Low, skiplength) + TickSize)) Limit;
			case 6: 	Buy ("LE # 7") 1 Contract Next Bar At MaxList(InsideAsk, MinList(sr, srskip, Lowest(Low, skiplength) + TickSize)) Limit;
			case 7: 	Buy ("LE # 8") 1 Contract Next Bar At MaxList(InsideAsk, MinList(sr, srskip, Lowest(Low, skiplength) + TickSize)) Limit;
			case 8: 	Buy ("LE # 9") 1 Contract Next Bar At MaxList(InsideAsk, MinList(sr, srskip, Lowest(Low, skiplength) + TickSize)) Limit;
			case 9: 	Buy ("LE # 10") 1 Contract Next Bar At MaxList(InsideAsk, MinList(sr, srskip, Lowest(Low, skiplength) + TickSize)) Limit;
		end;
That is what I want to avoid, because I have to build a 10 case/switch routine about 20 times in my code.

I've tried:
Buy ("LE # ", CurrentContracts + 1)

I've tried:
Buy (Text("LE # ", CurrentContracts + 1))

I've tried:
Buy (NumToStr(CurrentContracts, 0))

I've even tried just making one switch/case statement, like so:
 
Code
switch (CurrentContracts)
begin

	case 0:	begin nextlongname = "LE # 1"; nextshortname = "SE # 1"; end;
	case 1:	begin nextlongname = "LE # 2"; nextshortname = "SE # 2"; end;
	case 2:	begin nextlongname = "LE # 3"; nextshortname = "SE # 3"; end;
	case 3:	begin nextlongname = "LE # 4"; nextshortname = "SE # 4"; end;
	case 4:	begin nextlongname = "LE # 5"; nextshortname = "SE # 5"; end;
	case 5:	begin nextlongname = "LE # 6"; nextshortname = "SE # 6"; end;
	case 6:	begin nextlongname = "LE # 7"; nextshortname = "SE # 7"; end;
	case 7:	begin nextlongname = "LE # 8"; nextshortname = "SE # 8"; end;
	case 8:	begin nextlongname = "LE # 9"; nextshortname = "SE # 9"; end;
	case 9:	begin nextlongname = "LE # 10"; nextshortname = "SE # 10"; end;

end;
And then using:
Buy (nextlongname)

But same problem.

All result in the error posted above.

I am exploring other ways to get around this, but it seems like I must be doing something wrong.... surely this should work, yes?

The whole point of this is to granularly control a specific entry/exit point. I'm toying with using the PosTrade* reserve words but it would be far easier if I could just properly name the entries using a string.

Mike

We're here to help: just ask the community or contact our Help Desk

Quick Links: Change your Username or Register as a Vendor
Searching for trading reviews? Review this list
Lifetime Elite Membership: Sign-up for only $149 USD
Exclusive money saving offers from our Site Sponsors: Browse Offers
Report problems with the site: Using the NexusFi changelog thread
Follow me on Twitter Visit my NexusFi Trade Journal Started this thread Reply With Quote
Thanked by:

Can you help answer these questions
from other members on NexusFi?
MC PL editor upgrade
MultiCharts
PowerLanguage & EasyLanguage. How to get the platfor …
EasyLanguage Programming
Exit Strategy
NinjaTrader
Better Renko Gaps
The Elite Circle
How to apply profiles
Traders Hideout
 
Best Threads (Most Thanked)
in the last 7 days on NexusFi
Spoo-nalysis ES e-mini futures S&P 500
29 thanks
Tao te Trade: way of the WLD
24 thanks
Just another trading journal: PA, Wyckoff & Trends
24 thanks
Bigger Wins or Fewer Losses?
21 thanks
GFIs1 1 DAX trade per day journal
16 thanks
  #3 (permalink)
 NW27 
Newcastle, Australia
 
Experience: Intermediate
Platform: Multicharts 8 - Full Version
Broker: IB
Trading: SPI,FTSE100, 6E, 6A
Posts: 285 since Oct 2010
Thanks Given: 108
Thanks Received: 188


Hi Mike
I had the same issue but with exits.
I wanted the exits in the report to properly reflect the reason for the exit.
I found the same issue, can't use strings in the sell order line.
So i ended up with the case statement style of thing like you.

Thanks,
Neil.

(Sent from my Galaxy S2 via Tapatalk)

Reply With Quote
  #4 (permalink)
 
Big Mike's Avatar
 Big Mike 
Manta, Ecuador
Site Administrator
Developer
Swing Trader
 
Experience: Advanced
Platform: Custom solution
Broker: IBKR
Trading: Stocks & Futures
Frequency: Every few days
Duration: Weeks
Posts: 50,442 since Jun 2009
Thanks Given: 33,215
Thanks Received: 101,603

Worse, I later found out that each name has to be unique. So in all the different sections of my code, I wanted Contract #1 to always be referred to as "LE" or "SE" then "#1" for example. But it won't let me do that, as I already used that name in the code.

And it won't let me apply a CurrentBar modifier to the string....

Pretty neat.

For now, I have worked around it using a whole slew of switch/case statements, adding over 400 lines of code to my strategy.

Mike

We're here to help: just ask the community or contact our Help Desk

Quick Links: Change your Username or Register as a Vendor
Searching for trading reviews? Review this list
Lifetime Elite Membership: Sign-up for only $149 USD
Exclusive money saving offers from our Site Sponsors: Browse Offers
Report problems with the site: Using the NexusFi changelog thread
Follow me on Twitter Visit my NexusFi Trade Journal Started this thread Reply With Quote
  #5 (permalink)
 NW27 
Newcastle, Australia
 
Experience: Intermediate
Platform: Multicharts 8 - Full Version
Broker: IB
Trading: SPI,FTSE100, 6E, 6A
Posts: 285 since Oct 2010
Thanks Given: 108
Thanks Received: 188

Hi Mike
I had the same issue.
What i did was use a variable early in the code and just one set of orders at the end.
How about i send you the code. Send me a pm with your email .

Thanks,
Neil.

(Sent from my Galaxy S2 via Tapatalk)

Reply With Quote
  #6 (permalink)
 
Big Mike's Avatar
 Big Mike 
Manta, Ecuador
Site Administrator
Developer
Swing Trader
 
Experience: Advanced
Platform: Custom solution
Broker: IBKR
Trading: Stocks & Futures
Frequency: Every few days
Duration: Weeks
Posts: 50,442 since Jun 2009
Thanks Given: 33,215
Thanks Received: 101,603

I did some extra testing right now and it seems named orders are not at all what I was expecting anyway.

I wanted to name an order so I could manipulate that specific order later, by name. But it is not possible (by name), because of the "order name already in use" thing I mentioned earlier.

So for now I am just using PosTrade* and OpenEntry* reserve words to try and identify orders. I will need to rethink all this, it seems much too difficult compared to what it should be. I've asked MultiCharts for help in case I am missing something obvious.

Mike

We're here to help: just ask the community or contact our Help Desk

Quick Links: Change your Username or Register as a Vendor
Searching for trading reviews? Review this list
Lifetime Elite Membership: Sign-up for only $149 USD
Exclusive money saving offers from our Site Sponsors: Browse Offers
Report problems with the site: Using the NexusFi changelog thread
Follow me on Twitter Visit my NexusFi Trade Journal Started this thread Reply With Quote
  #7 (permalink)
 
MultiCharts's Avatar
 MultiCharts 
Columbus, Ohio, US
 
Experience: Intermediate
Platform: MultiCharts
Broker: Multiple/Multiple
Trading: ES, EUR/USD
Posts: 168 since Oct 2010
Thanks Given: 74
Thanks Received: 172

Hi Mike,

In MultiCharts the entries cannot be changed dynamically. They should be static from the very beginning of the script calculation in order to generate entries and exits properly.

The example script below shows the proper order naming routine:


 
Code
Var: PosNum(0),PosPrice1(0),PosPrice2(0),PosPrice3(0);   
 
switch (PosNum) begin
 
               case 1: Buy ("LE # 1") 1 Contract Next Bar At PosPrice1 Limit;
               case 2: Buy ("LE # 2") 1 Contract Next Bar At PosPrice2 Limit;
               case 3: Buy ("LE # 3") 1 Contract Next Bar At PosPrice3 Limit;
 
end; 

MultiCharts - Raising the Trading Standard.
Please send me a private message if you have any further questions about MultiCharts
Follow me on Twitter Reply With Quote
  #8 (permalink)
equalizer
Las Vegas, Nevada
 
Posts: 10 since Mar 2012
Thanks Given: 1
Thanks Received: 0

I encountered a similar issue - but it doesn't quite jive. I tried to set up an automatic scale out where it calculates the total order size divided by the number of units to be scaled out.

So then I encountered the unique name issue - tried using a String variable to name it, saw that it won't allow that. Tried the if/else or switch statement approach (or simply using NO name), and while that works, it only seems to do it once in my backtesting. basically, i have a catch-all in case the remaining quantity is too small to be divided in half.

When I backtest, my debug output says its issuing all the orders to sell, followed by the final. But no matter what I've tried, the chart and trade list will only show the first one, followed by the final one for the remaining size.

So my code confirms the strategy is working code-wise by outputing, for example:

Position Size: 100000
ScaleOut order #1 set for: 25000
Position Size: 75000
ScaleOut order #2 set for: 25000
Position Size: 50000
ScaleOut order #3 set for: 25000
Position Size: 25000
FINAL ScaleOut order set for: 25000

But on the chart, it will only show ScaleOut order #1 for 25000, then the next one will be the FINAL scaleout order, and for 75000!

Again, I believe I tried all the combinations of allowing multiple orders per bar. Is this some other limitation of intrabarorder generation?

Thanks...

Reply With Quote
  #9 (permalink)
 
Big Mike's Avatar
 Big Mike 
Manta, Ecuador
Site Administrator
Developer
Swing Trader
 
Experience: Advanced
Platform: Custom solution
Broker: IBKR
Trading: Stocks & Futures
Frequency: Every few days
Duration: Weeks
Posts: 50,442 since Jun 2009
Thanks Given: 33,215
Thanks Received: 101,603

Make sure you are using SetStopContract (or whatever equivalent for Shares), as it effects targets as well as stops.

Mike

We're here to help: just ask the community or contact our Help Desk

Quick Links: Change your Username or Register as a Vendor
Searching for trading reviews? Review this list
Lifetime Elite Membership: Sign-up for only $149 USD
Exclusive money saving offers from our Site Sponsors: Browse Offers
Report problems with the site: Using the NexusFi changelog thread
Follow me on Twitter Visit my NexusFi Trade Journal Started this thread Reply With Quote
  #10 (permalink)
equalizer
Las Vegas, Nevada
 
Posts: 10 since Mar 2012
Thanks Given: 1
Thanks Received: 0


I think Contract and Share are equivalent. SetStopContract is for the built-in stop though (which I am using for initial stop loss, but not for my custom trailing stop).

All that aside, I am not using stop orders (well I was, but then I changed it to market to see if that was the issue). So it's just a market order like this:

 
Code
Sell ("Out Order name") From Entry("Long Entry") outSize Contracts Next Bar At Market;
I was thinking maybe you cannot split one entry multiple times? So I could try issuing multiple order entries, but that would really not be ideal since there's a minimum commission at IB (basically 100,000 costs the same as 20,000 for forex). I realize I am splitting to less than ideal size when I exit, but I can live with that because it's for profit taking and also because I will ensure it's always trading full lots once I see it tested live more.

But perhaps that's the only way?

I worked with TradeStation a lot several years ago and I seem to remember being able to split one entry into multipel exits for stocks at that time, but, it was a long, long time ago.

Reply With Quote




Last Updated on July 26, 2016


© 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