// Workshop 4: Trend Trading ///////////////////
#include <profile.c>
#define initialPrice TradeVar[0]
#define seconds TradeVar[1]
int tradeAtSeconds()
{
seconds = second();
printf("\nseg: %d\n",seconds);
if (seconds > 50){
printf("\nTrade %d exited cuz out of time at: %d/%d/%d %d:%d:%d\n",TradeID,day(),month(),year(),hour(),minute(),second());
return 1;
}
if (TradeIsLong){
if (TradeIsNewBar)//first tick of a new 60 seconds-bar, I set the Entry Limit to 12 pips above initialPrice
TradeEntryLimit = initialPrice + 12 * PIP;
else
if (!TradeIsOpen)
if (TradePriceOpen >= TradeEntryLimit){
printf("\nLong %d entered at: %d/%d/%d %d:%d:%d\n",TradeID,day(),month(),year(),hour(),minute(),second());
return 2+4;}
else
if (TradeProfit/TradeUnits/PIP >= 27){//close the trade at this very second
printf("\nLong %d exited at: %d/%d/%d %d:%d:%d\n",TradeID,day(),month(),year(),hour(),minute(),second());
return 1;
}
}
else{
if (TradeIsNewBar)//first tick of a new 60 seconds-bar, I set the Entry Limit to 12 pips below initialPrice
TradeEntryLimit = initialPrice - 12 * PIP;
else
if (!TradeIsOpen)
if (TradePriceOpen <= TradeEntryLimit){
printf("\nShort %d entered at: %d/%d/%d %d:%d:%d\n",TradeID,day(),month(),year(),hour(),minute(),second());
return 2+4;}
else
if (TradeProfit/TradeUnits/PIP >= 27){//close the trade at this very second
printf("\nShort %d exited at: %d/%d/%d %d:%d:%d\n",TradeID,day(),month(),year(),hour(),minute(),second());
return 1;
}
}
return 4;
}
function run()
{
BarPeriod = 1;
set(TICKS);
StartDate = 20140606;
EndDate = 20140624;
vars Price = series(price());
vars Trend = series(LowPass(Price,500));
Stop = 4*ATR(100);
initialPrice = priceClose();
seconds = 0;
if(valley(Trend))
enterLong(tradeAtSeconds());
else if(peak(Trend))
enterShort(tradeAtSeconds());
//zoom in a certain date
// PlotDate = 20140606;
// PlotBars = 300;
// ColorEquity = ColorDD = 0;
// ColorUp = ColorDn = 0x00AAAAAA;
// plot("Trend",Trend[0],0,BLACK);
// set(PLOTNOW);
PlotWidth = 800;
PlotHeight1 = 300;
// ColorWin = ColorLoss = 0;
// plotTradeProfile(-50); // plot the trade profit distribution
set(LOGFILE); // log all trades
}