To make sure my questions are clear, I will focus on the 3 moving averages.
1. How do I buy a certain value of stock (say, if I wanted to treat "one unit" as $10,000)?
-I have only been able to find ways to buy a certain number of shares/contracts. Should I consider making a variable? What would that look like?
2. Perhaps more importantly, how do I make sure my buy and sell commands consider the overall position of the portfolio at the time of the trade? For example, how to make the overall position 3 units long, and not just say to buy 3 units?
-You will see that in my current code, the command in the example I just mentioned is to just buy 3 instead of making sure the portfolio shifts to being 3 long overall.
Here is my code for my moving average crossing signal (each bar represents a day):
Code: Select all
inputs: Price( Close ), FastLength( 51 ), MedLength( 105 ), SlowLength( 161 ) ;
variables: Value1 = 14000 dollars, Value3 = 42000 dollars ;
variables: var0(0), var1(0), var2(0) ;
var0 = AverageFC( Price, FastLength ) ;
var1 = AverageFC( Price, MedLength ) ;
var2 = AverageFC( Price, SlowLength ) ;
If var0 Crosses Over var1 and var1 > var2 Then Buy ("buy3") Value3 Next Bar at Open ;
If var0 Crosses Over var2 and var1 > var2 Then Buy ("buy") Value1 Next Bar at Open ;
If var0 Crosses Over var1 and var2 > var0 Then Sell Short ("sell") Value1 Next Bar at Open ;
Thank you in advance for your help!