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

Strategy help



PureBytes Links

Trading Reference Links



I am getting trades after the MaxDailyGain is hit. I am also getting trades
after time frames are hit, morning end, etc,. I am trying to get this
strategy to be optimized for maximum profit, but I want the system to turn
off when the maximum daily gain is reached. I also want the system to turn
off when their has been a previous profit and the current trade is
profitable and the two have reached the max daily gain, I want the trade to
exit even though the max gain per trade has not been met yet. I have had
problems where the max daily gain had been reached but because the current
trade did not hit the max gain per trade and the trade went the opposite
way, the system traded all day when it should have turned off.

Thanks for your help






Inputs: CS(5), DTILength(14), DTIBuySignal(0), DTISellSignal(0),
afterDTILength(14), DTIafterbuy(0), DTIaftersell(0),
	    MaxDailyGain(1000),MaxGainPerTrade(250),MaxLossPerTrade(500),
MorningBegin(940), MorningEnd(1200),
		AfternoonBegin(1300), AfternoonEnd(1600),TrixLength(9), TRXBuySignal(0),
TRXSellSignal(0),
		afterTrxLength(13), trxAfterBuy(0), trxAfterSell(0), DTIzeroexitvalS(0),
DTIzeroexitvalB(0), TRXzeroexitvalS(0),
	    TRXzeroexitvalB(0),MorningSession("Y"),
AfternoonSession("Y"),TrxTrades("N"),DTITrades("Y"),
	    DTIZeroexit("N"),TRXzeroexit("N"), Compounding("Y") ;


VARS: DTIVal(0),s(10), u(6), trxval(0),
cte(0),dailyprofit(0),afternoontrxval(0),
	  afternoonDTIval(0), dd(0), num_cts(0),
Stoptrading(False),GainYesterday( 0 );



dd=(2*-maxiddrawdown)+1800;
if compounding="Y" then num_cts=CS+(netprofit/dd)
	else num_cts=CS;
afternoonDTIval=dti(afterDTILength, s, u);
afternoontrxval=trix(close, aftertrxlength);
dailyprofit=(netprofit+openpositionprofit)-cte;
if d>d[1] then cte=netprofit;
If Date <> Date[1] then
	begin
	GainYesterday = NetProfit;
	StopTrading = false;
	end;


If NetProfit + OpenPositionProfit >= GainYesterday + MaxDailyGain then
	begin
	StopTrading = True;
	Sell("MaxDailyProf") this bar on close;
	end;


If StopTrading = false and Close > High[1] then { Sample Illustrative
entry }
	buy next bar at market;

DTIVal = DTI(DTILength, s,u);
TRXval = TRIX(close, TrixLength);


if dailyprofit<MaxDailyGain then begin
	If MorningSession="Y" then begin
		if t>Morningbegin then begin
			if t<morningend then begin
				if DTITrades="Y" then begin
					if DTIVal crosses over DTIBuySignal then buy ("Morning_DTI_B")num_cts
contracts this bar;
					if DTIVal crosses under DTISellSignal then sell short
("Morning_DTI_S")num_cts contracts this bar;
				end;

				if TrxTrades="Y" then begin
					if TRXval crosses over TRXBuySignal then buy ("Morning_TRX_B")num_cts
contracts this bar;
					if TRXval crosses under TRXSellSignal then sell
short("Morning_TRX_S")num_cts contracts this bar;
				end;
			end;
		end;
	end;
end;


if dailyprofit<MaxDailyGain then begin
	If afternoonsession="Y" then begin
		if t>afternoonbegin then begin
			if t<afternoonend then begin
				if DTITrades="Y" then begin
					if afternoonDTIVal crosses over DTIafterbuy then
buy("Afternoon_DTI_B")num_cts contracts this bar;
					if afternoonDTIVal crosses under DTIaftersell then sell short
("Afternoon_DTI_S")num_cts contracts this bar;
				end;

				if TrxTrades="Y" then begin
					if afternoonTRXval crosses over TRXafterbuy then buy
("Afternoon_TRX_B")num_cts contracts this bar;
					if afternoonTRXval crosses under trxaftersell then sell short
("Afternoon_TRX_S")num_cts contracts this bar;
				end;
			end;
		end;
	end;
end;

if T>=Morningend and T<afternoonbegin then begin
	if marketposition=1 then sell this bar;
	if marketposition=-1 then buytocover this bar;
end;

if T>=afternoonend then begin
	if marketposition=1 then sell this bar;
	if marketposition=-1 then buytocover this bar;
end;

if DTIzeroexit="Y" then begin
	if marketposition=1 then begin
		if DTIval crosses under DTIzeroexitvalS then sell this bar;
	end;

	if marketposition=-1 then begin
		if DTIval crosses over DTIzeroexitvalB then buytocover this bar;
	end;
end;

if TRXzeroexit="Y" then begin
	if marketposition=1 then begin
		if TRxval crosses under TRXzeroexitvalS then sell this bar;
	end;

	if marketposition=-1 then begin
		if TRXval crosses over TRXzeroexitvalB then buytocover this bar;
	end;
end;


setstopcontract;
setprofittarget(MaxGainPerTrade);
setstoploss(MaxLossPerTrade);
setexitonclose;