Welcome to NexusFi: the best trading community on the planet, with over 150,000 members Sign Up Now for Free
Genuine reviews from real traders, not fake reviews from stealth vendors
Quality education from leading professional traders
We are a friendly, helpful, and positive community
We do not tolerate rude behavior, trolling, or vendors advertising in posts
We are here to help, just let us know what you need
You'll need to register in order to view the content of the threads and start contributing to our community. It's free for basic access, or support us by becoming an Elite Member -- see if you qualify for a discount below.
-- Big Mike, Site Administrator
(If you already have an account, login at the top of the page)
I am new to this forum and I would like to get your support on the following strategy that I would like to adjust to trade the OR breakout for futures. I found this code on another post and I would like to make following modifications:
- add opening and closing time (for me 15.30 and 22.00 since I am based in Europe)currently this code takes the first bar of the day on the chart. I could use the index tickers but I usually trade on futures index
- add stop loss @high/low of opening range when going short/long
- take profit end of the day at 22:01 (CET time)
if date <> date[1] then begin
yHi = sessHi;
yLo = sessLo;
yOp = sessOp;
yCl = Close[1];
sessOp = Open;
sessLo = Low;
sessHi = High;
datr = XAverage(DailyATR(1), 7);
tradestoday = 0;
end;
if time > startTime*100 and time <= endTime*100 then begin
if High > SessHi then SessHi = High;
if Low < SessLo then SessLo = Low;
end;
if time > startTradeTime * 100 and time < 1320 and AbsValue(sessHi - sessLo) > (minrange * MinMove / PriceScale) and MarketPosition = 0 and exitdate(1) <> date then begin
SetStopContract;
SetStopLoss( stoploss * BigPointValue );
// entries
condition1 = false;
condition2 = false;
if mind_yesthl = 1 and Close + (target1 * MinMove / PriceScale) > yHi then condition1 = true;
if mind_yesthl = 1 and Close - (target1 * MinMove / PriceScale) < yLo then condition2 = true;
if mind_yesthl = 0 then begin condition1 = true; condition2 = true; end;
condition3 = false;
condition4 = false;
if mind_gap = 1 and sessOp > yCl and sessLo < yCl then condition3 = true;
if mind_gap = 1 and sessOp < yCl and sessHi > yCl then condition4 = true;
if mind_gap = 0 then begin condition3 = true; condition4 = true; end;
if use_yest = 0 and condition1 and condition3 and Close > SessHi then begin
Buy 3 Contracts Next Bar At Market;
tradestoday = 1;
end;
if use_yest = 0 and condition2 and condition4 and Close < SessLo then begin
Sellshort 3 Contracts Next Bar At Market;
tradestoday = 1;
end;
if use_yest = 1 and condition1 and condition3 and Close > yHi then begin
Buy 3 Contracts Next Bar At Market;
tradestoday = 1;
end;
if use_yest = 1 and condition2 and condition4 and Close < yLo then begin
Sellshort 3 Contracts Next Bar At Market;
tradestoday = 1;
end;
if use_yest = 2 and condition1 and condition3 and Close > yHi and Close > SessHi then begin
Buy 3 Contracts Next Bar At Market;
tradestoday = 1;
end;
if use_yest = 2 and condition2 and condition4 and Close < yLo and Close < SessLo then begin
Sellshort 3 Contracts Next Bar At Market;
tradestoday = 1;
end;
if use_yest = 3 and condition1 and condition3 and Close > SessHi and (Close > yHi or sessLo > yHi) then begin
Buy 3 Contracts Next Bar At Market;
tradestoday = 1;
end;
if use_yest = 3 and condition2 and condition4 and Close < SessLo and (Close < yLo or sessHi < yLo) then begin
Sellshort 3 Contracts Next Bar At Market;
tradestoday = 1;
end;
if use_yest = 4 and condition1 and condition3 and Close > SessHi and (Close > yHi or sessLo > yOp) then begin
Buy 3 Contracts Next Bar At Market;
tradestoday = 1;
end;
if use_yest = 4 and condition2 and condition4 and Close < SessLo and (Close < yLo or sessHi < yOp) then begin
Sellshort 3 Contracts Next Bar At Market;
tradestoday = 1;
end;
if use_yest = 5 and condition1 and condition3 and Close > SessHi and (Close > yHi or sessLo > yCl) then begin
Buy 3 Contracts Next Bar At Market;
tradestoday = 1;
end;
if use_yest = 5 and condition2 and condition4 and Close < SessLo and (Close < yLo or sessHi < yCl) then begin
Sellshort 3 Contracts Next Bar At Market;
tradestoday = 1;
end;
end;
if MarketPosition = 1 then begin
if CurrentContracts = 3 then begin
Sell 1 Contracts Next Bar At EntryPrice(0) + (target1 * MinMove / PriceScale) Limit;
Sell 1 Contracts Next Bar At EntryPrice(0) + ((target1+target2) * MinMove / PriceScale) Limit;
Sell 1 Contracts Next Bar At EntryPrice(0) + ((target1+target2+target3) * MinMove / PriceScale) Limit;
end;
if CurrentContracts = 2 then begin
Sell 1 Contracts Next Bar At EntryPrice(0) + ((target1+target2) * MinMove / PriceScale) Limit;
Sell 1 Contracts Next Bar At EntryPrice(0) + ((target1+target2+target3) * MinMove / PriceScale) Limit;
end;
if CurrentContracts = 1 then begin
Sell 1 Contracts Next Bar At EntryPrice(0) + (target1 * MinMove / PriceScale) Limit;
end;
end;
if MarketPosition = -1 then begin
if CurrentContracts = 3 then begin
Buytocover 1 Contracts Next Bar At EntryPrice(0) - (target1 * MinMove / PriceScale) Limit;
Buytocover 1 Contracts Next Bar At EntryPrice(0) - ((target1+target2) * MinMove / PriceScale) Limit;
Buytocover 1 Contracts Next Bar At EntryPrice(0) - ((target1+target2+target3) * MinMove / PriceScale) Limit;
end;
if CurrentContracts = 2 then begin
Buytocover 1 Contracts Next Bar At EntryPrice(0) - ((target1+target2) * MinMove / PriceScale) Limit;
Buytocover 1 Contracts Next Bar At EntryPrice(0) - ((target1+target2+target3) * MinMove / PriceScale) Limit;
end;
if CurrentContracts = 1 then begin
Buytocover 1 Contracts Next Bar At EntryPrice(0) - (target1 * MinMove / PriceScale) Limit;
end;
end;
if time > 1320 and MarketPosition = 1 then Sell All Contracts Next Bar At Market;
if time > 1320 and MarketPosition = -1 then Buytocover All Contracts Next Bar At Market;
if use_stop_method = 1 and MarketPosition = 1 then Sell All Contracts Next Bar At MinList(Low[BarsSinceEntry], Low[BarsSinceEntry+1], Low[BarsSinceEntry+2]) Stop;
if use_stop_method = 1 and MarketPosition = -1 then Buytocover All Contracts Next Bar At MaxList(High[BarsSinceEntry], High[BarsSinceEntry+1], High[BarsSinceEntry+2]) Stop;
if use_stop_method = 2 and MarketPosition = 1 and Lowest(Low, 3)[BarsSinceEntry] > XAverage(Close, 20) and Close < XAverage(Close, 20) then Sell All Contracts Next Bar At Market;
if use_stop_method = 2 and MarketPosition = -1 and Highest(High, 3)[BarsSinceEntry] < XAverage(Close, 20) and Close > XAverage(Close, 20) then Buytocover All Contracts Next Bar At Market;
// check for dt/db
if MarketPosition = 1 and Highest(High, 100)[1] = High then Sell All Contracts Next Bar At Market;
if MarketPosition = -1 and Lowest(Low, 100)[1] = Low then Buytocover All Contracts Next Bar At Market;