Plot entries and exits  [SOLVED]

Questions about MultiCharts and user contributed studies.
evdl
Posts: 401
Joined: 19 Jan 2011
Location: Netherlands
Has thanked: 85 times
Been thanked: 124 times

Plot entries and exits

Postby evdl » 07 Jul 2015

Using autotrader to enter and exit trades. But sometimes I block these trades with some tradebuttons I made. But I would like to plot the entries and exits my autotrader would have taken if I didn't block them manually. In this way I can see what would have happened.

I am using tick charts with barmagnifier set on 1 tick. The conditions to take an trade or an exit are calculated per tick. Now the problem.

When I use

Code: Select all


If condition1 = true
and condition2 = true

Then begin

If (MarketPosition = 0)

Then begin
// my plot
Entry_1_Plot = Text_New_Dt(DateTime, High, "Entry_1 Plot");

// entry signal
If manual_block_trade = false then begin
Buy ("LE_1") 1 contracts next bar at market;
end;
end;

end;
The entry signal is normally plotted on the chart by the trade engine of MC. But my own plot is not plotted because the condition1 and condition2 can be true for just one tick. And that is to short to plot the text on the chart because the conditions are met intrabar. The trade engine is probably plotting because it is getting confirmation from the broker or something.

Although this is always long enough timespan to take a trade. How can I get the entry text of "my plot" also plotted on the chart even if this conditions are only met in a short timespan or intrabar?

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

Re: Plot entries and exits

Postby Henry MultiСharts » 14 Jul 2015

Hello evdl,

We were unable to replicate this behavior on our end.
Please send us (support@multicharts.com) the following information for further analysis:
- workspace you are using;
- in QuoteManager select the symbos you are using, make a right click on it->Export data->Export instrument (with data). Send us the QMD export file for analysis;
- in Power Language editor->File->Export->Export with dependent functions the study you are using. Send us the study export file;
- specify the version and build number of MultiCharts you are running (in MultiCharts go to Help tab-> About).

evdl
Posts: 401
Joined: 19 Jan 2011
Location: Netherlands
Has thanked: 85 times
Been thanked: 124 times

Re: Plot entries and exits

Postby evdl » 14 Jul 2015

Thanks for your reply Henry.

I am not sure it is a problem with MC, but more a coding problem.

Will try to be a bit more specific. For example:

60tick chart and IOG on, and entry condition1 is true only on the 5th tick in the 60tick bar. MC will take a trade and the trade engine will show this entry on the chart. No problem here.

Now I want to plot a text with the textnew_s or textnew_dt reserved word when this trade takes place or plot a dot or arrow.

What I have noticed is that the textnew reserved word or the plot reserved word is only plotting when the condition1 is still valid on barclose. But with my example this is not the case (only on the 5th tick) and there is no plotting due to this.

The only way to get the plotting on the chart, is to use "If barstatus(1) = 2 then begin".

Is my assumption right that the textnew_s and plot reserved words only work on barclose? And can not be used to plot conditions met intrabar, even with IOG, barmagnifier on 1 tick or in realtime the update on every tick on, without the use of the barstatus and additional coding to prevent multiple plots in a bar.

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

Re: Plot entries and exits

Postby TJ » 14 Jul 2015

Thanks for your reply Henry.

I am not sure it is a problem with MC, but more a coding problem.

Will try to be a bit more specific. For example:

60tick chart and IOG on, and entry condition1 is true only on the 5th tick in the 60tick bar. MC will take a trade and the trade engine will show this entry on the chart. No problem here.

Now I want to plot a text with the textnew_s or textnew_dt reserved word when this trade takes place or plot a dot or arrow.

What I have noticed is that the textnew reserved word or the plot reserved word is only plotting when the condition1 is still valid on barclose. But with my example this is not the case (only on the 5th tick) and there is no plotting due to this.

The only way to get the plotting on the chart, is to use "If barstatus(1) = 2 then begin".

Is my assumption right that the textnew_s and plot reserved words only work on barclose? And can not be used to plot conditions met intrabar, even with IOG, barmagnifier on 1 tick or in realtime the update on every tick on, without the use of the barstatus and additional coding to prevent multiple plots in a bar.
You have to use intrabarpersist to capture that "fleeting moment" when the BUY/SELL order is triggered.

I don't have the time to code for you today, but this should point you to the direction where you can find a solution.

evdl
Posts: 401
Joined: 19 Jan 2011
Location: Netherlands
Has thanked: 85 times
Been thanked: 124 times

Re: Plot entries and exits

Postby evdl » 15 Jul 2015

The enty trigger is saved in an intrabarpersist variabel. The signal is catching the right entryvalue (close) in the variabel at the time of the buy or sell.

The trigger is only valid for a couple of ticks and not the whole bar. And the trigger (the variabel) is updated again to not valid as it should. To get the plot on the chart, I use the barstatus(1) = 2 and add some additional triggers to the entry variabel to prevent multiple plots on different prices.

Was wondering why the textnew and plot reserved words only work when entrytrigger is still valid on barclose even if you use barmagnifier. I suspect it is because MC is using the barclose time. Like in the SPR reports where a entry is done intrabar with IOG, but you always get the barclose time instead of the intrabar real entrytime.

With the use of text_s and text_dt versions, which are used to get seconds and milliseconds precision, you will catch an intrabartime and that is why it is not plotting on the chart (in backtesting) unless you use the barstatus and keep the trigger "alive". Which will cause multiple plots in realtime if you don't add additional triggers. Am I missing something, or is there a simplier way of doing this?

Code: Select all

If condition1 = true
and condition2 = true
then begin

If (MarketPosition = 0)

then begin
// my plot
If Plot_Entry1_trigger = 0
then begin
Plot_Entry1_entryprice = close; // catch entryprice (set intrabarpersist)
Plot_Entry1_trigger = 1; // block plot trigger (set intrabarpersist)
end;

end; // end of If (MarketPosition = 0) Then begin

end; // end of If condition1 = true


If Plot_Entry1_trigger = 1
then begin
Entry1_Plot = Text_New_Dt(DateTime, Plot_Entry1_entryprice, "Entry1 Plot");

If barstatus(1) =2
then begin
Plot_Entry1_trigger = 0; // reset plot trigger
end;

end; // end of If Plot_Entry1_trigger = 1

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

Re: Plot entries and exits  [SOLVED]

Postby Henry MultiСharts » 17 Jul 2015

Hello evdl,

As we do not have your complete code - here is a sample code that will place a drawing intrabar once per bar:

Code: Select all

[RecoverDrawings = False]
var: intrabarpersist flag(0);

if(not LastBarOnChart_s) then #return;
If barstatus = 1 then begin
if(flag = 0) then begin
value1 = text_new_bn(currentbar, close, "Text");
flag = 1;
end;
end;

if(barstatus = 2) then flag = 0;


Return to “MultiCharts”