Back to links
    ZLR Long for EURUSD


Anyone using information or codes on these pages does so at their own risk - no guarantees of stability or profitability are claimed. These codes are all for testing purposes only.

//Note: anything to the right of //two slashes or {between brackets} is either comments or code that is turned-off
//You must set commissions and slippage in "Format>Properties for all"
///////////////////// This strategy is for a ZLR Long trade only /////////////////////
//SSPs = suggested starting points - are usually set as default in inputs
Inputs: CCILength(14){Woodies standard = 14 or daily = 20}, CCIvStrength(5){sets depth of CCI v},
// StopValue(.0005){for exit strategy #1},
LSMAlength(25),
CCIMax(130); //CCI upper limit = not oversold - SSP of 130 is set as default
///////The above inputs provide for TS optimization in the entry portion

Variables: vCCI(0);vCCI=CCI(CCILength); //Set with input
Var: LSMA(0);LSMA=LinearRegValue(C,LSMAlength,0); //Defines LSMA and set it to 25 (woodies standard)
Var: EMA34(0);EMA34=Xaverage(C,34) //34 EMA
Var: ExitTrail(0), ExitValue(0), ExitReason("None"); //Used for exit #1 below

///////////////////// ZLR Entry code /////////////////////
If 1=1 //this "If 1=1" is from CJ not sure why he uses this - maybe just to start an If-then statement
and vCCI[1]>=0 and vCCI[2]>0 and vCCI[3]>0 and vCCI[4]>0 and vCCI[5]>0 //establishes min. 6 bars above zero
and Highest(vCCI,5)>=100 //CCI comes from outside 100s within last 5 bars
and vCCI[1]<100 //Pulled back inside 100s
and vCCI>vCCI[1] and vCCI[2]>vCCI[1] //2-tick hook
and vCCI<CCIMax //not oversold
and vCCI-vCCI[1]>CCIvStrength //Depth of CCI V - set w/input
and C>EMA34 and EMA34>EMA34[1] //Close above rising 34EMA
and C>LSMA and LSMA>LSMA[1] //Close above rising LSMA
Then Begin
Buy ("ZLR") This Bar at close;
End;

/////////////// EXITS ///////////////

//////// Exit strategy #1 /////////
// By default this exit is turned off
// To turn this exit on for testing remove set "CCIHookExit" in Inputs to true
// This Exit strategy is for exiting on the 1st CCI Hook - It is adjustable in the Inputs below
// Trailing routine exits at ExitValue minus "StopValue"(set w/input) -change to a higher or lower value to let your trades breathe.
// Change it to exit AT MARKET if you just want to exit at 1st hook immediately.

Input: CCIHookExit(false), CCIHookValue(0), CCIHookStrength(0), StopValue(.0006), TwoBarsAgainst(true);
If MarketPosition=1 //1=long position
and CCIHookExit=true
and TwoBarsAgainst=true
and Close < Close[1] and Close[1] < Close[2] //two bars close against trade direction
and vCCI[1]>CCIHookValue //CCI minimum value before exiting at hook below
and vCCI<vCCI[1]-CCIHookStrength //CCI hooks down - "CCIHhookStrength" determines how big the hook is
Then Begin
ExitValue=L{Low of this bar};
ExitTrail=1;
ExitReason="Hook&2Bars";
End;
If MarketPosition=1 //1=long position
and CCIHookExit=true
and TwoBarsAgainst=false
// and Close < Close[1] and Close[1] < Close[2] //two bars close against trade direction
and vCCI[1]>CCIHookValue //CCI minimum value before exiting at hook below
and vCCI<vCCI[1]-CCIHookStrength //CCI hooks down - "CCIHhookStrength" determines how big the hook is
Then Begin
ExitValue=L{Low of this bar};
ExitTrail=1;
ExitReason="Hook";
End;

If vCCI>vCCI[1] and CCIHookExit=true then ExitTrail=0; //Hooked back, Turn off, keep going.

///////////////////// Trailing Routine - exits at the ExitValue (set w/input StopValue above)
If ExitTrail=1 and MarketPosition=1 then sell ("Exit") next bar at ExitValue-StopValue stop {exit at this price or worse};


////// Exit strategy group #2 ////////
//This exit strategy group (declared as MultiExits below) is turned on by default. Set it to "false" in the input to turn it off.
{This exit strategy group includes stops and targets. It's set for divergence from the entry price instead of a specific price point.
There is a stop, a profit target, a breakeven stop, 2 different trailing stops, and an end-of-day exit.
This will exit your entire position, either long or short.
IntrabarOrderGeneration is set to false because these commands evaluate intrabar even when intrabar order generation is disabled.}
[IntrabarOrderGeneration = false]
inputs:{these are exit inputs: Suggested Starting Points (SSPs) are for EUR and similar denominated Forex instruments}
MultiExits(true),
ShareOrPosition( 1 ), //1 = per share basis, 2 = position basis
ProfitTargetAmt( 0 ), //SSP .005 or 0 if you don't want a specific profit target
StopLossAmt( .007 ), // SSP .007 or 0 if you don't want a stop loss
BreakevenFloorAmt( 0 ), //SSP .006 or 0 if you don't want a breakeven stop
DollarTrailingAmt( 0 ), //SSP .006 or 0 if you don't want a dollar trailing stop
PctTrailingFloorAmt( .002 ), //SSP .002 or 0 here and/or in next input if you don't want a percent trailing stop or XX for XX percent
PctTrailingPct( .01 ),// SSP .01. Enter 0 here and/or in previous input if you don't want percent trailing stop or XX for XX percent
ExitOnClose( false ); {Set to TRUE only for back-testing, if at all; in automated execution, the exit order will NOT be filled
at the close of the day; instead, the order can be sent into the extended session as a limit order. }

if MultiExits=true then begin

if ShareOrPosition = 1 then
SetStopShare
else
SetStopPosition;
if ProfitTargetAmt > 0 then
SetProfitTarget( ProfitTargetAmt );
if StopLossAmt > 0 then
SetStopLoss( StopLossAmt );
if BreakevenFloorAmt > 0 then
SetBreakeven( BreakevenFloorAmt );
if DollarTrailingAmt > 0 then
SetDollarTrailing( DollarTrailingAmt );
if PctTrailingFloorAmt > 0 and PctTrailingPct > 0 then
SetPercentTrailing( PctTrailingFloorAmt, PctTrailingPct );
if ExitOnClose = true then
SetExitOnClose;
end;