#define DEBUG function tradeOneNightStand() { 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; #ifdef DEBUG bool SMAShortR = rising(SMAShort); bool SMAShortF = falling(SMAShort); bool SMALongR = rising(SMALong); bool SMALongF = falling(SMALong); printf("\n%s: SMAShort:%.5f (%i|%i), SMALong: %.5f (%i|%i)",Asset,SMAShort[0],SMAShortF,SMAShortR,SMALong[0],SMALongF,SMALongR); #endif var BuyStop,SellStop; BuyStop = HH(10) + 1*PIP; SellStop = LL(10) - 1*PIP; if (dow() == 5 && NumOpenLong == 0 && NumPendingLong == 0 && SMAShort[0] > SMALong[0] && rising(SMAShort) && rising(SMALong)) { Margin = 0.1 * OptimalFLong * Capital; #ifdef DEBUG printf("\nNow I setup a long trade with a margin of %.5f and a BuyStop of %.5f",Margin,BuyStop); #endif enterLong(0,BuyStop); } else if (dow() == 5 && NumOpenShort == 0 && NumPendingShort == 0 && SMAShort[0] < SMALong[0] && falling(SMAShort) && falling(SMALong)) { Margin = 0.1 * OptimalFShort * Capital; #ifdef DEBUG printf("\nNow I setup a short trade with a margin of %.5f and a SellStop of %.5f",Margin,SellStop); #endif enterShort(0,SellStop); } if (dow() != 5 && dow() != 6 && dow() != 7) { exitLong(); exitShort(); } } function run() { set(PARAMETERS+FACTORS+LOGFILE); BarPeriod = 1440; StartDate = 2005; NumWFOCycles = 5; LookBack = 120; Capital = 50000; while(asset(loop("USD/CHF","USD/JPY","GBP/USD","EUR/USD","EUR/JPY","USD/CAD","USOil"))) //while(asset(loop("AUD/CAD","AUD/CHF","AUD/JPY","AUD/NZD","AUD/USD","CAD/CHF","CAD/JPY","CHF/JPY","EUR/AUD","EUR/CAD","EUR/CHF","EUR/GBP","EUR/JPY","EUR/NZD","GBP/AUD","GBP/CAD","GBP/CHF","GBP/JPY","GBP/NZD","GBP/USD","NZD/CAD","NZD/CHF","NZD/JPY","NZD/USD","USD/CAD","USD/CHF","USD/JPY","XAG/USD","XAU/USD","USOil"))) //while(asset(loop("AUD/JPY","AUD/USD","CHF/JPY","EUR/JPY","EUR/USD","GBP/USD","NZD/CHF","NZD/JPY","USD/CHF","USD/JPY","USOil"))) tradeOneNightStand(); }