Help understanding an impossible signal exit price

Questions about MultiCharts and user contributed studies.
tozwp
Posts: 145
Joined: 15 Apr 2011
Has thanked: 16 times
Been thanked: 8 times

Help understanding an impossible signal exit price

Postby tozwp » 28 Mar 2014

I have a simple signal that enters on a tick above the high of the previous bar with a stop at the low of that same bar. It runs in IOG mode and calculates stops during the bar. Today it entered a long trade at the proper price but it then showed an exit at the close of the previous bar even though price never traded anywhere near that price after the entry. Was wondering if someone could take a look at this? I've attached a pic of the trade after the close. The wrong exit ws there during the entire bar. The top window has the signal with the code running on it. The bottom is the same data but on a shorter time frame (15 minutes) just to see that where price traded during the larger time frame bar above. In the rest of the chart, this seems to work find. I couldn't find another example like this.

Here's the code:

Code: Select all

Inputs: nBarClose(2), T1(759), T2(1559), T3(2358), pip(0.001);

vars: Flag(false), size(0), ISL(0), R(100), Trig(0), Intrabarpersist RLevel(0),
intrabarpersist Rstop(0), intrabarpersist MaxRLevel(0), EODRstop(0), iStop(0), NoGap(false), MP(0);

[IntrabarOrderGeneration = True]

MP = Marketposition;

If MP = 0 then begin
RLevel = 0;
MaxRLevel = 0;
iStop = 0;
EODRstop = 0;
RStop = 0;
end;

If BarStatus(1) = 2 and MP <=0 then begin
Flag = IP;
Trig = High + pip;
R = (High - Low) + (pip * 2);
ISL = Low - pip;
end;

If BarStatus(1) <=1 then NoGap = c <= Trig + pip;

if MP <=0 and Flag and NoGap then begin
Buy("IP-L") 100{size} shares next bar at Trig Stop;
end;

If MP = 1 then flag = false;
If MP = 1 then RLevel = (c - Trig)/R;
If MP = 1 then MaxRLevel = Iff(RLevel > MaxRlevel, RLevel, MaxRLevel);

If MP = 1 and MaxRLevel < 1 then iStop = ISL;
If MP = 1 and MaxRLevel >= 1 then iStop = (IntPortion(MaxRLevel) * R) + ISL; //stop to Max R - 1
IF MP = 1 and (Time = T1 or Time = T2 or Time = T3) and MaxRLevel > 1 then EODRstop = (IntPortion(MaxRLevel) * R) + Trig;
If MP = 1 then RStop = Iff(EODRstop > iStop, EODRstop, iStop);//initialize EODRstop to 0 for long entry signals

if MP = 1 then sell("RStop") from entry("IP-L") next bar at RStop Stop;
If MP = 1 and BarsSinceEntry = nBarClose and MaxRLevel < 1 then Sell("LowR") from entry ("IP-L") this bar at Close;

If AtCommentaryBar Then begin
commentary("istop",istop:1:5);
end;
Attachments
SignalError..JPG
(142.53 KiB) Downloaded 374 times

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

Re: Help understanding an impossible signal exit price

Postby TJ » 28 Mar 2014

I have a simple signal that enters on a tick above the high of the previous bar with a stop at the low of that same bar. It runs in IOG mode and calculates stops during the bar. Today it entered a long trade at the proper price but it then showed an exit at the close of the previous bar even though price never traded anywhere near that price after the entry. Was wondering if someone could take a look at this? I've attached a pic of the trade after the close. The wrong exit ws there during the entire bar. The top window has the signal with the code running on it. The bottom is the same data but on a shorter time frame (15 minutes) just to see that where price traded during the larger time frame bar above. In the rest of the chart, this seems to work find. I couldn't find another example like this.
::
Is this a back test? live trade? or a forward test?

tozwp
Posts: 145
Joined: 15 Apr 2011
Has thanked: 16 times
Been thanked: 8 times

Re: Help understanding an impossible signal exit price

Postby tozwp » 28 Mar 2014

This signal was running on live data today and showed that entry and exit. It is not trading live though so I don't have a trade. During that bar formation today, it showed the proper entry but an impossible exit as price never traded at the price that the signal showed that it exited. That is why I am confused. Using the expert commentary for troubleshooting, I see that my entry value and stop values calculated correctly while the trade was active during the bar. If the trade was exited immediately, the marketposition would have been zero and these values would not have been calculated according to the script. Bottom line is that I don't understand why the signal would show an exit when and where there should not have been one. On prior bars, it seems to run fine with no strange exits, only on this bar.

tozwp
Posts: 145
Joined: 15 Apr 2011
Has thanked: 16 times
Been thanked: 8 times

Re: Help understanding an impossible signal exit price

Postby tozwp » 30 Mar 2014

Today I created a new chart with the same symbol & bar length, same custom session, same backtesting criteria under strategy properties and it now shows the correct entry and exit. The original chart still showed the wrong exit. Not sure what was going on during Friday's session/chart and why it showed that impossible exit. Nothing in the code changed. I'm going to keep an eye on it and see if it happens again.


Return to “MultiCharts”