Stop Loss Signals not working

Questions about MultiCharts and user contributed studies.
User avatar
virginiatrader
Posts: 79
Joined: 05 May 2007
Location: Virginia
Has thanked: 5 times
Been thanked: 5 times

Stop Loss Signals not working

Postby virginiatrader » 18 Oct 2011

Howdy, everyone...

I write reluctantly because all of this may be my own inability to diagnose the problem, but it seems that I have stop loss signals that do not activate when the criteria are met.

I am an old TS2000i user, so some of the signals are out-of-the-box and imported from old EasyLanguage code, others I wrote in EL and imported, and some I wrote in MC PowerLanguage.

The code for my trend-following system works fine when applied to any data series. But when I add some sort of stop loss, either adding the signal from within the Format Signals window, or by copying the code directly into my system, I get no indication that the signals are executing.

I am currently running MC 7.1 beta, having just changed from MC 7. The situation may have existed in the earlier production version, but I had not been working with stop loss signal for a while. All of the old code was imported and compiled with no issues noted.

Thinking it was a version problem, I reverted to MC 6, with no luck. This makes me think that I am doing something REALLY stupid, and come to the forum to beg for guidance. Perhaps someone has encountered this before.

Any help is appreciated in advance.

virginiatrader

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

Re: Stop Loss Signals not working

Postby TJ » 18 Oct 2011

Howdy, everyone...

I write reluctantly because all of this may be my own inability to diagnose the problem, but it seems that I have stop loss signals that do not activate when the criteria are met.

I am an old TS2000i user, so some of the signals are out-of-the-box and imported from old EasyLanguage code, others I wrote in EL and imported, and some I wrote in MC PowerLanguage.

The code for my trend-following system works fine when applied to any data series. But when I add some sort of stop loss, either adding the signal from within the Format Signals window, or by copying the code directly into my system, I get no indication that the signals are executing.

I am currently running MC 7.1 beta, having just changed from MC 7. The situation may have existed in the earlier production version, but I had not been working with stop loss signal for a while. All of the old code was imported and compiled with no issues noted.

Thinking it was a version problem, I reverted to MC 6, with no luck. This makes me think that I am doing something REALLY stupid, and come to the forum to beg for guidance. Perhaps someone has encountered this before.

Any help is appreciated in advance.

virginiatrader
The forum is for asking questions, so don't feel bad about asking.

Can you post the code?
We can't debug it if we don't know the code.

User avatar
virginiatrader
Posts: 79
Joined: 05 May 2007
Location: Virginia
Has thanked: 5 times
Been thanked: 5 times

Re: Stop Loss Signals not working

Postby virginiatrader » 18 Oct 2011

Thanks, TJ!

The system code:

Code: Select all

[IntrabarOrderGeneration = true]
inputs: lengthTrendAvg(52), lengthBreakout(4), lengthClose(2);
{*****************************************************************************}
if xaverage(close, lengthTrendAvg) of data2 > xaverage(close, lengthTrendAvg) of data2 [1]
then begin
if close of data2 > highest(high of data2, lengthBreakout) [1]
then buy ("CS4D2LE") 1 contracts {this bar at close} next bar at Open;
end;
{*****************************************************************************}
if marketposition = 1
then begin
if close of data2 < lowest(close of data2, lengthClose) [1]
and close > open
then sell ("cvrLng") {this bar at close} next bar at Open;
end;
{*****************************************************************************}
if xaverage(close, lengthTrendAvg) of data2 < xaverage(close, lengthTrendAvg) of data2 [1]
then begin
if close of data2 < lowest(low of data2, lengthBreakout) [1]
then sellshort ("CS4D2SE") 1 contracts {this bar at close} next bar at Open;
end;
{*****************************************************************************}
if marketposition = -1
then begin
if close of data2 > highest(close of data2, lengthClose) [1]
and close < open
then buytocover ("cvrShrt") {this bar at close} next bar at open;
end;
{*****************************************************************************}
My stop loss (short exit), coded in MC PL:

Code: Select all

Inputs: DollarRisk((2*ATRRangeCalc)*bigpointvalue), PositionBasis(False);
Variables: RiskCalc(0), OrderPriceBPV(0), OrderPriceATR(0);

If MarketPosition = -1 Then Begin
If PositionBasis Then
RiskCalc = (DollarRisk / CurrentContracts) - Commission
Else
RiskCalc = DollarRisk - Commission;

If BigPointValue <> 0 Then
OrderPriceBPV = (entryprice + bigpointvalue);
If BigPointValue <> 0 Then
OrderPriceATR = (EntryPrice + (RiskCalc / BigPointValue));

If OrderPriceBPV < OrderPriceATR then
buytocover ("BPY_S$_SL") Next Bar at OrderPriceBPV Stop;
If OrderPriceBPV > OrderPriceATR then
buytocover ("ATR_S$_SL") Next Bar at OrderPriceATR Stop;

End;
Thanks for looking this over. While the error could be in the code, the different order signals used to work. I admit I am not the greatest coder in the world, but it's got me baffled.

virginiatrader

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

Re: Stop Loss Signals not working

Postby TJ » 18 Oct 2011

...Thanks for looking this over. While the error could be in the code, the different order signals used to work. I admit I am not the greatest coder in the world, but it's got me baffled.

virginiatrader
I can't spot anything wrong right off the bat. I have to run the code with some streaming data to see where is the hangup.

User avatar
virginiatrader
Posts: 79
Joined: 05 May 2007
Location: Virginia
Has thanked: 5 times
Been thanked: 5 times

Re: Stop Loss Signals not working

Postby virginiatrader » 19 Oct 2011

Thanks, sir. I failed to mention that I run these signals on end-of-day data from two sources, Pinnacle Data, and Norgate Premium Data.

virginiatrader

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

Re: Stop Loss Signals not working

Postby Henry MultiСharts » 21 Oct 2011

Hello Virginiatrader.
Please provide additional information regarding your issue:
-What symbol are you trading.
-What symbol settings do you have (please attach a screenshot if possible).
-Are you doing backtesting or running autotrading.
-What autotrading mode is selected (Sync/Asinc).
-What exactly is incorrect-the order is not generated at all, it is generated with incorrect price, the order is rejected, ... .
-Was this script working in TS2000i.

User avatar
virginiatrader
Posts: 79
Joined: 05 May 2007
Location: Virginia
Has thanked: 5 times
Been thanked: 5 times

Re: Stop Loss Signals not working

Postby virginiatrader » 21 Oct 2011

HM:

Thanks for following this. I will collect the information you are asking for and post it ASAP.

Thanks!

virginiatrader

User avatar
virginiatrader
Posts: 79
Joined: 05 May 2007
Location: Virginia
Has thanked: 5 times
Been thanked: 5 times

Re: Stop Loss Signals not working

Postby virginiatrader » 26 Oct 2011

Hello, Henry Multicharts and TJ:

I am sorry it took so long to post my reply to HM's request. To answer HM's questions...

1) I trade a number of markets; I have included a chart of the US Treasury 5 Year Note, with my system applied (no stop loss code included).
2) I have attached several screenshots of the symbol settings and system settings..
3) I am back-testing on end-of-day data, with two data streams on the chart: DAILY and WEEKLY. The system signals are executed on the weekly data, and show as trade arrows on the daily data.
4) I am NOT auto-trading, and have attached a screenshot of the AT settings.
5) The problem is NOT with the execution of the system. The indications for a BUY, a SELL, a SELLSHORT, and a BUYTOCOVER show on the chart, and in the List of Trades in the Performance Summary. The issue is when i attempt to include a STOP-LOSS order, either within the system code, or as a separate LX and SX signal. All of the code compiles successfully, the base system continues to show trade arrows, but I get no stop-loss trade arrows or signals in the List of Trades.
6) The stops loss signals do work in TS2000i.

Thanks very much for your time and review of my problem.

virginiatrader
Attachments
Format Signals.bmp
(885.99 KiB) Downloaded 635 times
Format Objects Signals.bmp
(885.99 KiB) Downloaded 636 times
Strategy Properties Auto Trading.bmp
(1.22 MiB) Downloaded 636 times
Format Instrument Settings.bmp
(896.5 KiB) Downloaded 637 times
Treasury Note 5y with CS4D2 Signals.png
(58.56 KiB) Downloaded 635 times

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

Re: Stop Loss Signals not working

Postby Henry MultiСharts » 31 Oct 2011

Please make sure the symbol settings are correct.
Go to Quote manager->Double click on the symbol you need->Settings tab:
PriceScale = 1/32 and j of 32nd
Min. Movement = 1
Big Point Value = 1000

You need to modify your script to generate the prices that can be met.
You can print the order prices generated by your script and compare them with the expected prices.

If you fail to do that - please come to our live chat Monday-Friday 6:30 am - 4 pm EST.
Or you can provide us the workspace you are using, exported studies with dependent functions, QMD symbol export, the screenshots with TS and MC comparison where you expect the order to be.


Return to “MultiCharts”