Autotrading with Limitorders

Questions about MultiCharts and user contributed studies.
User avatar
aiti
Posts: 43
Joined: 25 May 2009
Location: Germany
Has thanked: 43 times
Been thanked: 20 times

Autotrading with Limitorders

Postby aiti » 03 Jul 2010

I have a problem with my strategy while autotrading with Interactive Brokers.

Code: Select all

inputs:
BollingerPrice( Open ),
Length( 20 ),
NumDevsDn( -2 ),
NumDevsUp( 2 ),
Profit ( 0.19 ),
Distance (0.02),
Start ( 1200 ),
Ende ( 1800 );

[IntrabarOrderGeneration = true];

variables:
var0 ( 0 ) , var1 ( 0 ) , TPl ( 0 ) ,LE ( 0 ) , SE ( 0 ) ,
TPs ( 0 ) ;

var0 = BollingerBand( BollingerPrice, Length, NumDevsDn ) ;
var1 = BollingerBand( BollingerPrice, Length, NumDevsUp) ;

TPl = EntryPrice ( 0 ) + Profit ;
TPs = EntryPrice ( 0 ) - Profit ;

condition1 = CurrentBar > 1 and (marketposition = 0 )
and Time > Start and Time < Ende ;

condition3 = Close [1] < var1[1] and Close[1] > var0[1];

if condition1 and condition3 then

begin
LE = var1[0] + Distance ;
SE = var0[0] - Distance ;

Buy ( "BreakLE" ) next bar at LE stop;
Sell short ("BreakSE" ) next bar at SE stop;
end ;

if (marketposition = 1 ) then
begin

Sell ( "Break_L+" ) next bar at TPl limit ;
Sell ( "Break_L-" ) next bar at var0[0] stop ;

end;

if (marketposition = -1 ) then
begin

buytocover ( "Break_S+" ) next bar at TPs limit ;
buytocover ( "Break_S-" ) next bar at var1[0] stop ;

end;


I am using a 5-Minute-timeframe.
If the condition is true the limitorders for entry will be sent to IB correct.
After getting a new bar I get the message "Order is not filled within the specified bar" and both limitorders were deleted.

While condition was still true,there were no new limitorders sent to IB within this new bar.

With the next new bar I got 2 new orders and the same game began.

So I am for 5 minutes with limit in the market,then for 5 minutes not,then again in .....

If one limit order got filled I got the TP and SL-Limits.With the next new bar I got the message again and the orders were deleted.But in this case immediately there were sent 2 new Limits to IB.

Is there a method that the entry-limits get renewed immediately after the deletion of the former orders?

User avatar
TJ
Posts: 7740
Joined: 29 Aug 2006
Location: Global Citizen
Has thanked: 1033 times
Been thanked: 2221 times

Postby TJ » 03 Jul 2010

i don't see how this can trigger anything

condition3 = Close [1] < var1[1] and Close[1] > var0[1];




tips:
don't use generic variable names...
you will spend half of your valuable life debugging a silly stupid typo.

User avatar
aiti
Posts: 43
Joined: 25 May 2009
Location: Germany
Has thanked: 43 times
Been thanked: 20 times

Postby aiti » 04 Jul 2010

i don't see how this can trigger anything

condition3 = Close [1] < var1[1] and Close[1] > var0[1];




tips:
don't use generic variable names...
you will spend half of your valuable life debugging a silly stupid typo.
Hi TJ,
Thank you for your quick answer. :D

If close[1] is between the Bollinger Bands the limitorders should be send.
The limits are the "Distance"-points outside the Bollinger Bands.

But now I understand the mistake.If close[0] is the same or a little bit over/under the Bollinger Bands then with the new bar I get no trigger and no limitorder will be send.Perhaps the next close will be between again then I get the limitorders,but only with the new bar. :shock:

And thank you again for your tips. :D
I won´t use generic variables in future.In the past I have searched a long time my codes for these typos,especially in variables.
But as a beginner I am learning by doing.My first coding experiences I got in copying and changing strategies delivered with MC. :wink: :idea:

User avatar
TJ
Posts: 7740
Joined: 29 Aug 2006
Location: Global Citizen
Has thanked: 1033 times
Been thanked: 2221 times

Postby TJ » 04 Jul 2010

aiti:

You are welcome.

I am glad that you see the importance of variable names.


When you are modifying MC's built-in indicators,
you can replace its generic variable names with your own.
This will help you to understand the indicator's logic,
and to speed up your own code development.

Enjoy.
TJ


tips #2:
add lots of comments in your code.
comments help you to read the logic of your code,


e.g.

Code: Select all

// this is a comment
// MultiCharts will ignore anything after 2 slash lines

{this is a comment
MultiCharts will ignore anything between 2 wiggly brackets}


{----- e.g. -----}

var:
In.Between(false),
UpperBand(0),
LowerBand(0);

....

// If close[1] is between the Bollinger Bands the limitorders should be send.
// The limits are the "Distance"-points outside the Bollinger Bands.

In.Between = Close[1] < UpperBand[1] and Close[1] > LowerBand[1];

.


Return to “MultiCharts”