[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Setting Limit Orders/ Saving a value in a loop



PureBytes Links

Trading Reference Links

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.

thanks in advance


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),MACDDi
ff(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");