Capturing the last entry price using IOG on a daily chart  [SOLVED]

Questions about MultiCharts and user contributed studies.
PD Quig
Posts: 191
Joined: 27 Apr 2010
Location: San Jose
Has thanked: 67 times
Been thanked: 10 times

Capturing the last entry price using IOG on a daily chart

Postby PD Quig » 23 Jul 2013

I have a proprietary swing indicator that I am applying to a daily chart that will cause entries at multiple levels within the same day or across several days (see attached pic). I am attempting to add a test to ensure that each long entry is lower than the prior entry (and higher for shorts). This is needed because every once in a while a lower indicator value on the next day will be a bit higher in price than the previous entry. I want to filter those out.

I thought this would be simple but the "next bar at market" order means that LastEntryPrice has to be trapped outside of the begin/end loop where the entry order statement is. I've tried 4-5 different approaches but keep running into a wall. I've resorted to capturing the close price when the 1st or 2nd loop is executed, but the actual entryprice occurs on the next line in the data stream: actual 1st entryprice = 1579.75 vs. 1580.00 (see Output). Close but not 100% accurate.

There must be an easy way to do this buy I'm not seeing it. Any thoughts would be greatly appreciated.


Here is the code stripped down to the basics:

Code: Select all

{******************************************************************************
Name : $Intraday_Entry_Test_v2.0
Description : Testing intrabar orders on a daily chart
Last Modified Date : 07/23/2013
Application : MultiCharts execution strategy
******************************************************************************}
[IntrabarOrderGeneration = true];

[LegacyColorValue = true];

//*****************************************************************************
// inputs and variable initialization section
//*****************************************************************************

Input:
Long_Entry_1_Contracts (1),
Long_Entry_2_Contracts (2),
Long_Entry_3_Contracts (3),
Long_Entry_1_Level (10),
Long_Entry_2_Level (4),
Long_Entry_3_Level (2),
Long_Exit_Level (90);

Variables:
myIndicator (0),
Intrabarpersist LastEntryPrice (0),
Intrabarpersist myMP (0);


//*****************************************************************************
// calculations section
//*****************************************************************************

myIndicator = SwingIndicator(close,14);

//*****************************************************************************
// entry execution section
//*****************************************************************************

// enter long

if marketposition <= 0 and myIndicator < Long_Entry_1_Level then begin

buy ("LE_1") Long_Entry_1_Contracts shares next bar at market;
myMP = 1;
LastEntryPrice = close; // approximation of the actual entry price
end;

if myMP = 1 and myIndicator < Long_Entry_2_Level then begin

buy ("LE_2") Long_Entry_2_Contracts shares next bar at market;
myMP = 2;
LastEntryPrice = close;
end;

if myMP = 2 and myIndicator < Long_Entry_3_Level then begin

buy ("LE_3") Long_Entry_3_Contracts shares next bar at market;
myMP = 3;
end;

//*****************************************************************************
// exit execution section
//*****************************************************************************

if myMP > 0 and myIndicator >= Long_Exit_Level then begin // exit long

myMP = 0;
sell ("LX") currentcontracts shares next bar at market;
end;
Attachments
Daily_bars_-_Intrabar_Output.png
(82.28 KiB) Downloaded 431 times
Daily_bars_-_Intrabar_Entries.png
(9.22 KiB) Downloaded 417 times

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

Re: Capturing the last entry price using IOG on a daily char

Postby TJ » 24 Jul 2013

Have you studied all the strategy keywords in the wiki?
There are a few new keywords introduced in the recent releases.

PD Quig
Posts: 191
Joined: 27 Apr 2010
Location: San Jose
Has thanked: 67 times
Been thanked: 10 times

Re: Capturing the last entry price using IOG on a daily char  [SOLVED]

Postby PD Quig » 24 Jul 2013

Thanks, TJ.

PosTradeEntryPrice was just what the doctor ordered--one new line of code solved it.


Return to “MultiCharts”