0% found this document useful (0 votes)
92 views

All Design Text Format

This document contains code for multiple trading strategies and signals. It includes snippets of code for a moving average crossover strategy, a MACD strategy, a breakout strategy using a 20 period moving average, and a strategy that looks for double tops and bottoms using high and low arrays. The code defines variables, conditions, entries, exits and plotting of signals.

Uploaded by

Simon Yu
Copyright
© Attribution Non-Commercial (BY-NC)
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
92 views

All Design Text Format

This document contains code for multiple trading strategies and signals. It includes snippets of code for a moving average crossover strategy, a MACD strategy, a breakout strategy using a 20 period moving average, and a strategy that looks for double tops and bottoms using high and low arrays. The code defines variables, conditions, entries, exits and plotting of signals.

Uploaded by

Simon Yu
Copyright
© Attribution Non-Commercial (BY-NC)
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 12

uncompiled:unfinished :

//Ma2x
// singlemoving average cross under then cross over between range bars setting
inputs: Price( Close ), Length( 9 ), ConfirmBars( 1 ),RangeBars(20) ;

var: BarCnt(0),BarCntNegX(0),BarCntPosX(0);
variables: var0( 0 ) ,Memo_Up2Down(0),Memo_Down2Up(0) ;
//condition1 = Price < AverageFC( Price, Length ) ; ///price fall below MA line
condition2=Price crosses over AverageFC( Price, Length ) ;
//condition3 = Price >= AverageFC( Price, Length ) ; ///price rise above MA lin
e
condition4=Price[1] crosses over AverageFC( Price, Length ) ;

if condition2 then begin


Memo_Up2Down=MRO(condition4,1500,1);
BarCntNegX=1;
end
else
BarCntNegX=BarCntNegX+1 ; // clear negative cross period counter to 1
when cross below MA
if condition4 then begin
Memo_Down2Up=MRO(condition2,1500,1);
BarCntPosX=1;
end
else
BarCntPosX=BarCntPosX+1 ; // clear positive cross period counter to 1
when cross above MA
compiled:

//sMACDTrendMa
inputs: FastLength( 48 ), SlowLength( 104 ),TrendLength(2400),MaLength(600), MA
CDLength( 36 ),Distance(200) ;
variables: var0( 0 ), var1( 0 ), var2( 0 ),var3(0) ,var4(0);
var0 = MACD( Close, FastLength, SlowLength ) ;
var1 = XAverage( var0, MACDLength ) ;
var2 = var0 - var1 ;
var3 = AverageFC(Close, TrendLength ) ;
var4 = AverageFC(Close, MaLength ) ;

condition1 = CurrentBar > 2 and var2 crosses over 0 ;


condition2= var4>var3 ;
condition3 = CurrentBar > 2 and var2 crosses under 0 ;
condition4= Close <=var3 ;
condition8= Close <=var4 ;
print(MRO(condition3,2500,2)) ;
condition5=Close[absvalue(MRO(condition3,2500,2))]<Close[absvalue(MRO(condition3
,2500,1)) ];
condition6=Close[absvalue(MRO(condition1,2500,3))]>=Close[absvalue(MRO(condition
1,2500,2)) ];
condition7=Close[absvalue(MRO(condition1,2500,2))]<=Close[absvalue(MRO(condition
1,2500,1)) ];

if condition1 and condition2 and condition6 and condition7 then


//if condition1 and condition6 and condition7 then
Buy ( "MacdLE" ) next bar at market ;

//if condition3 and condition4 and barssinceentry>=Distance and condition5 then


if condition3 and condition8 and barssinceentry>=Distance and condition5 then
Sell ( "MacdLX" ) next bar at market ;
//Ma2_20====signal =====>this include breakout setting
Inputs: Price(Close), AvgLen(20), StpPnts(10);
Vars: AvgVal(0), Buyit(0), Sellit(0);
AvgVal = XAverage(Price, AvgLen);
{Buy/Sell Entry Setup}
IF Lowest(Low, 2) > AvgVal AND Low 1 Bar Ago Crosses Above AvgVal AND
MarketPosition <> 1 Then Begin
Buyit = Highest(High, 2) + StpPnts Points;
Condition1 = True;
End;
IF Highest(High, 2) < AvgVal AND High 1 Bar Ago Crosses Below AvgVal
AND
MarketPosition <> -1 Then Begin
Sellit = Lowest(Low, 2) - StpPnts Points;
Condition2 = True;
End;
{Buy/Sell Entry Orders}
IF Lowest(Low, 2) > AvgVal AND Condition1 Then
Buy Next Bar at Buyit Stop;
IF Highest(High, 2) < AvgVal AND Condition2 Then
sellshort Next Bar at Sellit Stop;
{Long/Short Exits}
Sell Next Bar at AvgVal Stop;
buytocover Next Bar at AvgVal Stop;
IF MarketPosition <> 0 Then Begin
Condition1 = False;
Condition2 = False;
End;
//kaw03====signal
Inputs: pYYYY(2010), pMMDD(0226), pQty(2), pUp(1), pTimeA(0910), pTimeB(0951), p
Stop(30), pProfitTarget(0.45), pEnable(0);
Vars: pBar(0), pSBar(0), pEBar(0), pBarC(0), pSPrice(0), pEPrice(0), pPriceC(0);
Vars: pPriceCEnd(0), svPriceC(0);
Vars: pDay(0), pSDay(0), pEDay(0), pSTime(0), pETime(0);
Vars: pValue1(-1), pValue2(-1), pValue3(-1), pTemp(0), pOutPoint(0);
Vars: pShowMsg("0"), pVShowPos(5), pHShowPos(0), pExe(0), pCC(0);
if pBar = 0 then begin
pDay = (pYYYY-1900)*10000 + pMMDD;
If pTimeA > 10000 Then Begin
pTemp = Round(pTimeA / 10000,0);
pSDay = _DateModify(pDay, -1*pTemp);
pSTime = (pTimeA - 10000*pTemp);
End Else Begin
pSDay = pDay;
pSTime = pTimeA;
End;
If pTimeB > 10000 Then Begin
pTemp = Round(pTimeB / 10000,0);
pEDay = _DateModify(pDay, -1*pTemp);
pETime = (pTimeB - 10000*pTemp);
End Else Begin
pEDay = pDay;
pETime = pTimeB;
End;
End;
If time <> time[1] Then pBar = pBar+1;
pBarC = pBar;
if entrytime(0) <> 0 and pExe[1] = 0 and pPriceC[1] >= L[1] and pPriceC[
1] <= H[1] then pExe = 1;
if ExitTime(1) <> 0 then pExe = 999;
If pSDay <= date Then Begin
If time = pSTime and Date = pSDay Then Begin
pSBar = pBar;
pSPrice = Iff(pUp = 1, High, Low);
End;
If time = pETime and Date = pEDay Then Begin
pEBar = pBar;
pEPrice = Iff(pUp = 1, High, Low);
End;
If pSBar <> 0 and pEBar <> 0 Then Begin
pPriceC = Round(_PointABC(pSPrice, pSBar, pEPrice, pEBar
, pBarC+1), 0);
If pValue1 = -1 Then Begin
pValue1 = TL_New( pSDay , pSTime, pSPrice, date
, Time+1, pPriceC[1]);
TL_SetColor(pValue1, Iff(pUp = 1, red, green));
TL_SetExtRight(pValue1, true);
End Else Begin
TL_SetEnd (pValue1, date, Time+1, pPriceC[1]);
End;
pShowMsg = spaces(pVShowPos) + IffString(pUp = 1,"Up:","
Down:")+NumToStr(Iff(svPriceC=0,pPriceC[1],svPriceC),0);
If pPriceCEnd <> 0 Then Begin
pShowMsg = pShowMsg +"-"+NumToStr(pPriceCEnd,0);
End Else Begin
pShowMsg = pShowMsg +"-"+NumToStr(pOutPoint,0);
End;
pHShowPos = (HIGHEST(HIGH,30) + LOWEST(Low,30))/2 + pUp*
10;
If pValue2 = -1 Then Begin
pValue2 = TEXT_NEW(DATE,TIME,pHShowPos,pShowMsg)
;
TEXT_SETCOLOR(pValue2,Iff(pUp = 1, Red, Green))
;
End Else Begin
TEXT_SetLocation (pValue2, Date, Time, pHShowPos
);
TEXT_SetString(pValue2, pShowMsg);
End;
If EntryPrice(0) < 1 and pExe = 0 Then Begin
If pEnable = 1 and time < 1340 Then Begin
If pUp = 1 Then Begin
Buy("Buy") pQty SHARES next bar
pPriceC Stop;
End Else Begin
Sellshort("Sellshort") pQty SHAR
ES next bar pPriceC Stop;
End;
End;
End;
If EntryPrice(0) > 0 and pExe = 1 Then Begin
If svPriceC = 0 Then svPriceC = pPriceC[1]+2*Iff
(pUp=1,1,-1);
If pStop <> 0 Then Begin
pOutPoint = Round(_OutPoint(pStop, pProf
itTarget, 100, 2.5), 0);
If MARKETPOSITION < 0 Then Begin
BuyToCover("SellshortStop") next
bar pOutPoint Stop;
End Else If MARKETPOSITION > 0 Then Begi
n
Sell("BuyStop") next bar pOutPoi
nt Stop;
End;
If EntryPrice(0) > 0 and pOutPoint<>0 Th
en Begin
pValue3 = TL_New(Date ,Time, Iff
(pOutPoint[1]=0,pOutPoint,pOutPoint[1]), date , Time+1, pOutPoint);
TL_SetColor(pValue3, cyan);
End;
End;
End;
End;
End;
If time = 1340 Then Begin
Sell("BuyEnd") next bar at market;
BuyToCover("SellshortEnd") next bar at market;
End;
If ExitTime(1) = time and ExitDate(1) = date Then Begin
pPriceCEnd = pOutPoint[1];
End;

//Kway9-doubletop
inputs:
topstren(5),
botstren(5);
arrays:
swinghighs[2,3](0),
swinglows[2,3](0);
vars:
mp(0),
stopprice(0);
{record swinghighs into array}
if SwingHighBar(1,h,topstren,topstren+1)=topstren then begin
for value1=1 downto 0 begin
swinghighs[value1+1,0]=swinghighs[value1,0];
swinghighs[value1+1,1]=swinghighs[value1,1];
swinghighs[value1+1,2]=swinghighs[value1,2];
swinghighs[value1+1,3]=swinghighs[value1,3];
end;
swinghighs[0,0]=BarNumber[topstren];
swinghighs[0,1]=date[topstren];
swinghighs[0,2]=time_s[topstren];
swinghighs[0,3]=high[topstren];
end;
{record swinglows into array}
if SwingLowBar(1,l,botstren,botstren+1)=botstren then begin
for value1=1 downto 0 begin
swinglows[value1+1,0]=swinglows[value1,0];
swinglows[value1+1,1]=swinglows[value1,1];
swinglows[value1+1,2]=swinglows[value1,2];
swinglows[value1+1,3]=swinglows[value1,3];
end;
swinglows[0,0]=BarNumber[botstren];
swinglows[0,1]=date[botstren];
swinglows[0,2]=time_s[botstren];
swinglows[0,3]=low[botstren];
end;
{define swinghighs and swinglows relationship}
condition1=swinghighs[1,0]>swinglows[1,0] and swinghighs[1,0]<swinglows[0,0] and
swinghighs[0,0]>swinglows[0,0] and swinglows[0,3]>=swinglows[1,3];
{define entry and exit price/condition}
mp=marketposition;
if condition1 then begin
value99=tl_new_s(swinghighs[1,1],swinghighs[1,2],swinghighs[1,3],swinghi
ghs[0,1],swinghighs[0,2],swinghighs[0,3]);
value98=tl_getvalue_s(value99,swinglows[0,1],swinglows[0,2]) - swinglows
[0,3];
value97=tl_new_s(swinglows[0,1],swinglows[0,2],swinglows[0,3],swinghighs
[0,1],swinghighs[0,2],swinghighs[0,3] - value98);
value96=tl_getvalue_s(value97,date,time_s);
value95=text_new_s(swinghighs[0,1],swinghighs[0,2],swinghighs[0,3],"Righ
t Top");
value94=text_new_s(swinghighs[1,1],swinghighs[1,2],swinghighs[1,3],"Left
Top");
if mp=0 then sellshort next bar value96 stop;
condition2=low cross under value96;
if condition2 then begin
tl_setend_s(value97,date,time_s,tl_getvalue_s(value97,date,time_
s));
stopprice=swinghighs[0,3]+Average(range,topstren);
end else begin
tl_delete(value99);
tl_delete(value97);
text_delete(value95);
text_delete(value94);
end;
end;
if mp<0 then begin
buytocover next bar stopprice stop;
stopprice=stopprice-(.3*(stopprice-h));
text_new_s(date,time_s,stopprice,".");
end;

//KD-LE add second third length for optimization only


inputs: Length( 800 ),Dleng(300),Sleng(50), OverSold( 20 ) ;
variables: var0( 0 ), var1( 0 ), var2( 0 ), var3( 0 ) ;
Value1 = Stochastic( H, L, C, Length, Dleng, Sleng, 1, var0, var1, var2, var3 )
;
condition1 = CurrentBar > 2 and var2 crosses over var3 and var2 < OverSold ;
if condition1 then
Buy ( "StochLE" ) next bar at market ;

//KD-LX
inputs: Length( 800 ),Dleng(300),Sleng(50), OverBought( 80 ) ;
variables: var0( 0 ), var1( 0 ), var2( 0 ), var3( 0 ) ;
Value1 = Stochastic( H, L, C, Length, Dleng, Sleng, 1, var0, var1, var2, var3 )
;
condition1 = CurrentBar > 2 and var2 crosses under var3 and var2 > OverBought ;
if condition1 then
sell ( "StochLX" ) next bar at market ;

//breakout-optionbuy
//Type : Signal, Name : Breakout System
Input:
BLen(200),
XLen(100);
IF CurrentBar > 1 and Close > Highest(High,BLen)[1]
Then Buy next bar at market;
IF CurrentBar > 1 and Close < Lowest(Low,XLen)[1]
Then sell next bar at market;

//3MA-jay=====signal
//Type: System, Name: Simple Futures MA
Inputs: Price(Close), FastAvg(9), SlowAvg(50), AvgFltr(80);
Vars: FastMA(0), SlowMA(0), Filter(0);
FastMA = Average(Price, FastAvg);
SlowMA = Average(Price, SlowAvg);
Filter = Average(Price, AvgFltr);
Condition1 = Close > Filter;
Condition2 = Close < Filter;
condition3=Close > SlowMA ;
Condition4=Close < SlowMA;
IF( FastMA Crosses Above SlowMA AND Condition1 or FastMA cross Above Filter AND
condition3 ) Then
Buy This Bar on Close;
IF (FastMA Crosses Below SlowMA AND Condition1 or FastMA Crosses Below Filter AN
D Condition3) Then
Sell This Bar on Close;
IF (FastMA Crosses Below SlowMA AND Condition2 or FastMA Crosses Below Filter AN
D Condition4 ) Then
sellshort This Bar on Close;
IF (FastMA Crosses Above SlowMA AND Condition2 or FastMA Crosses Above Filter A
ND Condition4 ) Then
buytocover This Bar on Close;

//turtle-simple
/// Turtle 20-Day Breakout
//////////////////////////////////////
vars: N(0),StopLoss(1),DV(0),BB(0),AccountBalance(0),DollarRisk(0),LTT(0),Tracke
r(0),LastTrade(0),HBP(0),LBP(0);
input: InitialBalance(1000000),profittrail(100),BreakLength1(20),takeprofLengrat
io(0.25);
if marketposition = 0 then begin
BB = 0;
N = xAverage( TrueRange, BreakLength1);
DV = N * BigPointValue;
AccountBalance = InitialBalance;
DollarRisk = AccountBalance * .01;
//LTT = IntPortion(DollarRisk/DV); bugginggggggggggggggggggggggggggggggggggggggg
gggggggggg
LTT=1;
StopLoss = 2 * DV * LTT;
buy LTT shares next bar highest(h,BreakLength1) or higher;
sellshort LTT shares next bar lowest(l,BreakLength1) or lower;
end;
// PREVIOUS TRADE TRACKER
if HBP = 0 and h > highest(h,19)[1] then begin
Tracker = 1; HBP = h; LBP = 0;
end;
if LBP = 0 and l < lowest(l,19)[1] then begin
Tracker = -1; LBP = l; HBP = 0;
end;
if Tracker = 1 then begin
if l < HBP - (2*N) then LastTrade = -1;
if h > HBP + (4*N) then LastTrade = 1;
end;
if Tracker = -1 then begin
if h > LBP + (2*N) then LastTrade = -1;
if l < LBP - (4*N) then LastTrade = 1;
end;
//buggingggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggg
ggg
BB=0;//buginggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggg

sell ("out-S") next bar lowest(l,Round(BreakLength1*takeprofLengratio,0)) or low


er;

buytocover ("out-B") next bar highest(h,Round(BreakLength1*takeprofLengratio,0))


or higher;
//setstoploss (StopLoss); // halt the stop loss to expand the profit
//SetPercentTrailing(profittrail,65) ;
// COMMENTARY
commentary ("LTT: ",LTT,Newline);
commentary ("CurrentShares: ",CurrentShares,Newline);
commentary ("StopLoss: ",StopLoss,Newline);
commentary ("AccountBalance:",AccountBalance,NewLine);
commentary ("LastTrade: ",LastTrade,NewLine);

//turtlesystem
/// Turtle 20-Day Breakout
//////////////////////////////////////
vars: N(0),StopLoss(1),DV(0),BB(0),AccountBalance(0),DollarRisk(0),LTT(0),Tracke
r(0),LastTrade(0),HBP(0),LBP(0);
input: InitialBalance(1000000),BreakLength1(20),BreakLength2(55);
if marketposition = 0 then begin
BB = 0;
N = xAverage( TrueRange, BreakLength1);
DV = N * BigPointValue;
AccountBalance = InitialBalance;
DollarRisk = AccountBalance * .01;
//LTT = IntPortion(DollarRisk/DV); bugginggggggggggggggggggggggggggggggggggggggg
gggggggggg
LTT=1;
StopLoss = 2 * DV * LTT;
if LastTrade = -1 then begin
buy LTT shares next bar highest(h,BreakLength1) or higher;
buy LTT shares next bar highest(h,BreakLength1) + (0.5*N) or higher;
buy LTT shares next bar highest(h,BreakLength1) + (1.0*N) or higher;
buy LTT shares next bar highest(h,BreakLength1) + (1.5*N) or higher;
sellshort LTT shares next bar lowest(l,BreakLength1) or lower;
sellshort LTT shares next bar lowest(l,BreakLength1) - (0.5*N) or lower;
sellshort LTT shares next bar lowest(l,BreakLength1) - (1.0*N) or lower;
sellshort LTT shares next bar lowest(l,BreakLength1) - (1.5*N) or lower;
end;
if LastTrade = 1 then begin
buy LTT shares next bar highest(h,BreakLength2) or higher;
buy LTT shares next bar highest(h,BreakLength2) + (0.5*N) or higher;
buy LTT shares next bar highest(h,BreakLength2) + (1.0*N) or higher;
buy LTT shares next bar highest(h,BreakLength2) + (1.5*N) or higher;
sellshort LTT shares next bar lowest(l,BreakLength2) or lower;
sellshort LTT shares next bar lowest(l,BreakLength2) - (0.5*N) or lower;
sellshort LTT shares next bar lowest(l,BreakLength2) - (1.0*N) or lower;
sellshort LTT shares next bar lowest(l,BreakLength2) - (1.5*N) or lower;
end;
end;
// PREVIOUS TRADE TRACKER
if HBP = 0 and h > highest(h,19)[1] then begin
Tracker = 1; HBP = h; LBP = 0;
end;
if LBP = 0 and l < lowest(l,19)[1] then begin
Tracker = -1; LBP = l; HBP = 0;
end;
if Tracker = 1 then begin
if l < HBP - (2*N) then LastTrade = -1;
if h > HBP + (4*N) then LastTrade = 1;
end;
if Tracker = -1 then begin
if h > LBP + (2*N) then LastTrade = -1;
if l < LBP - (4*N) then LastTrade = 1;
end;
//buggingggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggg
ggg
BB=0;//buginggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggg
// LONG BreakLength1
if LastTrade = -1 and marketposition = 1 then begin
BB = BB + 1;
if currentshares = LTT then begin
buy LTT shares next bar highest(h,BreakLength1)[BB] + (0.5*N) or higher;
buy LTT shares next bar highest(h,BreakLength1)[BB] + (1.0*N) or higher;
buy LTT shares next bar highest(h,BreakLength1)[BB]+ (1.5*N) or higher;
end;
if currentshares = LTT * 2 then begin
buy LTT shares next bar highest(h,BreakLength1)[BB] + (1.0*N) or higher;
buy LTT shares next bar highest(h,BreakLength1)[BB] + (1.5*N) or higher;
end;
if currentshares = LTT * 3 then
buy LTT shares next bar highest(h,BreakLength1)[BB] + (1.5*N) or higher;
end;
// LONG BreakLength2
if LastTrade = 1 and marketposition = 1 then begin
BB = BB + 1;
if currentshares = LTT then begin
buy LTT shares next bar highest(h,BreakLength2)[BB] + (0.5*N) or higher;
buy LTT shares next bar highest(h,BreakLength2)[BB] + (1.0*N) or higher;
buy LTT shares next bar highest(h,BreakLength2)[BB]+ (1.5*N) or higher;
end;
if currentshares = LTT * 2 then begin
buy LTT shares next bar highest(h,BreakLength2)[BB] + (1.0*N) or higher;
buy LTT shares next bar highest(h,BreakLength2)[BB] + (1.5*N) or higher;
end;
if currentshares = LTT * 3 then
buy LTT shares next bar highest(h,BreakLength2)[BB] + (1.5*N) or higher;
end;
sell ("out-S") next bar lowest(l,BreakLength1*0.5) or lower;
// SHORT BreakLength1
if LastTrade = -1 and marketposition = -1 then begin
BB = BB + 1;
if currentshares = LTT then begin
sellshort LTT shares next bar lowest(l,BreakLength1)[BB] - (0.5*N) or lower;
sellshort LTT shares next bar lowest(l,BreakLength1)[BB] - (1.0*N) or lower;
sellshort LTT shares next bar lowest(l,BreakLength1)[BB] - (1.5*N) or lower;
end;
if currentshares = LTT * 2 then begin
sellshort LTT shares next bar lowest(l,BreakLength1)[BB] - (1.0*N) or lower;
sellshort LTT shares next bar lowest(l,BreakLength1)[BB] - (1.5*N) or lower;
end;
if currentshares = LTT * 3 then
sellshort LTT shares next bar lowest(l,BreakLength1)[BB] - (1.5*N) or lower;
end;
// SHORT BreakLength2
if LastTrade = 1 and marketposition = -1 then begin
BB = BB + 1;
if currentshares = LTT then begin
sellshort LTT shares next bar lowest(l,BreakLength2)[BB] - (0.5*N) or lower;
sellshort LTT shares next bar lowest(l,BreakLength2)[BB] - (1.0*N) or lower;
sellshort LTT shares next bar lowest(l,BreakLength2)[BB] - (1.5*N) or lower;
end;
if currentshares = LTT * 2 then begin
sellshort LTT shares next bar lowest(l,BreakLength2)[BB] - (1.0*N) or lower;
sellshort LTT shares next bar lowest(l,BreakLength2)[BB] - (1.5*N) or lower;
end;
if currentshares = LTT * 3 then
sellshort LTT shares next bar lowest(l,BreakLength2)[BB] - (1.5*N) or lower;
end;
buytocover ("out-B") next bar highest(h,BreakLength1*0.5) or higher;
// STOPS
if currentshares = (2 * LTT) then StopLoss = DV * 3.5 * LTT;
if currentshares = (3 * LTT) then StopLoss = DV * 4.5 * LTT;
if currentshares = (4 * LTT) then StopLoss = DV * 5.0 * LTT;
setstoploss (StopLoss);
// COMMENTARY
commentary ("LTT: ",LTT,Newline);
commentary ("CurrentShares: ",CurrentShares,Newline);
commentary ("StopLoss: ",StopLoss,Newline);
commentary ("AccountBalance:",AccountBalance,NewLine);
commentary ("LastTrade: ",LastTrade,NewLine);

You might also like