function run() { BarPeriod = 240; // 4 hour bars // calculate the buy/sell signal vars Price = series(price()); vars DomPeriod = series(DominantPeriod(Price,30)); var LowPeriod = LowPass(DomPeriod,500); vars HP = series(HighPass(Price,LowPeriod)); vars Signal = series(Fisher(HP,500)); var Threshold = 1.0; // buy and sell Stop = 4*ATR(100); Trail = 4*ATR(100); if(crossUnder(Signal,-Threshold)) enterLong(); else if(crossOver(Signal,Threshold)) enterShort(); // plot signals and thresholds plot("DominantPeriod",LowPeriod,NEW,BLUE); plot("Signal",Signal[0],NEW,RED); plot("Threshold1",Threshold,0,BLACK); plot("Threshold2",-Threshold,0,BLACK); PlotWidth = 600; PlotHeight1 = 300; }
function strategy1() { if(random() > 0) enterLong(); else enterShort(); }
function run() { vars Price = series(price()); vars Trend = series(LowPass(Price,1000)); Stop = 100*PIP; TakeProfit = 100*PIP; if(valley(Trend)) { //plotPriceProfile(50,0); enterLong(); } else if(peak(Trend)) { //plotPriceProfile(50,PMINUS); enterShort(); } PlotWidth = 1000; PlotHeight1 = 320; PlotScale = 4; //plotDay(Equity,PDIFF); //plotWeek(Equity,PDIFF); //plotMonth(Equity,PDIFF); //plotYear(Equity,PDIFF); plotTradeProfile(50); }
function strategy2() { Stop = 200*PIP; TakeProfit = 10*PIP; if(NumOpenTotal == 0) { if(random() < 0) enterShort(); else enterLong(); } }
// brute force optimization function run(){ set(PARAMETERS); int PeriodsEMA1[4] = { 5, 10, 15, 20 }; int PeriodsEMA2[3] = { 100, 150, 200 }; LookBack = 250; int Index = optimize(1,1,4*3,1) - 1; int PeriodEMA1 = PeriodsEMA1[Index%4]; int PeriodEMA2 = PeriodsEMA2[Index/4]; vars Price = series(price(0)); vars EMA1 = series(EMA(Price,PeriodEMA1)); vars EMA2 = series(EMA(Price,PeriodEMA2)); if(crossOver(EMA1,EMA2)) enterLong(); else if(crossUnder(EMA1,EMA2)) enterShort(); }
function tradeCounterTrend() { TimeFrame = 4; vars Price = series(price()); vars Filtered = series(BandPass(Price,optimize(30,25,35),0.5)); vars Signal = series(Fisher(Filtered,500)); var Threshold = optimize(1,0.5,1.5,0.1); Stop = optimize(4,2,10) * ATR(100); Trail = 4*ATR(100); if(crossUnder(Signal,-Threshold)) enterLong(); else if(crossOver(Signal,Threshold)) enterShort(); }
function tradeTrend() { TimeFrame = 1; vars Price = series(price()); vars Trend = series(LowPass(Price,optimize(500,300,700))); Stop = optimize(4,2,10) * ATR(100); Trail = 0; vars MMI_Raw = series(MMI(Price,300)); vars MMI_Smooth = series(LowPass(MMI_Raw,500)); if(falling(MMI_Smooth)) { if(valley(Trend)) enterLong(); else if(peak(Trend)) enterShort(); } }
// EUR/CHF grid trader main function int run() { BarPeriod = 60; Hedge = 5; // activate virtual hedging var Grid = 20*PIP; // set grid distance to 20 pips var Close = priceClose(); // place pending trades at 5 grid lines above and below the Close int i; for(i = Close/Grid - 4; i < Close/Grid + 4; i++) { var Price = i*Grid; // place short trades with profit target below the current price if(Price < Close && isFree(Price,Grid,true)) enterShort(10,Price,0,Grid); // place long trades with profit target above the current price else if(Price > Close && isFree(Price,Grid,false)) enterLong(10,Price,0,Grid); } }
function tradeOneNightStand() { vars Price = series(price()); vars SMA10 = series(SMA(Price, 10)); vars SMA40 = series(SMA(Price, 40)); //Stop = 3 * 90 * PIP; var BuyStop,SellStop; BuyStop = HH(10) + 1*PIP; SellStop = LL(10) - 1*PIP; if (dow() == 5 && NumOpenLong == 0 && NumPendingLong == 0 && SMA10[0] > SMA40[0]) enterLong(0,BuyStop); else if (dow() == 5 && NumOpenShort == 0 && NumPendingShort == 0 && SMA10[0] < SMA40[0]) enterShort(0,SellStop); if (dow() != 5 && dow() != 6 && dow() != 7) { exitLong(); exitShort(); } }