I like to trade leveraged ETF pairs. For example, UWT and DWT. They are inversely related, so when one goes up, the other goes down and vice versa.
I have separate systems for both of those ETF. Each system generates both LONG and SHORT signals. But I don’t like to sell short anything
When DWT generates a SHORT signal, I would actually like to go LONG UWT. When UWT generates a SHORT signal, I would like to actually go LONG DWT. I would also take all LONG signals generated by each system.
My question is, how would I code something that merges the 2 systems, takes all LONG signals generated by each system, and also uses each system’s SHORT signal to take a LONG position in the opposite ETF?
Thank you in advance for any guidance that you may be able to provide me.
A first step would probably be for you to read up on the “Foreign Functions” in the User’s Guide.
I would suggest that Next you make sure you are comfortable with the boolean logic for how to join two (or more) conditions.
condition1 = RSI(14) > 70;
condition2 = V>100000;
condition3 = C>5.25;
S1Buy = condition1 AND condition2 AND condition3;
I hope that this is the Guidance that you need.
Also, Use the Force… um… I mean Use the Search function on this site, and in the User’s Guide.
WHEN you make some progress, and hit your next stumbling block, Show us your code and where you are having difficulty. Then lots of other experienced AFLers would be much more willing to help Guide you to your solution. And you will learn LOTS on the way.
You’ll first need to define the long and short entry/exit criteria for both symbols using the price array output from the Foreign function.
Once you have that you can use a discriminator in the Buy statement to check which symbol is being processed, and then apply the criteria for that symbol. And repeat for Sell.
Something like this should get you started.
UWTClose = Foreign("UWT", "C");
DWTClose = Foreign("DWT", "C");
UWTLong = Cross(UWTClose, MA(UWTClose, 20));
UWTShort = // Add Short Criteria
DWTLong = Cross(DWTClose, MA(DWTClose, 15));
DWTShort = // Add Short Criteria
Symbol = Name();
Buy = (Symbol == "UWT" AND (UWTLong OR DWTShort)) OR
(Symbol == "DWT" AND (DWTLong OR UWTShort));