Posted By: Mithrandir77
Using a TMF to enter and exit at seconds and getting seconds==0 - 12/04/14 04:22
I made the following code by modifying workshop 4 so that it enters a trade after it receives confirmation that the trend is continuing, the problem is that inside the TMF tradeAtSeconds() I do printf("%d",seconds()) and it always prints 0 , if the barperiod is 1 shouldn't it be printing different seconds corresponding to the ocurrences of ticks inside 1 minute bars? Thanks for your help!
Code:
// 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 }