In Mikes Easylanguage video, he shows the following code:
if CurrentShares = 100 then begin
Sell("Exit L300-CS100 Target") 100 Shares next Bar at (EntryPrice + t3) Limit;
Sell("Exit L300-CS100 Stop") 100 Shares next Bar at St3 Stop;
end;
But the problem is, that it cant execute the sales on the current bar. So how can I make it so it uses "this bar" instead of "next bar"?
Thanks in advance.
Can you help answer these questions from other members on futures io?
It is obvious for @Bimi, but I prefer to add this comment for the OP.
With the above instruction, the trade will be triggered the first time the condition is met within the bar. Possibly in the middle of the bar or even at the first tick.
It is not a "buy at close".
Nicolas
Envoyé depuis mon GT-I9100 avec Tapatalk
The following 2 users say Thank You to Nicolas11 for this post:
Ok I did that, but i still have a problem, I want to enter using next bar, but possibly exit this bar. So I changed the code, and noticed that buy 100 shares next bar at the high of the current bar wont trigger a buy ever....
Here is the code
[intrabarordergeneration = true]
If Low > Low[1] and High > High[1] then begin
if barstatus(1) = 2 then Buy ("Enter Long") 300 Shares Next Bar At (High) stop;
end;
....
....
....
if CurrentShares = 100 then begin
Sell("Exit L300-CS100 Target") 100 Shares next Bar at (EntryPrice) Limit;
Sell("Exit L300-CS100 Stop") 100 Shares next Bar at st3 Stop;
end;
print ("this is ticksize = "+ NumToStr(ticksize ,2));
print ("this is enter = "+ NumToStr(entryprice ,2));
print ("this is stop = "+ NumToStr(st1 ,2));
print ("this is stopsize = "+ NumToStr(stopsize ,2));
if CurrentShares = 100 then begin
Sell("Exit L300-CS100 Target") 100 Shares next Bar at (EntryPrice + t3) Limit;
Sell("Exit L300-CS100 Stop") 100 Shares next Bar at st3 Stop;
end;
if CurrentShares = 200 then begin
Sell("Exit L200-CS200 Target") 100 Shares Next Bar at (EntryPrice + t2) Limit;
Sell("Exit L200-CS200 Stop") 100 Shares Next Bar at st2 Stop;
Sell("Exit L300-CS200 Target") 100 Shares Next Bar at (EntryPrice + t3) Limit;
Sell("Exit L300-CS200 Stop") 100 Shares Next Bar at st3 Stop;
end;
if CurrentShares = 300 then begin
Sell("Exit L100-CS300 Target") 100 Shares Next Bar at (EntryPrice + t1) Limit;
Sell("Exit L100-CS300 Stop") 100 Shares Next Bar at st1 Stop;
Sell("Exit L200-CS300 Target") 100 Shares Next Bar at (EntryPrice + t2) Limit;
Sell("Exit L200-CS300 Stop") 100 Shares Next Bar at st2 Stop;
Sell("Exit L300-CS300 Target") 100 Shares Next Bar at (EntryPrice + t3) Limit;
Sell("Exit L300-CS300 Stop") 100 Shares Next Bar at st3 Stop;
end;
if MarketPosition = 0 and barstatus(1) = 2 and Low > Low[1] and High > High[1] then begin
//and time>1000 and (time <1600)
Print("This is the closing tick of the bar.");
print ("this is buyTrigger = "+ NumToStr(buyTrigger ,0));
print ("timea = " + NumToStr(Time,0));
Buy ("Enter Long") 300 Shares Next Bar At high stop;
//SellShort("Enter Short") 300 Shares Next Bar at (Low-buypoint) stop;
if CurrentShares = 100 then begin
Sell("Exit L300-CS100 Target") 100 Shares next Bar at (EntryPrice + t3) Limit;
Sell("Exit L300-CS100 Stop") 100 Shares next Bar at st3 Stop;
end;
if CurrentShares = 200 then begin
Sell("Exit L200-CS200 Target") 100 Shares Next Bar at (EntryPrice + t2) Limit;
Sell("Exit L200-CS200 Stop") 100 Shares Next Bar at st2 Stop;
Sell("Exit L300-CS200 Target") 100 Shares Next Bar at (EntryPrice + t3) Limit;
Sell("Exit L300-CS200 Stop") 100 Shares Next Bar at st3 Stop;
end;
if CurrentShares = 300 then begin
print ("*********barstatus at exit commands = " + NumToStr(barstatus(1),0));
Sell("Exit L100-CS300 Target") 100 Shares Next Bar at (EntryPrice + t1) Limit;
Sell("Exit L100-CS300 Stop") 100 Shares Next Bar at st1 Stop;
Sell("Exit L200-CS300 Target") 100 Shares Next Bar at (EntryPrice + t1) Limit;
Sell("Exit L200-CS300 Stop") 100 Shares Next Bar at st2 Stop;
Sell("Exit L300-CS300 Target") 100 Shares Next Bar at (EntryPrice + t1) Limit;
Sell("Exit L300-CS300 Stop") 100 Shares Next Bar at st3 Stop;
end;
if CurrentShares = 100 then begin
BuyToCover("Exit S300-CS100 Target") 100 Shares Next Bar at (EntryPrice - t3) Limit;
BuyToCover("Exit S300-CS100 Stop") 100 Shares Next Bar at st3 Stop;
end;
if CurrentShares = 200 then begin
BuyToCover("Exit S200-CS200 Target") 100 Shares Next Bar at (EntryPrice - t2) Limit;
BuyToCover("Exit S200-CS200 Stop") 100 Shares Next Bar at st2 Stop;
BuyToCover("Exit S300-CS200 Target") 100 Shares Next Bar at (EntryPrice - t3) Limit;
BuyToCover("Exit S300-CS200 Stop") 100 Shares Next Bar at st3 Stop;
end;
if CurrentShares = 300 then begin
BuyToCover("Exit S100-CS300 Target") 100 Shares Next Bar at (EntryPrice - t1) Limit;
BuyToCover("Exit S100-CS300 Stop") 100 Shares Next Bar at st1 Stop;
BuyToCover("Exit S200-CS300 Target") 100 Shares Next Bar at (EntryPrice - t2) Limit;
BuyToCover("Exit S200-CS300 Stop") 100 Shares Next Bar at st2 Stop;
BuyToCover("Exit S300-CS300 Target") 100 Shares Next Bar at (EntryPrice - t3) Limit;
BuyToCover("Exit S300-CS300 Stop") 100 Shares Next Bar at st3 Stop;
end;
Thanks, that made the entries all occur on 1 bar, but.... lol, its so funny, now ALL entries are on the bar, even if i put my target 3 to a huge amount and my stop to a huge amount, it should have some exits on other bars.....
if MarketPosition = 0 and barstatus(1) = 2 and Low > Low[1] and High > High[1] then begin
//and time>1000 and (time <1600)
Print("This is the closing tick of the bar.");
print ("this is buyTrigger = "+ NumToStr(buyTrigger ,0));
print ("timea = " + NumToStr(Time,0));
//Buy ("Enter Long") 300 Shares Next Bar At (High+buypoint) stop;
Buy ("Enter Long") 300 Shares Next Bar At high stop;
//SellShort("Enter Short") 300 Shares Next Bar at (Low-buypoint) stop;
//print ("this is ticksize = "+ NumToStr(ticksize ,2));
//print ("this is enter = "+ NumToStr(entryprice ,2));
// print ("this is stop = "+ NumToStr(st1 ,2));
// print ("this is stopsize = "+ NumToStr(stopsize ,2));
//
if CurrentShares = 100 then begin
Sell("Exit L300-CS100 Target") 100 Shares next Bar at (EntryPrice + t3) Limit;
Sell("Exit L300-CS100 Stop") 100 Shares next Bar at st3 Stop;
end;
if CurrentShares = 200 then begin
Sell("Exit L200-CS200 Target") 100 Shares Next Bar at (EntryPrice + t2) Limit;
Sell("Exit L200-CS200 Stop") 100 Shares Next Bar at st2 Stop;
Sell("Exit L300-CS200 Target") 100 Shares Next Bar at (EntryPrice + t3) Limit;
Sell("Exit L300-CS200 Stop") 100 Shares Next Bar at st3 Stop;
end;
if CurrentShares = 300 then begin
print ("*********barstatus at exit commands = " + NumToStr(barstatus(1),0));
Sell("Exit L100-CS300 Target") 100 Shares Next Bar at (EntryPrice + t1) Limit;
Sell("Exit L100-CS300 Stop") 100 Shares Next Bar at st1 Stop;
Sell("Exit L200-CS300 Target") 100 Shares Next Bar at (EntryPrice + t1) Limit;
Sell("Exit L200-CS300 Stop") 100 Shares Next Bar at st2 Stop;
Sell("Exit L300-CS300 Target") 100 Shares Next Bar at (EntryPrice + t1) Limit;
Sell("Exit L300-CS300 Stop") 100 Shares Next Bar at st3 Stop;
end;
if CurrentShares = 100 then begin
BuyToCover("Exit S300-CS100 Target") 100 Shares Next Bar at (EntryPrice - t3) Limit;
BuyToCover("Exit S300-CS100 Stop") 100 Shares Next Bar at st3 Stop;
end;
if CurrentShares = 200 then begin
BuyToCover("Exit S200-CS200 Target") 100 Shares Next Bar at (EntryPrice - t2) Limit;
BuyToCover("Exit S200-CS200 Stop") 100 Shares Next Bar at st2 Stop;
BuyToCover("Exit S300-CS200 Target") 100 Shares Next Bar at (EntryPrice - t3) Limit;
BuyToCover("Exit S300-CS200 Stop") 100 Shares Next Bar at st3 Stop;
end;
if CurrentShares = 300 then begin
BuyToCover("Exit S100-CS300 Target") 100 Shares Next Bar at (EntryPrice - t1) Limit;
BuyToCover("Exit S100-CS300 Stop") 100 Shares Next Bar at st1 Stop;
BuyToCover("Exit S200-CS300 Target") 100 Shares Next Bar at (EntryPrice - t2) Limit;
BuyToCover("Exit S200-CS300 Stop") 100 Shares Next Bar at st2 Stop;
BuyToCover("Exit S300-CS300 Target") 100 Shares Next Bar at (EntryPrice - t3) Limit;
BuyToCover("Exit S300-CS300 Stop") 100 Shares Next Bar at st3 Stop;
end;
Without having checked, I would say that it is not possible to change the default setting, and that you have to check each time you add a strategy. But I may be wrong.
Nicolas
The following user says Thank You to Nicolas11 for this post:
if MarketPosition = 0 and barstatus(1) = 2 and Low > Low[1] and High > High[1] then begin
//and time>1000 and (time <1600)
Print("This is the closing tick of the bar.");
print ("this is buyTrigger = "+ NumToStr(buyTrigger ,0));
print ("timea = " + NumToStr(Time,0));
//Buy ("Enter Long") 300 Shares Next Bar At (High+buypoint) stop;
Buy ("Enter Long") 300 Shares Next Bar At high stop;
//SellShort("Enter Short") 300 Shares Next Bar at (Low-buypoint) stop;
//print ("this is ticksize = "+ NumToStr(ticksize ,2));
//print ("this is enter = "+ NumToStr(entryprice ,2));
// print ("this is stop = "+ NumToStr(st1 ,2));
// print ("this is stopsize = "+ NumToStr(stopsize ,2));
//
if CurrentShares = 100 then begin
Sell("Exit L300-CS100 Target") 100 Shares next Bar at (EntryPrice + t3) Limit;
Sell("Exit L300-CS100 Stop") 100 Shares next Bar at st3 Stop;
end;
if CurrentShares = 200 then begin
Sell("Exit L200-CS200 Target") 100 Shares Next Bar at (EntryPrice + t2) Limit;
Sell("Exit L200-CS200 Stop") 100 Shares Next Bar at st2 Stop;
Sell("Exit L300-CS200 Target") 100 Shares Next Bar at (EntryPrice + t3) Limit;
Sell("Exit L300-CS200 Stop") 100 Shares Next Bar at st3 Stop;
end;
if CurrentShares = 300 then begin
print ("*********barstatus at exit commands = " + NumToStr(barstatus(1),0));
Sell("Exit L100-CS300 Target") 100 Shares Next Bar at (EntryPrice + t1) Limit;
Sell("Exit L100-CS300 Stop") 100 Shares Next Bar at st1 Stop;
Sell("Exit L200-CS300 Target") 100 Shares Next Bar at (EntryPrice + t2) Limit;
Sell("Exit L200-CS300 Stop") 100 Shares Next Bar at st2 Stop;
Sell("Exit L300-CS300 Target") 100 Shares Next Bar at (EntryPrice + t3) Limit;
Sell("Exit L300-CS300 Stop") 100 Shares Next Bar at st3 Stop;
end;
if CurrentShares = 100 then begin
BuyToCover("Exit S300-CS100 Target") 100 Shares Next Bar at (EntryPrice - t3) Limit;
BuyToCover("Exit S300-CS100 Stop") 100 Shares Next Bar at st3 Stop;
end;
if CurrentShares = 200 then begin
BuyToCover("Exit S200-CS200 Target") 100 Shares Next Bar at (EntryPrice - t2) Limit;
BuyToCover("Exit S200-CS200 Stop") 100 Shares Next Bar at st2 Stop;
BuyToCover("Exit S300-CS200 Target") 100 Shares Next Bar at (EntryPrice - t3) Limit;
BuyToCover("Exit S300-CS200 Stop") 100 Shares Next Bar at st3 Stop;
end;
if CurrentShares = 300 then begin
BuyToCover("Exit S100-CS300 Target") 100 Shares Next Bar at (EntryPrice - t1) Limit;
BuyToCover("Exit S100-CS300 Stop") 100 Shares Next Bar at st1 Stop;
BuyToCover("Exit S200-CS300 Target") 100 Shares Next Bar at (EntryPrice - t2) Limit;
BuyToCover("Exit S200-CS300 Stop") 100 Shares Next Bar at st2 Stop;
BuyToCover("Exit S300-CS300 Target") 100 Shares Next Bar at (EntryPrice - t3) Limit;
BuyToCover("Exit S300-CS300 Stop") 100 Shares Next Bar at st3 Stop;
end;
Looks OK.
I cannot reproduce your problem on my computer, so it is difficult for me to help you.
I suggest that you replace all "at st1", "at st2" and "at st3" by "at EntryPrice-0.75" for long and "at EntryPrice+0.75" for long.
If it works, try to put again your current code, but step by step:
Begin with "at EntryPrice-75*TickSize"
Then more and more sophisticated until you understand at which step the problem appear.
The following 2 users say Thank You to Nicolas11 for this post:
if MarketPosition = 0 and barstatus(1) = 2 and Low >= Low[1] and High >= High[1] then begin
//and time>1000 and (time <1600)
//Print("This is the closing tick of the bar.");
// print ("this is buyTrigger = "+ NumToStr(buyTrigger ,0));
// print ("timea = " + NumToStr(Time,0));
print ("ticksize = " + numtoStr(TickSize,2));
//Buy ("Enter Long") 300 Shares Next Bar At (High+buypoint) stop;
Buy ("Enter Long") 300 Shares Next Bar At high stop;
//SellShort("Enter Short") 300 Shares Next Bar at (Low-buypoint) stop;
//print ("this is ticksize = "+ NumToStr(ticksize ,2));
//print ("this is enter = "+ NumToStr(entryprice ,2));
// print ("this is stop = "+ NumToStr(st1 ,2));
// print ("this is stopsize = "+ NumToStr(stopsize ,2));
//
if CurrentShares = 100 then begin
Sell("Exit L300-CS100 Target") 100 Shares next Bar at (EntryPrice + t3) Limit;
Sell("Exit L300-CS100 Stop") 100 Shares next Bar at (EntryPrice-1) Stop;
end;
if CurrentShares = 200 then begin
Sell("Exit L200-CS200 Target") 100 Shares Next Bar at (EntryPrice + t2) Limit;
Sell("Exit L200-CS200 Stop") 100 Shares Next Bar at (EntryPrice-1) Stop;
Sell("Exit L300-CS200 Target") 100 Shares Next Bar at (EntryPrice + t3) Limit;
Sell("Exit L300-CS200 Stop") 100 Shares Next Bar at (EntryPrice-1) Stop;
end;
if CurrentShares = 300 then begin
print ("*********barstatus at exit commands = " + NumToStr(barstatus(1),0));
Sell("Exit L100-CS300 Target") 100 Shares Next Bar at (EntryPrice + t1) Limit;
Sell("Exit L100-CS300 Stop") 100 Shares Next Bar at (EntryPrice-1) Stop;
Sell("Exit L200-CS300 Target") 100 Shares Next Bar at (EntryPrice + t2) Limit;
Sell("Exit L200-CS300 Stop") 100 Shares Next Bar at (EntryPrice-1) Stop;
Sell("Exit L300-CS300 Target") 100 Shares Next Bar at (EntryPrice + t3) Limit;
Sell("Exit L300-CS300 Stop") 100 Shares Next Bar at (EntryPrice-1) Stop;
end;
if CurrentShares = 100 then begin
BuyToCover("Exit S300-CS100 Target") 100 Shares Next Bar at (EntryPrice - t3) Limit;
BuyToCover("Exit S300-CS100 Stop") 100 Shares Next Bar at st3 Stop;
end;
if CurrentShares = 200 then begin
BuyToCover("Exit S200-CS200 Target") 100 Shares Next Bar at (EntryPrice - t2) Limit;
BuyToCover("Exit S200-CS200 Stop") 100 Shares Next Bar at st2 Stop;
BuyToCover("Exit S300-CS200 Target") 100 Shares Next Bar at (EntryPrice - t3) Limit;
BuyToCover("Exit S300-CS200 Stop") 100 Shares Next Bar at st3 Stop;
end;
if CurrentShares = 300 then begin
BuyToCover("Exit S100-CS300 Target") 100 Shares Next Bar at (EntryPrice - t1) Limit;
BuyToCover("Exit S100-CS300 Stop") 100 Shares Next Bar at st1 Stop;
BuyToCover("Exit S200-CS300 Target") 100 Shares Next Bar at (EntryPrice - t2) Limit;
BuyToCover("Exit S200-CS300 Stop") 100 Shares Next Bar at st2 Stop;
BuyToCover("Exit S300-CS300 Target") 100 Shares Next Bar at (EntryPrice - t3) Limit;
BuyToCover("Exit S300-CS300 Stop") 100 Shares Next Bar at st3 Stop;
end;
Please use the [ CODE] tags around your code next time.
I still cannot reproduce the problem on my side.
And the problem seems to evolve on your side.
On your last screenshot, the problem does not seem linked to stops, since the last trade was correctly stopped. And you were flat afterwards.
This time, the issue seems that the strategy does not enter trade whereas it is supposed to.
Could you:
1. print the time and the value of CurrentShares at each candle in order to check that you are flat when you are supposed to be flat?
2. delete "and BarStatus(1) = 2"
Any improvement?
Nicolas
The following user says Thank You to Nicolas11 for this post:
I need the " BarStatus(1) = 2" because I want to enter on the next bar on the break of the prior bar high...
I entered the
print(Date:8:0," ", Time:4:0, " --> CurrentShares = ", CurrentShares);
But I cant decipher the time, is it possible to put the # of shares held Below the bar itself?
Another approach to this whole thing would be to use a 1 minute chart, then what I would do is somehow get the high and the low of the rounded last hour bar... Then if it breaks above that in the next hour it would be a long. That would be the best way.
So that way, I would do the following: I would need a function that would get me the highest high and lowest low of the stock during the rounded hour timeframe: 10:00am to 10:59am , 11:00am to 11:59 am. then I can enter on next bar, and do a lot more elegant stop strategies... Do you know how i can write such a function that can do that?
What it would do is create a high and a low horizontal trendline for the next hour... and it would keep doing that moving forward
so each prior rounder prior hour would have a high and a low price, and then it would create a trend line for the next hour's worth of bars so u can see if it is breaking the high or the low of the prior hour.. That way I would have the power of using hour bars to determine entry prices and i can use 1 minute bars to determine exit strategy.
1. The 1-min workaround is another story. I think that we first need to solve what happens with the 1-hour bar.
2. "I cant decipher the time". I do not understand. Could you show me an example of what is printed?
On my side, it is rather clear:
3. "Is it possible to put the # of shares held Below the bar itself?"
Yes.
EDIT: This works for MultiCharts. I do not know for TradeStation.
4. "I need the " BarStatus(1) = 2" because I want to enter on the next bar on the break of the prior bar high..."
I am lost.
In the first message, I have the feeling that you wanted exactly the contrary: enter within a bar.
If you want to enter right at the opening of the next bar when a condition is met, you shall not use [intrabarordergeneration = true]
Please clarify.
3) ok i put that in the code, and i have enclosed screenshot
4) i want to enter in the next bar, once it breaks the high of the prior bar , but I want to be able to exit if my target is met on the same bar that I entered....
For the date, do not forget that 112 means 2012 in Easy Language (add 1900).
The text printing on the chart is OK. We see the "0". When the trade lasts on several bars, you should see 300, 200, 100. If you want to change the color or the size:
I have to make a break. I will come back later.
The following user says Thank You to Nicolas11 for this post:
If I have correctly understood what you are trying to do, this is not straight-forward.
I have myself struggled with it for a long time.
So thanks for your question, since it allows me clarifying things in my mind.
But the negative side is... I may be wrong!
You want the exits (stop-loss or profit target) to possibly occur on the same bar as the entry.
I think this requires [intrabarordergeneration = true].
But [IntrabarOrderGeneration = true] has a negative side effect: the condition for the entry is checked at any moment within the current bar. But you want the condition to be checked only at bar close. So there is your BarStatus = 2.
So... I'm OK with your code.
It remains that you have some problem.
I advise that you simplify your code to the simplest. For me, the simplest form is 10 lines:
Does it work? If yes, add the sophistications one by one until the problem appears.
Nicolas
The following user says Thank You to Nicolas11 for this post:
If one uses BarStatus = 2 with 'buy next bar', the order will be executed on the first tick of the next bar (assuming it's a market order, otherwise it will be cancelled). With IntrabarOrderGeneration set on, the stop-loss for the same bar can be send on the second tick of the bar.
I can't say I understand the whole thread, but if I understand it correctly the enter stop orders need to be submitted for the whole duration of the next bar? If so, you'll need to use a true/false value to keep continue submitting the stop order for the next bar.
Because with IntrabarOrderGeneration next bar actually means next tick, the enter stop needs to be resubmitted. Otherwise, if the enter stop conditions aren't triggered on the first tick of the next bar, the order is cancelled.
Such a thing could look like:
The following 3 users say Thank You to Jura for this post:
I implemented the code you are suggesting.. I agree its a good idea to make it as simple as possible to figure out the problem.
Here is the chart with circled red where it should have entered on the bars with red underlines in the circle, code is below also...
I am showing with 5 min bar charts and 60 Min bar chart
5 MIN BARS
60 MIN BARS
I used 1 dollar hardcoded for entrypice and exit price, since i am trading aapl.
variables:
TickSize (MinMove/PriceScale);
[IntrabarOrderGeneration = true]
// open new positions
if (MarketPosition = 0 and barstatus(1) = 2 and Low >= Low[1] and High >= High[1]) then begin
Buy ("Enter Long") 300 Shares Next Bar At high stop;
end;
Value1 = Text_New(Date, Time, Low-TickSize, NumToStr(CurrentShares, 0));
// manage open orders
if MarketPosition = 1 then begin
Sell("Profit Target") 300 Shares Next Bar at (EntryPrice + 1) Limit;
Sell("Stop Loss") 300 Shares Next Bar at (EntryPrice-1) Stop;
end;
First, I managed to reproduce your problem, on the same chart (AAPL 1min July 26th, 2012).
From @Jura's post above, I understand that, when [IntrabarOrderGeneration = true], "at next bar" means "at next tick".
So the strategy was entering "at next bar" (in the common sense) only if the first tick of the next bar was above the High of the current one.
But you want to enter at any tick within "next bar" provided that this tick is above the High of the current one.
So you have to use @Jura's idea.
I have integrated it into our small code. See below. It seems to work. See picture.
"at High stop" is correct when the above 3-line block of code is read on the last tick of the current bar.
But if these lines are read at a tick within the next bar (supposed to be the entry bar), should be "at High[1] stop".
I think that it could be corrected as follows:
The following 2 users say Thank You to Nicolas11 for this post:
Yes that is correct. It works now... You are correct that we need to store the PriceForEntry in a variable.... Thanks so much!
Because I would like to make sophisticated stops, it would be good to use a lower time frame chart, but use a higher time frame data for entries.
Yesterday I spoke of creating a high and a low for the complete hour and drawing a trendline on the chart for each next hour.. So if during 10am to 11am the highest tick was 610.20 and the lowest tick was 605.80 then we would have horizontal trendlines from 11am to 12am at 610.20 and 605.80. This would be a visual cue , but in fact the strategy would enter a trade long if it price broke above 610.20 and would enter short if it broke below 605.80. Then I can use the smaller time frame bars in the chart to manage the exit (do a trailing stop if i am in a long trade and it breaks the highest low of the last 2 bars or something).
Actually the existing strategy would look at the trendlines of the last 2 hours, to see if trendlines are higher high and lower low, and then if so , if the next hour breaks the high it enters long...
If you have time to code something like that, I would really appreciate it.
1. You're welcome, but your thanks shall also be directed to @Jura: he solved the most difficult part.
2. Even if it is possible, I think that there is no need to use 2 timeframes to manage your strategy. With [intrabarordergeneration = true], you can manage what happens at all ticks in the bar.
3. "the strategy would enter a trade long if it price broke above 610.20 and would enter short if it broke below 605.80"
Do you mean that the strategy would enter long at any bar on a breakout (up) of last bar's High?
If yes, you can very easily adapt the above code. I do not see the problem.
4. Trendlines --> I first need to understand 3.
Nicolas
The following user says Thank You to Nicolas11 for this post:
9am to 10am Highest high was 505.20 Lowest Low was 502.30
10am to 11am Highest high was 506.20 Lowest Low was 503.50
Therefore, if we were in hourly chart we would see that the last bar offered a higher high and a higher low.
So if during the next hour, price rose above 503.20 we would enter long.
The reason why I would like to have lower time frame bars is because by looking at how bars are painted I can do more sophisticated stops. For example if i had 300 shares long, after it hit target 1, then i can implement an trailing stop where I would look at the last 3 five minute bars and if price fell below the lowest low of the last 3 bars then it would stop me out of the trade.
Therefore, I use the hourly highest high and lowest lows to determine if the trade is qualified to go long, and at what price, then I can use a lower time frame bar (for example, 5 minute bars) to implement a more agile and sophisticated stop strategy.
Since we are using a 10 minute chart, it would look at the 6 bars from 9am to 10am and look for the highest and lowest price that the bars touched during that time.
9:10 Bar: High=500.10 Low = 500.00
9:20 Bar: High=500.50 Low = 498.10
9:30 Bar: High=502.10 Low = 500.10
9:40 Bar: High=501.10 Low = 499.22
9:50 Bar: High=505.20 Low = 500.20
10:00 Bar: High=505.20 Low = 501.20
The highest high = 505.20 and the Lowest low is 498.10 for the hour.
so then we would draw two horizontal trendlines (one at 505.20 and one at 498.10) that would span into the future from 10:10 to 11:00
So...
Within all 10-min bars of a given hour (10:10-11:00), you want to see a trendline showing the High and Low of the previous hour (09:10-10:00).
Correct?
The way I envision it is that the code will determine how many bars in the given time frame make up an hour, and then it will iterate through the bars to find the highest high and lowest low. That way the hourly code can work in different time scales, be it 1 min, 5 min, 10 min or 15 min...
I thought it would be a good idea to create a new thread specifically for EasyLanguage -- TradeStation / MultiCharts / OEC -- requests to get your indicator created for free.
If you have a request to …
I also suggest that, in the other thread, you use a brief description as your request. Not too far from:
Nicolas
The following user says Thank You to Nicolas11 for this post:
Hi, I discovered a problem with the current implementation.
It is possible for there to be more than one entry in a given bar, that means that if in a given hourly bar, the code enters a trade and exits the trade at target, and its still moving up, it can enter the trade again. I would like the code to enter trades max 1 time per bar.
Should we add another condition to the if statement below in the code, where it can only execute an entry if price is within a certain range also?
Let's suppose that, at the last tick of the bar (BarStatus = 2), EnterTrade is set to true (first part of the code)
With the 2nd part of the code, you ask to buy at the next tick (first tick of the next bar) at a given price.
But you also set EnterTrade to false.
So, if the given price is not reached on the first tick of the next bar, the code will not enter trade later within the bar.
Nicolas
The following user says Thank You to Nicolas11 for this post: