Trend line trading
-
- Posts: 191
- Joined: 27 Apr 2010
- Location: San Jose
- Has thanked: 67 times
- Been thanked: 10 times
Trend line trading
I read through a number of threads and saw some posts by bowlesj3 and others that discuss the MC TL and text functionality that could be used to develop TL-based trading. I don't want to re-create Chart Trading, but there are some limitations to it that finally discouraged me from using it: 1) it only does horizontal trendlines 2) all orders are transmitted to the broker's server for the stop hunter bots to see and 3) I have some custom entry and exit techniques for which I cannot use basic stop or limit orders.
Below is the basic outline for how I would ideally want to interact with trend line trading. I'm sure there are others out there who have thought this through and have some ideas. I'd appreciate some feedback and--as always--pointers to threads or other resources I might have missed.
User Story:
The trader activates the trend line trading signal on a chart in MC. He inputs the number of contracts to take off at profit target 1 and profit target 2 and from this the signal calculates the position size. The signal initially creates two trendlines in the bottom left corner of the chart: (Long Entry, Short Entry). “Clone Long Entry Trendline” and “Clone Short Entry Trendline” text blocks are also positioned in the lower left. Clicking on them enables the user to spawn new entry trendlines at any time.
The entry trendlines are initialized in an inactive state. The trendlines can be positioned on the chart. Each trendline has a label attached to its left terminus (LE, SE). Once in place a trendline may be activated/de-activated by clicking on its label text.
When a trendline is activated the following occurs: 1) the label text changes to indicate that the trendline is active 2) two separate target exit trendlines (LX1 and LX2) are created above the entry line in inactive state and 3) a stop trendline (LXS) will be created below the entry line in inactive state (vice versa for short trades). The default placements of the targets and stop will be based on user inputs to the signal.
When a long position is entered the target and stop trendlines will be automatically updated to active state. When the first target is hit, its trendline will be deleted from the chart. At any time when in a long position, the Short Entry line can be positioned above or below the current price and if crossed it will result in the long position being reversed. Any remaining long target and stop orders will be cancelled and new short target and stop trendlines will be auto-created and auto-activated. Hitting a stop will result in all remaining target trendlines being deleted.
That's it. Seems pretty reasonable, but then I may not know what I don't know.
Thanks,
PDQ
Below is the basic outline for how I would ideally want to interact with trend line trading. I'm sure there are others out there who have thought this through and have some ideas. I'd appreciate some feedback and--as always--pointers to threads or other resources I might have missed.
User Story:
The trader activates the trend line trading signal on a chart in MC. He inputs the number of contracts to take off at profit target 1 and profit target 2 and from this the signal calculates the position size. The signal initially creates two trendlines in the bottom left corner of the chart: (Long Entry, Short Entry). “Clone Long Entry Trendline” and “Clone Short Entry Trendline” text blocks are also positioned in the lower left. Clicking on them enables the user to spawn new entry trendlines at any time.
The entry trendlines are initialized in an inactive state. The trendlines can be positioned on the chart. Each trendline has a label attached to its left terminus (LE, SE). Once in place a trendline may be activated/de-activated by clicking on its label text.
When a trendline is activated the following occurs: 1) the label text changes to indicate that the trendline is active 2) two separate target exit trendlines (LX1 and LX2) are created above the entry line in inactive state and 3) a stop trendline (LXS) will be created below the entry line in inactive state (vice versa for short trades). The default placements of the targets and stop will be based on user inputs to the signal.
When a long position is entered the target and stop trendlines will be automatically updated to active state. When the first target is hit, its trendline will be deleted from the chart. At any time when in a long position, the Short Entry line can be positioned above or below the current price and if crossed it will result in the long position being reversed. Any remaining long target and stop orders will be cancelled and new short target and stop trendlines will be auto-created and auto-activated. Hitting a stop will result in all remaining target trendlines being deleted.
That's it. Seems pretty reasonable, but then I may not know what I don't know.
Thanks,
PDQ
- Roman MultiCharts
- Posts: 50
- Joined: 28 Nov 2011
- Has thanked: 21 times
- Been thanked: 67 times
Re: Trend line trading
Hello PD Quig,
Could you please be more specific in your request? What exact aspects of TL coding would you like the community to help you with?
Could you please be more specific in your request? What exact aspects of TL coding would you like the community to help you with?
-
- Posts: 191
- Joined: 27 Apr 2010
- Location: San Jose
- Has thanked: 67 times
- Been thanked: 10 times
Re: Trend line trading
Hi Roman,
I am looking for sample code for trend line trading--rather than starting from ground zero. I looked through the user contributed studies and didn't find anything that appeared to directly address trend line trading.
There was a note from TJ back in Jan 2009 (viewtopic.php?f=5&t=5941) asking if anybody had access to some TS code on their forum:
PDQ
I am looking for sample code for trend line trading--rather than starting from ground zero. I looked through the user contributed studies and didn't find anything that appeared to directly address trend line trading.
There was a note from TJ back in Jan 2009 (viewtopic.php?f=5&t=5941) asking if anybody had access to some TS code on their forum:
This is exactly the kind of thing I'm looking for as a starter."In TS, you can hand draw a line on a chart and have an order executed based on price crossing the line you drew. You can enter three lines of different color for entry, stop loss, and profit target. The code is readily available on their forum if you have access to it.
https://www.TS.com/Discussion ... ic_ID=5863
PDQ
Re: Trend line trading
I am pretty sure what you want to do could be done (not that I am 100% sure what you want to do but I think I understand it). I assume you know the MC_TL_GetActive/MC_Text_GetActive commands are the ones you highlight to trip off whatever you want to do. I have never used the TL_GetActive/Text_GetActive commands which act like TS version. When I read about them I could not figure out a use for them but they may be of some use somehow. If I understand you correctly, to input data into the program , MC can't do this. You would need an external program and you would have to pass the data via Global Variables. However, come to think of it, I guess you could enter data into a text box and if it is NOT highlighted that could be a signal to your program and you could pick it up from there (now that is a new idea for me but I think you could get that to work).
If your trend lines are on an angle and they are activated by your highlighting the line you can calculate the current price point of the line and when price hits that you do whatever. You calculate this based upon the two anchor points, get the change per bar and then calculate the bars from the last end point to current price (don't clip any decimals).
I am thinking you could be looking at a few weeks to get this all running. I did a lot of that sort of programming (meaning 3 to 6 weeks of constant programming). I am at the point now where I do everything I can to avoid that and try to avoid any more than a few hours of trading time lost.
If your trend lines are on an angle and they are activated by your highlighting the line you can calculate the current price point of the line and when price hits that you do whatever. You calculate this based upon the two anchor points, get the change per bar and then calculate the bars from the last end point to current price (don't clip any decimals).
I am thinking you could be looking at a few weeks to get this all running. I did a lot of that sort of programming (meaning 3 to 6 weeks of constant programming). I am at the point now where I do everything I can to avoid that and try to avoid any more than a few hours of trading time lost.
- TJ
- Posts: 7742
- Joined: 29 Aug 2006
- Location: Global Citizen
- Has thanked: 1033 times
- Been thanked: 2222 times
Re: Trend line trading
look under autotradeHi Roman,
I am looking for sample code for trend line trading--rather than starting from ground zero. I looked through the user contributed studies and didn't find anything that appeared to directly address trend line trading.
There was a note from TJ back in Jan 2009 (viewtopic.php?f=5&t=5941) asking if anybody had access to some TS code on their forum:This is exactly the kind of thing I'm looking for as a starter."In TS, you can hand draw a line on a chart and have an order executed based on price crossing the line you drew. You can enter three lines of different color for entry, stop loss, and profit target. The code is readily available on their forum if you have access to it.
https://www.TS.com/Discussion ... ic_ID=5863
PDQ
http://www.tradersxchange.com/
-
- Posts: 191
- Joined: 27 Apr 2010
- Location: San Jose
- Has thanked: 67 times
- Been thanked: 10 times
Re: Trend line trading
Thanks, TJ. I spent more time Googling after the close and found this as well:
http://systemtradersuccess.com/a-semi-a ... -strategy/
There is a downloadable .ELD that looks very well done.
UPDATE: won't compile. Uses method, #region / #endregion, switch, case constructs. The code is nicely-structured, but it is also far too complicated for what I'm looking for. The search continues.
http://systemtradersuccess.com/a-semi-a ... -strategy/
There is a downloadable .ELD that looks very well done.
UPDATE: won't compile. Uses method, #region / #endregion, switch, case constructs. The code is nicely-structured, but it is also far too complicated for what I'm looking for. The search continues.
-
- Posts: 191
- Joined: 27 Apr 2010
- Location: San Jose
- Has thanked: 67 times
- Been thanked: 10 times
Re: Trend line trading
bowlesj3,
One point: I am not thinking of entering data through the chart. I guess I wasn't clear: the inputs would all be done per Format>Signal as per normal. The only tasks to be done in the chart window itself are 1) spawn new entry trendlines and 2) activate/De-activate trend lines 3) move trendlines.
Thanks.
Exactly. I'm not interested in a science project, but have concluded after a few months of trading my new system that my performance would benefit from some automation. I can execute without the benefits of trend lines or a Chart Trader, but I have made enough order entry and order modification mistakes to warrant an investment of after hours time. My wife says I'll never be done coding--and there's probably some truth to that.I did a lot of that sort of programming (meaning 3 to 6 weeks of constant programming). I am at the point now where I do everything I can to avoid that and try to avoid any more than a few hours of trading time lost.
One point: I am not thinking of entering data through the chart. I guess I wasn't clear: the inputs would all be done per Format>Signal as per normal. The only tasks to be done in the chart window itself are 1) spawn new entry trendlines and 2) activate/De-activate trend lines 3) move trendlines.
Thanks.
Re: Trend line trading
Yes I suppose. My system (rules and programming) is 99.9% done. It took me 4 years of very heavy programming and 2 years of fairly heavy programming but it has huge amounts of code outside of MC in an external program which talks to MC via the GVs. The external program also sends key strokes out which control MC to a certain extent. Some code was dumped because I decided it was not all that useful after all but maybe 70% of it was kept. At this point I have a list of stuff that can speed me up a bit, help me find things in the market, whatever. It is a fairly big list and I do not expect to get it all done ever (it is not that important). I sort my to-do list in priority sequence every weekend and pick off 1 or 2 items to work on Saturday morning for maybe 1 to 3 hours. I then test it for 1 to 3 hours on Monday. It could be infinite but if you take this approach it is fine. You have a major surge then an organized tail end of minor improvements. If something important comes up you just skip that work on the weekend.My wife says I'll never be done coding--and there's probably some truth to that.
-
- Posts: 196
- Joined: 08 Aug 2012
- Has thanked: 41 times
- Been thanked: 41 times
Re: Trend line trading
look under autotradeHi Roman,
I am looking for sample code for trend line trading--rather than starting from ground zero. I looked through the user contributed studies and didn't find anything that appeared to directly address trend line trading.
There was a note from TJ back in Jan 2009 (viewtopic.php?f=5&t=5941) asking if anybody had access to some TS code on their forum:This is exactly the kind of thing I'm looking for as a starter."In TS, you can hand draw a line on a chart and have an order executed based on price crossing the line you drew. You can enter three lines of different color for entry, stop loss, and profit target. The code is readily available on their forum if you have access to it.
https://www.TS.com/Discussion ... ic_ID=5863
PDQ
http://www.tradersxchange.com/
Is there a way to load code from tradersxchange into the .net editor to compile the code ?
thanks
shane
- TJ
- Posts: 7742
- Joined: 29 Aug 2006
- Location: Global Citizen
- Has thanked: 1033 times
- Been thanked: 2222 times
Re: Trend line trading
No.Is there a way to load code from tradersxchange into the .net editor to compile the code ?
thanks
shane
EasyLanguage codes are not compatible in MultiCharts .net.
-
- Posts: 191
- Joined: 27 Apr 2010
- Location: San Jose
- Has thanked: 67 times
- Been thanked: 10 times
Re: Trend line trading
Pushing some pieces around and need another set of eyes here.
The simple code below calculates initial values for a stop, target_1, and target_2 upon entry into a position. These values are used to initialize three corresponding horizontal trend lines and associated text. Once these trend lines have been created, the goal is to be able to manually move the trend lines to new values and to have those new values fed back to the signal, modifying the stop and target executions.
I'm trying to get the signal to leave the trend lines alone after initialization and to wait until they are moved to redraw. But I'm encountering a more basic problem: the trend lines disappear one tick after they are drawn even though the loop in which they are drawn is only entered once.
Evidently, I'm missing something obvious. I'd appreciate feedback.
The simple code below calculates initial values for a stop, target_1, and target_2 upon entry into a position. These values are used to initialize three corresponding horizontal trend lines and associated text. Once these trend lines have been created, the goal is to be able to manually move the trend lines to new values and to have those new values fed back to the signal, modifying the stop and target executions.
I'm trying to get the signal to leave the trend lines alone after initialization and to wait until they are moved to redraw. But I'm encountering a more basic problem: the trend lines disappear one tick after they are drawn even though the loop in which they are drawn is only entered once.
Evidently, I'm missing something obvious. I'd appreciate feedback.
Code: Select all
{**********************************************************************************************************************************************************
Name : $Testing_TL_Trading_v1.0
Description : testing trading using trend lines in MC
Last Modified Date : 01/20/2014 --
**********************************************************************************************************************************************************}
[IntrabarOrderGeneration = true];
[LegacyColorValue = true];
{*********************************************************************************************************************************************************
inputs and variable initialization section
*********************************************************************************************************************************************************}
inputs:
Trade_Direction ("L"), { defines whether trade direction is looking long or short -- testing only }
StartTime (0930), { time after which trades can be executed }
EODCloseTime (1600), { close short position out before eod ramp }
myShortEntry (1169.7), { hardcoded for testing }
Target_1_Contracts (1), { contracts taken off at target 1 }
Target_2_Contracts (1), { contracts taken off at target 2 }
Target_1_Points (1.2), { points above/below entry to set default target 1 profit }
Target_2_Points (3.0), { points above/below entry to set default target 2 profit }
StopBufferTicks (.2), { an incremental amount beyond the initial calculated stop }
LinePlotLength (50), { length of trend line plotted to right of last price bar }
TextPlotOffset (1), { prints the text to right on trend line end }
BackTesting_Mode (false); { set to true when doing after hours backtesting }
variables:
PlotEndDate (0),
PlotEndTime (0),
PlotStartDate (0),
PlotStartTime (0),
TextOffsetTime (0),
intrabarpersist TradePeriod (false),
intrabarpersist SetupLong (false),
intrabarpersist SetupShort (false),
intrabarpersist myLongEntry (0),
// intrabarpersist myShortEntry (0), { commented out for testing }
intrabarpersist PositionSize (0),
intrabarpersist StopLossPrice (0),
intrabarpersist ProfitTargetPrice_1 (0),
intrabarpersist ProfitTargetPrice_2 (0),
Line_Stop (0),
Line_Targ1 (0),
Line_Targ2 (0),
Text_Stop (0),
Text_Stop_str (""),
Text_Targ1 (0),
Text_Targ1_str (""),
Text_Targ2 (0),
Text_Targ2_str ("");
{*********************************************************************************************************************************************************
perform one-time intializations
*********************************************************************************************************************************************************}
once begin
PositionSize = Target_1_Contracts + Target_2_Contracts;
end;
{*********************************************************************************************************************************************************
check each incoming tick for entry and exit levels from trendlines
*********************************************************************************************************************************************************}
// code to trap manual changes to trendlines will go here
//
//
// manual trendline changes will update the following values
//
// myLongEntry, myShortEntry, StopLossPrice, ProfitTargetPrice_1, ProfitTargetPrice_1
{*********************************************************************************************************************************************************
entries execution section
*********************************************************************************************************************************************************}
TradePeriod = time > StartTime and time < EODCloseTime;
if TradePeriod and marketposition = 0 then begin
if Trade_Direction = "L" then begin { trade direction will be derived from trend lines later }
if close > myLongEntry then SetupLong = true;
if SetupLong then buy ("LE_LMT") PositionSize shares next bar at myLongEntry limit;
ProfitTargetPrice_1 = myLongEntry + Target_1_Points;
ProfitTargetPrice_2 = myLongEntry + Target_2_Points;
end;
if Trade_Direction = "S" then begin { trade direction will be derived from trend lines later }
if time > 1215 and close <= myShortEntry then SetupShort = true; { hard-coded time for testing only }
if SetupShort then sellshort ("SE_LMT") PositionSize shares next bar at myShortEntry limit;
ProfitTargetPrice_1 = myShortEntry - Target_1_Points;
ProfitTargetPrice_2 = myShortEntry - Target_2_Points;
end;
end;
{*********************************************************************************************************************************************************
target execution section
*********************************************************************************************************************************************************}
if marketposition = 1 then begin
if close >= ProfitTargetPrice_1 then Sell ("Trg1_LX") Target_1_Contracts shares next bar at market; { market-if-touched order }
if close >= ProfitTargetPrice_2 then Sell ("Trg2_LX") Target_2_Contracts shares next bar at market; { market-if-touched order }
end;
if marketposition = -1 then begin
if close <= ProfitTargetPrice_1 then buytocover ("Trg1_SX") Target_1_Contracts shares next bar at market; { market-if-touched order }
if close <= ProfitTargetPrice_2 then buytocover ("Trg2_SX") Target_2_Contracts shares next bar at market; { market-if-touched order }
end;
{*********************************************************************************************************************************************************
stop loss section
*********************************************************************************************************************************************************}
If marketposition = 1 then begin
once begin
StopLossPrice = low[1] - StopBufferTicks;
end;
if close <= StopLossPrice then sell ("Stop_LX") CurrentShares shares next bar at market; { market-if-touched order }
end;
If marketposition = -1 then begin
once begin
StopLossPrice = high[1] + StopBufferTicks;
end;
if close >= StopLossPrice then sell ("Stop_SX") CurrentShares shares next bar at market; { market-if-touched order }
end;
{*********************************************************************************************************************************************************
close positions EOD
*********************************************************************************************************************************************************}
// live trading EOD exit
if BackTesting_Mode = false and date = currentdate and GetAppinfo(aiRealTimeCalc) = 1 and currenttime >= EODCloseTime then begin
Sell ("RT_EOD X") next bar at market;
Buytocover("RT_EOD_SX") next bar at market;
end
else
// backtesting exit
if time >= EODCloseTime then begin
Sell ("BT_EOD X") CurrentShares shares this bar;
Buytocover ("BT_EOD_SX") CurrentShares shares this bar;
end;
{*********************************************************************************************************************************************************
plot initial trend lines and text section
*********************************************************************************************************************************************************}
// initialize stop and target trend lines upon entry
if marketposition <> 0 then once begin { this loop is only entered once }
// set trend line and text plot start and end values
PlotStartTime = (Calctime(time,+5));
PlotStartDate = Date;
PlotEndTime = (Calctime(PlotStartTime,+LinePlotLength));
PlotEndDate = Date;
TextOffsetTime = (Calctime(PlotEndTime,+TextPlotOffset));
if TL_Exist(Line_Stop) then TL_Delete(Line_Stop);
if TL_Exist(Line_Targ1) then TL_Delete(Line_Targ1);
if TL_Exist(Line_Targ2) then TL_Delete(Line_Targ2);
// delete any existing text
if Text_Exist(Text_Stop) then Text_Delete(Text_Stop);
if Text_Exist(Text_Targ1) then Text_Delete(Text_Targ1);
if Text_Exist(Text_Targ2) then Text_Delete(Text_Targ2);
// create text strings to plot by concatenating data
Text_Stop_str = numtostr(StopLossPrice,1) + " (Stop)"; // stop
Text_Targ1_str = numtostr(ProfitTargetPrice_1,1) + " (Target-1)"; // targets
Text_Targ2_str = numtostr(ProfitTargetPrice_2,1) + " (Target-2)";
// plot trendlines and associated text
Line_Stop = TL_New(PlotStartDate,PlotStartTime,StopLossPrice,Date,PlotEndTime,StopLossPrice);
TL_setstyle(Line_Stop,tool_dotted);
TL_setcolor(Line_Stop,tool_red);
Text_Stop = Text_New(PlotStartDate,TextOffsetTime,StopLossPrice,Text_Stop_str);
Text_SetColor(Text_Stop,tool_red);
Text_SetStyle(Text_Stop,0,1);
Line_Targ1 = TL_New(PlotStartDate,PlotStartTime,ProfitTargetPrice_1,Date,PlotEndTime,ProfitTargetPrice_1);
TL_setstyle(Line_Targ1,tool_dotted);
TL_setcolor(Line_Targ1,tool_darkgreen);
Text_Targ1 = Text_New(PlotStartDate,TextOffsetTime,ProfitTargetPrice_1,Text_Targ1_str);
Text_SetColor(Text_Targ1,tool_darkgreen);
Text_SetStyle(Text_Targ1,0,1);
Line_Targ2 = TL_New(PlotStartDate,PlotStartTime,ProfitTargetPrice_2,Date,PlotEndTime,ProfitTargetPrice_2);
TL_setstyle(Line_Targ2,tool_dashed3);
TL_setcolor(Line_Targ2,tool_darkgreen);
Text_Targ2 = Text_New(PlotStartDate,TextOffsetTime,ProfitTargetPrice_2,Text_Targ2_str);
Text_SetColor(Text_Targ2,tool_darkgreen);
Text_SetStyle(Text_Targ2,0,1);
end;
- Attachments
-
- TLs_disappear_one_tick_after_entry.png
- (34.71 KiB) Downloaded 2552 times
-
- TLs_initialized_on_entry_tick.png
- (37.5 KiB) Downloaded 2541 times
Re: Trend line trading
Yes there is an MC quirk. This tread details it.the trend lines disappear one tick after they are drawn even though the loop in which they are drawn is only entered once.
viewtopic.php?f=1&t=10571
Basically MC keeps deleting the trend line until barstatus=2. The easiest way around this is to create all your trend lines on currentbar=2 and simply move them into place or hide them (never deleting them). This assumes that you can do this. If not you just keep putting them out there until barstatus=2.
Now for moving the trend line the function(s) in this thread are your best bet.
viewtopic.php?f=5&t=7748
Okay, having said all this, I think after I finished all my code there is a new way to get them to be retained rather than being deleted on every new tick until barstatus=2. I never got around to trying and I do not remember the method. I am trying to think if I updated the thread above with the method. Anyway, for now you have a solution.
Re: Trend line trading
Yes there is an MC quirk. This tread details it.the trend lines disappear one tick after they are drawn even though the loop in which they are drawn is only entered once.
viewtopic.php?f=1&t=10571
Basically MC keeps deleting the trend line until barstatus=2. The easiest way around this is to create all your trend lines on currentbar=2 and simply move them into place or hide them (never deleting them). This assumes that you can do this. If not you just keep putting them out there until barstatus=2 and have a switch that stops putting them out there once the last TL_new command executed during barstatus=2
Now for moving the trend line the function(s) in this thread are your best bet.
viewtopic.php?f=5&t=7748
One is for minute bars and the other is for seconds bars. They will save you major headaches since the logic is built in which is required for the move. This function will move them correctly 999 times in 1,000 times. Without it you will get a bad move maybe 1 in every 100 times (rough guess).
Okay, having said all this, I think after I finished all my code there is a new way to get trend lines to be retained rather than being deleted on every new tick until barstatus=2. I ever got around to trying and I do not remember the method. I am trying to think if I updated the thread above with the method. Anyway, for now you have a solution.
Of note, this also occurs with arrows and text.
-
- Posts: 191
- Joined: 27 Apr 2010
- Location: San Jose
- Has thanked: 67 times
- Been thanked: 10 times
Re: Trend line trading
Digging through the threads, I saw that TL_Persist, Text_Persist, etc. were released in MC 8.5 (see attached screen shot). The commands are not available in 8.7.
What's up?
Update: I added the [RecoverDrawings = false] parameter and that fixed it.
What's up?
Update: I added the [RecoverDrawings = false] parameter and that fixed it.
- Attachments
-
- TL_Persist.png
- (63.81 KiB) Downloaded 2539 times
Re: Trend line trading
Yes, there was a note in the link to that PM entry.
https://www.multicharts.com/pm/viewissu ... _no=MC-436
Here it is.
Like I said, I never got around to trying it because my system is done. I requested it because I knew it would create problems for others (or myself for that matter). I had already gotten in the habit of putting my drawings out on currentbar=1. Let me know if it works.
https://www.multicharts.com/pm/viewissu ... _no=MC-436
Here it is.
Code: Select all
[RecoverDrawings = false] should help
Re: Trend line trading
If you find that [RecoverDrawings = false] works I think the Wiki should be updated to make note of this in the TL_new, Arw_new and Text_new command pages. I just checked TL_New and it does not mention this parameter. So if it works I will put it on my to-do list to update the Wiki.
Re: Trend line trading
No problem.
I went back and checked. Yes I guess I did miss it. So we both found it. Thanks for checking if it worked. I can't because I am still on 8.0 and it said it went in on 8.5. I have been meaning to update MC but have just been too busy with important stuff. I guess I should update. I will update the wiki as I said.
I went back and checked. Yes I guess I did miss it. So we both found it. Thanks for checking if it worked. I can't because I am still on 8.0 and it said it went in on 8.5. I have been meaning to update MC but have just been too busy with important stuff. I guess I should update. I will update the wiki as I said.
-
- Posts: 191
- Joined: 27 Apr 2010
- Location: San Jose
- Has thanked: 67 times
- Been thanked: 10 times
Re: Trend line trading
On to the next TL trading issue:
I am getting an array out of bounds error when there are trendlines on the chart other than the ones drawn by my signal. When there are no drawing objects on the chart other than those created by the signal the code works as expected.
The function I use (see below) gets the ID, beginning date, beginning time, and value of the trendlines that the signal draws based on their color and style. It writes those values into three arrays. It is only supposed to operate on the trendlines that this signal has drawn because I am specifying TLType = 1 from the EasyLanguage Trendline and Text Object Parameters, as per below:
Here is the function fetching the trendlines:
I am getting an array out of bounds error when there are trendlines on the chart other than the ones drawn by my signal. When there are no drawing objects on the chart other than those created by the signal the code works as expected.
The function I use (see below) gets the ID, beginning date, beginning time, and value of the trendlines that the signal draws based on their color and style. It writes those values into three arrays. It is only supposed to operate on the trendlines that this signal has drawn because I am specifying TLType = 1 from the EasyLanguage Trendline and Text Object Parameters, as per below:
- 1. Trendline/text object created by the current analysis technique/strategy.
2. Trendline/text object created by an analysis technique/strategy other than the current analysis technique/strategy or manually drawn by the user.
3. Trendline/text object created by other means.
4. Trendline/text object created by the current analysis technique/strategy or manually drawn by the user.
5. Trendline/text object created by an analysis technique/strategy other than the current analysis technique/strategy.
6. Trendline/text object created by any analysis technique/strategy.
7. Trendline/text object manually drawn by the user.
Here is the function fetching the trendlines:
Code: Select all
[LegacyColorValue = true];
inputs:
TLType (Numeric), { input trendline type is set = 1 by the signal}
TLColor (Numeric), { trendline color }
TLStyle (Numeric), { trendline style }
{ outputs }
oTL_ID (NumericRef), { trendline reference number }
oBDate[nn](NumericArrayRef), { trendline beginning date }
oBTime[mm](NumericArrayRef), { trendline beginning time }
oValue[pp](NumericArrayRef); { trendline value at date + time }
vars:
ID (0);
_TL_FindColorStyle_PB = 0;
ID = TL_GetFirst(TLType);
while ID > 0 begin
if TL_GetColor(ID) = TLColor and TL_GetStyle(ID) = TLStyle then begin
oTL_ID = ID;
oBDate[ID] = TL_GetBeginDate(ID);
oBTime[ID] = TL_GetBeginTime(ID);
oValue[ID] = TL_GetValue(ID, Date, Time);
_TL_FindColorStyle_PB = ID;
end;
ID = TL_GetNext( ID, TLType) ;
end;
- Attachments
-
- array_out_of_bounds.png
- (69.72 KiB) Downloaded 2546 times
Re: Trend line trading
2 thoughts:
1/ I sort of assumed you had programmed before. However, if I am incorrect, reading this thread may give you some ideas for figuring it out.
viewtopic.php?f=16&t=10397
Typically I would print the ID of anything going into your array.
2/ You might want to create a new thread since you marked this one solved.
1/ I sort of assumed you had programmed before. However, if I am incorrect, reading this thread may give you some ideas for figuring it out.
viewtopic.php?f=16&t=10397
Typically I would print the ID of anything going into your array.
2/ You might want to create a new thread since you marked this one solved.
Re: Trend line trading
Hi andrei,
If you can get the date and time of the bar yes you could do that. You need to study the arw_GetNext command to know basically everything about it. You set up a while loop Similar to the following. If it does not find an arrow to match the bar date and time it will run out of arrows and return a -2 which will end the loop. If it does find the arrow it should stop the loop with the break command. This code is not actually tested. It is extracted from code I have used which has this loop.
If you can get the date and time of the bar yes you could do that. You need to study the arw_GetNext command to know basically everything about it. You set up a while loop Similar to the following. If it does not find an arrow to match the bar date and time it will run out of arrows and return a -2 which will end the loop. If it does find the arrow it should stop the loop with the break command. This code is not actually tested. It is extracted from code I have used which has this loop.
Code: Select all
Arw_ID = 0;
While Arw_ID > -2
begin
if Arw_ID = 0 then
begin
Arw_ID = Arw_GetFirst(7);
end
else
begin
TempDate = arw_getdate(Arw_ID);
TempTime =arw_GetTime(Arw_ID);
if BarDate = TempDate and BarTime = TempTime then
begin
{do whatever}
break;
end; {end of IF statement}
Arw_ID = Arw_GetNext(Arw_ID,7);
end; {end of if}
end; {End of while loop}