Enter & Exit on the last minute of 60min bar

Questions about MultiCharts and user contributed studies.
Spark
Posts: 12
Joined: 30 May 2013
Has thanked: 8 times

Enter & Exit on the last minute of 60min bar

Postby Spark » 30 May 2013

Hello!

The question is about auto-trading, not backtesting.

I'm trying to execute orders on the last 30 seconds of the bar.

That's the code of my simple breakout strategy, maybe someone would find it useful, but now it doesn't work.

Code: Select all

[IntrabarOrderGeneration = True]
inputs: Price( Close ), Length(20), MAPeriod (100) ;
variables: var0( 0 ), var1( 0 ), var2 ( 0 ) ;

var0 = Lowest( Low, Length)[1] ;
var1 = Highest( High, Length)[1] ;
var2 = AverageFC( Price, MAPeriod ) ;

condition1 = (Time_s > 102930 and Time_s < 102959)
or (Time_s > 112930 and Time_s < 112959)
or (Time_s > 122930 and Time_s < 122959)
or (Time_s > 132930 and Time_s < 132959)
or (Time_s > 142930 and Time_s < 142959)
or (Time_s > 152930 and Time_s < 152959)
or (Time_s > 162930 and Time_s < 162959);
if condition1 then
Begin


if MarketPosition = 0 then
Begin

if Last > var2 and Last > var1 then
Buy ( "Long Breakout" ) next bar at market;

if Last < var2 and Last < var0 then
SellShort ( "Short Breakout" ) next bar at market;
End;


if MarketPosition <> 0 then
Begin

if Last < var2 then
Sell ( "Long Exit" ) next bar at market;


if Last > var2 then
BuyToCover ( "Short Exit" ) next bar at market;
End;


End;
Should I add IntraBarPersist to variables? Does anyone have any other idea what's wrong with my strategy code?

Thank you!

User avatar
Henry MultiСharts
Posts: 9165
Joined: 25 Aug 2011
Has thanked: 1264 times
Been thanked: 2957 times

Re: Enter & Exit on the last minute of 60min bar

Postby Henry MultiСharts » 30 May 2013

Hello Spark,

What does not work exactly? Have you tried to debug your code?
Please have a look at the following article: Why an Order Was or Was Not Executed

Spark
Posts: 12
Joined: 30 May 2013
Has thanked: 8 times

Re: Enter & Exit on the last minute of 60min bar

Postby Spark » 04 Jun 2013

Thank you very much!


Return to “MultiCharts”