-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
17 changed files
with
712 additions
and
83 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,146 @@ | ||
// #define FULLY_OPTIM | ||
// #define STOP_OPTIM | ||
// #define SMA_OPTIM | ||
// #define SMA_AND_STOP_OPTIM | ||
// #define ONLY_REINV_OPTIM | ||
#define NOT_OPTIM | ||
|
||
|
||
function tradeOneNightStand() | ||
{ | ||
#ifdef FULLY_OPTIM | ||
vars Price = series(price()); | ||
vars SMAShort = series(SMA(Price, optimize(10,5,20))); | ||
vars SMALong = series(SMA(Price, optimize(40,30,80,5))); | ||
|
||
Stop = optimize(100,100,500,10) * PIP; | ||
var BuyStop = HH(10) + 1*PIP; | ||
var SellStop = LL(10) - 1*PIP; | ||
|
||
if(between(tow(),42355,50005)) { // check the time interval around thursday midnight | ||
if (SMAShort[0] > SMALong[0] && rising(SMAShort) && rising(SMALong) && NumOpenLong == 0 && NumPendingLong == 0) { | ||
Margin = 0.1 * OptimalFLong * Capital * sqrt(1 + ProfitClosed/Capital); | ||
enterLong(0,BuyStop); | ||
} | ||
else if (SMAShort[0] < SMALong[0] && falling(SMAShort) && falling(SMALong) && NumOpenShort == 0 && NumPendingShort == 0) { | ||
Margin = 0.1 * OptimalFShort * Capital * sqrt(1 + ProfitClosed/Capital); | ||
enterShort(0,SellStop); | ||
} | ||
} | ||
#endif | ||
|
||
#ifdef STOP_OPTIM | ||
vars Price = series(price()); | ||
vars SMAShort = series(SMA(Price, 10)); | ||
vars SMALong = series(SMA(Price, 40)); | ||
|
||
Stop = optimize(100,100,500,10) * PIP; | ||
var BuyStop = HH(10) + 1*PIP; | ||
var SellStop = LL(10) - 1*PIP; | ||
|
||
if(between(tow(),42355,50005)) { // check the time interval around thursday midnight | ||
if (SMAShort[0] > SMALong[0] && rising(SMAShort) && rising(SMALong) && NumOpenLong == 0 && NumPendingLong == 0) { | ||
enterLong(0,BuyStop); | ||
} | ||
else if (SMAShort[0] < SMALong[0] && falling(SMAShort) && falling(SMALong) && NumOpenShort == 0 && NumPendingShort == 0) { | ||
enterShort(0,SellStop); | ||
} | ||
} | ||
#endif | ||
|
||
#ifdef SMA_OPTIM | ||
vars Price = series(price()); | ||
vars SMAShort = series(SMA(Price, optimize(10,5,20))); | ||
vars SMALong = series(SMA(Price, optimize(40,30,80,5))); | ||
|
||
Stop = 100 * PIP; | ||
var BuyStop = HH(10) + 1*PIP; | ||
var SellStop = LL(10) - 1*PIP; | ||
|
||
if(between(tow(),42355,50005)) { // check the time interval around thursday midnight | ||
if (SMAShort[0] > SMALong[0] && rising(SMAShort) && rising(SMALong) && NumOpenLong == 0 && NumPendingLong == 0) { | ||
enterLong(0,BuyStop); | ||
} | ||
else if (SMAShort[0] < SMALong[0] && falling(SMAShort) && falling(SMALong) && NumOpenShort == 0 && NumPendingShort == 0) { | ||
enterShort(0,SellStop); | ||
} | ||
} | ||
#endif | ||
|
||
#ifdef SMA_AND_STOP_OPTIM | ||
vars Price = series(price()); | ||
vars SMAShort = series(SMA(Price, optimize(10,5,20))); | ||
vars SMALong = series(SMA(Price, optimize(40,30,80,5))); | ||
|
||
Stop = optimize(100,100,500,10) * PIP; | ||
var BuyStop = HH(10) + 1*PIP; | ||
var SellStop = LL(10) - 1*PIP; | ||
|
||
if(between(tow(),42355,50005)) { // check the time interval around thursday midnight | ||
if (SMAShort[0] > SMALong[0] && rising(SMAShort) && rising(SMALong) && NumOpenLong == 0 && NumPendingLong == 0) { | ||
enterLong(0,BuyStop); | ||
} | ||
else if (SMAShort[0] < SMALong[0] && falling(SMAShort) && falling(SMALong) && NumOpenShort == 0 && NumPendingShort == 0) { | ||
enterShort(0,SellStop); | ||
} | ||
} | ||
#endif | ||
|
||
#ifdef ONLY_REINV_OPTIM | ||
vars Price = series(price()); | ||
vars SMAShort = series(SMA(Price, 10)); | ||
vars SMALong = series(SMA(Price, 40)); | ||
|
||
Stop = 100 * PIP; | ||
var BuyStop = HH(10) + 1*PIP; | ||
var SellStop = LL(10) - 1*PIP; | ||
|
||
if(between(tow(),42355,50005)) { // check the time interval around thursday midnight | ||
if (SMAShort[0] > SMALong[0] && rising(SMAShort) && rising(SMALong) && NumOpenLong == 0 && NumPendingLong == 0) { | ||
Margin = 0.1 * OptimalFLong * Capital * sqrt(1 + ProfitClosed/Capital); | ||
enterLong(0,BuyStop); | ||
} | ||
else if (SMAShort[0] < SMALong[0] && falling(SMAShort) && falling(SMALong) && NumOpenShort == 0 && NumPendingShort == 0) { | ||
Margin = 0.1 * OptimalFShort * Capital * sqrt(1 + ProfitClosed/Capital); | ||
enterShort(0,SellStop); | ||
} | ||
} | ||
#endif | ||
|
||
|
||
#ifdef NOT_OPTIM | ||
vars Price = series(price()); | ||
vars SMAShort = series(SMA(Price, 10)); | ||
vars SMALong = series(SMA(Price, 40)); | ||
|
||
Stop = 100 * PIP; | ||
var BuyStop = HH(10) + 1*PIP; | ||
var SellStop = LL(10) - 1*PIP; | ||
|
||
if(between(tow(),42355,50005)) { // check the time interval around thursday midnight | ||
if (SMAShort[0] > SMALong[0] && rising(SMAShort) && rising(SMALong) && NumOpenLong == 0 && NumPendingLong == 0) { | ||
enterLong(0,BuyStop); | ||
} | ||
else if (SMAShort[0] < SMALong[0] && falling(SMAShort) && falling(SMALong) && NumOpenShort == 0 && NumPendingShort == 0) { | ||
enterShort(0,SellStop); | ||
} | ||
} | ||
#endif | ||
|
||
if (dow() != 4 && dow() != 5 && dow() != 6) // exit on Monday morning's open, or Tuesday morning's open, if Monday is a holiday | ||
{ | ||
exitShort(); | ||
exitLong(); | ||
} | ||
} | ||
|
||
function run() | ||
{ | ||
set(LOGFILE|PLOTNOW); | ||
// set(PARAMETERS,FACTORS,LOGFILE,PLOTNOW); // generate and use optimized parameters and factors | ||
|
||
BarPeriod = 15; | ||
// while(asset(loop("EUR/USD","USD/CHF","GBP/USD","USD/JPY"))) | ||
asset("USD/CHF"); | ||
tradeOneNightStand(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
|
||
function checkEquity() { | ||
vars EquityCurve = series(EquityLong+EquityShort); // generate equity curve including phantom trades | ||
vars EquityLP = series(LowPass(EquityCurve,10)); | ||
if(EquityLP[0] < LowPass(EquityLP,100) && falling(EquityLP)) // don't trade when the equity curve goes down & and is below its own lowpass filtered value | ||
setf(TradeMode,TR_PHANTOM); // drawdown -> phantom trades | ||
else | ||
resf(TradeMode,TR_PHANTOM); // profitable -> normal trades | ||
} | ||
|
||
function tradeCounterTrend() | ||
{ | ||
|
||
BarPeriod = 240; | ||
// Counter trend trading is affected by market cycles and more sensitive to the bar period than trend trading | ||
// Bar periods that are in sync with the worldwide markets - such as 4 or 8 hours - ... | ||
// ... are especially profitable with this type of trading | ||
|
||
LookBack = 500; | ||
set(PARAMETERS); | ||
StartDate = 2005; | ||
|
||
NumWFOCycles = 10; | ||
|
||
vars Price = series(price()); | ||
vars Filtered = series(BandPass(Price,optimize(30,20,40),0.5)); | ||
// BandPass is similar to LowPass + it dampens short cycles => curve with medium-period peaks and valleys | ||
|
||
vars Signal = series(FisherN(Filtered,500)); // Normalisation in order to compare with threshold | ||
|
||
var Threshold = optimize(1,0.5,1.5,0.1); | ||
|
||
checkEquity(); // equity curve trading | ||
|
||
// buy and sell | ||
Stop = optimize(4,2,10) * ATR(100); | ||
Trail = 4*ATR(100); // 4 average candles away from the current price | ||
// Trailing often - not always - improves the profit of a strategy, ... | ||
// but is almost always better than placing a profit target | ||
|
||
if(crossUnder(Signal,-Threshold)) enterLong(); // price is supposedly close to the bottom of the main cycle | ||
else if(crossOver(Signal,Threshold)) enterShort(); // price is closed to peak | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
function trade_Ehlers() | ||
{ | ||
// simplier than in the Excel | ||
|
||
TimeFrame = 2; | ||
|
||
vars Price = series(price()); | ||
vars Smoothed = series(LowPass(Price,optimize(100,50,200,25))); | ||
vars Trendline = series(HTTrendline(Price)); | ||
vars Trendmode = series(HTTrendMode(Price)); | ||
|
||
MaxLong = MaxShort = 1; | ||
|
||
Stop = optimize(30,3,21,3) * ATR(30); | ||
|
||
if(Trendmode == 1) { | ||
if(crossOver(Smoothed, Trendline)) enterLong(); | ||
else if(crossUnder(Smoothed, Trendline)) enterShort(); | ||
} | ||
else if(Trendmode == 0){ | ||
if(Smoothed[0] > Trendline[0]) enterLong(); | ||
else if(Smoothed[0] < Trendline[0]) enterShort(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
void run() { | ||
set(LOGFILE); // could print the hour and lhour to the log for checking | ||
|
||
BarPeriod = 15; | ||
StartDate = 2010; | ||
EndDate = 2019; | ||
asset("USD/JPY"); | ||
|
||
int timezone = JST; | ||
if(lhour(timezone) == 10 && minute() == 00) enterShort(); | ||
if(lhour(timezone) == 12 && minute() == 30) exitShort(); | ||
|
||
BarZone = JST; | ||
if(hour() == 10 && minute() == 00) enterShort(); | ||
if(hour() == 12 && minute() == 30) exitShort(); | ||
} |
Oops, something went wrong.