PureBytes Links
Trading Reference Links
|
At 11:57 AM -0400 4/12/99, Edmond Sorel wrote:
>This is the Code for an intra-day trading system for the S&P Index Futures
>I was tinkering with the lookforward value of the MACD Cross for the setting
>of Limit orders on the floor
>
>What I want is the value of the variable (NextPrice) to be saved when the
>set up (Value1 > Value2) occurs and preserved as the limit rather than to be
>updated throughout the life of the trade which would mean that I would have
>to call down to the floor every 10 min for a new limit value.
It is not clear exactly what you need put I will assume some things.
You could add new variables to save the value of NextPrice as below:
---------
if Value1 crosses over Value2 then
BuyStop = NextPrice;
if Value1 crosses under Value2 then
ExitStop = NextPrice;
if Value1 > Value2 then buy("Entry@xxxx") BuyStop stop;
if Value1 < Value2 then exitlong("Exit@xxxxx") ExitStop Limit ;
---------
This code will keep the buy active as long as Value1 > Value2 but keep the BuyStop price as it was when the values crossed. It also saves the ExitStop value if that is what you wanted.
Other comments. The range of the begin/end loops in your code do not look right. I have reformatted the code below so it is easy to see that you use the value of XAve1 on CurrentBar = 1 but do not initialize it until CurrentBar = 2. It is usually better to indent the code to show the levels so that you can see what is in which group.
I made all of these changes in the second version below. (This has not been tested or verified.)
Bob Fulks
---------
Original code reformatted:
Input: Price(c), FastMA(12), SlowMA(26), MacdMA(9), NextDiff(0);
VARS: B(0), XAve1(0), Xave2(0), F1(0), F2(0), F3(0), MACDVal1(0),
MACDVal2(0), MACDDiff(0), NextPrice(0);
Value1 = MACD(Close,FastMA,SlowMA);
Value2 = XAverage(MACD(Close,FastMA,SlowMA),MacdMA);
Value3 = Value1 - Value2;
if FastMA + 1 <> 0 and SlowMA + 1 <> 0 then begin
if CurrentBar <= 1 then begin
F1 = 2 / (FastMA + 1);
XAve1 = Price;
F2 = 2 / (SlowMA + 1);
XAve2 = Price;
F3 = 2 / (MacdMA + 1);
MACDVal1 = 0;
MACDVal2 = 0;
MACDDiff = 0;
end else
XAve1 = F1 * Price + (1 - F1) * XAve1[1];
Xave2 = F2 * Price + (1 - F2) * XAve2[1];
MACDVal1 = XAve1 - XAve2;
MACDVal2 = F3*MACDVal1 + (1 - F3) * MACDVal2[1];
MACDDiff = MACDVal1 - MACDVal2;
end;
NextPrice = (NextDiff / (1 - F3) + MACDVal2 - (1 - F1) * XAve1
+ (1 - F2) * Xave2)/(F1-F2);
if TIME > 1030 and time < 1500 then begin
if Value1 > Value2 then buy("Entry@xxxx") NextPrice stop;
if Value1 < Value2 then exitlong("Exit@xxxxx") NextPrice Limit ;
end;
if Time > 1550 then exitlong("Exit@xxxx");
---------
Revised code:
Input: Price(c), FastMA(12), SlowMA(26), MacdMA(9), NextDiff(0);
VARS: B(0), XAve1(Price), Xave2(Price), F1(0), F2(0), F3(0), MACDVal1(0),
MACDVal2(0), MACDDiff(0), NextPrice(0), BuyStop(0), ExitStop(0);
Value1 = MACD(Close,FastMA,SlowMA);
Value2 = XAverage(MACD(Close,FastMA,SlowMA),MacdMA);
Value3 = Value1 - Value2;
if FastMA + 1 <> 0 and SlowMA + 1 <> 0 then begin
if CurrentBar <= 1 then begin
F1 = 2 / (FastMA + 1);
XAve1 = Price;
F2 = 2 / (SlowMA + 1);
XAve2 = Price;
F3 = 2 / (MacdMA + 1);
MACDVal1 = 0;
MACDVal2 = 0;
MACDDiff = 0;
end else begin
XAve1 = F1 * Price + (1 - F1) * XAve1[1];
Xave2 = F2 * Price + (1 - F2) * XAve2[1];
MACDVal1 = XAve1 - XAve2;
MACDVal2 = F3*MACDVal1 + (1 - F3) * MACDVal2[1];
MACDDiff = MACDVal1 - MACDVal2;
NextPrice = (NextDiff / (1 - F3) + MACDVal2 - (1 - F1) * XAve1
+ (1 - F2) * Xave2)/(F1-F2);
if Value1 crosses over Value2 then
BuyStop = NextPrice;
if Value1 crosses under Value2 then
ExitStop = NextPrice;
if TIME > 1030 and time < 1500 then begin
if Value1 > Value2 then buy("Entry@xxxx") BuyStop stop;
if Value1 < Value2 then exitlong("Exit@xxxxx") ExitStop Limit ;
end;
if Time > 1550 then exitlong("Exit@xxxx");
end;
end;
--------
|