NexusFi: Find Your Edge


Home Menu

 





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




 
Search this Thread

If then If then

  #1 (permalink)
jkepha
San Antonio, TX
 
Posts: 31 since Apr 2020
Thanks Given: 10
Thanks Received: 6

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 NexusFi?
What broker to use for trading palladium futures
Commodities
ZombieSqueeze
Platforms and Indicators
Trade idea based off three indicators.
Traders Hideout
MC PL editor upgrade
MultiCharts
Better Renko Gaps
The Elite Circle
 
  #2 (permalink)
 
bobwest's Avatar
 bobwest 
Western Florida
Site Moderator
 
Experience: Advanced
Platform: Sierra Chart
Trading: ES, YM
Frequency: Several times daily
Duration: Minutes
Posts: 8,172 since Jan 2013
Thanks Given: 57,501
Thanks Received: 26,292


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
Thanked by:
  #3 (permalink)
 ABCTG   is a Vendor
 
Posts: 2,436 since Apr 2013
Thanks Given: 482
Thanks Received: 1,629


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
Thanked by:
  #4 (permalink)
 
SMCJB's Avatar
 SMCJB 
Houston TX
Legendary Market Wizard
 
Experience: Advanced
Platform: TT and Stellar
Broker: Advantage Futures
Trading: Primarily Energy but also a little Equities, Fixed Income, Metals and Crypto.
Frequency: Many times daily
Duration: Never
Posts: 5,049 since Dec 2013
Thanks Given: 4,388
Thanks Received: 10,207


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
Thanked by:
  #5 (permalink)
 
trendisyourfriend's Avatar
 trendisyourfriend 
Quebec Canada
Market Wizard
 
Experience: Intermediate
Platform: NinjaTrader
Broker: AMP/CQG
Trading: ES, NQ, YM
Frequency: Daily
Duration: Minutes
Posts: 4,527 since Oct 2009
Thanks Given: 4,176
Thanks Received: 6,020

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




Last Updated on August 5, 2021


© 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