NexusFi: Find Your Edge


Home Menu

 





Cannot implicitly convert string to boolean


Discussion in NinjaTrader

Updated
      Top Posters
    1. looks_one gordo with 3 posts (0 thanks)
    2. looks_two Big Mike with 2 posts (0 thanks)
    3. looks_3 Trader.Jon with 1 posts (0 thanks)
    4. looks_4 Quick Summary with 1 posts (0 thanks)
    1. trending_up 3,921 views
    2. thumb_up 0 thanks given
    3. group 3 followers
    1. forum 7 posts
    2. attach_file 1 attachments




 
Search this Thread

Cannot implicitly convert string to boolean

  #1 (permalink)
 
gordo's Avatar
 gordo 
Tonganoxie, Kansas
 
Experience: Intermediate
Platform: NinjaTrader
Broker: Mirus Futures/Zen-Fire
Trading: CL,6E
Posts: 160 since Nov 2009
Thanks Given: 129
Thanks Received: 401

Here is the code where I am trying to build a series of boolean logic steps into a string:

privatestring tradeStringLong = "TradeReset";
privatestring tradeStringShort = "TradeReset";
.
.
.
if (UseMACD)
{
tradeStringLong += " && macdSeries[0] >= macdSeries[1]";
tradeStringShort += " && macdSeries[0] < macdSeries[1]";
}
if (UseDszlDszl)
{
tradeStringLong += " && dszlDirection1 == 1 && dszlDirection2 == 1";
tradeStringShort += " && dszlDirection1 == -1 && dszlDirection2 == -1";
}
if (UseCCI)
{
tradeStringLong += " && cciDirection == 1";
tradeStringShort += " && cciDirection == -1";
}
.
.
.

So I end up with a string with different instructions depending on which indicators I want to use. Below is where I am trying to execute the code by converting the string back to useable boolean logic:

if (tradeStringLong)
GoLong();
if (tradeStringShort)
GoShort();

This does not work and I get the error message. I looked at Eval() but that is not supported. I found Boolean.Parse() but that doesn't seem to work either. Any ideas on how to make this code work?

Visit my NexusFi Trade Journal Started this thread Reply With Quote

Can you help answer these questions
from other members on NexusFi?
Better Renko Gaps
The Elite Circle
Trade idea based off three indicators.
Traders Hideout
Pivot Indicator like the old SwingTemp by Big Mike
NinjaTrader
REcommedations for programming help
Sierra Chart
Cheap historycal L1 data for stocks
Stocks and ETFs
 
  #3 (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,469 since Jun 2009
Thanks Given: 33,246
Thanks Received: 101,669


You should wrap code with php or code tags.

From memory only, months since I did any NT programming, but I would use approach of:

 
Code
                            
tradestringlong = (macdSeries[0] >= macdSeries[1] ? true false); 

and change in init to actual boolean.

Mike



Join the free Markets Chat beta: one platform, all the trade rooms!

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 Reply With Quote
  #4 (permalink)
 
gordo's Avatar
 gordo 
Tonganoxie, Kansas
 
Experience: Intermediate
Platform: NinjaTrader
Broker: Mirus Futures/Zen-Fire
Trading: CL,6E
Posts: 160 since Nov 2009
Thanks Given: 129
Thanks Received: 401

Mike

Not exactly what I had in mind, but your comments sparked another angle to get the job done. That is to just cascade the boolean throughout. I was just trying to learn something new and cool.

Thanks Mike!

G

Visit my NexusFi Trade Journal Started this thread Reply With Quote
  #5 (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,469 since Jun 2009
Thanks Given: 33,246
Thanks Received: 101,669


gordo View Post
Mike

Not exactly what I had in mind, but your comments sparked another angle to get the job done. That is to just cascade the boolean throughout. I was just trying to learn something new and cool.

Thanks Mike!

G

Yeah actually the code I gave you was quite inefficient, but I am totally out of it lately, very sick. The condition you were evaluating was already a boolean so no need to do the true:false switch lol.

Have fun,
Mike



Join the free Markets Chat beta: one platform, all the trade rooms!

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 Reply With Quote
  #6 (permalink)
 
Trader.Jon's Avatar
 Trader.Jon 
Near the BEuTiFULL Horse Shoe
 
Experience: Beginner
Platform: NinjaTrader
Broker: MBTrading Dukascopy ZenFire
Trading: $EURUSD when it is trending
Posts: 473 since Jul 2009
Thanks Given: 401
Thanks Received: 184


gordo View Post
Mike

Not exactly what I had in mind, but your comments sparked another angle to get the job done. That is to just cascade the boolean throughout. I was just trying to learn something new and cool.

Thanks Mike!

G

gordo,

Would you please post your solution? I may find it helpful in what I am trying to do as well!

TIA!
Jon

Reply With Quote
  #7 (permalink)
 
sam028's Avatar
 sam028 
Site Moderator
 
Posts: 3,765 since Jun 2009
Thanks Given: 3,825
Thanks Received: 4,629

You can maybe rewrite your own Eval(), using the CSharpCodeProvider class, which will compile/execute the code previously generated by the indicator.
But not efficient at all, it's for @gordo who was looking for something "new and cool", but may not to be use in serious code.

Success requires no deodorant! (Sun Tzu)
Follow me on Twitter Reply With Quote
  #8 (permalink)
 
gordo's Avatar
 gordo 
Tonganoxie, Kansas
 
Experience: Intermediate
Platform: NinjaTrader
Broker: Mirus Futures/Zen-Fire
Trading: CL,6E
Posts: 160 since Nov 2009
Thanks Given: 129
Thanks Received: 401


Trader.Jon View Post
gordo,

Would you please post your solution? I may find it helpful in what I am trying to do as well!

TIA!
Jon


Jon

Took me MONTHS to figure this out. Better than years....I guess!

Here is what I did. I was hoping for something cooler, but this works.

Gordo

Attached Files
Elite Membership required to download: text.txt
Visit my NexusFi Trade Journal Started this thread Reply With Quote




Last Updated on February 22, 2011


© 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