If then If then - futures io
futures io



If then If then


Discussion in EasyLanguage Programming

Updated
      Top Posters
    1. looks_one trendisyourfriend with 1 posts (0 thanks)
    2. looks_two ABCTG with 1 posts (3 thanks)
    3. looks_3 jkepha with 1 posts (0 thanks)
    4. looks_4 bobwest with 1 posts (2 thanks)
    1. trending_up 1,208 views
    2. thumb_up 7 thanks given
    3. group 4 followers
    1. forum 4 posts
    2. attach_file 0 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
 

If then If then

(login for full post details)
  #1 (permalink)
jkepha
San Antonio, TX
 
 
Posts: 30 since Apr 2020
Thanks: 10 given, 6 received

Hello,

I haven't been able to figure this out..

Here's my goal. If condition1 then just wait until condition2 happens, then sell short.

I've been researching if...then..begin, if..then...if then..begin, once, while, and many combinations and a few others. Been playing with it for a long while. I can't get it to work.

Here's a code sample.

if condition1 begin if condition2 then sellshort

Any help would be appreciated.

Thanks,
Ryan

Reply With Quote

Can you help answer these questions
from other members on futures io?
Displaying Individual order entry bars for multiple Brac …
NinjaTrader
Looking for combined bar type (UniRenko with HeikinAshi) NT8
NinjaTrader
Bookmap replay files
Platforms and Indicators
Can anyone help convert this pine script to EasyLanguage?
EasyLanguage Programming
NFP
TradeStation
 
 
(login for full post details)
  #2 (permalink)
 bobwest 
Site Moderator
Sarasota FL
 
Experience: Advanced
Platform: Sierra Chart
Trading: ES, YM
 
bobwest's Avatar
 
Posts: 6,832 since Jan 2013
Thanks: 50,729 given, 22,750 received


jkepha View Post
Hello,

I haven't been able to figure this out..

Here's my goal. If condition1 then just wait until condition2 happens, then sell short.

I've been researching if...then..begin, if..then...if then..begin, once, while, and many combinations and a few others. Been playing with it for a long while. I can't get it to work.

Here's a code sample.

if condition1 begin if condition2 then sellshort

Any help would be appreciated.

Thanks,
Ryan

Somebody, perhaps @ABCTG, who knows what they are talking about in EasyLanguage, will probably give you a better-informed answer, but until they come along, here's my take (as a programmer, but not an EL programmer.):

Usually when a language has a begin and end construct, it sets up a block, and you will want to use that block structure in your logic. So I suggest you try something like this, which nests the conditions within different blocks (if I don't have the correct syntax for an if statement in EL, such as whether it needs a "then" or something, I'm just trying to illustrate how to do the blocks. You may have to change something to fit how EL actually does things.)

What this is intended to do is (1) if thing1 is true, then (2) check if thing2 is also true, and do something if so. Otherwise, just skip it:
 
Code
// This is not actual EasyLanguage code, but illustrates how begin/end blocks can be nested: 

if thing1
begin
     
     if thing2
     begin
          do something here
     end

end
You can see that the "outer" begin/end block is for the first condition and anything that is executed if thing1 is true. The "inner" begin/end block is what happens if thing2 is true. If you have an "if", you need a "begin", some code, and an "end". If you have another condition within that first "if" block, then the second "if" needs its own complete block. As I said, this is not necessarily literal EL code, just an illustration of how to do the blocks, assuming EL is like other block-structured languages.

I hope this works, and I hope I understood you correctly. If not, just wait for someone who actually codes in EL and knows what he's doing in it.

Bob.

When one door closes, another opens.
-- Cervantes, Don Quixote
Reply With Quote
The following 2 users say Thank You to bobwest for this post:
 
(login for full post details)
  #3 (permalink)
 ABCTG   is a Vendor
 
 
Posts: 2,291 since Apr 2013
Thanks: 419 given, 1,525 received


Ryan,

apart from your problem I would suggest using meaningful variable names as this will make your programming life much easier in the long run.
Do not use generic variables like Value1 or Condition1 as these make your code much harder to read.

You could use a boolean variable that you set to true when you first condition occurs and then include this variable in a check for your second condition that includes your actual order conditions.
Depending on your preference you could only do this while you are flat or not yet short as this would prevent situations where the variable is set while you are already in a trade.
When you are filled or when you issue the order you set this boolean variable back to false.

Regards,

ABCTG


jkepha View Post
Hello,

I haven't been able to figure this out..

Here's my goal. If condition1 then just wait until condition2 happens, then sell short.

I've been researching if...then..begin, if..then...if then..begin, once, while, and many combinations and a few others. Been playing with it for a long while. I can't get it to work.

Here's a code sample.

if condition1 begin if condition2 then sellshort

Any help would be appreciated.

Thanks,
Ryan


Follow me on Twitter Reply With Quote
The following 3 users say Thank You to ABCTG for this post:
 
(login for full post details)
  #4 (permalink)
 SMCJB 
Legendary Market Wizard
Houston, TX
 
Experience: Advanced
Platform: Trading Technologies
Broker: Primary Advantage Futures. Also ED&F and Tradestation
Trading: Primarily Energy but also a little GE, GC, SI & Bitcoin
 
Posts: 4,282 since Dec 2013
Thanks: 3,593 given, 8,548 received


bobwest View Post
 
Code
// This is not actual EasyLanguage code, but illustrates how begin/end blocks can be nested: 

if thing1
begin
     
     if thing2
     begin
          do something here
     end

end
You can see that the "outer" begin/end block is for the first condition and anything that is executed if thing1 is true. The "inner" begin/end block is what happens if thing2 is true. If you have an "if", you need a "begin", some code, and an "end". If you have another condition within that first "if" block, then the second "if" needs its own complete block. As I said, this is not necessarily literal EL code, just an illustration of how to do the blocks, assuming EL is like other block-structured languages.

Nice explanation Bob.

Maybe not relevant to this specific question but I find that when multiple (non-nested) IF statements are involved, often SWITCH & CASE can clean the code up considerably.

Reply With Quote
The following 2 users say Thank You to SMCJB for this post:
 
(login for full post details)
  #5 (permalink)
 trendisyourfriend 
Market Wizard
Quebec
 
Experience: Intermediate
Platform: NinjaTrader wt Rancho Dinero's profiling tools
Broker: AMP/CQG
Trading: ES, NQ, YM
 
trendisyourfriend's Avatar
 
Posts: 4,110 since Oct 2009
Thanks: 3,778 given, 5,332 received

I don't know if there is something similar with easylanguage but with C sharp we can convert a boolean value into a number using this syntax:

Convert.ToInt32(true) : 1
Convert.ToInt32(false): 0

For example to avoid nesting multiple blocks when looking for multiple true values you could do this:

condition1 = Convert.ToInt32(B > A)
condition2 = Convert.ToInt32(D > C)
condition3 = Convert.ToInt32(E > D)

If (condition1 + condition2 + condition3 = 3) then
do something
End If

Reply With Quote


futures io Trading Community Platforms and Indicators EasyLanguage Programming > If then If then


Last Updated on August 5, 2021


Upcoming Webinars and Events
 

NinjaTrader Indicator Challenge!

Ongoing
     



Copyright © 2021 by futures io, s.a., Av Ricardo J. Alfaro, Century Tower, Panama, Ph: +507 833-9432 (Panama and Intl), +1 888-312-3001 (USA and Canada), 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