Skip to content

Commit

Permalink
Add files via upload
Browse files Browse the repository at this point in the history
  • Loading branch information
alexanu authored Jul 30, 2020
1 parent 0464b75 commit d71b3b8
Show file tree
Hide file tree
Showing 17 changed files with 712 additions and 83 deletions.
146 changes: 146 additions & 0 deletions Strat_1NightStand.c
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();
}
7 changes: 5 additions & 2 deletions Strat_BTFD.c
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
function run()
{
set(PARAMETERS|TESTNOW|LOGFILE); // generate and use optimized parameters
set(TESTNOW|LOGFILE|PLOTNOW);
set(PARAMETERS); // generate and use optimized parameters

BarPeriod = 60;
TimeFrame = 1;

vars Price = series(price());
vars Trend = series(LowPass(Price,500)); // Like moving average but faster
Stop = optimize(4,2,10) * ATR(100);
Stop = ATR(100);
// Stop = optimize(4,2,10) * ATR(100);


vars MMI_Raw = series(MMI(Price,300)); // Is market trending or not? Market Meanness Index
Expand Down
30 changes: 13 additions & 17 deletions Strat_BrokerArb.c
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
// Broker arbitrage example ////////////////////////////
// you can compare currency or CFD prices between broker A and broker B ...
// ... and enter a long position with the cheaper broker and a short position with the other

// There is special account list and asset list

#define ASSET_A "EURUSD_A"
#define ASSET_B "EURUSD_B"
Expand All @@ -18,24 +22,16 @@ function tick()
strdate(HMS,0),1000.*modf(second(),0),PriceA,PriceB);

asset(ASSET_A);
if(NumOpenShort && Difference < 0)
exitShort();
else if(NumOpenLong && Difference > 0)
exitLong();
else if(!NumOpenShort && Difference > Threshold) // go short with the expensive asset
enterShort();
else if(!NumOpenLong && Difference < -Threshold) // go long with the cheap asset
enterLong();

if(NumOpenShort && Difference < 0) exitShort();
else if(NumOpenLong && Difference > 0) exitLong();
else if(!NumOpenShort && Difference > Threshold) enterShort(); // go short with the expensive asset
else if(!NumOpenLong && Difference < -Threshold) enterLong(); // go long with the cheap asset

asset(ASSET_B);
if(NumOpenShort && Difference > 0)
exitShort();
else if(NumOpenLong && Difference < 0)
exitLong();
else if(!NumOpenShort && Difference < -Threshold)
enterShort();
else if(!NumOpenLong && Difference > Threshold)
enterLong();
if(NumOpenShort && Difference > 0) exitShort();
else if(NumOpenLong && Difference < 0) exitLong();
else if(!NumOpenShort && Difference < -Threshold) enterShort();
else if(!NumOpenLong && Difference > Threshold) enterLong();
}

function run()
Expand Down
43 changes: 43 additions & 0 deletions Strat_CNTR_with_EquityCurve.c
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
}
24 changes: 24 additions & 0 deletions Strat_Ehlers_Trend.c
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();
}
}
16 changes: 6 additions & 10 deletions Strat_GridTrader.c
Original file line number Diff line number Diff line change
Expand Up @@ -22,20 +22,16 @@ int run()
var Price, Grid = 200*PIP; // set grid distance to 200 pips
var Close = priceClose();

// place pending trades at 5 grid lines
// above and below the current price
// place pending trades at 5 grid lines
// above and below the current price
for(Price = 0; Price < Close+5*Grid; Price += Grid)
{
// find the lowest grid line
if(Price < Close-5*Grid) continue;
// place not more than 200 trades
if(NumOpenTotal + NumPendingTotal > 200) break;
// place short trades below the current price
if(Price < Close-5*Grid) continue; // find the lowest grid line
if(NumOpenTotal + NumPendingTotal > 200) break; // place not more than 200 trades
if(Price < Close and !findTrade(Price,Grid,true))
enterShort(1,Price,20*Grid,Grid);
// place long trades above the current price
enterShort(1,Price,20*Grid,Grid); // place short trades below the current price
else if(Price > Close and !findTrade(Price,Grid,false))
enterLong(1,Price,20*Grid,Grid);
enterLong(1,Price,20*Grid,Grid); // place long trades above the current price
}
}

Expand Down
16 changes: 16 additions & 0 deletions Strat_Intraday_2.c
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();
}
Loading

0 comments on commit d71b3b8

Please sign in to comment.