Site Administrator Swing Trader Data Scientist & DevOps
Manta, Ecuador
Experience: Advanced
Platform: Custom solution
Trading: Futures & Crypto
Posts: 50,013 since Jun 2009
Thanks: 32,472 given,
98,311
received
Last year I did a video tutorial on creating an advanced NinjaTrader strategy, and you guys liked it. So I thought that since I don't use NT any more it would be a good idea to do the same strategy as an example in EasyLanguage with MultiCharts.
First, here is a link to the NinjaTrader Video Tutorial:
In this video tutorial I show how to create a strategy from scratch (not using the wizard, which I never use).
The strategy contains a few optimizable parameters such as SMA length, EMA length, HMA length, three different targets with custom tick settings …
OK, so in this video I show you how to create a strategy with optimizable parameters such as SMA length, EMA length, HMA length, three different targets, a stop, and the option to move target 2 to breakeven after target 1 is hit, as well as an option to move target 3 to breakeven after target 2 is hit.
Remember, this strategy is just an example! It took only a few minutes to write, and even though it shows to be profitable - it isn't (it won't be). Simple strategies are usually best to avoid curve fitting, but this one is too simple to actually work fully automated. A good strategy may take dozens of hours to create.
This example was created just so you could get your feet wet and learn some of the basics of strategy creation in MultiCharts or EasyLanguage.
Site Administrator Swing Trader Data Scientist & DevOps
Manta, Ecuador
Experience: Advanced
Platform: Custom solution
Trading: Futures & Crypto
Posts: 50,013 since Jun 2009
Thanks: 32,472 given,
98,311
received
Here is the code for the strategy created in our video example. I've also attached a MultiCharts pla to make it easy for importing, and that pla also contains the jtHMA function (since HMA is not built-in to MultiCharts).
Site Administrator Swing Trader Data Scientist & DevOps
Manta, Ecuador
Experience: Advanced
Platform: Custom solution
Trading: Futures & Crypto
Posts: 50,013 since Jun 2009
Thanks: 32,472 given,
98,311
received
Here is a follow-up. This is a 1-year backtest on the EUR/USD, 6 range chart, with $2 commission per side and $12.50 slippage per contract.
Results came back with 28k net profit on 2,159 trades, 40% win rate, w/l ratio of 1.56. However, when you look at the equity curve and other performance metrics, you'll see this strategy needs work. As expected. This video was just an example, you could use it as a starting point.
Thank you for the presentation....very useful to a 'dumb techy' like me...worth a laugh when you apologized for having to type 'slow'...in comparison to the Ninja video where I had to hit the "pause" button a million times to follow what you were doing.
Hope your hand/wrist are healing well..
Trader
The following 2 users say Thank You to Family Trader for this post:
Very good to show me for the multiple contracts control in the MC..
Well, the MDD seems quite huge... for such strategy...
Thanks for your sharing, anyway,, I learned a lot!!
Wish for sharing more MC coding examples...
Hi Big Mike,
could you help me please with writing this simple strategy in EasyLanguage?
Strategy:
Indicators - EMA(x), SMA(y), MACD(m,n,o), CCI(p); where x<y
Our pozition is everytime e.g. 5 % of 100000$ - initial capital.
Bull's position:
Signal for entry- EMA(x) crosses up SMA(y), where x<y, and MACD>=0 ∧ CCI>=0
Moment of entry - closing price of the candle, in which crossover hapend
STOPLOSS - minimum of the candle, which is the lowest in recent x days, where x is EMA's period, (I think it is called SWING LOW) and it moves with time
PROFIT TARGET - is in the same distance like STOPLOSSE every time and when we achieve it, we close half amount of our position
Signal for exit- EMA(x) crosses down SMA(y), where x<y, in this moment we sell the second half of position or whole position in that case we didn't achieve PROFIT TARGET yet.
Bear's position
the rules are same but vice versa
That's it and I have also one suggestion for next video tutorial - how backtest portfolio in MultiCHarts
Thank you for any help
and I'm sorry for my bad English
Hi,
I wrote some code according to the video and my trading rules above and tried it
on day chart of google, but it doesn't make any trades...is the algorithm correct?
if emav crosses over smav then begin
alert("prekrizeni nahoru");
if macdv >= 0 and cciv >= 0 then begin
Buy ("Enter long") stocks Contracts Next Bar At Market;
end;
end;
if emav crosses under smav then begin
if macdv < 0 and cciv < 0 then begin
SellShort ("Enter short") stocks Contracts Next Bar At Market;
end;
end;
end;
// manage open orders
if MarketPosition = 1 then begin // 1 - means long position opened
for timer = 0 to emalength - 1 begin
if st > Close[timer] then begin
st = Close[timer]; // stoploss on the swing low
end;
end ;
tar = Close + (Close - st);
Sell ("Exit long Target") stocks/2 Contracts Next Bar At tar Limit;
Sell ("Exit long Stop") currentcontracts Contracts Next Bar At st Stop;
end;
if MarketPosition = -1 then begin // -1 - means short position opened
for timer = 0 to emalength - 1 begin
if st < Close[timer] then begin
st = Close[timer]; // stoploss on the swing high
end;
end ;
tar = Close - (st - Close);
BuyToCover ("Exit short Target") stocks/2 Contracts Next Bar At tar Limit;
BuyToCover ("Exit short Stop") currentcontracts Contracts Next Bar At st Stop;
In your example, what if your profit or stop loss gets hit on the entry bar. How can you make it so that it will exit on the entry bar and not on the next bar?
@erchis - Your code will make trades if you just change from Close/money to money/Close. I did not check all of your code but here is a picture of the GOOG trades that it made in Jan-Feb 2011 (very few trades were made in 2012).
If you want to continue the discussion, you should open a new thread in this same sub-forum so that we don't get too far away from the topic of Mike's video tutorial. Also, there is more discussion of EasyLanguage strategies in the Elite section if you want to become a member.
Len
The following user says Thank You to Lampert for this post:
@guppy - The important setting is intra-bar order generation. This allows orders to be made before the bar has been completed. This can be turned on under Format > Signal > Properties. Or you can add the following statement at the beginning of your code:
[IntrabarOrderGeneration = True]
Under Format > Signal > Properties, there are three options for setting the number of entries and exits per bar. You can try these different settings to see their effects.
In addition, the keywords SetProfitTarget and SetStopLoss generate orders before the bar has been completed even if IntrabarOrderGeneration is turned off.
For backtesting, it is also necessary to turn on the bar magnifier under Format > Strategy Properties > Backtesting. This allows data within the bar to be used for intrabar order generation. Calculations can be done on tick data or intra-day data depending on which box is checked.
In general, I always use [IntrabarOrderGeneration = True] in my code. For backtesting, I also use the bar magnifier with either tick data or 1 minute data depending availability.
Here are 4 different results from 4 different settings. Each of these results used the same futures.io (formerly BMT) MoneyMaker code that is shown at the beginning of this thread.
Len
The following 6 users say Thank You to Lampert for this post:
How do you debug in easylanguage / Multicharts ?
If for example, you want to log variables in a logfile / logview, or want to do some execution stop at some point in your program to watch your variables, is this possible ?
In the easy language editor, you use the print command in your code and view the output at the bottom of the editor screen.
Don't forget about my printtext function in the download area.
Regards,
Neil.
The following user says Thank You to NW27 for this post:
thanks a lot first to BigMike for uploading this gerat Video. I just started to teach myself easylanguage and used this video as a starting point. This is realy awesome to learn!
Now that I succesfully mirror-coded your strategy and did the same with adding the HMA function, I ran into two issues now:
1. If I want to use the HMA within the chart, I do have to add it as an "indicator" I suppose. Unfortunately, this won't compile in my case. Giving me this message:
2. If I want to add the futures.io (formerly BMT) Test Strategy to a chart, it tells me that system tried to reference back more bars (51) than allowed by the current MaxBarsBack setting.
I am converting from Tradestation to MC, but am struggling with some of the settings I need. In viewing the tutorial on youtube, it seems as if I might have a different version of MC than the video. I only have the option of putting in $1 on commissions, and I can't figure out how I set the point value to $100 when testing the Russell 2000.
Any help would be greatly appreciated!
the code posted is for a function. It sounds like you tried to compile it within an indicator.
Paste it within a function called jtHMA and call the function from an indicator.
MC will raise a Max bars back error when something in the code calls for more than the default 50 bars. If you are using a length input for an average of 100 for example, you will need a "Maximum number of bars study will reference" of 100 at least.
To change this go to Format Signal -> Properties and within the Strategy Properties switch to the Properties tab.
There you'll find the input field to raise the max bars setting.
Regards,
ABCTG
sagetrade
Hey Guys,
thanks a lot first to BigMike for uploading this gerat Video. I just started to teach myself easylanguage and used this video as a starting point. This is realy awesome to learn!
Now that I succesfully mirror-coded your strategy and did the same with adding the HMA function, I ran into two issues now:
1. If I want to use the HMA within the chart, I do have to add it as an "indicator" I suppose. Unfortunately, this won't compile in my case. Giving me this message:
2. If I want to add the futures.io (formerly BMT) Test Strategy to a chart, it tells me that system tried to reference back more bars (51) than allowed by the current MaxBarsBack setting.
Im new to MC so thanks a lot for helping me out!
The following 2 users say Thank You to ABCTG for this post:
i've been incorporating big mike's methodology into my strategy that i am testing on tradestation. i've been trying to get my head around the following problem for the past few hours but couldn't find any solution to it:
whereas the system enters a long/short position ok, it wouldn't take into account any of the limits placed (for both stop and take profit) but would close the position at the entry price on the bar where the trade was entered.as a result the strategy is not generating any profit or loss (ignoring comms). (for additional info i'm backtesting on FGBL futures and i am using a 1min chart).
Big Mike says the variable "Ticksize" is not standard with MC.
I tried compiling the script and got an error highlighting that line of code of course. So, how do I get the ticksize variable in MC?
please post the full code you are having problems with and I will try helping you.
Regards,
ABCTG
Hi ABCTG,
Trying to code a simple scale-out logic in Multicharts, using a kind of different order placing mechanism.
My code looks for arrows on the chart, and whenever one is found, it enters a position according to arrow orientation and the number present within the arrow text attribute. I also need to scale out. Let's say, I enter with 3 contracts long, and I need to have 3 levels with 3 separate sell orders.
Essentially, this helps me manually place trades on history data on a chart - kind of a playback (done just by scrolling the chart to the right bar by bar) with the option of placing trades as well, and get a performance report on these "manually" entered trades.
What doesn't work:
Let's say, a long position opened on bar number 3 with code:
buy ("myOrder") 3 contracts this bar at close;
At bar 5 I sell 2 of those contracts:
sell ("myOrder") 2 contracts this bar at close;
At bar 7 I want to sell the last contract as well, basically, closing the "myOrder" position entirely:
sell ("myOrder") 1 contracts this bar at close;
However, I get the following error message in Multicharts:
"error in stuy ... "myOrder" name has already been used for the other order".
If I don't specify an order name at all, even though I sell 3 contracts across two consecutive sell orders, at the last bar, I still have MarketPosition = 1 which means position is not entirely closed, which can be seen on the graph as well (I can see the first sell order for 2 contracts, but no the second sell order for 1 contract).
Is there a workaround to this, or something I miss
?
you should specify different order names for each order and tie the exits to your entry. This should do what you have in mind.
buy ("myOrder") 3 contracts this bar at close;
...
sell ("myExit1") 2 contracts from Entry ("myOrder") this bar at close;
...
sell ("myExit2") 1 contracts from Entry ("myOrder") this bar at close;
Regards,
ABCTG
andby
Let's say, a long position opened on bar number 3 with code:
buy ("myOrder") 3 contracts this bar at close;
At bar 5 I sell 2 of those contracts:
sell ("myOrder") 2 contracts this bar at close;
At bar 7 I want to sell the last contract as well, basically, closing the "myOrder" position entirely:
sell ("myOrder") 1 contracts this bar at close;
The following user says Thank You to ABCTG for this post:
you should specify different order names for each order and tie the exits to your entry. This should do what you have in mind.
buy ("myOrder") 3 contracts this bar at close;
...
sell ("myExit1") 2 contracts from Entry ("myOrder") this bar at close;
...
sell ("myExit2") 1 contracts from Entry ("myOrder") this bar at close;
Regards,
ABCTG
ABCTG,
Thanks for a fast answer!
Uploaded the code under:
As a Multicharts user, I am not too happy with their market replay functionality which got left behind in terms of integration with some more exotic features MC has released. For example, while in play-back you cannot place trades on the chart.
Consequently, …
Kind Regards,
Andy
The following user says Thank You to andby for this post:
As a Multicharts user, I am not too happy with their market replay functionality which got left behind in terms of integration with some more exotic features MC has released. For example, while in play-back you cannot place trades on the chart.
Consequently, …
Big Mike says the variable "Ticksize" is not standard with MC.
I tried compiling the script and got an error highlighting that line of code of course. So, how do I get the ticksize variable in MC?
Broker: Tradestation/Tradestation, NinjaTrader, FXCM and Tallinex
Trading: ES, CL, EUR/USD, TF
Posts: 181 since Aug 2009
Thanks: 103 given,
56
received
Big Mike
Last year I did a video tutorial on creating an advanced NinjaTrader strategy, and you guys liked it. So I thought that since I don't use NT any more it would be a good idea to do the same strategy as an example in EasyLanguage with MultiCharts.
First, here is a link to the NinjaTrader Video Tutorial:
In this video tutorial I show how to create a strategy from scratch (not using the wizard, which I never use).
The strategy contains a few optimizable parameters such as SMA length, EMA length, HMA length, three different targets with custom tick settings …
OK, so in this video I show you how to create a strategy with optimizable parameters such as SMA length, EMA length, HMA length, three different targets, a stop, and the option to move target 2 to breakeven after target 1 is hit, as well as an option to move target 3 to breakeven after target 2 is hit.
Remember, this strategy is just an example! It took only a few minutes to write, and even though it shows to be profitable - it isn't (it won't be). Simple strategies are usually best to avoid curve fitting, but this one is too simple to actually work fully automated. A good strategy may take dozens of hours to create.
This example was created just so you could get your feet wet and learn some of the basics of strategy creation in MultiCharts or EasyLanguage.
Mike
Hi Mike
thanks for this video and also for the Ninja one as they both helped me learn.
The one thing that is a little confusing for me is how different Easy Language is from Ninja in terms of setting stops and targets.
With Ninja, you just set it at the beginning. With Easy Language, it seems like you have to set them at the beginning, then again after target1 is hit, then again after target2 is hit.
So my question is will this strategy work Live? Does Easy Language automatically cancel all orders after something is filled?
Does Tradestation/Multicharts have order states like Ninja does
in Multicharts for example orders that are sent as one group like an entry with a stop and target would be treated as OCO. Once the stop or target is hit the other order would get cancelled.
Regards,
ABCTG
spinnybobo
Hi Mike
thanks for this video and also for the Ninja one as they both helped me learn.
The one thing that is a little confusing for me is how different Easy Language is from Ninja in terms of setting stops and targets.
With Ninja, you just set it at the beginning. With Easy Language, it seems like you have to set them at the beginning, then again after target1 is hit, then again after target2 is hit.
So my question is will this strategy work Live? Does Easy Language automatically cancel all orders after something is filled?
Does Tradestation/Multicharts have order states like Ninja does
Broker: Tradestation/Tradestation, NinjaTrader, FXCM and Tallinex
Trading: ES, CL, EUR/USD, TF
Posts: 181 since Aug 2009
Thanks: 103 given,
56
received
ABCTG
Hi Spencer,
in Multicharts for example orders that are sent as one group like an entry with a stop and target would be treated as OCO. Once the stop or target is hit the other order would get cancelled.
Regards,
ABCTG
Hey thanks ABCTG
when you say "the other order would get cancelled" do you mean ALL the other orders? Or do you mean just the amount of contracts --- like target1 gets hit and it is 1 contract so it only takes 1 contract off the stop? It seems like the way it is written here, it makes me think when ANY stop or target is hit, it cancels everything which is why it is reset ?
I didn't test this particular code, but from what I see the worst that could happen is that when there is a scale out of the position the remaining stop order gets cancelled and resend with the new (remaining) size.
I would always suggest to test drive the code behavior on a demo account to make sure it does what you want it to do.
Regards,
ABCTG
spinnybobo
Hey thanks ABCTG
when you say "the other order would get cancelled" do you mean ALL the other orders? Or do you mean just the amount of contracts --- like target1 gets hit and it is 1 contract so it only takes 1 contract off the stop? It seems like the way it is written here, it makes me think when ANY stop or target is hit, it cancels everything which is why it is reset ?
I have the a similar problem where I would like to execute all trades on the same bar if possible instead of waiting for next one. Pl. see image. where last position should have hit target on prior bar. Also in this case it stops out directly. Do not know shy. Seem to be the wrong sequence trade. many thanks in advance.
[IntrabarOrderGeneration = true]
inputs:
smalength ( 200 ),
emalength ( 100 ),
hmalength ( 34 ),
target1 ( 12 ),
target2 ( 12 ),
target3 ( 20 ),
stopsize ( 12 ),
BE2 ( 0 ), // 0=false, 1=true
BE3 ( 0 ), // 0=false, 1=true
rsilength ( 14 ),
Price ( Close) ,
Oversold ( 30 ),
Overbought ( 70 );
vars:
TickSize ( MinMove / PriceScale ),
smav ( 0 ),
emav ( 0 ),
hmav ( 0 ),
t1 ( target1 * TickSize ),
t2 ( (target1 + target2) * TickSize ),
t3 ( (target1 + target2 + target3) * TickSize ),
st1 ( 0 ),
st2 ( 0 ),
st3 ( 0 ),
var0 ( 0 );
smav = Average(Close, smalength);
emav = XAverage(Close, emalength);
hmav = jtHMA(Close, hmalength);
var0 = RSI(Price,rsilength);
// open new positions
if (BarStatus(1) = 2) then begin
condition8 = var0 crosses above oversold;
end;
if (BarStatus(1) = 2) then begin
condition18 = var0 crosses belowx overbought;
end;
if MarketPosition = 0 then begin
if condition8 then begin
Buy ("Enter long") 3 Contracts Next Bar At Market;
end;
if condition18 then begin
SellShort ("Enter short") 3 Contracts Next Bar At Market;
end;
end;
// manage open orders
if MarketPosition = 1 then begin
st1 = EntryPrice - (stopsize * TickSize);
st2 = iff(BE2 = 1, EntryPrice, EntryPrice - (stopsize * TickSize));
st3 = iff(BE3 = 1, EntryPrice, EntryPrice - (stopsize * TickSize));
if CurrentContracts = 1 then begin
Sell ("Exit l3-c1 Target") 1 Contracts Next Bar At (EntryPrice + t3) Limit;
Sell ("Exit l3-c1 Stop") 1 Contracts Next Bar At st3 Stop;
end;
if CurrentContracts = 2 then begin
Sell ("Exit l2-c2 Target") 1 Contracts Next Bar At (EntryPrice + t2) Limit;
Sell ("Exit l2-c2 Stop") 1 Contracts Next Bar At st2 Stop;
Sell ("Exit l3-c2 Target") 1 Contracts Next Bar At (EntryPrice + t3) Limit;
Sell ("Exit l3-c2 Stop") 1 Contracts Next Bar At st3 Stop;
end;
if CurrentContracts = 3 then begin
Sell ("Exit l1-c3 Target") 1 Contracts Next Bar At (EntryPrice + t1) Limit;
Sell ("Exit l1-c3 Stop") 1 Contracts Next Bar At st1 Stop;
Sell ("Exit l2-c3 Target") 1 Contracts Next Bar At (EntryPrice + t2) Limit;
Sell ("Exit l2-c3 Stop") 1 Contracts Next Bar At st2 Stop;
Sell ("Exit l3-c3 Target") 1 Contracts Next Bar At (EntryPrice + t3) Limit;
Sell ("Exit l3-c3 Stop") 1 Contracts Next Bar At st3 Stop;
end;
end;
if MarketPosition = -1 then begin
st1 = EntryPrice + (stopsize * TickSize);
st2 = iff(BE2 = 1, EntryPrice, EntryPrice + (stopsize * TickSize));
st3 = iff(BE3 = 1, EntryPrice, EntryPrice + (stopsize * TickSize));
if CurrentContracts = 1 then begin
BuyToCover ("Exit s3-c1 Target") 1 Contracts Next Bar At (EntryPrice - t3) Limit;
BuyToCover ("Exit s3-c1 Stop") 1 Contracts Next Bar At st3 Stop;
end;
if CurrentContracts = 2 then begin
BuyToCover ("Exit s2-c2 Target") 1 Contracts Next Bar At (EntryPrice - t2) Limit;
BuyToCover ("Exit s2-c2 Stop") 1 Contracts Next Bar At st2 Stop;
BuyToCover ("Exit s3-c2 Target") 1 Contracts Next Bar At (EntryPrice - t3) Limit;
BuyToCover ("Exit s3-c2 Stop") 1 Contracts Next Bar At st3 Stop;
end;
if CurrentContracts = 3 then begin
BuyToCover ("Exit s1-c3 Target") 1 Contracts Next Bar At (EntryPrice - t1) Limit;
BuyToCover ("Exit s1-c3 Stop") 1 Contracts Next Bar At st1 Stop;
BuyToCover ("Exit s2-c3 Target") 1 Contracts Next Bar At (EntryPrice - t2) Limit;
BuyToCover ("Exit s2-c3 Stop") 1 Contracts Next Bar At st2 Stop;
BuyToCover ("Exit s3-c3 Target") 1 Contracts Next Bar At (EntryPrice - t3) Limit;
BuyToCover ("Exit s3-c3 Stop") 1 Contracts Next Bar At st3 Stop;
end;
end;
I have the a similar problem where I would like to execute all trades on the same bar if possible instead of waiting for next one. Pl. see image. where last position should have hit target on prior bar. Also in this case it stops out directly. Do not know shy. Seem to be the wrong sequence trade. many thanks in advance.
Enable intrabar order generation, and use bar magnifier to allow trades within a bar, as opposed to next bar.
I would be interested in seeing a sample code for a trailing stop with a trailing step.
The built in trailing stop function (setdollartrailing) works in a very primitive way, in that it starts trailing once peak profit is hit based on the amount of loss entered in the setdollartrailing function.
What I want is to be able to start a trailing stop from any price that I specify, and then step it by x number of pips, rather than 1 pip, which seems to be the default.
I need to know if anyone can use or program the dollar difference tool in Multicharts easylanguage.
means if we draw a trendline it gives the difference of the price...
Please help anyone is aware of it!
Hi everyone, Just joined today and love the site. My question is from a past post Mike had done regarding his post, "How to create an advanced MultiCharts EasyLanguage Strategy." I'm using TradeStation and programming a strategy. I actually copied Mike's coding and it's exactly what I'm looking for when it comes to scaling out, but have added in my own entry criteria, Unfortunately, I have a couple of problems I can't seem to figure out.
1. I have a particular signal that the trade is executed on. Kind of like a trend signal. After all my targets 3 targets are hit, the problem I'm having is, I don't want the strategy to execute another trade on the same trend signal. Once I'm filled on my third target, it will immediately execute another order and most of the time I'm stopped out giving away all the profits I just made. Does anyone know the coding to only allow it to execute one trade per signal?
2. Does anyone know the coding for a start and stop time the strategy will run? Basically just want to trade the morning E Mini S&P session, nothing after lunch.. I've tried to use the following, but not sure where to put it in the code so it functions properly.
input:
begin_time(0929),
end_time(1200);
if time > begin_time and time < end_time then
begin
{--Enter trade criteria here}
{--- EOD liquidation ---}
if time > end_time then
begin
if marketposition > 0 then sell next bar at market;
if marketposition < 0 then buytocover next bar at market;
end;
3. My final question is, what would be the coding for a maximum loss dollar wise per day and a maximum profit per day.. Once either of those are met, the system stops trading. I would need it to take into account any previous days profit or losses as well as calculate the current trade into the total.. Another words, if my max loss were $500 and I'm down $300 and the system executes another trade, it realizes I only have $200 more to go before it stop trading for the day.
If someone could help me with these final touches, I would appreciate it more than you know. I would need the coding and where to put them. Actually, if you could put them in the following code from Mike on June 2011, that would be terrific.
1. This is hard to say without the exact code. In general you can store the time or bar when your signal conditions are true in a variable. Then before you issue your entry, you use a second variable and check if the value within the second variable is different than the value in the first variable - if it is, you allow the entry and update the second variable to the value of the first variable. This would only allow entries on new signals.
2. Your entry conditions and entry orders would have to go within the section labeled "{--Enter trade criteria here}".
3. @Big Mike posted some code that can accomplish that:
I needed this for my own strategies, so I wanted to share it here.
This will allow a dollar limit of daily loss and daily profit targets, whereby if one or the other is hit then the strategy will stop for the day.
If you wanted to make it weekly, it …
Regards,
ABCTG
FormerAMEXTrader
Hi everyone, Just joined today and love the site. My question is from a past post Mike had done regarding his post, "How to create an advanced MultiCharts EasyLanguage Strategy." I'm using TradeStation and programming a strategy. I actually copied Mike's coding and it's exactly what I'm looking for when it comes to scaling out, but have added in my own entry criteria, Unfortunately, I have a couple of problems I can't seem to figure out.
1. I have a particular signal that the trade is executed on. Kind of like a trend signal. After all my targets 3 targets are hit, the problem I'm having is, I don't want the strategy to execute another trade on the same trend signal. Once I'm filled on my third target, it will immediately execute another order and most of the time I'm stopped out giving away all the profits I just made. Does anyone know the coding to only allow it to execute one trade per signal?
2. Does anyone know the coding for a start and stop time the strategy will run? Basically just want to trade the morning E Mini S&P session, nothing after lunch.. I've tried to use the following, but not sure where to put it in the code so it functions properly.
input:
begin_time(0929),
end_time(1200);
if time > begin_time and time < end_time then
begin
{--Enter trade criteria here}
{--- EOD liquidation ---}
if time > end_time then
begin
if marketposition > 0 then sell next bar at market;
if marketposition < 0 then buytocover next bar at market;
end;
3. My final question is, what would be the coding for a maximum loss dollar wise per day and a maximum profit per day.. Once either of those are met, the system stops trading. I would need it to take into account any previous days profit or losses as well as calculate the current trade into the total.. Another words, if my max loss were $500 and I'm down $300 and the system executes another trade, it realizes I only have $200 more to go before it stop trading for the day.
If someone could help me with these final touches, I would appreciate it more than you know. I would need the coding and where to put them. Actually, if you could put them in the following code from Mike on June 2011, that would be terrific.
@guppy - The important setting is intra-bar order generation. This allows orders to be made before the bar has been completed. This can be turned on under Format > Signal > Properties. Or you can add the following statement at the beginning of your code:
[IntrabarOrderGeneration = True]
Under Format > Signal > Properties, there are three options for setting the number of entries and exits per bar. You can try these different settings to see their effects.
In addition, the keywords SetProfitTarget and SetStopLoss generate orders before the bar has been completed even if IntrabarOrderGeneration is turned off.
For backtesting, it is also necessary to turn on the bar magnifier under Format > Strategy Properties > Backtesting. This allows data within the bar to be used for intrabar order generation. Calculations can be done on tick data or intra-day data depending on which box is checked.
In general, I always use [IntrabarOrderGeneration = True] in my code. For backtesting, I also use the bar magnifier with either tick data or 1 minute data depending availability.
Here are 4 different results from 4 different settings. Each of these results used the same futures.io (formerly BMT) MoneyMaker code that is shown at the beginning of this thread.
Len
So what is the best configuration to run backrests on Multicharts? I use IoG with limit order to one and bar magnifier on 1 minute precision and fill limit order when above of one tick of the price.