VIDEO TUTORIAL: How to create an advanced MultiCharts EasyLanguage Strategy - futures io
futures io futures trading



VIDEO TUTORIAL: How to create an advanced MultiCharts EasyLanguage Strategy


Discussion in MultiCharts

Updated
      Top Posters
    1. looks_one ABCTG with 7 posts (3 thanks)
    2. looks_two Big Mike with 6 posts (82 thanks)
    3. looks_3 andby with 3 posts (1 thanks)
    4. looks_4 spinnybobo with 2 posts (0 thanks)
      Best Posters
    1. looks_one Big Mike with 13.7 thanks per post
    2. looks_two Lampert with 3.5 thanks per post
    3. looks_3 Family Trader with 2.0 thanks per post
    4. looks_4 ABCTG with 0.4 thanks per post
    1. trending_up 33,653 views
    2. thumb_up 96 thanks given
    3. group 31 followers
    1. forum 40 posts
    2. attach_file 16 attachments




Welcome to futures io: the largest futures trading community on the planet, with well over 125,000 members
  • Genuine reviews from real traders, not fake reviews from stealth vendors
  • Quality education from leading professional traders
  • We are a friendly, helpful, and positive community
  • We do not tolerate rude behavior, trolling, or vendors advertising in posts
  • We are here to help, just let us know what you need
You'll need to register in order to view the content of the threads and start contributing to our community.  It's free and simple.

-- Big Mike, Site Administrator

(If you already have an account, login at the top of the page)

 
Search this Thread
 

VIDEO TUTORIAL: How to create an advanced MultiCharts EasyLanguage Strategy

(login for full post details)
  #1 (permalink)
Site Administrator
Swing Trader
Data Scientist & DevOps
Manta, Ecuador
 
Experience: Advanced
Platform: My own custom solution
Trading: Emini Futures
 
Big Mike's Avatar
 
Posts: 49,412 since Jun 2009
Thanks: 32,068 given, 96,717 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:


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

We're here to help -- just ask

For the best trading education, watch our webinars
Searching for trading reviews? Review this list

Follow us on Twitter, YouTube, and Facebook

Support our community as an Elite Member:
https://futures.io/elite/
Follow me on Twitter Visit my futures io Trade Journal Started this thread Reply With Quote

Can you help answer these questions
from other members on futures io?
Polygonio developers and reviews
Trading Reviews and Vendors
Financial Modeling Prep (free to use: financialmodelingprepcom) API
Trading Reviews and Vendors
Help get more ThinkOrSwim content on futures io!
ThinkOrSwim
Moores Research vs spread software SeasonAlgo
Trading Reviews and Vendors
Rising relative strength vs SPX/NDX as part of TOS scanner?
ThinkOrSwim
 
Best Threads (Most Thanked)
in the last 7 days on futures io
The war of the two worlds (options traders vs futures traders)
109 thanks
Big Mike in Ecuador
87 thanks
Spoo-nalysis ES e-mini futures S&P 500
50 thanks
The Small Exchange (www.smallexchange.com)
47 thanks
How did you learn to trade?
37 thanks
 
(login for full post details)
  #2 (permalink)
Site Administrator
Swing Trader
Data Scientist & DevOps
Manta, Ecuador
 
Experience: Advanced
Platform: My own custom solution
Trading: Emini Futures
 
Big Mike's Avatar
 
Posts: 49,412 since Jun 2009
Thanks: 32,068 given, 96,717 received

Here is the code for jtHMA function if you need it:

 
Code
                            


{jtHMA Hull Moving Average Function}
{
AuthorAtavachron}
{
May 2005}

Inputsprice(NumericSeries), length(NumericSimple);
VarshalvedLength(0), sqrRootLength(0);

{
Original equation is:
---------------------
waverage(2*waverage(close,period/2)-waverage(close ,period), SquareRoot(Period)
Implementation below is more efficient with lengthy Weighted Moving Averages.
In additionthe length needs to be converted to an integer value after it is halved and
its square root is obtained in order for this to work with Weighted Moving Averaging
}

if ((
ceiling(length 2) - (length 2)) <= 0.5then
halvedLength 
ceiling(length 2)
else
halvedLength floor(length 2);

if ((
ceiling(SquareRoot(length)) - SquareRoot(length)) <= 0.5then
sqrRootLength 
ceiling(SquareRoot(length))
else
sqrRootLength floor(SquareRoot(length));

Value1 WAverage(pricehalvedLength);
Value2 WAverage(pricelength);
Value3 WAverage((Value1 Value2), sqrRootLength);

jtHMA Value3
Mike

We're here to help -- just ask

For the best trading education, watch our webinars
Searching for trading reviews? Review this list

Follow us on Twitter, YouTube, and Facebook

Support our community as an Elite Member:
https://futures.io/elite/
Follow me on Twitter Visit my futures io Trade Journal Started this thread Reply With Quote
The following 8 users say Thank You to Big Mike for this post:
 
(login for full post details)
  #3 (permalink)
Site Administrator
Swing Trader
Data Scientist & DevOps
Manta, Ecuador
 
Experience: Advanced
Platform: My own custom solution
Trading: Emini Futures
 
Big Mike's Avatar
 
Posts: 49,412 since Jun 2009
Thanks: 32,068 given, 96,717 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).

 
Code
                            


{
Big Mike Trading https://futures.io
June 2011
}


inputs:
    
smalength 200 ),
    
emalength 100 ),
    
hmalength 34 ),
    
target1 12 ),
    
target2 12 ),
    
target3 20 ),
    
stopsize 12 ),
    
BE2 ), // 0=false, 1=true
    
BE3 ); // 0=false, 1=true
    
vars:
    
TickSize    MinMove PriceScale ),
    
smav        ),
    
emav        ),
    
hmav        ),
    
t1        Target1 TickSize ),
    
t2        ( (Target1 Target2) * TickSize ),
    
t3        ( (Target1 Target2 Target3) * TickSize ),
    
st1        ),
    
st2        ),
    
st3        );
    
smav Average(Closesmalength);
emav XAverage(Closeemalength);
hmav jtHMA(Closehmalength);


// open new positions

if MarketPosition 0 then begin

    
if smav smav[1] and emav emav[1] and hmav hmav[1then begin
    
        Buy 
("Enter long"3 Contracts Next Bar At Market;
    
    
end

    if 
smav smav[1] and emav emav[1] and hmav hmav[1then 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 1EntryPriceEntryPrice - (stopsize TickSize));
    
st3 iff(BE3 1EntryPriceEntryPrice - (stopsize TickSize));
    
    if 
CurrentContracts 1 then begin
        Sell 
("Exit l3-c1 Target"1 Contracts Next Bar At (EntryPrice t3Limit;
        
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 t2Limit;
        
Sell ("Exit l2-c2 Stop"1 Contracts Next Bar At st2 Stop;
        
Sell ("Exit l3-c2 Target"1 Contracts Next Bar At (EntryPrice t3Limit;
        
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 t1Limit;
        
Sell ("Exit l1-c3 Stop"1 Contracts Next Bar At st1 Stop;
        
Sell ("Exit l2-c3 Target"1 Contracts Next Bar At (EntryPrice t2Limit;
        
Sell ("Exit l2-c3 Stop"1 Contracts Next Bar At st2 Stop;
        
Sell ("Exit l3-c3 Target"1 Contracts Next Bar At (EntryPrice t3Limit;
        
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 1EntryPriceEntryPrice + (stopsize TickSize));
    
st3 iff(BE3 1EntryPriceEntryPrice + (stopsize TickSize));
    
    if 
CurrentContracts 1 then begin
        BuyToCover 
("Exit s3-c1 Target"1 Contracts Next Bar At (EntryPrice t3Limit;
        
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 t2Limit;
        
BuyToCover ("Exit s2-c2 Stop"1 Contracts Next Bar At st2 Stop;
        
BuyToCover ("Exit s3-c2 Target"1 Contracts Next Bar At (EntryPrice t3Limit;
        
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 t1Limit;
        
BuyToCover ("Exit s1-c3 Stop"1 Contracts Next Bar At st1 Stop;
        
BuyToCover ("Exit s2-c3 Target"1 Contracts Next Bar At (EntryPrice t2Limit;
        
BuyToCover ("Exit s2-c3 Stop"1 Contracts Next Bar At st2 Stop;
        
BuyToCover ("Exit s3-c3 Target"1 Contracts Next Bar At (EntryPrice t3Limit;
        
BuyToCover ("Exit s3-c3 Stop"1 Contracts Next Bar At st3 Stop;
    
end;
    
end
Mike

We're here to help -- just ask

For the best trading education, watch our webinars
Searching for trading reviews? Review this list

Follow us on Twitter, YouTube, and Facebook

Support our community as an Elite Member:
https://futures.io/elite/
Attached Files
Register to download File Type: pla BMT_MoneyMaker.pla (13.4 KB, 316 views)
Follow me on Twitter Visit my futures io Trade Journal Started this thread Reply With Quote
The following 17 users say Thank You to Big Mike for this post:
 
(login for full post details)
  #4 (permalink)
Site Administrator
Swing Trader
Data Scientist & DevOps
Manta, Ecuador
 
Experience: Advanced
Platform: My own custom solution
Trading: Emini Futures
 
Big Mike's Avatar
 
Posts: 49,412 since Jun 2009
Thanks: 32,068 given, 96,717 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.

Mike

We're here to help -- just ask

For the best trading education, watch our webinars
Searching for trading reviews? Review this list

Follow us on Twitter, YouTube, and Facebook

Support our community as an Elite Member:
https://futures.io/elite/
Attached Thumbnails
Click image for larger version

Name:	6-4-2011 4-15-15 PM.png
Views:	328
Size:	224.9 KB
ID:	40201   Click image for larger version

Name:	6-4-2011 4-17-11 PM.png
Views:	291
Size:	21.3 KB
ID:	40202   Click image for larger version

Name:	6-4-2011 4-18-12 PM.png
Views:	409
Size:	158.0 KB
ID:	40203   Click image for larger version

Name:	6-4-2011 4-18-59 PM.png
Views:	331
Size:	50.1 KB
ID:	40204   Click image for larger version

Name:	6-4-2011 4-19-55 PM.png
Views:	270
Size:	11.3 KB
ID:	40205   Click image for larger version

Name:	6-4-2011 4-20-05 PM.png
Views:	324
Size:	17.4 KB
ID:	40206   Click image for larger version

Name:	6-4-2011 4-20-19 PM.png
Views:	245
Size:	27.2 KB
ID:	40207   Click image for larger version

Name:	6-4-2011 4-21-27 PM.png
Views:	301
Size:	77.8 KB
ID:	40208  
Follow me on Twitter Visit my futures io Trade Journal Started this thread Reply With Quote
The following 12 users say Thank You to Big Mike for this post:
 
(login for full post details)
  #5 (permalink)
Site Administrator
Swing Trader
Data Scientist & DevOps
Manta, Ecuador
 
Experience: Advanced
Platform: My own custom solution
Trading: Emini Futures
 
Big Mike's Avatar
 
Posts: 49,412 since Jun 2009
Thanks: 32,068 given, 96,717 received

Feel free to make a request for future video tutorials in this thread.

Mike

We're here to help -- just ask

For the best trading education, watch our webinars
Searching for trading reviews? Review this list

Follow us on Twitter, YouTube, and Facebook

Support our community as an Elite Member:
https://futures.io/elite/
Follow me on Twitter Visit my futures io Trade Journal Started this thread Reply With Quote
The following 2 users say Thank You to Big Mike for this post:
 
(login for full post details)
  #6 (permalink)
Palm Beach County
 
Experience: Advanced
Platform: OEC about to change to Ninja
Trading: ES ,EUR/USD
 
Posts: 179 since Feb 2011
Thanks: 66 given, 90 received

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

Visit my futures io Trade Journal Reply With Quote
The following 2 users say Thank You to Family Trader for this post:
 
(login for full post details)
  #7 (permalink)
Taipei/Taiwan
 
Experience: Beginner
Platform: Multicharts/NinjaTrader
Broker: AMP/CQG
Trading: ES
 
Posts: 42 since Oct 2011
Thanks: 139 given, 25 received


Big Mike View Post
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.

Mike

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...

-Steel

Reply With Quote
 
(login for full post details)
  #8 (permalink)
Plzeň
 
 
Posts: 3 since May 2012
Thanks: 0 given, 0 received

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

Reply With Quote
 
(login for full post details)
  #9 (permalink)
Plzeň
 
 
Posts: 3 since May 2012
Thanks: 0 given, 0 received

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?

Thanks very much

CODE:
---------------------------------------------------------------------------------------------------------------
inputs:

smalength ( 26 ),

emalength ( 8 ),

macdfastlength ( 5 ),

macdslowlength ( 10 ),

ccilength (14);



vars:

TickSize ( MinMove / PriceScale ),

smav ( 0 ),

emav ( 0 ),

macdv ( 0 ),

cciv ( 0 ),

money ( 70000 ),

stocks ( Close/money ),

tar ( 0 ),

st ( Close ),

timer ( 0 );



smav = Average(Close, smalength);

emav = XAverage(Close, emalength);

macdv = MACD(Close, macdfastlength , macdslowlength);

cciv = CCI(ccilength);


// open new positions


if MarketPosition = 0 then begin


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;

end;

Reply With Quote
 
(login for full post details)
  #10 (permalink)
Los Angeles, CA
 
Experience: Advanced
Platform: Tradestation
Broker: Tradestation
Trading: ES,HG,GC,YM,Nq,RB,NG
 
Posts: 52 since Aug 2011
Thanks: 11 given, 8 received


Hi Mike,

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?




Big Mike View Post
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.

Mike


Reply With Quote
 
(login for full post details)
  #11 (permalink)
Calgary, Canada
 
Experience: Intermediate
Platform: Multicharts
Broker: IB, IQFeed
Trading: GC
 
Lampert's Avatar
 
Posts: 76 since Nov 2011
Thanks: 73 given, 139 received


erchis View Post
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?
. . . . . .

money ( 70000 ),

stocks ( Close/money ),
. . . . . .

@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


Reply With Quote
The following user says Thank You to Lampert for this post:
 
(login for full post details)
  #12 (permalink)
Calgary, Canada
 
Experience: Intermediate
Platform: Multicharts
Broker: IB, IQFeed
Trading: GC
 
Lampert's Avatar
 
Posts: 76 since Nov 2011
Thanks: 73 given, 139 received


guppy View Post
Hi Mike,

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?

@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





Reply With Quote
The following 6 users say Thank You to Lampert for this post:
 
(login for full post details)
  #13 (permalink)
Springfield, Missouri
 
Experience: Intermediate
Platform: NinjaTrader
Broker: Interactive Brokers
Trading: EUR/USD
 
Posts: 28 since Sep 2012
Thanks: 29 given, 5 received

Hello,

This video will not play for me. Says: "300: Player initialization failed..."

Is this video located elsewhere too? Or could you upload it again BigMike? Thanks!

Reply With Quote
 
(login for full post details)
  #14 (permalink)
Site Administrator
Swing Trader
Data Scientist & DevOps
Manta, Ecuador
 
Experience: Advanced
Platform: My own custom solution
Trading: Emini Futures
 
Big Mike's Avatar
 
Posts: 49,412 since Jun 2009
Thanks: 32,068 given, 96,717 received


Arich View Post
Hello,

This video will not play for me. Says: "300: Player initialization failed..."

Is this video located elsewhere too? Or could you upload it again BigMike? Thanks!

Try a different browser, like chrome, make sure you have the latest Flash player, make sure you aren't using any blocking scripts. Video works fine.

Mike

We're here to help -- just ask

For the best trading education, watch our webinars
Searching for trading reviews? Review this list

Follow us on Twitter, YouTube, and Facebook

Support our community as an Elite Member:
https://futures.io/elite/
Follow me on Twitter Visit my futures io Trade Journal Started this thread Reply With Quote
The following user says Thank You to Big Mike for this post:
 
(login for full post details)
  #15 (permalink)
Norwich, UK
 
Experience: Intermediate
Platform: Multiple:research&executi
Broker: Started with Stage5/OEC ... multiple
Trading: Anything found profitable goes ...
 
andby's Avatar
 
Posts: 160 since Jul 2012
Thanks: 87 given, 85 received

Hi Mike,

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 ?

Thx

Visit my futures io Trade Journal Reply With Quote
 
(login for full post details)
  #16 (permalink)
Newcastle, Australia
 
Experience: Intermediate
Platform: Multicharts 8 - Full Version
Broker: IB
Trading: SPI,FTSE100, 6E, 6A
 
Posts: 285 since Oct 2010
Thanks: 108 given, 185 received

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.

Reply With Quote
The following user says Thank You to NW27 for this post:
 
(login for full post details)
  #17 (permalink)
Frankfurt / Germany
 
 
Posts: 47 since Jul 2013
Thanks: 28 given, 11 received


Big Mike View Post
Here is the code for jtHMA function if you need it:

 
Code
                            


{jtHMA Hull Moving Average Function}
{
AuthorAtavachron}
{
May 2005}

Inputsprice(NumericSeries), length(NumericSimple);
VarshalvedLength(0), sqrRootLength(0);

{
Original equation is:
---------------------
waverage(2*waverage(close,period/2)-waverage(close ,period), SquareRoot(Period)
Implementation below is more efficient with lengthy Weighted Moving Averages.
In additionthe length needs to be converted to an integer value after it is halved and
its square root is obtained in order for this to work with Weighted Moving Averaging
}

if ((
ceiling(length 2) - (length 2)) <= 0.5then
halvedLength 
ceiling(length 2)
else
halvedLength floor(length 2);

if ((
ceiling(SquareRoot(length)) - SquareRoot(length)) <= 0.5then
sqrRootLength 
ceiling(SquareRoot(length))
else
sqrRootLength floor(SquareRoot(length));

Value1 WAverage(pricehalvedLength);
Value2 WAverage(pricelength);
Value3 WAverage((Value1 Value2), sqrRootLength);

jtHMA Value3
Mike

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:

------ Compiled with error(s): ------
Wrong expression
errLine 9, errColumn 14, errLineEnd 9, errColumnEnd 27
causal study: (Function)

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!

Reply With Quote
 
(login for full post details)
  #18 (permalink)
Tremonton
 
Experience: Intermediate
Platform: ???? still looking
Broker: IB
Trading: TF
 
Posts: 4 since Aug 2011
Thanks: 4 given, 0 received

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!

Thanks

Reply With Quote
 
(login for full post details)
  #19 (permalink)
Frankfurt / Germany
 
 
Posts: 47 since Jul 2013
Thanks: 28 given, 11 received

has anybody help for my problem?

Reply With Quote
 
(login for full post details)
  #20 (permalink)
 
 
Posts: 2,225 since Apr 2013
Thanks: 406 given, 1,468 received

Hi sagetrade,

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 View Post
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:

------ Compiled with error(s): ------
Wrong expression
errLine 9, errColumn 14, errLineEnd 9, errColumnEnd 27
causal study: (Function)

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!


Follow me on Twitter Reply With Quote
The following 2 users say Thank You to ABCTG for this post:
 
(login for full post details)
  #21 (permalink)
London, UK
 
 
Posts: 2 since Oct 2013
Thanks: 1 given, 0 received

hi everyone,

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).

please see code below:


inputs: stopsize(8), tp (10);

vars: ticksize (minmove/pricescale), tgt1 (tp*ticksize), st1(0);


//enter position (only at the close of bar):

if barstatus(1) = 2 then begin

if marketposition = 0 and condition1 then
buy("enter long") next bar 1 contracts at close limit;

if marketposition = 0 and condition2 then
sellshort ("enter short") next bar 1 contracts at close limit;

end;


// trade management (which is causing issues):

if marketposition = 1 then
st1 = entryprice - (stopsize*ticksize);

sell ("longtarget_hit") 1 contracts next bar at (entryprice(0) + tgt1) limit;
sell ("longstop_triggered") 1 contracts next bar at st1 stop;


if marketposition = -1 then
st1 = entryprice + (stopsize*ticksize);

buytocover ("shorttarget_hit") 1 contracts next bar at (entryprice(0) - tgt1) limit;
buytocver ("shortstop_triggered") 1 contracts next bar at st1;



any help much appreciated,

cheers,

bermondsey

Reply With Quote
 
(login for full post details)
  #22 (permalink)
London, United Kingdom
 
Experience: Intermediate
Platform: MetaTrader
Trading: EUR/USD
 
Posts: 20 since Feb 2014
Thanks: 2 given, 1 received

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?

Thanks

Reply With Quote
 
(login for full post details)
  #23 (permalink)
 
 
Posts: 2,225 since Apr 2013
Thanks: 406 given, 1,468 received

saj1011,

please post the full code you are having problems with and I will try helping you.

Regards,
ABCTG

Follow me on Twitter Reply With Quote
 
(login for full post details)
  #24 (permalink)
Norwich, UK
 
Experience: Intermediate
Platform: Multiple:research&executi
Broker: Started with Stage5/OEC ... multiple
Trading: Anything found profitable goes ...
 
andby's Avatar
 
Posts: 160 since Jul 2012
Thanks: 87 given, 85 received


ABCTG View Post
saj1011,

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
?

Visit my futures io Trade Journal Reply With Quote
 
(login for full post details)
  #25 (permalink)
 
 
Posts: 2,225 since Apr 2013
Thanks: 406 given, 1,468 received

andby,

you should specify different order names for each order and tie the exits to your entry. This should do what you have in mind.
 
Code
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 View Post
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;


Follow me on Twitter Reply With Quote
The following user says Thank You to ABCTG for this post:
 
(login for full post details)
  #26 (permalink)
Norwich, UK
 
Experience: Intermediate
Platform: Multiple:research&executi
Broker: Started with Stage5/OEC ... multiple
Trading: Anything found profitable goes ...
 
andby's Avatar
 
Posts: 160 since Jul 2012
Thanks: 87 given, 85 received


ABCTG View Post
andby,

you should specify different order names for each order and tie the exits to your entry. This should do what you have in mind.
 
Code
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:



Kind Regards,
Andy

Visit my futures io Trade Journal Reply With Quote
The following user says Thank You to andby for this post:
 
(login for full post details)
  #27 (permalink)
 
 
Posts: 2,225 since Apr 2013
Thanks: 406 given, 1,468 received

andby,

you are welcome, I am glad if it helped.
Thanks for sharing your code.

Regards,
ABCTG


andby View Post
ABCTG,

Thanks for a fast answer!
Uploaded the code under:



Kind Regards,
Andy


Follow me on Twitter Reply With Quote
 
(login for full post details)
  #28 (permalink)
Netherlands
 
Experience: Intermediate
Platform: multicharts
Broker: Interactive Brokers
Trading: Stocks
 
Posts: 7 since Aug 2012
Thanks: 2 given, 9 received


saj1011 View Post
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?

Thanks

should be MinMove

Reply With Quote
 
(login for full post details)
  #29 (permalink)
Crete, IL/USA
 
Experience: Intermediate
Platform: NinjaTrader, Mt4
Broker: Tradestation/Tradestation, NinjaTrader, FXCM and Tallinex
Trading: ES, CL, EUR/USD, TF
 
spinnybobo's Avatar
 
Posts: 181 since Aug 2009
Thanks: 103 given, 56 received


Big Mike View Post
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:


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

thanks
Spencer

Follow me on Twitter Reply With Quote
 
(login for full post details)
  #30 (permalink)
 
 
Posts: 2,225 since Apr 2013
Thanks: 406 given, 1,468 received

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




spinnybobo View Post
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

thanks
Spencer


Follow me on Twitter Reply With Quote
 
(login for full post details)
  #31 (permalink)
Crete, IL/USA
 
Experience: Intermediate
Platform: NinjaTrader, Mt4
Broker: Tradestation/Tradestation, NinjaTrader, FXCM and Tallinex
Trading: ES, CL, EUR/USD, TF
 
spinnybobo's Avatar
 
Posts: 181 since Aug 2009
Thanks: 103 given, 56 received


ABCTG View Post
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 ?

thanks
Spencer

Follow me on Twitter Reply With Quote
 
(login for full post details)
  #32 (permalink)
 
 
Posts: 2,225 since Apr 2013
Thanks: 406 given, 1,468 received

Spencer,

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 View Post
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 ?

thanks
Spencer


Follow me on Twitter Reply With Quote
 
(login for full post details)
  #33 (permalink)
Hsinchu+Taiwan
 
 
Posts: 1 since Jun 2014
Thanks: 2 given, 0 received

Dear Mike,
Much thanks for your sharing, it helps me a lot.
best regards,
Ben

Reply With Quote
 
(login for full post details)
  #34 (permalink)
Helsingborg
 
Experience: Intermediate
Platform: Bullcharts, Multicharts
Trading: ES and scandinavian Stocks
 
Posts: 17 since May 2011
Thanks: 6 given, 5 received

Hi,

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.


 
Code

[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;

Reply With Quote
 
(login for full post details)
  #35 (permalink)
Dubai, UAE
 
 
Posts: 10 since Sep 2014
Thanks: 2 given, 1 received


stefanols View Post
Hi,

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.

Reply With Quote
 
(login for full post details)
  #36 (permalink)
Dubai, UAE
 
 
Posts: 10 since Sep 2014
Thanks: 2 given, 1 received

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.

Reply With Quote
 
(login for full post details)
  #37 (permalink)
New York + US
 
Experience: Intermediate
Platform: MultiCharts
Trading: Indian Stocks
 
Posts: 37 since Aug 2015
Thanks: 10 given, 2 received

Hello folks,

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!

Reply With Quote
 
(login for full post details)
  #38 (permalink)
New York, New York, United States
 
Experience: Beginner
Platform: TOS
Trading: Options
 
vitrader's Avatar
 
Posts: 53 since Jul 2015
Thanks: 13 given, 7 received

I would love to see more video tutorials for Multicharts.

Reply With Quote
 
(login for full post details)
  #39 (permalink)
Sarasota Fl
 
 
Posts: 1 since Nov 2017
Thanks: 0 given, 0 received

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.


Mikes coding:

Big Mike Trading

June 2011

}





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



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 );



smav = Average(Close, smalength);

emav = XAverage(Close, emalength);

hmav = jtHMA(Close, hmalength);





// open new positions



if MarketPosition = 0 then begin



if smav > smav[1] and emav > emav[1] and hmav > hmav[1] then begin



Buy ("Enter long") 3 Contracts Next Bar At Market;



end;



if smav < smav[1] and emav < emav[1] and hmav < hmav[1] 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;


Thanks so much in advance
Paul

Reply With Quote
 
(login for full post details)
  #40 (permalink)
 
 
Posts: 2,225 since Apr 2013
Thanks: 406 given, 1,468 received

Paul,

regarding your questions:

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:

Regards,

ABCTG


FormerAMEXTrader View Post
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.


Mikes coding:

Big Mike Trading

June 2011

}





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



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 );



smav = Average(Close, smalength);

emav = XAverage(Close, emalength);

hmav = jtHMA(Close, hmalength);





// open new positions



if MarketPosition = 0 then begin



if smav > smav[1] and emav > emav[1] and hmav > hmav[1] then begin



Buy ("Enter long") 3 Contracts Next Bar At Market;



end;



if smav < smav[1] and emav < emav[1] and hmav < hmav[1] 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;


Thanks so much in advance
Paul


Follow me on Twitter Reply With Quote
 
(login for full post details)
  #41 (permalink)
Florence
 
 
Posts: 17 since Jan 2021
Thanks: 12 given, 4 received


Lampert View 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





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.

Reply With Quote


futures io Trading Community Platforms and Indicators MultiCharts > VIDEO TUTORIAL: How to create an advanced MultiCharts EasyLanguage Strategy


Last Updated on January 13, 2021


Upcoming Webinars and Events
 

NinjaTrader Indicator Challenge!

Ongoing
 

Finding Trading Opportunities Using Profile Charts w/Tradovate

Jan 28
 

Journal Challenge!

February
 

Battlestations!

March
     



Copyright © 2021 by futures io, s.a., Av Ricardo J. Alfaro, Century Tower, Panama, +507 833-9432, info@futures.io
All information is for educational use only and is not investment advice.
There is a substantial risk of loss in trading commodity futures, stocks, options and foreign exchange products. Past performance is not indicative of future results.
no new posts