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
Can you help answer these questions from other members on futures io?
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:
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
The following 2 users say Thank You to bobwest for this post:
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
The following 3 users say Thank You to ABCTG for this post:
Normally Houston TX but currently travelling a lot
Experience: Advanced
Platform: TT and Stellar
Broker: Primary Advantage Futures. Also ED&F and Tradestation
Trading: Primarily Energy but also a little Equities, Fixed Income, Metals and Crypto.
Posts: 4,747 since Dec 2013
Thanks: 4,063 given,
9,562
received
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.
The following 2 users say Thank You to SMCJB for this post: