// watch out for
overnight gap downs
///// This code ends trading once the Daily Net
Points are achieved or end time constraint is met.
//// Designed for use on
futures contracts
/// If used within an Auto Execution Strategy, you may elect to revisit the "marketposition" terms.
//// Co-written by ZAC & RANGER 2010 Rev 0 / tested and found operational
inputs:
DailyNetPoints(9),
StopLossTicks(12),
ProfitTargetTicks(12),
BreakEvenTicks (6),
NumberContracts(4),
start_time(0830),
end_time(1445),
ExitOnClose( true );
variables:
Prior_Date(date),
Prior_Net_Profit(0),
StopPx_Amt(0),
Daily_NP_Amt(0),
ownshares(0),
Profit_Target_Amt(111110),
Break_Even_Amt(0);
StopPx_Amt = ((StopLossTicks/4)*BigPointValue) * NumberContracts;
Daily_NP_Amt = (DailyNetPoints * BigPointValue) * NumberContracts;
Profit_Target_Amt = ((ProfitTargetTicks/4)*BigPointValue) * NumberContracts;
Break_Even_Amt = ((BreakEvenTicks/4)*BigPointValue) * NumberContracts;
once
begin
Prior_Date = Date - 1;
end;
if Time > start_time and Time < end_time then
BEGIN
if Date > Prior_Date then
begin
Prior_Date = Date;
Prior_Net_Profit = netprofit;
end;
if netprofit - Prior_Net_Profit <= Daily_NP_Amt then
begin
///////////START ENTRY/EXIT SIGNALS HERE
inputs:
dailyloss(30); // daily loss maximum Has to be positive!
inputs:
FastLength( 12 ),
SlowLength( 26 ) ,
MACDLength( 9 ) ;
variables:
//todaynet(0),yesterdaynet(0);
double EMAFast(0), EMASlow(0), EMASell(0), stats(0);
EMAFast = XAverage(close,3);
EMASlow = XAverage(close,8);
EMASell = XAverage(close,1);
variables: MovAvg1(0), MovAvg2(0);
MovAvg1 = Average(Close,10);
MovAvg2 = Average(Close,20);
variables:
MyMACD( 0.000 ), MACDAvg( 0.000 );
MyMACD = MACD( Close, FastLength, SlowLength );
MACDAvg = XAverage( MyMACD, MACDLength );
Condition1 = EMAFast crosses above EMASlow; // buy condition
Condition2 = EMASell crosses below EMAFast; // sell condition
Condition3 = (MyMACD > MACDAvg); //
bullish
//if ownshares = 1 then Condition4 = MACDAvg < MyMACD; //
bearish
Condition5 = MovAvg1 > MovAvg2;
Condition6 = MovAvg2 > MovAvg1;
//{ +++++++++++++++++++++ }
//{ +++ Entries +++++++++ }
//{ +++++++++++++++++++++ }
if ownshares = 0 then begin
if Condition5 {and Condition3} then begin
Buy ("cond1") 1 shares this bar at close ;
ownshares = ownshares + 1;
//Alert( "" );
end;
end;
//{ +++++++++++++ }
//{ ++ Exits ++++ }
//{ +++++++++++++ }
if ownshares = 1 then begin
//If Close < Close[1] and Close[1] < Close[2] then begin
if Condition6 {or Condition4} then begin
Sell ("cond2 sell") all shares this bar;
ownshares = 0;
//Alert( "" );
end;
end;
//if netprofit <= dailyloss then begin // I want to completely exit the script
// sell all shares next bar at market;
// end;
// end;
if ownshares = 1 then begin
//if positionprofit < -100 {or Condition4} then sell all shares next bar at market; // trying to be like a
drawdown maximum / panic sell
end;
///////////////END ENTRY EXIT SIGNALS HERE
end else {ends when daily profit objective is reached}
begin
if marketposition = 1 then sell ("ProfitMax") next bar on Open;
if marketposition = -1 then buytocover ("ProfitMaxx") next bar on Open;
ownshares = 0;
end;
END else
if Time > end_time then {ends when time limit is hit}
begin
if marketposition = 1 then sell ("
EOD-0") this bar on Close;
if marketposition = -1 then buytocover ("EOD-1") this bar on Close;
ownshares = 0;
end;
if ExitOnClose = true then SetExitOnClose ; {exit on close of market - this can be rem if desired}
if marketposition <> 0 then
begin
SetDollarTrailing( StopPx_Amt ) ;
SetBreakeven( Break_Even_Amt ) ;
if Profit_Target_Amt > 0 then SetProfitTarget(Profit_Target_Amt ) ;
end;
//while stats < 1 begin
print ("Profit: " , GrossProfit , " Profit: " , NetProfit , " Loss: " , GrossLoss , " Losers: " , NumLosTrades , " Win Percent: " , PercentProfit , "% Total Trades: " , TotalTrades, " pos profit ",positionprofit);
//stats = stats + 1;
//end;
{if High > High[1] AND Close < Close[1] Then Plot1(High, “Key Rev Dn”);if Low < Low[1] AND Close > Close[1] Then Plot2(Low, “Key Rev Up”);}