Login Page - Create Account

Support Board


Date/Time: Sat, 20 Apr 2024 10:30:10 +0000



How do I write spreadsheet code utalizing"IF"

View Count: 1342

[2014-04-14 12:41:36]
User14682 - Posts: 83
I am interested in using "IF" to make my existing code better.

Existing Buy Code: =OR(AND(AA3>AG3,AA4<AG4,AG3>AC3,AG3>AE3,AG3>AI3),AND(AA3>AI3,AA4<AI4,AI3>AC3,AI3>AE3,AI3>AG3),AND(AA3>AC3,AA4<AC4,AC3>AE3,AC3>AG3,AC3>AI3))


I would like to say If:
=OR(AND(AA3>AG3,AA4<AG4,AG3>AC3,AG3>AE3,AG3>AI3),AND(AA3>AI3,AA4<AI4,AI3>AC3,AI3>AE3,AI3>AG3)) -- Buy 2

then do this:
AND(AA3>AC3,AA4<AC4,AC3>AE3,AC3>AG3,AC3>AI3) -- Buy 1

Any help would be greatly appreciated

Thanks!!!!!!!
[2014-04-15 11:08:31]
MotoMoto - Posts: 47
I am not sure what 'buy2' and 'buy1' means for you (do you want to send 2 separate orders), but it seems like you are simply wanting a filter.
So you could separate these into different columns and compare them....
or use
if(or(and(A),and(B)),and(C),0)
or
are you looking for this.

if(or(and(A),and(B)),buy2,if(and(C),buy1,0))
breaking this down
'if(or(and(A),and(B))' is true --> buy2
if not, then run the next if statement 'if(and(C)' is true ---> buy 1

Then buy1, and buy2, mean different things such as - buy quantity of 3, buy quantity 1 if existing position is already open.

Hope that is not confusing :)



[2014-04-15 13:09:00]
User14682 - Posts: 83
I want to buy 2 contracts if this is true

=OR(AND(AA3>AG3,AA4<AG4,AG3>AC3,AG3>AE3,AG3>AI3),AND(AA3>AI3,AA4<AI4,AI3>AC3,AI3>AE3,AI3>AG3))

And buy 1 contract based on the next code only if the first line is true

AND(AA3>AC3,AA4<AC4,AC3>AE3,AC3>AG3,AC3>AI3)


[2014-04-15 13:42:20]
MotoMoto - Posts: 47
$j$26 is the place to modify the quantity.

If I am reading it right -
If the first line is true - you will buy 2 contracts, then if the next line is ALSO true you wish to buy an additional contract

You could output a value in Col O of 2,3 or 0 and then test to see if this is what you want.

=if(OR(AND(AA3>AG3,AA4<AG4,AG3>AC3,AG3>AE3,AG3>AI3),AND(AA3>AI3,AA4<AI4,AI3>AC3,AI3>AE3,AI3>AG3)),if(AND(AA3>AC3,AA4<AC4,AC3>AE3,AC3>AG3,AC3>AI3)),3,2),0)

alternatively you might be asking

=if(OR(AND(AA3>AG3,AA4<AG4,AG3>AC3,AG3>AE3,AG3>AI3),AND(AA3>AI3,AA4<AI4,AI3>AC3,AI3>AE3,AI3>AG3)),if(AND(AA3>AC3,AA4<AC4,AC3>AE3,AC3>AG3,AC3>AI3)),1,2),0)
Date Time Of Last Edit: 2014-04-15 13:44:49

To post a message in this thread, you need to log in with your Sierra Chart account:

Login

Login Page - Create Account