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 4,562 views
    2. thumb_up 0 thanks given
    3. group 3 followers
    1. forum 7 posts
    2. attach_file 1 attachments




 
Search this Thread
  #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: 402

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?
SEC Chairman Calls for New Golden Age of SEC-CFTC Regula …
Traders Hideout
More Than Capable: Hegseths War Warning Validates $114M …
Prediction Markets & Event Contracts
Day 96 Missiles Hit Kuwait and Bahrain: June 15 Peace at …
Prediction Markets & Event Contracts
Iran War Prediction Markets: Ceasefire 16%, Ground Invas …
Prediction Markets & Event Contracts
Iran Ceasefire Surges to 19.5% on US 15-Point Plan -- 82 …
Prediction Markets & Event Contracts
 
Best Threads (Most Thanked)
in the last 7 days on NexusFi
Sober Journey With S&P
21 thanks
2026 Jlab journal
10 thanks
Algo automated / semi-automated trading anyone?
6 thanks
Lady Vols Primer: Trading Volatility Journal
6 thanks
2026 Fire Horse
5 thanks
  #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,669 since Jun 2009
Thanks Given: 33,669
Thanks Received: 102,557


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




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 X 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: 402

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,669 since Jun 2009
Thanks Given: 33,669
Thanks Received: 102,557


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




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 X 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,756 since Jun 2009
Thanks Given: 3,825
Thanks Received: 4,632

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 X 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: 402


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


© 2026 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 - Downloads - Top
no new posts