PDA

View Full Version : Initial stop coding error


GeeBee
1st May 2005, 03:42 AM
Hi everyone this my first post here.
I have just recently bought Tradesim Pro so am on a very steep learning curve.
Would somebody mind having a look at the attached code for a STTC system that I am having trouble coding,
I want to enter the trade on the open the day after the trigger and bid up to 1/2*ATR(10) above trigger day close,my initial stop is Entry price minus 2*ATR(10) and trailing stop is a close below the lowest low in the last five days.
When I put my triggers, gates, stops etc into a Metastock explorer and click OK it has a problem with the LongInitialStop function,I get a meassage that says "This is not a recognised name,constant or operator" ???

LongInitialStop := LongentryPrice-Ref(2.5*ATR(10),-1);

The entire code is as follows

{=== SET DATE VARIABLES ===}
DayStart := 1; MthStart := 1; YearStart := 2001;
DayStop := 31; MthStop := 3; YearStop := 2004;

{=== LONG TRADES ===}

LE := C+0.5*ATR(10);

LongEntryTrigger :=
{T} H>Ref(H,-1)AND
{1}Ref(H,-1)>Ref(H,-2)AND
{2}Ref(H,-2)>Ref(H,-3)AND
{3}Mov(C,120,S)>Ref(Mov(C,120,S),-40)+4*ATR(80) AND
{4}C>0.5 AND
{5}ATR(30)/ C >0.015 AND
{6}Mov(V,21,S)* Mov(C,21,S)>150000 AND
{7}V>1 AND
{8}C>O AND


Ref(L,1)<=LE;

{LongEntryPrice -Ref(0.5*ATR(10),-1);}

LongExitTrigger:=
ExtFml("TradeSim.TrailingStop",TRIGGER,LONG,Ref(LLV(L,5),-1),HIGH,CLOSE);

LongExitPrice := OPEN;

LongInitialStop := LongentryPrice-Ref(2.5*ATR(10),-1);

ExtFml( "TradeSim.Initialize");
ExtFml( "TradeSim.SetStartRecordDate",DayStart,MthStart,YearStart);
ExtFml( "TradeSim.SetStopRecordDate",DayStop,MthStop,YearStop);
ExtFml( "TradeSim.EnableDelayOfEntryByOneBar");
ExtFml( "TradeSim.EnableDelayOfAllExitsByOneBar");
ExtFml( "TradeSim.EnableProtectiveStop",0);
ExtFml( "TradeSim.UseClosingPriceAsStopThreshold");
ExtFml( "TradeSim.EnableTradePyramiding",Trigger, 0, 200);
ExtFml( "TradeSim.RecordTrades",
"STTC BullmK1",LONG,LongEntryTrigger,LongEntryPrice,LongInitialS top,LongExitTrigger,LongExitPrice,START); { Recorder Control }



Thanks for any advice.
GB

Jose
2nd May 2005, 02:59 AM
Try this:

&#123;=== SET DATE VARIABLES ===&#125;
DayStart&#58;=1;
MthStart&#58;=1;
YearStart&#58;=2001;
DayStop&#58;=31;
MthStop&#58;=3;
YearStop&#58;=2004;

&#123;=== LONG TRADES ===&#125;

LE&#58;=C+0.5*ATR&#40;10&#41;;

LongEntryTrigger&#58;=&#123;T&#125; H>Ref&#40;H,-1&#41;
AND &#123;1&#125; Ref&#40;H,-1&#41;>Ref&#40;H,-2&#41;
AND &#123;2&#125; Ref&#40;H,-2&#41;>Ref&#40;H,-3&#41;
AND &#123;3&#125; Mov&#40;C,120,S&#41;>Ref&#40;Mov&#40;C,120,S&#41;,-40&#41;+4*ATR&#40;80&#41;
AND &#123;4&#125; C>0.5
AND &#123;5&#125; ATR&#40;30&#41;/C>0.015
AND &#123;6&#125; Mov&#40;V*C,21,S&#41;>150000
&#123; 7 redundant &#125;
AND &#123;8&#125; C>O
AND &#123;9&#125; Ref&#40;L,1&#41;<=LE;

LongEntryPrice&#58;=Ref&#40;0.5*ATR&#40;10&#41;,-1&#41;; &#123; <- error found here &#125;

LongExitTrigger&#58;=
ExtFml&#40;"TradeSim.TrailingStop",TRIGGER,LONG,Ref&#40;LLV&#40;L,5&#41;,-1&#41;,H,C&#41;;

LongExitPrice&#58;=OPEN;

LongInitialStop&#58;=LongentryPrice-Ref&#40;2.5*ATR&#40;10&#41;,-1&#41;;

&#123; Recorder Control &#125;
ExtFml&#40;"TradeSim.Initialize"&#41;;
ExtFml&#40;"TradeSim.SetStartRecordDate",DayStart,MthStart,YearStart&#41;;
ExtFml&#40;"TradeSim.SetStopRecordDate",DayStop,MthStop,YearStop&#41;;
ExtFml&#40;"TradeSim.EnableDelayOfEntryByOneBar"&#41;;
ExtFml&#40;"TradeSim.EnableDelayOfAllExitsByOneBar"&#41;;
ExtFml&#40;"TradeSim.EnableProtectiveStop",0&#41;;
ExtFml&#40;"TradeSim.UseClosingPriceAsStopThreshold"&#41;;
ExtFml&#40;"TradeSim.EnableTradePyramiding",Trigger,0,200&#41;;
ExtFml&#40;"TradeSim.RecordTrades",
"STTC BullmK1",
LONG,
LongEntryTrigger,
LongEntryPrice,
LongInitialStop,
LongExitTrigger,
LongExitPrice,
START&#41;;



jose '-)

GeeBee
2nd May 2005, 07:43 AM
Thanks for your help Jose

I ran this code through Metastock Explorer opened the reports and in the Trades column every stock has N/A as though no trades where found???

GB :x

Jose
2nd May 2005, 10:23 AM
GB, there are logical errors in your LongExitTrigger trailing stop.
Try this:


LongExitTrigger&#58;=ExtFml&#40;"TradeSim.TrailingStop",
TRIGGER, &#123;mode&#58; band or trigger&#125;
LONG, &#123;long or short&#125;
C-Ref&#40;LLV&#40;L,5&#41;,-1&#41;, &#123;trailing stop buffer&#125; &#123; <-- error here &#125;
HIGH, &#123;RefPoint for stop calc&#125;
CLOSE&#41;; &#123;threshold - stop breached&#125;


And rather than pile entry condition upon entry condition and hope for the best, it's always a good idea to test every component of a TradeSim exploration, by plotting it as a visual MetaStock indicator first.
For example:


LE&#58;=C+0.5*ATR&#40;10&#41;;
LongEntryTrigger&#58;=
&#123;T&#125; sum&#40;H>Ref&#40;H,-1&#41;,3&#41;=3
AND &#123;1&#125; Mov&#40;C,120,S&#41;>Ref&#40;Mov&#40;C,120,S&#41;,-40&#41;+4*ATR&#40;80&#41;
AND &#123;2&#125; C>0.5
AND &#123;3&#125; ATR&#40;30&#41;/C>0.015
AND &#123;4&#125; Mov&#40;V*C,21,S&#41;>150000
AND &#123;5&#125; C>O
AND &#123;6&#125; Ref&#40;L,1&#41;<=LE;

LongExitTrigger&#58;=ExtFml&#40;"TradeSim.TrailingStop",
TRIGGER, &#123;mode&#58; band or trigger&#125;
LONG, &#123;long or short&#125;
C-Ref&#40;LLV&#40;L,5&#41;,-1&#41;, &#123;trailing stop buffer&#125;
HIGH, &#123;RefPoint for stop calc&#125;
CLOSE&#41;; &#123;threshold - stop breached&#125;

&#123; Plot trigger signals in own window &#125;
LongEntryTrigger-LongExitTrigger


The indicator above plots very few entry signals - perhaps take another look at each of the entry conditions. Try switching some of them off, and plot signals to see result.


jose '-)

GeeBee
4th May 2005, 12:43 PM
Sorry for the delayed response Ive been on nightshifts,thanks very much for your help Jose it has given me something to build on.

I havent had Tradesim for long and its taking a bit of getting use to.

GB
:?