/* DISCLAIMERS:
The following code and ideas are for educational purposes only
and is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR,
CONDITIONS OF ANY KIND, either express or implied.
Trading involves substantial risk of loss and is not suitable for all
investors. Past performance is not indicative of future results.
DESCRIPTION: Identify Hi and Low of Open Range and enter into 3 trades
on break of either Hi or Low. Set 1 Stop & 3 Targets for scale outs.
*/
// Define AssetVar to be used in run function & TMF
#define EntryHI AssetVar[0]
#define EntryLO AssetVar[1]
#define Range AssetVar[2]
#define TradesToday AssetVar[3]
#define TradesLong AssetVar[4]
#define TradesShort AssetVar[5]
int tmf() {
// 3 longs / 3 shorts - with 1 Stop & 3 Targets for scale outs
enterLong(0,EntryHI,Range,Range); // (Lots, Entry, Stop, Target)
enterLong(0,EntryHI,Range,Range*2);
enterLong(0,EntryHI,Range,Range*3);
enterShort(0,EntryLO,Range,Range);
enterShort(0,EntryLO,Range,Range*2);
enterShort(0,EntryLO,Range,Range*3);
if (TradeIsEntry) { // ?? Always appears to be false as printf is never printed. ??
printf("\nTMF-A. TradeIsEntry! %.5d\n",TradeIsEntry);
TradesToday += 1;
if (TradeIsLong) {
TradesLong += 1;
printf("\nTMF-B. Trade for %s is Long.\n TradesToday: (%.0f) & TradesLong: (%.0f) s/b 1, while TradesShort: (%.0f) s/b 0\n",Asset,TradesToday,TradesLong,TradesShort);
}
if (TradeIsShort) {
TradesShort += 1;
printf("\nTMF-C. Trade for %s is Short.\n TradesToday: (%.0f) & TradesShort: (%.0f) s/b 1, while TradesLong: (%.0f) s/b 0\n",Asset,TradesToday,TradesShort,TradesLong);
}
}
return 0;
}
function run() {
set(TICKS|LOGFILE); //|RISKLIMIT|PLOTNOW);
BarPeriod = 30; // 1 Hour
var WiggleRoom = 1; // Room in *PIPs to add/subtract from entries
int limit = 3; // max number of trades
Risk = 200; // Max Risk per trade
// DATE & TIME VARIABLES (TIMES ARE IN CHICAGO TIME (Central))
StartDate = 20100102; // Start date
EndDate = 20100105; // End date
AssetZone = CST; // Set timezone to Central (i.e. Chicago)
int marketstarthour = 8;
int marketstartminute = 30;
int marketendhour = 15;
int marketendminute = 0;
int StartTradingHour = 9;
int StartTradingMinute = 0;
int StopTradingHour = 14;
int StopTradingMinute = 30;
int OpenRangeHourEnds = 9; // Open Range Hour ends
int OpenRangeMinuteEnds = 0; // Open Range Minute ends
// COSTS
Spread = Commission = Slippage = RollLong = RollShort = 0; // Ignore costs
// INITRUN
if (is(INITRUN)) {
EntryHI = 0; EntryLO = 0; Range = 0; TradesToday = 0; TradesLong = 0;
TradesShort = 0; } // Clear Variables prior to initial run
while(asset(loop("SPX500"))) { // Define Assets
vars hi = series(priceHigh()); // Create Series of Highs
vars lo = series(priceLow()); // Create Series of Lows
// Print details for debugging
printf("\nA. %s - hi %.5f, lo %.5f\n",Asset,hi[0],lo[0]);
vars BarHI = series(MaxVal(hi,BarPeriod)); // Series of Max Highs
vars BarLO = series(MinVal(lo,BarPeriod)); // Series of Min Lows
vars BarRange = series(BarHI[0]-BarLO[0]); // Series of Hi-Lo Ranges
// Print details for debugging
printf("\nB. %s - BarHI %.5f, BarLO %.5f, BarRange %.5f\n",Asset,BarHI[0],BarLO[0],BarRange[0]);
if(lhour() == OpenRangeHourEnds && minute() == OpenRangeMinuteEnds) {
EntryHI = BarHI[0]+WiggleRoom*PIP;
EntryLO = BarLO[0]-WiggleRoom*PIP;
Range = BarRange[0]+(2*WiggleRoom*PIP);
// Print details for debugging
printf("\nC. %s - EntryHI: %.5f, EntryLO: %.5f, Range: %.5f\n",Asset,EntryHI,EntryLO,Range);
}
if (lhour() >= StartTradingHour && minute() >= StartTradingMinute && lhour() <= StopTradingHour && minute() <= StopTradingMinute ) {
tmf(); // Call TMF for trades
//enterLong(tmf);
//enterShort(tmf);
}
}
}