Posted By: Cstyle
Setting TradeStopLimit and TradeTrailLimit - 06/29/16 00:33
I'm trying to write a simple strategy which starts to trail only after the trade is profitable. I'm using a TMF with TradeStopLimit and TradeTrailLimit, but it is not behaving as I would expect:
The values being written to the log for TradeStopLimit and TradeTrailLimit via printf also don't seem right. What am I doing wrong?
Thanks!
Code:
#include <profile.c> int TrailWhenProfitable() { static bool TrailInitiated; if(NumOpenLong > 0 ) { if (priceClose() > TradePriceOpen + (2 * ATR(100)) && TrailInitiated == false) { TradeStopLimit = TradePriceOpen; TradeTrailLimit = TradePriceOpen + ATR(100); TrailInitiated = true; printf(" TradeStopLimit = %.3f, TradeTrailLimit = %.3f", TradeStopLimit, TradeTrailLimit); printf(" ATR = %.3f, priceClose = %.3f", ATR(100), priceClose()); printf(" TradePriceOpen = %.3f, TradePriceClose = %.3f", TradePriceOpen, TradePriceClose); } } else TrailInitiated = false; return 0; } function run() { StartDate = 2009; EndDate = 2016; LookBack = 500; set(LOGFILE); // log all trades set(TICKS); // normally needed for TMF vars Price = series(price()); vars Trend = series(LowPass(Price,500)); if(valley(Trend) && NumOpenLong == 0) { enterLong(TrailWhenProfitable); } }
The values being written to the log for TradeStopLimit and TradeTrailLimit via printf also don't seem right. What am I doing wrong?
Thanks!